1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ModuleBase_Dialog.h"
21 #include "ModuleBase_WidgetFactory.h"
22 #include "ModuleBase_IWorkshop.h"
23 #include "ModuleBase_IPropertyPanel.h"
24 #include "ModuleBase_PageWidget.h"
25 #include "ModuleBase_ModelDialogWidget.h"
26 #include "ModuleBase_Tools.h"
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Events.h>
30 #include <Events_Loop.h>
32 #include <Config_WidgetAPI.h>
33 #include <Config_Keywords.h>
35 #include <QMainWindow>
37 #include <QDialogButtonBox>
38 #include <QPushButton>
41 ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent,
42 const std::string& theDescription) :
43 QDialog(theParent->desktop(),
44 Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
45 myDescription(theDescription),
46 myWorkshop(theParent),
49 Config_WidgetAPI aApi(myDescription, "");
50 myId = aApi.getProperty("id");
52 std::shared_ptr<Config_FeatureMessage> aFeatureInfo = myWorkshop->featureInfo(myId.c_str());
53 myHelpPage = aFeatureInfo->helpFileName();
55 ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
56 QString aTitle = ModuleBase_Tools::translate("ModuleBase_Dialog",
57 aFactory.widgetAPI()->getProperty(FEATURE_TEXT));
59 setWindowTitle(aTitle);
61 SessionPtr aMgr = ModelAPI_Session::get();
62 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
64 myFeature = aDoc->addFeature(myId);
67 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
68 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
70 QVBoxLayout* aLayout = new QVBoxLayout(this);
71 aLayout->setContentsMargins(0, 0, 0, 0);
72 aLayout->setSpacing(1);
74 ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
75 aLayout->addWidget(aPage);
77 aFactory.createWidget(aPage, false);
78 myWidgets = aFactory.getModelWidgets();
80 QFrame* aFrame = new QFrame(this);
81 aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
82 aLayout->addWidget(aFrame);
84 QHBoxLayout* aBtnLayout = new QHBoxLayout(aFrame);
85 ModuleBase_Tools::adjustMargins(aBtnLayout);
87 myButtonsBox = new QDialogButtonBox(
88 QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help,
89 Qt::Horizontal, aFrame);
90 aBtnLayout->addWidget(myButtonsBox);
92 myButtonsBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
93 myButtonsBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
94 myButtonsBox->button(QDialogButtonBox::Help)->setIcon(QIcon(":pictures/button_help.png"));
96 connect(myButtonsBox, SIGNAL(accepted()), this, SLOT(accept()));
97 connect(myButtonsBox, SIGNAL(rejected()), this, SLOT(reject()));
98 connect(myButtonsBox, SIGNAL(helpRequested()), this, SLOT(onHelpRequest()));
100 foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
101 initializeWidget(aWidget);
105 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
107 ModuleBase_ModelDialogWidget* aDlgWgt = dynamic_cast<ModuleBase_ModelDialogWidget*>(theWidget);
109 aDlgWgt->setDialogButtons(myButtonsBox);
111 theWidget->setFeature(myFeature);
112 theWidget->restoreValue();
115 void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
117 QDialog::showEvent(theEvent);
118 if (myWidgets.length() > 0) {
119 myActiveWidget = myWidgets.first();
120 myActiveWidget->activate();
124 void ModuleBase_Dialog::accept()
126 if (myActiveWidget) {
127 if (!myActiveWidget->storeValue())
133 void ModuleBase_Dialog::onHelpRequest()
135 myWorkshop->showHelpPage(myHelpPage.c_str());