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 : ModuleBase_ModelWidget(theParent, theData),
22 myIsFocusOnCurrentPage(false)
24 // it is not obligatory to be ignored when property panel tries to activate next active widget
25 // but if focus is moved to this control, it can accept it.
26 myIsObligatory = false;
29 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
33 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
34 const QString& theName, const QString& theCaseId,
35 const QPixmap& theIcon )
37 if (!myPages.count()) {
38 setDefaultValue(theCaseId.toStdString());
40 myCaseIds << theCaseId;
43 return myPages.count();
46 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
48 QList<QWidget*> aResult;
49 int anIndex = currentPageIndex();
50 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
51 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
52 aResult << eachModelWidget->getControls();
57 bool ModuleBase_PagedContainer::focusTo()
59 int anIndex = currentPageIndex();
60 if (anIndex > myPages.count())
62 return myPages[anIndex]->takeFocus();
65 void ModuleBase_PagedContainer::setHighlighted(bool)
67 //page containers should not be highlighted, do nothing
70 void ModuleBase_PagedContainer::enableFocusProcessing()
72 myIsFocusOnCurrentPage = true;
75 bool ModuleBase_PagedContainer::restoreValueCustom()
77 // A rare case when plugin was not loaded.
80 DataPtr aData = myFeature->data();
81 AttributeStringPtr aStringAttr = aData->string(attributeID());
82 QString aCaseId = QString::fromStdString(aStringAttr->value());
83 int idx = myCaseIds.indexOf(aCaseId);
86 setCurrentPageIndex(idx);
90 void ModuleBase_PagedContainer::activateCustom()
92 // activate current page
96 bool ModuleBase_PagedContainer::storeValueCustom()
98 // A rare case when plugin was not loaded.
101 DataPtr aData = myFeature->data();
102 AttributeStringPtr aStringAttr = aData->string(attributeID());
103 QString aWidgetValue = myCaseIds.at(currentPageIndex());
104 aStringAttr->setValue(aWidgetValue.toStdString());
105 updateObject(myFeature); // for preview
110 void ModuleBase_PagedContainer::onPageChanged()
113 if (myIsFocusOnCurrentPage) focusTo();