Skip to content

Commit

Permalink
implemented save as and warning about unsaved changes
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Sep 1, 2024
1 parent 68fdd78 commit f24cd3d
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 45 deletions.
27 changes: 6 additions & 21 deletions plugins/gate_libraries/definitions/example_library.hgl
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,6 @@
"function": "(I0 & I1)"
}
]
},
{
"name": "test",
"direction": "input",
"type": "none",
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
{
"name": "test",
"direction": "input",
"type": "none"
}
]
}
]
},
Expand Down Expand Up @@ -518,7 +503,7 @@
"name": "I0",
"direction": "input",
"type": "none",
"ascending": false,
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
Expand All @@ -533,7 +518,7 @@
"name": "I1",
"direction": "input",
"type": "none",
"ascending": false,
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
Expand All @@ -548,7 +533,7 @@
"name": "I2",
"direction": "input",
"type": "none",
"ascending": false,
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
Expand All @@ -563,7 +548,7 @@
"name": "I3",
"direction": "input",
"type": "none",
"ascending": false,
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
Expand All @@ -578,7 +563,7 @@
"name": "I4",
"direction": "input",
"type": "none",
"ascending": false,
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
Expand All @@ -593,7 +578,7 @@
"name": "O",
"direction": "output",
"type": "none",
"ascending": false,
"ascending": true,
"start_index": 0,
"ordered": false,
"pins": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <QFrame>
#include <QUuid>
#include <QTableView>
#include <QMessageBox>
#include <QFileDialog>
#include "gui/pin_model/pin_proxy_model.h"
#include "hgl_writer/include/hgl_writer/hgl_writer.h"

Expand Down Expand Up @@ -102,6 +104,7 @@ namespace hal
void handleDoubleClicked(QModelIndex index);
void handleSaveAction();
void handleSaveAsAction();
void handleUnsavedChanges();

public:
GatelibraryContentWidget(GatelibraryTableModel* model, QWidget* parent = nullptr);
Expand Down Expand Up @@ -176,5 +179,7 @@ namespace hal
QUuid mUuid;
GateLibrary* mGateLibrary;
std::filesystem::path mPath;

bool mDirty;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace hal
{
class GateLibraryWizard : public QWizard
{
Q_OBJECT

friend class RAMPortWizardPage;
friend class PinsWizardPage;
friend class FlipFlopWizardPage;
Expand All @@ -67,13 +69,14 @@ namespace hal

GateLibraryWizard(GateLibrary* gateLibrary, GateType* gateType = nullptr, QWidget* parent = nullptr);

// void setData(GateLibrary* gateLibrary, GateType* gateType);
QList<PinItem*> getPingroups();
std::unique_ptr<GateTypeComponent> setComponents();
GateType* getRecentCreatedGate();
void accept() override;
int nextId() const override;
QUuid getUuid();
Q_SIGNALS:
void triggerUnsavedChanges();
private:
GateLibrary* mGateLibrary;
GateType* mGateType;
Expand Down
4 changes: 2 additions & 2 deletions plugins/gui/resources/stylesheet/light.qss
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,10 @@ hal--GatelibraryContentWidget
qproperty-searchActiveIconStyle: "all->#30ac4f";
qproperty-deleteIconStyle: "all->#FFFFFF";
qproperty-deleteIconPath: ":/icons/trashcan";
qproperty-saveIconStyle: "all->#3192C5";
qproperty-saveIconPath: ":/icons/folder-down";
qproperty-saveAsIconStyle: "all->#FFFFFF";
qproperty-saveIconStyle: "all->#FFFFFF";
qproperty-saveAsIconPath: ":/icons/save-as";
qproperty-saveAsIconStyle: "all->#FFFFFF";
}

hal--ImportNetlistDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ namespace hal
connect(mSearchAction, &QAction::triggered, this, &GatelibraryContentWidget::toggleSearchbar);
connect(mEditAction, &QAction::triggered, this, &GatelibraryContentWidget::handleEditAction);
connect(mDeleteAction, &QAction::triggered, this, &GatelibraryContentWidget::handleDeleteAction);

connect(mDeleteAction, &QAction::triggered, this, &GatelibraryContentWidget::handleUnsavedChanges);

connect(mSaveAction, &QAction::triggered, this, &GatelibraryContentWidget::handleSaveAction);
connect(mSaveAsAction, &QAction::triggered, this, &GatelibraryContentWidget::handleSaveAsAction);
connect(mSearchbar, &Searchbar::triggerNewSearch, mPinProxyModel, &SearchProxyModel::startSearch);
Expand All @@ -68,7 +71,7 @@ namespace hal

mToolbar->addAction(mSaveAction);
mToolbar->addAction(mSaveAsAction);

mDirty = false;

layout->addWidget(mToolbar);
layout->addWidget(mTableView);
Expand Down Expand Up @@ -121,7 +124,6 @@ namespace hal
QModelIndex inx = mPinProxyModel->mapToSource(mTableView->currentIndex());
if (inx.isValid())
Q_EMIT triggerDeleteType(inx);

}

void GatelibraryContentWidget::handleCurrentSelectionChanged(QModelIndex prevIndex){
Expand All @@ -139,19 +141,52 @@ namespace hal

void GatelibraryContentWidget::handleSaveAction()
{
//TODO
QMessageBox msg;
msg.setWindowTitle("Save");
msg.setText("Gate library saved successfully");

gFileStatusManager->fileSaved(mUuid);
HGLWriter* writer = new HGLWriter();
writer->write(mGateLibrary, mPath);
if(writer->write(mGateLibrary, mPath))
msg.exec();

mDirty = false;
mSaveAction->setEnabled(mDirty);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath));

