Salome HOME
Issue #624: vertical buttons in switcher are implemented as a row of toolbuttons
[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                                       const QIcon& theIcon )
34 {
35   if (!myPages.count()) {
36     setDefaultValue(theCaseId.toStdString());
37   }
38   myCaseIds << theCaseId;
39   myPages << thePage;
40
41   return myPages.count();
42 }
43
44 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
45 {
46   QList<QWidget*> aResult;
47   int anIndex = currentPageIndex();
48   QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
49   foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
50     aResult << eachModelWidget->getControls();
51   }
52   return aResult;
53 }
54
55 bool ModuleBase_PagedContainer::focusTo()
56 {
57   int anIndex = currentPageIndex();
58   if (anIndex > myPages.count())
59     return false;
60   return myPages[anIndex]->takeFocus();
61 }
62
63 void ModuleBase_PagedContainer::setHighlighted(bool)
64 {
65   //page containers should not be highlighted, do nothing
66 }
67
68 void ModuleBase_PagedContainer::enableFocusProcessing()
69 {
70   myIsFocusOnCurrentPage = true;
71 }
72
73 bool ModuleBase_PagedContainer::restoreValueCustom()
74 {
75   // A rare case when plugin was not loaded.
76   if(!myFeature)
77     return false;
78   DataPtr aData = myFeature->data();
79   AttributeStringPtr aStringAttr = aData->string(attributeID());
80   QString aCaseId = QString::fromStdString(aStringAttr->value());
81   int idx = myCaseIds.indexOf(aCaseId);
82   if (idx == -1)
83     return false;
84   setCurrentPageIndex(idx);
85   return true;
86 }
87
88 void ModuleBase_PagedContainer::activateCustom()
89 {
90   // activate current page
91   focusTo();
92 }
93
94 bool ModuleBase_PagedContainer::storeValueCustom() const
95 {
96   // A rare case when plugin was not loaded.
97   if(!myFeature)
98     return false;
99   DataPtr aData = myFeature->data();
100   AttributeStringPtr aStringAttr = aData->string(attributeID());
101   QString aWidgetValue = myCaseIds.at(currentPageIndex());
102   aStringAttr->setValue(aWidgetValue.toStdString());
103   updateObject(myFeature); // for preview
104   return true;
105 }
106
107
108 void ModuleBase_PagedContainer::onPageChanged()
109 {
110   storeValue();
111   if (myIsFocusOnCurrentPage) focusTo();
112 }
113
114