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 if (!myPages.count()) {
35 setDefaultValue(theCaseId.toStdString());
37 myCaseIds << theCaseId;
40 return myPages.count();
43 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
45 QList<QWidget*> aResult;
46 int anIndex = currentPageIndex();
47 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
48 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
49 aResult << eachModelWidget->getControls();
54 bool ModuleBase_PagedContainer::focusTo()
56 int anIndex = currentPageIndex();
57 if (anIndex > myPages.count())
59 return myPages[anIndex]->takeFocus();
62 void ModuleBase_PagedContainer::setHighlighted(bool)
64 //page containers should not be highlighted, do nothing
67 void ModuleBase_PagedContainer::enableFocusProcessing()
69 myIsFocusOnCurrentPage = true;
72 bool ModuleBase_PagedContainer::restoreValue()
74 // A rare case when plugin was not loaded.
77 DataPtr aData = myFeature->data();
78 AttributeStringPtr aStringAttr = aData->string(attributeID());
79 QString aCaseId = QString::fromStdString(aStringAttr->value());
80 int idx = myCaseIds.indexOf(aCaseId);
83 setCurrentPageIndex(idx);
87 void ModuleBase_PagedContainer::activateCustom()
89 // activate current page
93 bool ModuleBase_PagedContainer::storeValueCustom() const
95 // A rare case when plugin was not loaded.
98 DataPtr aData = myFeature->data();
99 AttributeStringPtr aStringAttr = aData->string(attributeID());
100 QString aWidgetValue = myCaseIds.at(currentPageIndex());
101 aStringAttr->setValue(aWidgetValue.toStdString());
102 updateObject(myFeature); // for preview
107 void ModuleBase_PagedContainer::onPageChanged()
110 if (myIsFocusOnCurrentPage) focusTo();