Skip to content

Commit

Permalink
Added GeneralTab to gatelibrary_manager's tab widget
Browse files Browse the repository at this point in the history
Added close button to gatelibrary_manager to get back to previous screen
Added docstrings
  • Loading branch information
HerrKermet committed Dec 1, 2023
1 parent 18ba4b0 commit 39e51e6
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

#pragma once

#include "hal_core/netlist/gate_library/gate_library.h"
#include "gui/gatelibrary_management/gatelibrary_wizard.h"
#include "gatelibrary_table_model.h"
#include "gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h"

#include "gatelibrary_table_model.h"
#include "gui/gatelibrary_management/gatelibrary_wizard.h"
#include "hal_core/netlist/gate_library/gate_library.h"

#include <QFrame>
#include <QGridLayout>
#include <QTableView>
#include <QPushButton>
#include <QTabWidget>
#include <QTableView>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h>

namespace hal
{
Expand All @@ -61,20 +61,43 @@ namespace hal
bool initialize(GateLibrary* gateLibrary = nullptr);

public Q_SLOTS:
/**
* Opens the Wizard to edit or add a new gate
*/
void handleCallWizard();

/**
* Updates widgets based on the selected item from the TableView
* @param index
*/
void handleSelectionChanged(const QModelIndex& index);

/**
* Emits close() and closes the widget.
*/
void handleCancelClicked();

Q_SIGNALS:
/**
* Q_SIGNAL that is emitted when either the Save or Cancel button is clicked.
*/
void close();


private:

QTabWidget* mTabWidget;
QGridLayout* mLayout;
QPushButton* mEditBtn;
QPushButton* mAddBtn;
QTableView* mTableView;
GatelibraryTableModel* mTableModel;

QPushButton* mEditBtn;
QPushButton* mAddBtn;
QPushButton* mCancelBtn;


GateLibraryTabFlipFlop* mFlipFlopTab;
GateLibraryTabGeneral* mGeneralTab;

const GateLibrary* mGateLibrary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

namespace hal
{
/**
* Widget which shows information about the flip flop properties of a given gate
*/
class GateLibraryTabFlipFlop : public QWidget, public GateLibraryTabInterface
{
Q_OBJECT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 "gatelibrary_tab_interface.h"
#include "hal_core/defines.h"
#include "hal_core/netlist/gate_library/gate_type.h"

#include <QGridLayout>
#include <QLabel>

namespace hal
{
/**
* Widget which shows general information of a given gate
*/
class GateLibraryTabGeneral : public QWidget, public GateLibraryTabInterface
{
Q_OBJECT

public:
GateLibraryTabGeneral(QWidget* parent = nullptr);


void update(GateType* gate) override;


private:

QGridLayout* mGridLayout;

QLabel* mNameLabel;
QLabel* mIdLabel;
QLabel* mComponentLabel;
QLabel* mBooleanFunctionLabel;
QLabel* mPinLabel;

QLabel* mNamePropertyLabel;
QLabel* mIdPropertyLabel;
QLabel* mComponentPropertyLabel;
QLabel* mBooleanFunctionPropertyLabel;
QLabel* mPinPropertyLabel;

};

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
namespace hal
{


/**
* Interface class to provide methods for the GateLibrary's TabWidgets
*/
class GateLibraryTabInterface
{

public:

/**
* Updates the Widget based on the properties of the given gate or resets it if gate is null
* @param gate
*/
virtual void update(GateType* gate) = 0;
};

Expand Down
5 changes: 5 additions & 0 deletions plugins/gui/include/gui/main_window/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ namespace hal
*/
void closeSettings();

/**
* Q_SLOT to close the Gatelibrary menu.
*/
void closeGateLibraryManager();

/**
* Q_SLOT to open (toggle to the) PluginManager menu.
*/
Expand Down
14 changes: 12 additions & 2 deletions plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace hal
mTableView->setSelectionMode(QAbstractItemView::SingleSelection);

//pages for the tab widget
auto* generalPage = new QWidget(this);
mGeneralTab = new GateLibraryTabGeneral(this);
auto* pinPage = new QWidget(this);
mFlipFlopTab = new GateLibraryTabFlipFlop(this);
auto* booleanFunctionPage = new QWidget(this);
Expand All @@ -41,11 +41,12 @@ namespace hal
//buttons
mEditBtn = new QPushButton("Edit", this);
mAddBtn = new QPushButton("Add", this);
mCancelBtn = new QPushButton("Cancel", this);


//adding pages to the tab widget
mTabWidget = new QTabWidget(this);
mTabWidget->addTab(generalPage, "General");
mTabWidget->addTab(mGeneralTab, "General");
mTabWidget->addTab(pinPage, "Pins");
mTabWidget->addTab(mFlipFlopTab, "Flip Flops");
mTabWidget->addTab(booleanFunctionPage, "Boolean Functions");
Expand All @@ -56,11 +57,13 @@ namespace hal
mLayout->addWidget(mEditBtn,1,0);
mLayout->addWidget(mAddBtn,1,1);
mLayout->addWidget(mTabWidget,0,2);
mLayout->addWidget(mCancelBtn, 1, 2);


//signal - slots
connect(mAddBtn, &QPushButton::clicked, this, &GateLibraryManager::handleCallWizard);
connect(mTableView, &QTableView::clicked, this, &GateLibraryManager::handleSelectionChanged);
connect(mCancelBtn, &QPushButton::clicked, this, &GateLibraryManager::handleCancelClicked);

setLayout(mLayout);
repolish(); // CALL FROM PARENT
Expand Down Expand Up @@ -122,6 +125,7 @@ namespace hal
GateLibraryWizard wiz;
wiz.exec();
}

void GateLibraryManager::handleSelectionChanged(const QModelIndex& index)
{
GateType* gate;
Expand All @@ -131,6 +135,12 @@ namespace hal

//update tabs
mFlipFlopTab->update(gate);
mGeneralTab->update(gate);
}

void GateLibraryManager::handleCancelClicked()
{
Q_EMIT close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

#include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h"

#include "gui/gui_globals.h"
#include "hal_core/netlist/gate_library/gate_type_component/ff_component.h"

namespace hal
{

GateLibraryTabGeneral::GateLibraryTabGeneral(QWidget* parent) : QWidget(parent)
{
mGridLayout = new QGridLayout(parent);

mNameLabel = new QLabel("Name", parent);
mIdLabel = new QLabel("ID", parent);
mComponentLabel = new QLabel("Component", parent);
mBooleanFunctionLabel = new QLabel("Boolean function", parent);
mPinLabel = new QLabel("Pins", parent);

mNamePropertyLabel = new QLabel(" - ", parent);
mIdPropertyLabel = new QLabel(" - ", parent);
mComponentPropertyLabel = new QLabel(" - ", parent);
mBooleanFunctionPropertyLabel = new QLabel(" - ", parent);
mPinPropertyLabel = new QLabel(" - ", parent);

mGridLayout->addWidget(mIdLabel, 0, 0);
mGridLayout->addWidget(mIdPropertyLabel, 0, 1, Qt::AlignLeft);
mGridLayout->addWidget(mNameLabel, 1, 0);
mGridLayout->addWidget(mNamePropertyLabel, 1, 1, Qt::AlignLeft);
mGridLayout->addWidget(mComponentLabel, 2, 0);
mGridLayout->addWidget(mComponentPropertyLabel, 2, 1, Qt::AlignLeft);
mGridLayout->addWidget(mBooleanFunctionLabel, 3, 0);
mGridLayout->addWidget(mBooleanFunctionPropertyLabel, 3, 1, Qt::AlignLeft);
mGridLayout->addWidget(mPinLabel, 4, 0);
mGridLayout->addWidget(mPinPropertyLabel, 4, 1, Qt::AlignLeft);

setLayout(mGridLayout);

}

void GateLibraryTabGeneral::update(GateType* gate)
{

if(!gate){
//TODO make default look
mNamePropertyLabel->setText("-");
mIdPropertyLabel->setText("-");
mComponentPropertyLabel->setText("-");
mBooleanFunctionPropertyLabel->setText("-");
mPinPropertyLabel->setText("-");

return;
}

mNamePropertyLabel->setText(QString::fromStdString(gate->get_name()));
mIdPropertyLabel->setText(QString::number(gate->get_id()));
//TODO add component
mComponentPropertyLabel->setText("TODO");
mBooleanFunctionPropertyLabel->setText(QString::fromStdString(gate->get_boolean_function().to_string()));

QString in = " ";
QString out = " ";

for(auto const& pin : gate->get_input_pin_names()){
in += QString::fromStdString(pin) + "\n ";
}

for(auto const& pin : gate->get_output_pin_names()){
out += QString::fromStdString(pin) + "\n ";
}

mPinPropertyLabel->setText("In:\n" + in + "\nOut:\n" + out);





}


}
20 changes: 10 additions & 10 deletions plugins/gui/src/main_window/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ namespace hal
connect(mActionSettings, &Action::triggered, this, &MainWindow::openSettings);
connect(mActionPlugins, &Action::triggered, this, &MainWindow::openPluginManager);
connect(mSettings, &MainSettingsWidget::close, this, &MainWindow::closeSettings);
connect(mGateLibraryManager, &GateLibraryManager::close, this, &MainWindow::closeGateLibraryManager);
connect(mActionSave, &Action::triggered, this, &MainWindow::handleSaveTriggered);
connect(mActionSaveAs, &Action::triggered, this, &MainWindow::handleSaveAsTriggered);
connect(mActionExportProject, &Action::triggered, this, &MainWindow::handleExportProjectTriggered);
Expand Down Expand Up @@ -659,6 +660,15 @@ namespace hal
mStackedWidget->setCurrentWidget(mWelcomeScreen);
}

void MainWindow::closeGateLibraryManager()
{
bool isFileOpen = FileManager::get_instance()->fileOpen();
if(isFileOpen)
mStackedWidget->setCurrentWidget(mLayoutArea);
else
mStackedWidget->setCurrentWidget(mWelcomeScreen);
}

void MainWindow::openPluginManager()
{
mPluginManager->repolish();
Expand Down Expand Up @@ -810,19 +820,9 @@ namespace hal

void MainWindow::handleActionGatelibraryManager()
{
/**
* TODO
* check if netlist is already loaded
* if yes then skip file dialog and fetchGateLibrary GateLibraryManager in read-only mode
* else open file-dialog and search for suitable files and then open GateLibraryManager
*/

if(mGateLibraryManager->initialize())
mStackedWidget->setCurrentWidget(mGateLibraryManager);
/*previous reference code*/

//GatelibraryManagementDialog dialog;
//dialog.exec();
}

void MainWindow::handleImportProjectTriggered()
Expand Down

0 comments on commit 39e51e6

Please sign in to comment.