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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * ModuleBase_PagedContainer.cpp
23 * Created on: Mar 13, 2015
27 #include <ModuleBase_PagedContainer.h>
28 #include <ModuleBase_PageBase.h>
29 #include <ModuleBase_ModelWidget.h>
30 #include <ModuleBase_Tools.h>
32 #include <ModelAPI_AttributeString.h>
36 #include <QVBoxLayout>
39 ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent,
40 const Config_WidgetAPI* theData)
41 : ModuleBase_ModelWidget(theParent, theData),
42 myIsFocusOnCurrentPage(false)
44 // it is not obligatory to be ignored when property panel tries to activate next active widget
45 // but if focus is moved to this control, it can accept it.
46 myIsObligatory = false;
49 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
53 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
54 const QString& theName, const QString& theCaseId,
55 const QPixmap& theIcon )
57 if (!myPages.count()) {
58 setDefaultValue(theCaseId.toStdString());
60 myCaseIds << theCaseId;
63 return myPages.count();
66 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
68 QList<QWidget*> aResult;
69 int anIndex = currentPageIndex();
70 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
71 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
72 aResult << eachModelWidget->getControls();
77 bool ModuleBase_PagedContainer::focusTo()
79 int anIndex = currentPageIndex();
80 if (anIndex > myPages.count())
82 return myPages[anIndex]->takeFocus();
85 void ModuleBase_PagedContainer::setHighlighted(bool)
87 //page containers should not be highlighted, do nothing
90 void ModuleBase_PagedContainer::enableFocusProcessing()
92 myIsFocusOnCurrentPage = true;
95 bool ModuleBase_PagedContainer::restoreValueCustom()
97 // A rare case when plugin was not loaded.
100 DataPtr aData = myFeature->data();
101 AttributeStringPtr aStringAttr = aData->string(attributeID());
102 QString aCaseId = QString::fromStdString(aStringAttr->value());
103 int idx = myCaseIds.indexOf(aCaseId);
106 setCurrentPageIndex(idx);
110 void ModuleBase_PagedContainer::activateCustom()
112 // activate current page
116 bool ModuleBase_PagedContainer::storeValueCustom()
118 // A rare case when plugin was not loaded.
121 DataPtr aData = myFeature->data();
122 AttributeStringPtr aStringAttr = aData->string(attributeID());
123 QString aWidgetValue = myCaseIds.at(currentPageIndex());
124 aStringAttr->setValue(aWidgetValue.toStdString());
125 updateObject(myFeature); // for preview
130 void ModuleBase_PagedContainer::onPageChanged()
134 // focus might be changed only if the value is correcly stored
135 // if it is not stored, reentrant manager will handle by this widget
136 // after it will restart operation, the widget might be removed
137 if (myIsFocusOnCurrentPage)