From f7dd78cc20efa07917f2e0f2af2267418393984a Mon Sep 17 00:00:00 2001 From: tarapn79 Date: Wed, 5 Jun 2024 09:09:45 +0200 Subject: [PATCH] Implemented validation for Boolean Function WizardPage --- .../gatelibrary_pages/bool_wizardpage.h | 1 + .../generalinfo_wizardpage.h | 1 - .../gatelibrary_manager.cpp | 2 ++ .../gatelibrary_pages/bool_wizardpage.cpp | 20 +++++++++++++++++++ .../generalinfo_wizardpage.cpp | 7 ------- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/bool_wizardpage.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/bool_wizardpage.h index c62e636ee63..86df50bd549 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/bool_wizardpage.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/bool_wizardpage.h @@ -41,6 +41,7 @@ namespace hal { public: BoolWizardPage(QWidget* parent = nullptr); void initializePage() override; + bool validatePage() override; void setData(GateType* gate); private: diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h index 61a44d73a4c..38fe0d4b916 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h @@ -46,7 +46,6 @@ namespace hal { QStringList getProperties(); void setMode(bool edit); bool validatePage() override; - //int nextId() const override; public Q_SLOTS: void addProperty(); void deleteProperty(); diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp index ea1fef5b0f3..9656c602aa3 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp @@ -168,12 +168,14 @@ namespace hal return; GateLibraryWizard wiz(mEditableGatelibrary, mTableModel->getGateTypeAtIndex(index.row())); wiz.exec(); + wiz.accept(); } void GateLibraryManager::handleAddWizard() { GateLibraryWizard wiz(mEditableGatelibrary); wiz.exec(); + wiz.accept(); } void GateLibraryManager::handleDeleteType(QModelIndex index) diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/bool_wizardpage.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/bool_wizardpage.cpp index 785b8aeeb84..bd4e5b796be 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/bool_wizardpage.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/bool_wizardpage.cpp @@ -59,4 +59,24 @@ namespace hal void BoolWizardPage::setData(GateType *gate){ mGate = gate; } + + bool BoolWizardPage::validatePage(){ + + int rowCount = 0; + QList inputPins = mWizard->mPinModel->getInputPins(); + QList outputPins = mWizard->mPinModel->getOutputPins(); + while(mLayout->itemAtPosition(rowCount, 1) != nullptr){ + QLabel* label = static_cast(mLayout->itemAtPosition(rowCount, 1)->widget()); + auto bfres = BooleanFunction::from_string(label->text().toStdString()); + if(bfres.is_error()) return false; + BooleanFunction bf = bfres.get(); + std::set names = bf.get_variable_names(); + for(auto item : inputPins) + { + if(names.find(item->getName().toStdString()) == names.end()) return false; + } + rowCount++; + } + return true; + } } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp index 779a1597fd1..18b9a86e117 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp @@ -120,11 +120,4 @@ namespace hal } return true; } -// int GeneralInfoWizardPage::nextId() const -// { -// auto parentWizard = wizard(); -// if(!parentWizard) -// return -1; -// return static_cast(parentWizard)->getNextPageId(GateLibraryWizard::GeneralInfo); -// } }