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)
25 // it is not obligatory to be ignored when property panel tries to activate next active widget
26 // but if focus is moved to this control, it can accept it.
27 myIsObligatory = false;
30 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
34 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
35 const QString& theName, const QString& theCaseId,
36 const QPixmap& theIcon )
38 if (!myPages.count()) {
39 setDefaultValue(theCaseId.toStdString());
41 myCaseIds << theCaseId;
44 return myPages.count();
47 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
49 QList<QWidget*> aResult;
50 int anIndex = currentPageIndex();
51 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
52 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
53 aResult << eachModelWidget->getControls();
58 bool ModuleBase_PagedContainer::focusTo()
60 int anIndex = currentPageIndex();
61 if (anIndex > myPages.count())
63 return myPages[anIndex]->takeFocus();
66 void ModuleBase_PagedContainer::setHighlighted(bool)
68 //page containers should not be highlighted, do nothing
71 void ModuleBase_PagedContainer::enableFocusProcessing()
73 myIsFocusOnCurrentPage = true;
76 bool ModuleBase_PagedContainer::restoreValueCustom()
78 // A rare case when plugin was not loaded.
81 DataPtr aData = myFeature->data();
82 AttributeStringPtr aStringAttr = aData->string(attributeID());
83 QString aCaseId = QString::fromStdString(aStringAttr->value());
84 int idx = myCaseIds.indexOf(aCaseId);
87 setCurrentPageIndex(idx);
91 void ModuleBase_PagedContainer::activateCustom()
93 // activate current page
97 bool ModuleBase_PagedContainer::storeValueCustom() const
99 // A rare case when plugin was not loaded.
102 DataPtr aData = myFeature->data();
103 AttributeStringPtr aStringAttr = aData->string(attributeID());
104 QString aWidgetValue = myCaseIds.at(currentPageIndex());
105 aStringAttr->setValue(aWidgetValue.toStdString());
106 updateObject(myFeature); // for preview
111 void ModuleBase_PagedContainer::onPageChanged()
114 if (myIsFocusOnCurrentPage) focusTo();