1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "ModuleBase_Dialog.h"
5 #include "ModuleBase_WidgetFactory.h"
6 #include "ModuleBase_IWorkshop.h"
7 #include "ModuleBase_IPropertyPanel.h"
8 #include "ModuleBase_PageWidget.h"
9 #include "ModuleBase_ModelDialogWidget.h"
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Events.h>
13 #include <Events_Loop.h>
15 #include <Config_WidgetAPI.h>
16 #include <Config_Keywords.h>
18 #include <QMainWindow>
20 #include <QDialogButtonBox>
21 #include <QPushButton>
24 ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId,
25 const std::string& theDescription) :
26 QDialog(theParent->desktop()),
28 myDescription(theDescription),
29 myWorkshop(theParent),
32 ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
33 std::string aTitle = aFactory.widgetAPI()->getProperty(FEATURE_TEXT);
35 setWindowTitle(aTitle.c_str());
37 SessionPtr aMgr = ModelAPI_Session::get();
38 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
40 myFeature = aDoc->addFeature(myId.toStdString());
43 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
44 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
46 QVBoxLayout* aLayout = new QVBoxLayout(this);
47 aLayout->setContentsMargins(0, 0, 0, 0);
48 aLayout->setSpacing(1);
49 //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
51 ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
52 aLayout->addWidget(aPage);
54 aFactory.createWidget(aPage, false);
55 myWidgets = aFactory.getModelWidgets();
57 QFrame* aFrame = new QFrame(this);
58 aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
59 aLayout->addWidget(aFrame);
61 QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
62 ModuleBase_Tools::adjustMargins(aBtnLayout);
64 myButtonsBox = new QDialogButtonBox(
65 QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
66 aBtnLayout->addWidget(myButtonsBox);
68 myButtonsBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
69 myButtonsBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
71 connect(myButtonsBox, SIGNAL(accepted()), this, SLOT(accept()));
72 connect(myButtonsBox, SIGNAL(rejected()), this, SLOT(reject()));
74 foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
75 initializeWidget(aWidget);
79 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
81 ModuleBase_ModelDialogWidget* aDlgWgt = dynamic_cast<ModuleBase_ModelDialogWidget*>(theWidget);
83 aDlgWgt->setDialogButtons(myButtonsBox);
85 theWidget->setFeature(myFeature);
86 theWidget->restoreValue();
89 void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
91 QDialog::showEvent(theEvent);
92 if (myWidgets.length() > 0) {
93 myActiveWidget = myWidgets.first();
94 myActiveWidget->activate();
98 void ModuleBase_Dialog::accept()
100 if (myActiveWidget) {
101 if (!myActiveWidget->storeValue())