diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h index be9fab075bf..ae0556a8e02 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h @@ -120,8 +120,7 @@ namespace hal GateLibraryTabTruthTable* mBooleanFunctionTab; GateLibraryTabPin* mPinTab; - const GateLibrary* mNonEditableGateLibrary; - GateLibrary* mEditableGatelibrary; + GateLibrary* mGateLibrary; std::unique_ptr mDemoNetlist; std::filesystem::path mPath; diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ram_port.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ram_port.cpp index f4f0a0717bf..d5f3359df12 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ram_port.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ram_port.cpp @@ -15,9 +15,9 @@ namespace hal void GateLibraryFrameRAMPort::update(GateType* gt) { QLayoutItem* item; - if (!mLayout->isEmpty()) + while (!mLayout->isEmpty()) { - while ((item = mLayout->takeAt(0)) != nullptr) { + if ((item = mLayout->takeAt(0)) != nullptr) { delete item->widget(); delete item; } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp index 8344b1802b5..1d0b4a3b0cb 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp @@ -29,9 +29,8 @@ namespace hal { GateLibraryManager::GateLibraryManager(MainWindow *parent) - : QFrame(parent), mFrameWidth(0), mLayout(new QGridLayout()), mNonEditableGateLibrary(nullptr), mEditableGatelibrary(nullptr) + : QFrame(parent), mFrameWidth(0), mLayout(new QGridLayout()), mGateLibrary(nullptr) { - //TODO: GateLibrarymanager will stay in readOnly mode even if closing project and opening a new gateLibrary mSplitter = new QSplitter(this); QWidget* rightWindow = new QWidget(mSplitter); QGridLayout* rlay = new QGridLayout(rightWindow); @@ -111,11 +110,9 @@ namespace hal if(!gateLibrary) { if(gNetlist && gNetlist->get_gate_library()){ - //TODO find better way to handle const/not const gateLibrary - mNonEditableGateLibrary = gNetlist->get_gate_library(); - mDemoNetlist = netlist_factory::create_netlist(mNonEditableGateLibrary); + // readonly flag makes sure mGateLibrary does not get modified, const attribute not needed + mGateLibrary = const_cast(gNetlist->get_gate_library()); mReadOnly = true; - } else { @@ -136,8 +133,7 @@ namespace hal auto gateLibrary = gate_library_manager::load(std::filesystem::path(fileName.toStdString())); - mEditableGatelibrary = gateLibrary; - mDemoNetlist = netlist_factory::create_netlist(mEditableGatelibrary); + mGateLibrary = gateLibrary; mReadOnly = false; QDir dir(QDir::home()); @@ -149,20 +145,13 @@ namespace hal else { mReadOnly = readOnly; - if(mReadOnly) - { - mDemoNetlist = netlist_factory::create_netlist(mNonEditableGateLibrary); - mNonEditableGateLibrary = gateLibrary; - } - else - { - mDemoNetlist = netlist_factory::create_netlist(mEditableGatelibrary); - mEditableGatelibrary = gateLibrary; - } + mGateLibrary = gateLibrary; } + + mDemoNetlist = netlist_factory::create_netlist(mGateLibrary); mGraphicsView->showGate(nullptr); updateTabs(nullptr); - mTableModel->loadFile(mReadOnly ? mNonEditableGateLibrary : mEditableGatelibrary); + mTableModel->loadFile(mGateLibrary); mContentWidget->activate(mReadOnly); mContentWidget->toggleSelection(false); @@ -173,39 +162,38 @@ namespace hal { if(mReadOnly) return; - mWizard = new GateLibraryWizard(mEditableGatelibrary, mTableModel->getGateTypeAtIndex(index.row())); + mWizard = new GateLibraryWizard(mGateLibrary, mTableModel->getGateTypeAtIndex(index.row())); connect(mWizard, &GateLibraryWizard::triggerUnsavedChanges, mContentWidget, &GatelibraryContentWidget::handleUnsavedChanges); mWizard->exec(); - initialize(mEditableGatelibrary); + initialize(mGateLibrary); mContentWidget->mTableView->selectRow(index.row()); - mContentWidget->setGateLibrary(mEditableGatelibrary); + mContentWidget->setGateLibrary(mGateLibrary); mContentWidget->setGateLibraryPath(mPath); } void GateLibraryManager::handleAddWizard() { - mWizard = new GateLibraryWizard(mEditableGatelibrary); + mWizard = new GateLibraryWizard(mGateLibrary); connect(mWizard, &GateLibraryWizard::triggerUnsavedChanges, mContentWidget, &GatelibraryContentWidget::handleUnsavedChanges); mWizard->exec(); - - initialize(mEditableGatelibrary); + initialize(mGateLibrary); for (int r=0; rrowCount(); r++) { if(mTableModel->getGateTypeAtIndex(r) == mWizard->getRecentCreatedGate()) mContentWidget->mTableView->selectRow(r); } - mContentWidget->setGateLibrary(mEditableGatelibrary); + mContentWidget->setGateLibrary(mGateLibrary); mContentWidget->setGateLibraryPath(mPath); } void GateLibraryManager::handleDeleteType(QModelIndex index) { GateType* gate = mTableModel->getGateTypeAtIndex(index.row()); - mEditableGatelibrary->remove_gate_type(gate->get_name()); - initialize(mEditableGatelibrary); + mGateLibrary->remove_gate_type(gate->get_name()); + initialize(mGateLibrary); gFileStatusManager->gatelibChanged(); //qInfo() << "handleDeleteType " << QString::fromStdString(gate->get_name()) << ":" << gate->get_id(); } @@ -214,7 +202,7 @@ namespace hal { QSet* occupiedIds = new QSet; u32 freeId = 1; - for (auto gt : mEditableGatelibrary->get_gate_types()) { + for (auto gt : mGateLibrary->get_gate_types()) { occupiedIds->insert(gt.second->get_id()); } while(occupiedIds->contains(freeId)) @@ -292,7 +280,7 @@ namespace hal Q_EMIT close(); break; case QMessageBox::Discard: - gate_library_manager::remove(std::filesystem::path(mEditableGatelibrary->get_path())); + gate_library_manager::remove(std::filesystem::path(mGateLibrary->get_path())); mDemoNetlist.reset(); //delete unique pointer gFileStatusManager->gatelibSaved(); window()->setWindowTitle("HAL"); diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp index 89abfae3676..2db6e9be5a7 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp @@ -70,9 +70,9 @@ namespace hal { // Clear existing labels QLayoutItem* item; - if (!mLayout->isEmpty()) + while (!mLayout->isEmpty()) { - while ((item = mLayout->takeAt(0)) != nullptr) { + if ((item = mLayout->takeAt(0)) != nullptr) { delete item->widget(); delete item; }