Skip to content

Commit

Permalink
Reuse MainWindow actions 'save' and 'save as' to serialize GateLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Sep 4, 2024
1 parent f24cd3d commit f5d1fdc
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 277 deletions.
24 changes: 24 additions & 0 deletions plugins/gui/include/gui/file_status_manager/file_status_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace hal
class FileStatusManager : public QObject
{
Q_OBJECT
Q_SIGNALS:
void status_changed(bool gateLibrary, bool isDirty);

public:
/**
* The constructor.
Expand Down Expand Up @@ -92,6 +95,26 @@ namespace hal
*/
void netlistSaved();

/**
* Resets the netlist-modified flag that affects the modifiedFilesExisting() method.
*/
void netlistClosed();

/**
* Sets the gate-library-modified flag that can be queried by isGatelibModified() method.
*/
void gatelibChanged();

/**
* Unsets the gate-library-modified flag that can be queried by isGatelibModified() method.
*/
void gatelibSaved();

/**
* Query method whether GateLibraryManager has unsaved changes.
*/
bool isGatelibModified() const;

/**
* Removes all registered files and unsets every modified-flag, effectively resetting
* the state of the manager.
Expand All @@ -111,5 +134,6 @@ namespace hal
QMap<QUuid, QString> mModifiedFilesDescriptors;

bool mNetlistModified;
bool mGatelibModified;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <QAction>
#include <QFrame>
#include <QUuid>
#include <QTableView>
#include <QMessageBox>
#include <QFileDialog>
Expand All @@ -55,10 +54,6 @@ namespace hal
Q_PROPERTY(QString searchActiveIconStyle READ searchActiveIconStyle WRITE setSearchActiveIconStyle)
Q_PROPERTY(QString deleteIconPath READ deleteIconPath WRITE setDeleteIconPath);
Q_PROPERTY(QString deleteIconStyle READ deleteIconStyle WRITE setDeleteIconStyle);
Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath);
Q_PROPERTY(QString saveIconStyle READ saveIconStyle WRITE setSaveIconStyle);
Q_PROPERTY(QString saveAsIconPath READ saveAsIconPath WRITE setSaveAsIconPath);
Q_PROPERTY(QString saveAsIconStyle READ saveAsIconStyle WRITE setSaveAsIconStyle);

friend class GateLibraryManager;

Expand All @@ -83,10 +78,6 @@ namespace hal
QString mSearchActiveIconStyle;
QString mDeleteIconPath;
QString mDeleteIconStyle;
QString mSaveIconPath;
QString mSaveIconStyle;
QString mSaveAsIconPath;
QString mSaveAsIconStyle;

bool mReadOnly = false;

Expand All @@ -102,9 +93,11 @@ namespace hal
void handleDeleteAction();
void handleCurrentSelectionChanged(QModelIndex prevIndex);
void handleDoubleClicked(QModelIndex index);
void handleUnsavedChanges();

public Q_SLOTS:
void handleSaveAction();
void handleSaveAsAction();
void handleUnsavedChanges();

public:
GatelibraryContentWidget(GatelibraryTableModel* model, QWidget* parent = nullptr);
Expand All @@ -117,8 +110,6 @@ namespace hal

void toggleSelection(bool selected);

void setUuid(QUuid uid);

void setGateLibrary(GateLibrary* gl);

void setGateLibraryPath(std::filesystem::path p);
Expand All @@ -141,14 +132,6 @@ namespace hal

QString deleteIconStyle() const;

QString saveIconPath() const;

QString saveIconStyle() const;

QString saveAsIconPath() const;

QString saveAsIconStyle() const;

void setDisabledIconStyle(const QString& s);

void setEnabledIconStyle(const QString& s);
Expand All @@ -167,19 +150,8 @@ namespace hal

void setDeleteIconStyle(const QString& s);

void setSaveIconPath(const QString& s);

void setSaveIconStyle(const QString& s);

void setSaveAsIconPath(const QString& s);

void setSaveAsIconStyle(const QString& s);

private:
QUuid mUuid;
GateLibrary* mGateLibrary;
std::filesystem::path mPath;

bool mDirty;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace hal
bool initialize(GateLibrary* gateLibrary = nullptr, bool readOnly = false);
u32 getNextGateId();
void updateTabs(GateType* gateType);
QUuid getUuid();

public Q_SLOTS:
/**
Expand All @@ -89,6 +88,9 @@ namespace hal
*/
void handleCancelClicked();

void handleSaveAction();
void handleSaveAsAction();

Q_SIGNALS:
/**
* Q_SIGNAL that is emitted when either the Save or Cancel button is clicked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace hal
GateType* getRecentCreatedGate();
void accept() override;
int nextId() const override;
QUuid getUuid();
Q_SIGNALS:
void triggerUnsavedChanges();
private:
Expand All @@ -94,7 +93,5 @@ namespace hal
PinModel* mPinModel;
GateLibraryTabPin* mPinTab;
GateType* mNewGateType;

QUuid mUuid;
};
}
140 changes: 140 additions & 0 deletions plugins/gui/include/gui/main_window/file_actions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once
#include "gui/action/action.h"
#include <QString>


namespace hal {
class MainWindow;
class GateLibraryManager;
class SettingsItemKeybind;

class FileActions : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath)
Q_PROPERTY(QString saveAsIconPath READ saveAsIconPath WRITE setSaveAsIconPath)
Q_PROPERTY(QString enabledIconStyle READ enabledIconStyle WRITE setEnabledIconStyle)
Q_PROPERTY(QString disabledIconStyle READ disabledIconStyle WRITE setDisabledIconStyle)

MainWindow* mMainWindowReference;
GateLibraryManager* mGatelibReference;

Action* mActionSave;
Action* mActionSaveAs;
QString mSaveIconPath;
QString mSaveAsIconPath;

QString mEnabledIconStyle;
QString mDisabledIconStyle;
SettingsItemKeybind* mSettingSaveFile;

private Q_SLOTS:

/**
* Q_SLOT to save the current project as a .hal file.
* call to FileManager::emitSaveTriggered().
*/
void handleSaveTriggered();

/**
* Q_SLOT to save the current project as a new .hal file.
* Will query for new name.
* call to FileManager::emitSaveTriggered().
*/
void handleSaveAsTriggered();

public Q_SLOTS:
void handleFileStatusChanged(bool gateLibrary, bool isDirty);

public:
FileActions(QWidget* parent = nullptr);

/**
* Q_PROPERTY READ function for the 'Save File'-icon path.
*
* @returns the 'SaveFile'-icon path
*/
QString saveIconPath() const {return mSaveIconPath; }

/**
* Q_PROPERTY READ function for the 'SaveAs File'-icon path.
*
* @returns the 'SaveAsFile'-icon path
*/
QString saveAsIconPath() const { return mSaveAsIconPath; }

/**
* Q_PROPERTY READ function for the 'Enabled'-icon style.
*
* @returns the 'Enabled'-icon style
*/
QString enabledIconStyle() const { return mEnabledIconStyle; }

/**
* Q_PROPERTY READ function for the 'Disabled'-icon style.
*
* @returns the 'Disabled'-icon style
*/
QString disabledIconStyle() const { return mDisabledIconStyle; }

/**
* Q_PROPERTY WRITE function for the 'Save File'-icon path.
*
* @param path - The new path
*/
void setSaveIconPath(const QString& path) { mSaveIconPath = path; }

/**
* Q_PROPERTY WRITE function for the 'SaveAs File'-icon path.
*
* @param path - The new path
*/
void setSaveAsIconPath(const QString& path) { mSaveAsIconPath = path; }

/**
* Q_PROPERTY WRITE function for the 'Enabled'-icon style.
*
* @param style - The new style
*/
void setEnabledIconStyle(const QString& style) { mEnabledIconStyle = style; }

/**
* Q_PROPERTY WRITE function for the 'Disabled'-icon style.
*
* @param style - The new style
*/
void setDisabledIconStyle(const QString& style) { mDisabledIconStyle = style; }

Action* save() const { return mActionSave; }
Action* saveAs() const { return mActionSaveAs; }

void setup(GateLibraryManager* glcw = nullptr);

void repolish();
};
}
Loading

0 comments on commit f5d1fdc

Please sign in to comment.