From: vsv Date: Thu, 14 May 2020 15:03:38 +0000 (+0300) Subject: Issue #3224: Provide help button for feature dialog boxes X-Git-Tag: V9_5_0b1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=44b3aa1055279520a1b3d7a6a77f90bf8db5d087;p=modules%2Fshaper.git Issue #3224: Provide help button for feature dialog boxes --- diff --git a/src/ModuleBase/ModuleBase_Dialog.cpp b/src/ModuleBase/ModuleBase_Dialog.cpp index 18766dd99..0b1d25459 100644 --- a/src/ModuleBase/ModuleBase_Dialog.cpp +++ b/src/ModuleBase/ModuleBase_Dialog.cpp @@ -38,15 +38,20 @@ #include -ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId, - const std::string& theDescription) : +ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, + const std::string& theDescription) : QDialog(theParent->desktop(), Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), - myId(theId), myDescription(theDescription), myWorkshop(theParent), myActiveWidget(0) { + Config_WidgetAPI aApi(myDescription, ""); + myId = aApi.getProperty("id"); + + std::shared_ptr aFeatureInfo = myWorkshop->featureInfo(myId.c_str()); + myHelpPage = aFeatureInfo->helpFileName(); + ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop); QString aTitle = ModuleBase_Tools::translate("ModuleBase_Dialog", aFactory.widgetAPI()->getProperty(FEATURE_TEXT)); @@ -56,7 +61,7 @@ ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QStr SessionPtr aMgr = ModelAPI_Session::get(); std::shared_ptr aDoc = aMgr->activeDocument(); - myFeature = aDoc->addFeature(myId.toStdString()); + myFeature = aDoc->addFeature(myId); if (!myFeature.get()) return; Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); @@ -65,7 +70,6 @@ ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QStr QVBoxLayout* aLayout = new QVBoxLayout(this); aLayout->setContentsMargins(0, 0, 0, 0); aLayout->setSpacing(1); - //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this); aLayout->addWidget(aPage); @@ -81,14 +85,17 @@ ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QStr ModuleBase_Tools::adjustMargins(aBtnLayout); myButtonsBox = new QDialogButtonBox( - QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame); + QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, + Qt::Horizontal, aFrame); aBtnLayout->addWidget(myButtonsBox); myButtonsBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png")); myButtonsBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png")); + myButtonsBox->button(QDialogButtonBox::Help)->setIcon(QIcon(":pictures/button_help.png")); connect(myButtonsBox, SIGNAL(accepted()), this, SLOT(accept())); connect(myButtonsBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(myButtonsBox, SIGNAL(helpRequested()), this, SLOT(onHelpRequest())); foreach (ModuleBase_ModelWidget* aWidget, myWidgets) { initializeWidget(aWidget); @@ -122,3 +129,8 @@ void ModuleBase_Dialog::accept() } QDialog::accept(); } + +void ModuleBase_Dialog::onHelpRequest() +{ + myWorkshop->showHelpPage(myHelpPage.c_str()); +} diff --git a/src/ModuleBase/ModuleBase_Dialog.h b/src/ModuleBase/ModuleBase_Dialog.h index 7ef0b6e6b..46f0e7068 100644 --- a/src/ModuleBase/ModuleBase_Dialog.h +++ b/src/ModuleBase/ModuleBase_Dialog.h @@ -44,8 +44,7 @@ public: /// \param theParent a workshop object instance /// \param theId an Id of a feature /// \param theDescription an XML description of the feature - ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId, - const std::string& theDescription); + ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const std::string& theDescription); /// Redefinition of virtual method virtual void accept(); @@ -54,12 +53,15 @@ protected: /// Redefinition of virtual method virtual void showEvent(QShowEvent* theEvent); +private slots: + void onHelpRequest(); + private: /// Initialising of the widget void initializeWidget(ModuleBase_ModelWidget* theWidget); /// Id of the feature - QString myId; + std::string myId; /// XML description of the feature std::string myDescription; @@ -78,6 +80,8 @@ private: /// Buttons of the dialog QDialogButtonBox* myButtonsBox; + + std::string myHelpPage; }; #endif diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 9b584ab63..082df98c1 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -95,7 +95,7 @@ void ModuleBase_IModule::launchModal(const QString& theCmdId) SessionPtr aMgr = ModelAPI_Session::get(); aMgr->startOperation(theCmdId.toStdString()); - ModuleBase_Dialog aDlg(myWorkshop, theCmdId, aXmlCfg); + ModuleBase_Dialog aDlg(myWorkshop, aXmlCfg); if (aDlg.exec() == QDialog::Accepted) aMgr->finishOperation(); else diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index c49dda4ff..d7480c10e 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -161,6 +161,9 @@ Q_OBJECT //! Returns current state of cancel button virtual bool isCancelEnabled() const = 0; + //! Show help of a current operation + virtual void showHelpPage(const QString& thePage) const = 0; + signals: /// Signal selection changed. void selectionChanged(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 608969312..28a773ec6 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -261,3 +261,8 @@ bool XGUI_ModuleConnector::isCancelEnabled() const } return isEnabled; } + +void XGUI_ModuleConnector::showHelpPage(const QString& thePage) const +{ + workshop()->showHelpPage(thePage); +} diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index f21b6e803..f504abfa1 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -145,6 +145,9 @@ Q_OBJECT //! Returns current state of cancel button virtual bool isCancelEnabled() const; + //! Show help of a current operation + virtual void showHelpPage(const QString& thePage) const; + private: QObjectPtrList activeObjects(const QObjectPtrList& theObjList) const; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index e1aa196e4..42276a065 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -639,16 +639,22 @@ void XGUI_Workshop::onPreviewActionClicked() //****************************************************** -void XGUI_Workshop::onHelpActionClicked() +void XGUI_Workshop::onHelpActionClicked() const { XGUI_OperationMgr* anOperationMgr = operationMgr(); if (anOperationMgr) { ModuleBase_Operation* aOperation = anOperationMgr->currentOperation(); if (aOperation) { - QString aHelpPage = aOperation->helpFileName(); - if (!aHelpPage.isEmpty()) { - QString aDocDir; - const QChar aSep = QDir::separator(); + showHelpPage(aOperation->helpFileName()); + } + } +} + +void XGUI_Workshop::showHelpPage(const QString& thePage) const +{ + if (!thePage.isEmpty()) { + QString aDocDir; + const QChar aSep = QDir::separator(); // QString platform; // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); //#ifdef WIN32 @@ -659,21 +665,19 @@ void XGUI_Workshop::onHelpActionClicked() // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform); #ifdef HAVE_SALOME - QString aDir(getenv("SHAPER_ROOT_DIR")); - if (!aDir.isEmpty()) { - aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep + - "salome" + aSep + "gui" + aSep + "SHAPER"; - } + QString aDir(getenv("SHAPER_ROOT_DIR")); + if (!aDir.isEmpty()) { + aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep + + "salome" + aSep + "gui" + aSep + "SHAPER"; + } #else - QString aDir(getenv("CADBUILDER_ROOT_DIR")); - aDocDir = aDir + aSep + "doc" + aSep + "gui"; + QString aDir(getenv("CADBUILDER_ROOT_DIR")); + aDocDir = aDir + aSep + "doc" + aSep + "gui"; #endif - QString aFileName = aDocDir + aSep + aHelpPage; - if (QFile::exists(aFileName)) { - QUrl aUrl = QUrl::fromLocalFile(aFileName); - QDesktopServices::openUrl(aUrl); - } - } + QString aFileName = aDocDir + aSep + thePage; + if (QFile::exists(aFileName)) { + QUrl aUrl = QUrl::fromLocalFile(aFileName); + QDesktopServices::openUrl(aUrl); } } } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 7b69f0341..c503990f9 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -335,6 +335,8 @@ Q_OBJECT /// The method updates a Color Scale object in the viewer void updateColorScaleVisibility(); + void showHelpPage(const QString& thePage) const; + signals: /// Emitted when selection happens in Salome viewer void salomeViewerSelection(); @@ -494,7 +496,7 @@ private: void onPreviewActionClicked(); /// Called on help button clicked in the property panel. - void onHelpActionClicked(); + void onHelpActionClicked() const; //! The slot is called only once on resizing of Object Browser void onDockSizeChanged();