1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 * ModuleBase_PagedContainer.cpp
5 * Created on: Mar 13, 2015
9 #include <ModuleBase_PagedContainer.h>
10 #include <ModuleBase_PageBase.h>
11 #include <ModuleBase_ModelWidget.h>
12 #include <ModuleBase_Tools.h>
14 #include <ModelAPI_AttributeString.h>
18 #include <QVBoxLayout>
21 ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent,
22 const Config_WidgetAPI* theData)
23 : ModuleBase_ModelWidget(theParent, theData),
24 myIsFocusOnCurrentPage(false)
26 // it is not obligatory to be ignored when property panel tries to activate next active widget
27 // but if focus is moved to this control, it can accept it.
28 myIsObligatory = false;
31 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
35 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
36 const QString& theName, const QString& theCaseId,
37 const QPixmap& theIcon )
39 if (!myPages.count()) {
40 setDefaultValue(theCaseId.toStdString());
42 myCaseIds << theCaseId;
45 return myPages.count();
48 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
50 QList<QWidget*> aResult;
51 int anIndex = currentPageIndex();
52 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
53 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
54 aResult << eachModelWidget->getControls();
59 bool ModuleBase_PagedContainer::focusTo()
61 int anIndex = currentPageIndex();
62 if (anIndex > myPages.count())
64 return myPages[anIndex]->takeFocus();
67 void ModuleBase_PagedContainer::setHighlighted(bool)
69 //page containers should not be highlighted, do nothing
72 void ModuleBase_PagedContainer::enableFocusProcessing()
74 myIsFocusOnCurrentPage = true;
77 bool ModuleBase_PagedContainer::restoreValueCustom()
79 // A rare case when plugin was not loaded.
82 DataPtr aData = myFeature->data();
83 AttributeStringPtr aStringAttr = aData->string(attributeID());
84 QString aCaseId = QString::fromStdString(aStringAttr->value());
85 int idx = myCaseIds.indexOf(aCaseId);
88 setCurrentPageIndex(idx);
92 void ModuleBase_PagedContainer::activateCustom()
94 // activate current page
98 bool ModuleBase_PagedContainer::storeValueCustom()
100 // A rare case when plugin was not loaded.
103 DataPtr aData = myFeature->data();
104 AttributeStringPtr aStringAttr = aData->string(attributeID());
105 QString aWidgetValue = myCaseIds.at(currentPageIndex());
106 aStringAttr->setValue(aWidgetValue.toStdString());
107 updateObject(myFeature); // for preview
112 void ModuleBase_PagedContainer::onPageChanged()
116 // focus might be changed only if the value is correcly stored
117 // if it is not stored, reentrant manager will handle by this widget
118 // after it will restart operation, the widget might be removed
119 if (myIsFocusOnCurrentPage)