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"
10 #include <ModelAPI_Session.h>
12 #include <QMainWindow>
14 #include <QDialogButtonBox>
15 #include <QPushButton>
18 ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId,
19 const std::string& theDescription) :
20 QDialog(theParent->desktop()),
22 myDescription(theDescription),
25 ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
27 SessionPtr aMgr = ModelAPI_Session::get();
28 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
30 aMgr->startOperation(myId.toStdString());
31 myFeature = aDoc->addFeature(myId.toStdString());
35 QVBoxLayout* aLayout = new QVBoxLayout(this);
36 aLayout->setContentsMargins(0, 0, 0, 0);
37 aLayout->setSpacing(1);
38 //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
40 ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
41 aLayout->addWidget(aPage);
43 aFactory.createWidget(aPage, false);
44 myWidgets = aFactory.getModelWidgets();
45 foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
46 initializeWidget(aWidget);
49 QFrame* aFrame = new QFrame(this);
50 aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
51 aLayout->addWidget(aFrame);
53 QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
54 ModuleBase_Tools::adjustMargins(aBtnLayout);
56 QDialogButtonBox* aBtnBox = new QDialogButtonBox(
57 QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
58 aBtnLayout->addWidget(aBtnBox);
60 aBtnBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
61 aBtnBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
63 connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
64 connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
69 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
71 theWidget->setFeature(myFeature);
74 void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
76 QDialog::showEvent(theEvent);
77 if (myWidgets.length() > 0)
78 myWidgets.first()->activate();