1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <ModuleBase_PagedContainer.h>
22 #include <ModuleBase_PageBase.h>
23 #include <ModuleBase_ModelWidget.h>
24 #include <ModuleBase_Tools.h>
26 #include <ModelAPI_AttributeString.h>
30 #include <QVBoxLayout>
33 ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent,
34 const Config_WidgetAPI* theData)
35 : ModuleBase_ModelWidget(theParent, theData),
36 myIsFocusOnCurrentPage(false)
38 // it is not obligatory to be ignored when property panel tries to activate next active widget
39 // but if focus is moved to this control, it can accept it.
40 myIsObligatory = false;
43 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
47 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
48 const QString& theName, const QString& theCaseId,
49 const QPixmap& theIcon )
51 if (!myPages.count()) {
52 setDefaultValue(theCaseId.toStdString());
54 myCaseIds << theCaseId;
57 return myPages.count();
60 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
62 QList<QWidget*> aResult;
63 int anIndex = currentPageIndex();
64 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
65 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
66 aResult << eachModelWidget->getControls();
71 bool ModuleBase_PagedContainer::focusTo()
73 int anIndex = currentPageIndex();
74 if (anIndex > myPages.count())
76 return myPages[anIndex]->takeFocus();
79 void ModuleBase_PagedContainer::setHighlighted(bool)
81 //page containers should not be highlighted, do nothing
84 void ModuleBase_PagedContainer::enableFocusProcessing()
86 myIsFocusOnCurrentPage = true;
89 bool ModuleBase_PagedContainer::restoreValueCustom()
91 // A rare case when plugin was not loaded.
94 DataPtr aData = myFeature->data();
95 AttributeStringPtr aStringAttr = aData->string(attributeID());
96 QString aCaseId = QString::fromStdString(aStringAttr->value());
97 int idx = myCaseIds.indexOf(aCaseId);
100 setCurrentPageIndex(idx);
104 void ModuleBase_PagedContainer::activateCustom()
106 // activate current page
110 bool ModuleBase_PagedContainer::storeValueCustom()
112 // A rare case when plugin was not loaded.
115 DataPtr aData = myFeature->data();
116 AttributeStringPtr aStringAttr = aData->string(attributeID());
117 QString aWidgetValue = myCaseIds.at(currentPageIndex());
118 aStringAttr->setValue(aWidgetValue.toStdString());
119 updateObject(myFeature); // for preview
124 void ModuleBase_PagedContainer::onPageChanged()
128 // focus might be changed only if the value is correcly stored
129 // if it is not stored, reentrant manager will handle by this widget
130 // after it will restart operation, the widget might be removed
131 if (myIsFocusOnCurrentPage)