Salome HOME
d067e100c6132365785787373c2bdb665079a8c7
[modules/shaper.git] / src / ModuleBase / ModuleBase_PagedContainer.cpp
1 /*
2  * ModuleBase_PagedContainer.cpp
3  *
4  *  Created on: Mar 13, 2015
5  *      Author: sbh
6  */
7
8 #include <ModuleBase_PagedContainer.h>
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_ModelWidget.h>
11 #include <ModuleBase_Tools.h>
12
13 #include <ModelAPI_AttributeString.h>
14
15 #include <QWidget>
16 #include <Qlist>
17 #include <QVBoxLayout>
18
19
20 ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent, const Config_WidgetAPI* theData,
21                                                      const std::string& theParentId)
22 : ModuleBase_ModelWidget(theParent, theData, theParentId),
23   myIsFocusOnCurrentPage(false)
24 {
25 }
26
27 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
28 {
29 }
30
31 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
32                                       const QString& theName, const QString& theCaseId)
33 {
34   myCaseIds << theCaseId;
35   myPages << thePage;
36   return myPages.count();
37 }
38
39 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
40 {
41   QList<QWidget*> aResult;
42   int anIndex = currentPageIndex();
43   QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
44   foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
45     aResult << eachModelWidget->getControls();
46   }
47   return aResult;
48 }
49
50 bool ModuleBase_PagedContainer::focusTo()
51 {
52   int anIndex = currentPageIndex();
53   if (anIndex > myPages.count())
54     return false;
55   return myPages[anIndex]->takeFocus();
56 }
57
58 void ModuleBase_PagedContainer::setHighlighted(bool)
59 {
60   //page containers should not be highlighted, do nothing
61 }
62
63 void ModuleBase_PagedContainer::enableFocusProcessing()
64 {
65   myIsFocusOnCurrentPage = true;
66 }
67
68 bool ModuleBase_PagedContainer::restoreValue()
69 {
70   // A rare case when plugin was not loaded.
71   if(!myFeature)
72     return false;
73   DataPtr aData = myFeature->data();
74   AttributeStringPtr aStringAttr = aData->string(attributeID());
75   QString aCaseId = QString::fromStdString(aStringAttr->value());
76   int idx = myCaseIds.indexOf(aCaseId);
77   if (idx == -1)
78     return false;
79   setCurrentPageIndex(idx);
80   return true;
81 }
82
83 void ModuleBase_PagedContainer::activateCustom()
84 {
85   // activate current page
86   focusTo();
87 }
88
89 bool ModuleBase_PagedContainer::storeValueCustom() const
90 {
91   // A rare case when plugin was not loaded.
92   if(!myFeature)
93     return false;
94   DataPtr aData = myFeature->data();
95   AttributeStringPtr aStringAttr = aData->string(attributeID());
96   QString aWidgetValue = myCaseIds.at(currentPageIndex());
97   aStringAttr->setValue(aWidgetValue.toStdString());
98   return true;
99 }
100
101
102 void ModuleBase_PagedContainer::onPageChanged()
103 {
104   storeValue();
105   if (myIsFocusOnCurrentPage) focusTo();
106 }
107
108