Skip to content

Commit

Permalink
CustomMenu now has two buttons "Cancel" and "Apply", change the way s…
Browse files Browse the repository at this point in the history
…ave settings feature works, relying on feedback, implement savefiltersettings option
  • Loading branch information
w0lek committed Nov 16, 2023
1 parent 7f83a52 commit 7f55c04
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 39 deletions.
42 changes: 40 additions & 2 deletions src/InteractivePathAnalysis/custommenu.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
#include "custommenu.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QDebug>

CustomMenu::CustomMenu(QPushButton* caller): QWidget(caller)
{
setWindowFlags(Qt::Popup);

QVBoxLayout* layout = new QVBoxLayout;
QWidget::setLayout(layout);

m_contentLayout = new QVBoxLayout;
m_contentLayout->setContentsMargins(0,0,0,0);
layout->addLayout(m_contentLayout);

QHBoxLayout* buttonsLayout = new QHBoxLayout;
layout->addLayout(buttonsLayout);

QPushButton* bnCancel = new QPushButton(tr("Cancel"));
QPushButton* bnApply = new QPushButton(tr("Apply"));

connect(bnCancel, &QPushButton::clicked, this, [this](){
hide();

});
connect(bnApply, &QPushButton::clicked, this, [this](){
m_isAccepted = true;
hide();
emit accepted();
});

buttonsLayout->addStretch(1);
buttonsLayout->addWidget(bnCancel);
buttonsLayout->addWidget(bnApply);
buttonsLayout->addStretch(1);

connect(caller, &QPushButton::clicked, this, [this](){
if (!isVisible()) {
QWidget* parentWidget = qobject_cast<QWidget*>(parent());
Expand All @@ -19,9 +49,15 @@ CustomMenu::CustomMenu(QPushButton* caller): QWidget(caller)
hide(); // initially hide
}

void CustomMenu::addContentLayout(QLayout* layout)
{
m_contentLayout->addLayout(layout);
}

void CustomMenu::popup(QPoint pos)
{
show(); // show first before move, otherwise on first run we will have not proper widget size due to not initilized geometry
m_isAccepted = false;
QWidget::show(); // show first before move, otherwise on first run we will have not proper widget size due to not initilized geometry
switch(m_alignment) {
case Alignment::LEFT: /*do nothing*/ break;
case Alignment::RIGHT: pos.setX(pos.x() - width()); break;
Expand All @@ -40,6 +76,8 @@ void CustomMenu::mousePressEvent(QMouseEvent* event)

void CustomMenu::hideEvent(QHideEvent* event)
{
emit hidden();
if (!m_isAccepted) {
emit declined();
}
QWidget::hideEvent(event);
}
10 changes: 9 additions & 1 deletion src/InteractivePathAnalysis/custommenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QMouseEvent>

class QPushButton;
class QVBoxLayout;

class CustomMenu final : public QWidget
{
Expand All @@ -18,16 +19,23 @@ class CustomMenu final : public QWidget

explicit CustomMenu(QPushButton* caller);

void addContentLayout(QLayout*);
void setLayout(QLayout* layout)=delete;

void setAlignment(Alignment alignment) { m_alignment = alignment; }
void show()=delete;
void popup(QPoint pos);

signals:
void hidden();
void accepted();
void declined();

protected:
void mousePressEvent(QMouseEvent* event) override final;
void hideEvent(QHideEvent* event) override final;

private:
bool m_isAccepted = false;
Alignment m_alignment = Alignment::LEFT;
QVBoxLayout* m_contentLayout = nullptr;
};
3 changes: 1 addition & 2 deletions src/InteractivePathAnalysis/ncriticalpathparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class NCriticalPathParameters {
~NCriticalPathParameters()=default;

void saveToSettings();
void load();

void setCriticalPathNum(int criticalPathNum) { m_criticalPathNum = criticalPathNum; }
void setPathType(const QString& pathType) { m_pathType = pathType; }
Expand All @@ -34,8 +35,6 @@ class NCriticalPathParameters {
bool m_isFlatRouting;
#endif
int m_highLightMode;

void load();
};

using NCriticalPathParametersPtr = std::shared_ptr<NCriticalPathParameters>;
22 changes: 22 additions & 0 deletions src/InteractivePathAnalysis/ncriticalpathsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ void NCriticalPathSettings::setCriticalPathNum(int value)
m_settings.setValue(OPT_N_CRITICAL_PATH_NUM, value);
}

void NCriticalPathSettings::setSavePathListSettings(bool value)
{
m_settings.setValue(OPT_SAVE_PATH_LIST_SETTINGS, value);
}

void NCriticalPathSettings::setSaveFilterSettings(bool value)
{
m_settings.setValue(OPT_SAVE_FILTER_SETTINGS, value);
}

void NCriticalPathSettings::load()
{
if (QVariant value = m_settings.value(OPT_HIGH_LIGHT_MODE); value.isValid()) {
Expand All @@ -50,4 +60,16 @@ void NCriticalPathSettings::load()
} else {
m_criticalPathNum = 100;
}

if (QVariant value = m_settings.value(OPT_SAVE_PATH_LIST_SETTINGS); value.isValid()) {
m_savePathListSettings = value.toBool();
} else {
m_savePathListSettings = true;
}

if (QVariant value = m_settings.value(OPT_SAVE_FILTER_SETTINGS); value.isValid()) {
m_saveFilterSettings = value.toBool();
} else {
m_saveFilterSettings = true;
}
}
12 changes: 10 additions & 2 deletions src/InteractivePathAnalysis/ncriticalpathsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ class NCriticalPathSettings {
const char* OPT_PATH_TYPE = "critpaths.type";
const char* OPT_N_CRITICAL_PATH_NUM = "critpaths.criticalPathNum";
const char* OPT_PATH_DETAIL_LEVEL = "critpaths.detailLevel";
const char* OPT_SAVE_PATH_LIST_SETTINGS = "savePathListSettings";
const char* OPT_SAVE_FILTER_SETTINGS = "saveFilterSettings";

NCriticalPathSettings();

public:
static NCriticalPathSettings& instance();
~NCriticalPathSettings()=default;

void load();

void setHighLightMode(int);
void setPathType(const QString&);
void setPathDetailLevel(int);
void setCriticalPathNum(int);
void setSavePathListSettings(bool);
void setSaveFilterSettings(bool);

int getHighLightMode() const { return m_hightLightMode; }
QString getPathType() const { return m_pathType; }
int getPathDetailLevel() const { return m_pathDetailLevel; }
int getCriticalPathNum() const { return m_criticalPathNum; }
bool getSavePathListSettings() const { return m_savePathListSettings; }
bool getSaveFilterSettings() const { return m_saveFilterSettings; }

private:
QSettings m_settings;
Expand All @@ -31,6 +39,6 @@ class NCriticalPathSettings {
QString m_pathType;
int m_pathDetailLevel;
int m_criticalPathNum;

void load();
bool m_savePathListSettings;
bool m_saveFilterSettings;
};
79 changes: 52 additions & 27 deletions src/InteractivePathAnalysis/ncriticalpathtoolswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ NCriticalPathToolsWidget::NCriticalPathToolsWidget(
layout->setSpacing(NCriticalPathTheme::instance().borderSize());
setLayout(layout);

QPushButton* bnPathsOptions = new QPushButton("Paths Cfg...");
QPushButton* bnPathsOptions = new QPushButton("Configuration");
layout->addWidget(bnPathsOptions);
setupCriticalPathsOptionsMenu(bnPathsOptions);

Expand All @@ -53,7 +53,7 @@ NCriticalPathToolsWidget::NCriticalPathToolsWidget(
connect(&m_process, &Process::runStatusChanged, this, [this](bool isRunning){
m_bnRunPnRView->setEnabled(!isRunning);
m_isFirstTimeConnectedToParticularPnRViewInstance = true; // to get new path list on next PnRView run
m_isPathListDirty = true;
m_isPathListSettingsChanged = true;
emit PnRViewRunStatusChanged(isRunning);
});

Expand All @@ -75,7 +75,7 @@ NCriticalPathToolsWidget::NCriticalPathToolsWidget(

void NCriticalPathToolsWidget::onPathListReceived()
{
m_isPathListDirty = false;
m_isPathListSettingsChanged = false;
}

QString NCriticalPathToolsWidget::projectLocation()
Expand Down Expand Up @@ -153,24 +153,35 @@ QString NCriticalPathToolsWidget::vprBaseCommand()
#endif
}

void NCriticalPathToolsWidget::restoreConfiguration()
{
NCriticalPathSettings::instance().load();
m_parameters->load();
resetConfigurationMenu();
}

void NCriticalPathToolsWidget::setupCriticalPathsOptionsMenu(QPushButton* caller)
{
if (m_pathsOptionsMenu) {
return;
}

m_pathsOptionsMenu = new CustomMenu(caller);
connect(m_pathsOptionsMenu, &CustomMenu::hidden, this, [this](){
if (m_isPathListDirty) {
emit pathListRequested("autorefresh because it's dirty");
connect(m_pathsOptionsMenu, &CustomMenu::declined, this, [this](){
restoreConfiguration();
m_isPathListSettingsChanged = false;
});
connect(m_pathsOptionsMenu, &CustomMenu::accepted, this, [this](){
if (m_isPathListSettingsChanged) {
emit pathListRequested("autorefresh because path list configuration changed");
}
if (m_cbSaveSettings->isChecked()) {
saveConfiguration();
}
});

QVBoxLayout* mainLayout = new QVBoxLayout;
m_pathsOptionsMenu->setLayout(mainLayout);

QFormLayout* formLayout = new QFormLayout;
mainLayout->addLayout(formLayout);
m_pathsOptionsMenu->addContentLayout(formLayout);

//
m_cbHighlightMode = new QComboBox;
Expand All @@ -179,7 +190,6 @@ void NCriticalPathToolsWidget::setupCriticalPathsOptionsMenu(QPushButton* caller
m_cbHighlightMode->addItem("Routing");
m_cbHighlightMode->addItem("Routing Delays");

m_cbHighlightMode->setCurrentIndex(m_parameters->getHighLightMode());
connect(m_cbHighlightMode, qOverload<int>(&QComboBox::currentIndexChanged), this, [this](int index) {
m_parameters->setHighLightMode(index);
emit highLightModeChanged();
Expand All @@ -192,10 +202,9 @@ void NCriticalPathToolsWidget::setupCriticalPathsOptionsMenu(QPushButton* caller
m_cbPathType->addItem("setup");
m_cbPathType->addItem("hold");
// m_cbPathType->addItem("skew");
m_cbPathType->setCurrentText(m_parameters->getPathType());
connect(m_cbPathType, &QComboBox::currentTextChanged, this, [this](const QString& newText) {
m_parameters->setPathType(newText);
m_isPathListDirty = true;
m_isPathListSettingsChanged = true;
});
formLayout->addRow(new QLabel(tr("Type:")), m_cbPathType);

Expand All @@ -205,10 +214,9 @@ void NCriticalPathToolsWidget::setupCriticalPathsOptionsMenu(QPushButton* caller
m_cbDetail->addItem("aggregated");
m_cbDetail->addItem("detailed routing");
m_cbDetail->addItem("debug");
m_cbDetail->setCurrentIndex(m_parameters->getDetailLevel());
connect(m_cbDetail, qOverload<int>(&QComboBox::currentIndexChanged), this, [this](int index) {
m_parameters->setDetailLevel(index);
m_isPathListDirty = true;
m_isPathListSettingsChanged = true;
});
formLayout->addRow(new QLabel(tr("Report detail:")), m_cbDetail);

Expand All @@ -217,25 +225,42 @@ void NCriticalPathToolsWidget::setupCriticalPathsOptionsMenu(QPushButton* caller
QIntValidator intValidator(m_leNCriticalPathNum);
m_leNCriticalPathNum->setValidator(&intValidator);

m_leNCriticalPathNum->setText(QString::number(m_parameters->getCriticalPathNum()));
connect(m_leNCriticalPathNum, &QLineEdit::textChanged, this, [this](const QString& text) {
m_parameters->setCriticalPathNum(text.toInt());
m_isPathListDirty = true;
m_isPathListSettingsChanged = true;
});
formLayout->addRow(new QLabel(tr("Paths num limit:")), m_leNCriticalPathNum);

QHBoxLayout* hLayout = new QHBoxLayout;
mainLayout->addLayout(hLayout);
m_cbSaveSettings = new QCheckBox("Save settings on apply");
m_cbSaveSettings->setChecked(NCriticalPathSettings::instance().getSavePathListSettings());
connect(m_cbSaveSettings, &QCheckBox::toggled, this, [](bool checked){
NCriticalPathSettings::instance().setSavePathListSettings(checked);
});
formLayout->addRow(m_cbSaveSettings);

QPushButton* bnSaveSettings = new QPushButton("Save Settings");
hLayout->addStretch(1);
hLayout->addWidget(bnSaveSettings);
hLayout->addStretch(1);

connect(bnSaveSettings, &QPushButton::clicked, this, &NCriticalPathToolsWidget::saveCriticalPathsSettings);
resetConfigurationMenu();
}

void NCriticalPathToolsWidget::resetConfigurationMenu()
{
m_cbHighlightMode->blockSignals(true);
m_cbHighlightMode->setCurrentIndex(m_parameters->getHighLightMode());
m_cbHighlightMode->blockSignals(false);

m_cbPathType->blockSignals(true);
m_cbPathType->setCurrentText(m_parameters->getPathType());
m_cbPathType->blockSignals(false);

m_cbDetail->blockSignals(true);
m_cbDetail->setCurrentIndex(m_parameters->getDetailLevel());
m_cbDetail->blockSignals(false);

m_leNCriticalPathNum->blockSignals(true);
m_leNCriticalPathNum->setText(QString::number(m_parameters->getCriticalPathNum()));
m_leNCriticalPathNum->blockSignals(false);
}

void NCriticalPathToolsWidget::saveCriticalPathsSettings()
void NCriticalPathToolsWidget::saveConfiguration()
{
m_parameters->saveToSettings();
}
Expand All @@ -249,7 +274,7 @@ void NCriticalPathToolsWidget::setupProjectMenu(QPushButton* caller)
m_FOEDAGProjMenu = new CustomMenu(caller);

QFormLayout* layout = new QFormLayout;
m_FOEDAGProjMenu->setLayout(layout);
m_FOEDAGProjMenu->addContentLayout(layout);

//
m_leProj = new QLineEdit;
Expand Down
7 changes: 5 additions & 2 deletions src/InteractivePathAnalysis/ncriticalpathtoolswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public slots:

private:
bool m_isFirstTimeConnectedToParticularPnRViewInstance = true;
bool m_isPathListDirty = true;
bool m_isPathListSettingsChanged = true;
#ifdef STANDALONE_APP
QLineEdit* m_leProj = nullptr;
QCheckBox* m_cbIsFlatRouting = nullptr;
Expand All @@ -57,6 +57,7 @@ public slots:
QComboBox* m_cbHighlightMode = nullptr;
QComboBox* m_cbPathType = nullptr;
QComboBox* m_cbDetail = nullptr;
QCheckBox* m_cbSaveSettings = nullptr;
Process m_process;

NCriticalPathParametersPtr m_parameters;
Expand All @@ -77,6 +78,8 @@ public slots:
QString vprBaseCommand();

void runPnRView();
void saveCriticalPathsSettings();
void saveConfiguration();
void restoreConfiguration();
void resetConfigurationMenu();
};

Loading

0 comments on commit 7f55c04

Please sign in to comment.