Skip to content

Commit

Permalink
Manage BooleanFunctionEdit fields without memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Jun 16, 2024
1 parent ae8cb3d commit 77c37cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ namespace hal {

class BoolWizardPage:public QWizardPage
{
friend BooleanFunctionEdit;
Q_OBJECT
public:
BoolWizardPage(QWidget* parent = nullptr);
void initializePage() override;
bool isComplete() const override;
void setData(GateType* gate);
private Q_SLOTS:
void handleStateChanged(const QString& stat);

private:
QGridLayout* mLayout;
GateLibraryWizard* mWizard;
QList<BooleanFunctionEdit*> mEditFunctions;
GateType* mGate = nullptr;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace hal
setState(nextState);
}
//--------------------------------------------
BoolWizardPage::BoolWizardPage(QWidget* parent) : QWizardPage(parent)
BoolWizardPage::BoolWizardPage(QWidget* parent)
: QWizardPage(parent)
{
setTitle("Boolean functions");
setSubTitle("Enter the boolean functions");
Expand All @@ -74,6 +75,13 @@ namespace hal
for (PinItem* pi : inputPins)
input_pins.insert(pi->getName().toStdString());

if (mEditFunctions.isEmpty())
{
for (BooleanFunctionEdit* bfe : mEditFunctions)
delete bfe;
mEditFunctions.clear();
}

if(mGate != nullptr){
auto boolFunctions = mGate->get_boolean_functions();
auto list = QList<QPair<QString, BooleanFunction>>();
Expand All @@ -85,6 +93,8 @@ namespace hal
mLayout->addWidget(label, boolFuncCnt, 0);
mLayout->addWidget(lineEdit, boolFuncCnt, 1);
lineEdit->setText(QString::fromStdString(bf.second.to_string()));
connect(lineEdit,&BooleanFunctionEdit::stateChanged,this,&BoolWizardPage::handleStateChanged);
mEditFunctions.append(lineEdit);
boolFuncCnt++;
}
}
Expand All @@ -103,6 +113,8 @@ namespace hal
BooleanFunctionEdit* lineEdit = new BooleanFunctionEdit(input_pins, this);
mLayout->addWidget(label, rowCount, 0);
mLayout->addWidget(lineEdit, rowCount, 1);
connect(lineEdit,&BooleanFunctionEdit::stateChanged,this,&BoolWizardPage::handleStateChanged);
mEditFunctions.append(lineEdit);
rowCount++;
}
}
Expand All @@ -114,22 +126,26 @@ namespace hal
setLayout(mLayout);
}

void BoolWizardPage::setData(GateType *gate){
void BoolWizardPage::setData(GateType *gate)
{
mGate = gate;
}

bool BoolWizardPage::isComplete() const{
void BoolWizardPage::handleStateChanged(const QString& stat)
{
Q_UNUSED(stat);
Q_EMIT completeChanged();
}

for(int i = 0; i<mLayout->rowCount(); i++)
bool BoolWizardPage::isComplete() const
{
for(BooleanFunctionEdit* lineEdit : mEditFunctions)
{
BooleanFunctionEdit* lineEdit = static_cast<BooleanFunctionEdit*>(mLayout->itemAtPosition(i, 1)->widget());
connect(lineEdit, &BooleanFunctionEdit::editingFinished, this, &BoolWizardPage::completeChanged);
if(!lineEdit->isValid())
{
return false;
}
}
return true;
}

}

0 comments on commit 77c37cf

Please sign in to comment.