2 * ModuleBase_PagedContainer.cpp
4 * Created on: Mar 13, 2015
8 #include <ModuleBase_PagedContainer.h>
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_ModelWidget.h>
11 #include <ModuleBase_Tools.h>
13 #include <ModelAPI_AttributeString.h>
17 #include <QVBoxLayout>
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)
27 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
31 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
32 const QString& theName, const QString& theCaseId)
34 myCaseIds << theCaseId;
36 storeValueCustom(); // to store the initial state
37 return myPages.count();
40 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
42 QList<QWidget*> aResult;
43 int anIndex = currentPageIndex();
44 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
45 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
46 aResult << eachModelWidget->getControls();
51 bool ModuleBase_PagedContainer::focusTo()
53 int anIndex = currentPageIndex();
54 if (anIndex > myPages.count())
56 return myPages[anIndex]->takeFocus();
59 void ModuleBase_PagedContainer::setHighlighted(bool)
61 //page containers should not be highlighted, do nothing
64 void ModuleBase_PagedContainer::enableFocusProcessing()
66 myIsFocusOnCurrentPage = true;
69 bool ModuleBase_PagedContainer::restoreValue()
71 // A rare case when plugin was not loaded.
74 DataPtr aData = myFeature->data();
75 AttributeStringPtr aStringAttr = aData->string(attributeID());
76 QString aCaseId = QString::fromStdString(aStringAttr->value());
77 int idx = myCaseIds.indexOf(aCaseId);
80 setCurrentPageIndex(idx);
84 void ModuleBase_PagedContainer::activateCustom()
86 // activate current page
90 bool ModuleBase_PagedContainer::storeValueCustom() const
92 // A rare case when plugin was not loaded.
95 DataPtr aData = myFeature->data();
96 AttributeStringPtr aStringAttr = aData->string(attributeID());
97 QString aWidgetValue = myCaseIds.at(currentPageIndex());
98 aStringAttr->setValue(aWidgetValue.toStdString());
99 updateObject(myFeature); // for preview
104 void ModuleBase_PagedContainer::onPageChanged()
107 if (myIsFocusOnCurrentPage) focusTo();