Skip to content

Commit

Permalink
Use const strings for the state of the boolean function editor
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Jun 8, 2024
1 parent 6d00d6c commit a4057c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ namespace hal {
QString mState;
std::set<std::string> mLegalVariables;

const char* EMPTY = "Empty";
const char* VALID = "Valid";
const char* INVALID = "Invalid";
Q_SIGNALS:
void stateChanged(QString s);
private Q_SLOTS:
Expand All @@ -63,6 +66,8 @@ namespace hal {
BooleanFunctionEdit(std::set<std::string>& legalVar, QWidget* parent = nullptr);
QString state() const { return mState; }
void setState(const QString& s);
bool isValid() const { return mState == VALID; }
void setFunctionText(const QString& txt);
};

class BoolWizardPage:public QWizardPage
Expand Down
3 changes: 2 additions & 1 deletion plugins/gui/resources/stylesheet/dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,8 @@ hal--BooleanFunctionEdit[state="Empty"]

hal--BooleanFunctionEdit[state="Invalid"]
{
background: red;
background: #802010;
color : #F0E0C0;
}

hal--GuiPluginManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace hal
{
BooleanFunctionEdit::BooleanFunctionEdit(std::set<std::string> &legalVar, QWidget *parent)
: QLineEdit(parent), mState("Valid"), mLegalVariables(legalVar)
: QLineEdit(parent), mState(VALID), mLegalVariables(legalVar)
{
connect(this, &QLineEdit::editingFinished, this, &BooleanFunctionEdit::handleEditingFinished);
setState("Empty");
setState(EMPTY); // do an active transition to enforce style
}

void BooleanFunctionEdit::setState(const QString &s)
Expand All @@ -26,15 +26,15 @@ namespace hal
{
if (text().isEmpty())
{
setState("Empty");
setState(EMPTY);
return;
}

QString nextState = "Valid"; // think positive
QString nextState = VALID; // think positive

auto bfres = BooleanFunction::from_string(text().toStdString());
if(bfres.is_error())
nextState = "Invalid";
nextState = INVALID;
else
{
BooleanFunction bf = bfres.get();
Expand All @@ -44,7 +44,7 @@ namespace hal
{
if (mLegalVariables.find(vname) == mLegalVariables.end())
{
nextState = "Invalid";
nextState = INVALID;
break;
}
}
Expand All @@ -53,6 +53,11 @@ namespace hal
setState(nextState);
}

void BooleanFunctionEdit::setFunctionText(const QString &txt)
{
setText(txt);
handleEditingFinished();
}
//--------------------------------------------
BoolWizardPage::BoolWizardPage(QWidget* parent) : QWizardPage(parent)
{
Expand Down Expand Up @@ -80,7 +85,7 @@ namespace hal
BooleanFunctionEdit* lineEdit = new BooleanFunctionEdit(input_pins, this);
mLayout->addWidget(label, boolFuncCnt, 0);
mLayout->addWidget(lineEdit, boolFuncCnt, 1);
lineEdit->setText(QString::fromStdString(bf.second.to_string()));
lineEdit->setFunctionText(QString::fromStdString(bf.second.to_string()));
boolFuncCnt++;
}
}
Expand Down

0 comments on commit a4057c0

Please sign in to comment.