mSaveAsAction->setEnabled(mDirty);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath));

}

void GatelibraryContentWidget::handleSaveAsAction()
{
//TODO
QString path = QDir::currentPath();
QFile gldpath(":/path/gate_library_definitions");
if (gldpath.open(QIODevice::ReadOnly))
path = QString::fromUtf8(gldpath.readAll());

QString filename = QFileDialog::getSaveFileName(this, "Save as", path, "HGL *.hgl");
gFileStatusManager->fileSaved(mUuid);
HGLWriter* writer = new HGLWriter();
writer->write(mGateLibrary, mPath);
writer->write(mGateLibrary, std::filesystem::path(filename.toStdString()));

mDirty = false;
mSaveAction->setEnabled(mDirty);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath));

mSaveAsAction->setEnabled(mDirty);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath));
}

void GatelibraryContentWidget::handleUnsavedChanges()
{
mDirty = true;
mSaveAction->setEnabled(mDirty);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle,mSaveIconPath));

mSaveAsAction->setEnabled(mDirty);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle,mSaveAsIconPath));
}

void GatelibraryContentWidget::toggleSearchbar()
Expand Down Expand Up @@ -182,8 +217,6 @@ namespace hal
toggleReadOnlyMode(readOnly);

mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle,mSearchIconPath));
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath));
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath));

}

Expand All @@ -198,11 +231,20 @@ namespace hal
mAddAction->setEnabled(!readOnly);
mAddAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mAddTypeIconPath));

mSaveAction->setEnabled(!readOnly);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveIconPath));

mSaveAsAction->setEnabled(!readOnly);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveAsIconPath));
if (mDirty)
{
mSaveAction->setEnabled(!readOnly);
mSaveAsAction->setEnabled(!readOnly);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveIconPath));
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveAsIconPath));
}
else
{
mSaveAction->setEnabled(mDirty);
mSaveAsAction->setEnabled(mDirty);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath));
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath));
}
}

void GatelibraryContentWidget::toggleSelection(bool selected)
Expand All @@ -212,11 +254,6 @@ namespace hal
mEditAction->setEnabled(selected);
mEditAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle,mEditTypeIconPath));

mSaveAction->setEnabled(selected);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle,mSaveIconPath));
mSaveAsAction->setEnabled(selected);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle,mSaveAsIconPath));

}

QString GatelibraryContentWidget::disabledIconStyle() const
Expand Down
30 changes: 29 additions & 1 deletion plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ namespace hal
if(mReadOnly)
return;
mWizard = new GateLibraryWizard(mEditableGatelibrary, mTableModel->getGateTypeAtIndex(index.row()));
connect(mWizard, &GateLibraryWizard::triggerUnsavedChanges, mContentWidget, &GatelibraryContentWidget::handleUnsavedChanges);

mWizard->exec();
initialize(mEditableGatelibrary);

Expand All @@ -184,6 +186,8 @@ namespace hal
void GateLibraryManager::handleAddWizard()
{
mWizard = new GateLibraryWizard(mEditableGatelibrary);
connect(mWizard, &GateLibraryWizard::triggerUnsavedChanges, mContentWidget, &GatelibraryContentWidget::handleUnsavedChanges);

mWizard->exec();

initialize(mEditableGatelibrary);
Expand Down Expand Up @@ -241,7 +245,31 @@ namespace hal

void GateLibraryManager::handleCancelClicked()
{
Q_EMIT close();
if(!mContentWidget->mDirty)
Q_EMIT close();
else
{
QMessageBox* msgBox = new QMessageBox(this);
msgBox->setWindowTitle("Unsaved changes");
msgBox->setInformativeText("The current gate library has been modified. Do you want to save your changes or discard them?");
msgBox->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);

int r = msgBox->exec();
switch(r)
{
case QMessageBox::Save:
mContentWidget->handleSaveAsAction();
Q_EMIT close();
break;
case QMessageBox::Discard:
Q_EMIT close();
break;
case QMessageBox::Cancel:
msgBox->reject();
break;
}

}
}

GateType* GateLibraryManager::getSelectedGate()
Expand Down
4 changes: 2 additions & 2 deletions plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace hal
statePage->setData(mGateType);
boolPage->setData(mGateType);
}

}

void GateLibraryWizard::accept()
Expand Down Expand Up @@ -124,6 +125,7 @@ namespace hal

mUuid = QUuid::createUuid();
gFileStatusManager->fileChanged(mUuid, QString("GateLibrary %1 modified").arg(QString::fromStdString(mGateLibrary->get_name())));
Q_EMIT triggerUnsavedChanges();
}

QUuid GateLibraryWizard::getUuid(){
Expand Down Expand Up @@ -263,8 +265,6 @@ namespace hal
return Pin;
case Pin:
if(properties.contains(GateTypeProperty::ff) || properties.contains(GateTypeProperty::latch)) return State;
/*if(properties.contains(GateTypeProperty::ff)) return FlipFlop;
else if(properties.contains(GateTypeProperty::latch)) return Latch;*/
else if(properties.contains(GateTypeProperty::c_lut)) return LUT;
else if(properties.contains(GateTypeProperty::ram)) return RAM;
return BoolFunc;
Expand Down

0 comments on commit f24cd3d

Please sign in to comment.