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,
33 const QPixmap& theIcon )
35 if (!myPages.count()) {
36 setDefaultValue(theCaseId.toStdString());
38 myCaseIds << theCaseId;
41 return myPages.count();
44 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
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();
55 bool ModuleBase_PagedContainer::focusTo()
57 int anIndex = currentPageIndex();
58 if (anIndex > myPages.count())
60 return myPages[anIndex]->takeFocus();
63 void ModuleBase_PagedContainer::setHighlighted(bool)
65 //page containers should not be highlighted, do nothing
68 void ModuleBase_PagedContainer::enableFocusProcessing()
70 myIsFocusOnCurrentPage = true;
73 bool ModuleBase_PagedContainer::restoreValueCustom()
75 // A rare case when plugin was not loaded.
78 DataPtr aData = myFeature->data();
79 AttributeStringPtr aStringAttr = aData->string(attributeID());
80 QString aCaseId = QString::fromStdString(aStringAttr->value());
81 int idx = myCaseIds.indexOf(aCaseId);
84 setCurrentPageIndex(idx);
88 void ModuleBase_PagedContainer::activateCustom()
90 // activate current page
94 bool ModuleBase_PagedContainer::storeValueCustom() const
96 // A rare case when plugin was not loaded.
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
108 void ModuleBase_PagedContainer::onPageChanged()
111 if (myIsFocusOnCurrentPage) focusTo();