From: vsv Date: Wed, 7 Nov 2018 10:10:53 +0000 (+0300) Subject: Issue #2734: Add "Reset" button to the dialog box X-Git-Tag: Jan2019~38^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=437800222d180c99595cf3d01ad36de3d781e765;p=modules%2Fshaper.git Issue #2734: Add "Reset" button to the dialog box --- diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 28f3de9a4..48b1ed425 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -823,7 +823,10 @@ void SHAPERGUI::onEditToolbars() { SHAPERGUI_ToolbarsDlg aDlg(this); if (aDlg.exec() == QDialog::Accepted) { - updateToolbars(aDlg.result()); + if (aDlg.isReset()) + resetToolbars(); + else + updateToolbars(aDlg.result()); } } @@ -846,6 +849,10 @@ int SHAPERGUI::getNextCommandId() const void SHAPERGUI::updateToolbars(const QMap& theNewToolbars) { + // Store default toolbars + if (myDefaultToolbars.size() == 0) + myDefaultToolbars = myToolbars; + QtxActionToolMgr* aMgr = toolMgr(); QStringList aToolbars = theNewToolbars.keys(); QIntList aCommands, aOldCmd; @@ -1047,3 +1054,12 @@ QIntList SHAPERGUI::getFreeCommands() const } return aFreeCommands; } + +void SHAPERGUI::resetToolbars() +{ + if (!myDefaultToolbars.isEmpty()) + updateToolbars(myDefaultToolbars); + myIsToolbarsModified = false; + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + aResMgr->remove(ToolbarsSection); +} diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h index 9504446a2..72c458d6a 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -165,6 +165,12 @@ Q_OBJECT /// Returns free commands which are not in toolbars in the module QIntList getFreeCommands() const; + /// Returns structure of default tool bars + QMap defaultToolbars() const + { return (myDefaultToolbars.size() == 0)? myToolbars : myDefaultToolbars; } + + void resetToolbars(); + public slots: /// \brief The method is redefined to connect to the study viewer before the data /// model is filled by opened file. This file open will flush redisplay signals for, @@ -270,6 +276,7 @@ private slots: /// List of registered actions QIntList myActionsList; QMap myToolbars; + QMap myDefaultToolbars; bool myIsToolbarsModified; }; diff --git a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp index e1e6b1137..26bb4cc9e 100644 --- a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp +++ b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp @@ -80,7 +80,8 @@ private: SHAPERGUI_ToolbarsDlg::SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule) : QDialog(theModule->application()->desktop()), myModule(theModule), - myResult(theModule->shaperToolbars()) + myResult(theModule->shaperToolbars()), + myIsReset(false) { myFreeCommands = theModule->getFreeCommands(); @@ -122,18 +123,27 @@ SHAPERGUI_ToolbarsDlg::SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule) aContolsLay->addWidget(aButtonsWgt); QPushButton* aAddBtn = new QPushButton(tr("Add..."), aButtonsWgt); + aAddBtn->setToolTip(tr("Add a new empty toolbar to the toolbars list")); connect(aAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd())); aBtnLayout->addWidget(aAddBtn); QPushButton* aEditBtn = new QPushButton(tr("Edit..."), aButtonsWgt); + aEditBtn->setToolTip(tr("Edit currently selected toolbar")); connect(aEditBtn, SIGNAL(clicked(bool)), SLOT(onEdit())); aBtnLayout->addWidget(aEditBtn); QPushButton* aDeleteBtn = new QPushButton(tr("Delete"), aButtonsWgt); + aDeleteBtn->setToolTip(tr("Delete currently selected toolbar")); connect(aDeleteBtn, SIGNAL(clicked(bool)), SLOT(onDelete())); aBtnLayout->addWidget(aDeleteBtn); aBtnLayout->addStretch(1); + QPushButton* aResetBtn = new QPushButton(tr("Reset"), aButtonsWgt); + aResetBtn->setToolTip(tr("Restore default toolbars structure")); + connect(aResetBtn, SIGNAL(clicked(bool)), SLOT(onReset())); + aBtnLayout->addWidget(aResetBtn); + aBtnLayout->addSpacing(19); + // Buttons part of the dialog QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); @@ -153,6 +163,7 @@ void SHAPERGUI_ToolbarsDlg::onAdd() if (!myResult.contains(aNewToolbar)) { myResult[aNewToolbar] = QIntList(); updateToolbarsList(); + myIsReset = false; } else { QString aMsg = tr("A tool bar with name %1 already exists").arg(aNewToolbar); @@ -176,6 +187,7 @@ void SHAPERGUI_ToolbarsDlg::onEdit() myResult[aToolbarName] = aDlg.toolbarItems(); updateNumber(); updateToolbarsList(); + myIsReset = false; } } } @@ -196,6 +208,7 @@ void SHAPERGUI_ToolbarsDlg::onDelete() myResult.remove(aToolbarName); updateToolbarsList(); updateNumber(); + myIsReset = false; } } } @@ -223,6 +236,15 @@ void SHAPERGUI_ToolbarsDlg::updateNumber() myFreeNbLbl->setText(QString::number(myFreeCommands.size())); } +void SHAPERGUI_ToolbarsDlg::onReset() +{ + myResult = myModule->defaultToolbars(); + updateNumber(); + updateToolbarsList(); + myIsReset = true; +} + + //************************************************************************************ //************************************************************************************ //************************************************************************************ @@ -234,7 +256,7 @@ SHAPERGUI_ToolbarItemsDlg::SHAPERGUI_ToolbarItemsDlg(QWidget* theParent, : QDialog(theParent), myModule(theModule) { - setWindowTitle(tr("Edit toolbar items")); + setWindowTitle(tr("Edit toolbar")); QVBoxLayout* aMailLayout = new QVBoxLayout(this); diff --git a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h index 19d40013c..d9fcbde45 100644 --- a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h +++ b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h @@ -104,6 +104,11 @@ public: /// Returns result of editing QMap result() const { return myResult; } + /// Returns a flag of resetted toolbars structure + bool isReset() const { + return myIsReset; + } + private slots: /// A slot to add a new toolbar void onAdd(); @@ -114,6 +119,9 @@ private slots: /// A slot to delete a current toolbar void onDelete(); + /// A slot to delete a current toolbar + void onReset(); + /// A slot called on double click on item in list void onDoubleClick(const QModelIndex& theIdx); @@ -131,6 +139,8 @@ private: QLabel* myFreeNbLbl; QListWidget* myToolbarsList; + + bool myIsReset; };