]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Dialog.cpp
Salome HOME
Parameters management implementation
[modules/shaper.git] / src / ModuleBase / ModuleBase_Dialog.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
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
10 #include <ModelAPI_Session.h>
11
12 #include <QMainWindow>
13 #include <QLayout>
14 #include <QDialogButtonBox>
15 #include <QPushButton>
16
17
18 ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId, 
19                                      const std::string& theDescription) : 
20                                      QDialog(theParent->desktop()), 
21                                      myId(theId), 
22                                      myDescription(theDescription), 
23                                      myWorkshop(theParent)
24 {
25   ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
26
27   SessionPtr aMgr = ModelAPI_Session::get();
28   std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
29
30   aMgr->startOperation(myId.toStdString());
31   myFeature = aDoc->addFeature(myId.toStdString());
32   if (!myFeature.get())
33     return;
34
35   QVBoxLayout* aLayout = new QVBoxLayout(this);
36   aLayout->setContentsMargins(0, 0, 0, 0);
37   aLayout->setSpacing(1);
38   //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
39
40   ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
41   aLayout->addWidget(aPage);
42
43   aFactory.createWidget(aPage, false);
44   myWidgets = aFactory.getModelWidgets();
45   foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
46     initializeWidget(aWidget);
47   }
48
49   QFrame* aFrame = new QFrame(this);
50   aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
51   aLayout->addWidget(aFrame);
52
53   QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
54   ModuleBase_Tools::adjustMargins(aBtnLayout);
55
56   QDialogButtonBox* aBtnBox = new QDialogButtonBox(
57     QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
58   aBtnLayout->addWidget(aBtnBox);
59
60   aBtnBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
61   aBtnBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
62
63   connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
64   connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
65
66   
67 }
68
69 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
70 {
71   theWidget->setFeature(myFeature);
72 }
73
74 void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
75 {
76   QDialog::showEvent(theEvent);
77   if (myWidgets.length() > 0)
78     myWidgets.first()->activate();
79 }