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 static QMap<std::string, std::string> defaultValues;
35 ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent,
36 const Config_WidgetAPI* theData)
37 : ModuleBase_ModelWidget(theParent, theData),
38 myIsFocusOnCurrentPage(false), myIsFirst(true), myRemeberChoice(true)
40 // it is not obligatory to be ignored when property panel tries to activate next active widget
41 // but if focus is moved to this control, it can accept it.
42 myIsObligatory = false;
43 if (defaultValues.contains(myFeatureId + attributeID()))
44 myDefValue = defaultValues[myFeatureId + attributeID()];
47 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
51 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
52 const QString& theName, const QString& theCaseId,
53 const QPixmap& theIcon,
54 const QString& theTooltip)
56 if (!myPages.count()) {
57 setDefaultValue(theCaseId.toStdString());
59 myCaseIds << theCaseId;
62 return myPages.count();
65 QList<QWidget*> ModuleBase_PagedContainer::getControls() const
67 QList<QWidget*> aResult;
68 int anIndex = currentPageIndex();
69 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
70 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
71 aResult << eachModelWidget->getControls();
76 bool ModuleBase_PagedContainer::focusTo()
78 int anIndex = currentPageIndex();
79 if (anIndex > myPages.count())
81 return myPages[anIndex]->takeFocus();
84 void ModuleBase_PagedContainer::setHighlighted(bool)
86 //page containers should not be highlighted, do nothing
89 void ModuleBase_PagedContainer::enableFocusProcessing()
91 myIsFocusOnCurrentPage = true;
94 bool ModuleBase_PagedContainer::restoreValueCustom()
96 // A rare case when plugin was not loaded.
100 std::string aDefVal = myRemeberChoice? myDefValue : "";
102 DataPtr aData = myFeature->data();
103 AttributeStringPtr aStringAttr = aData->string(attributeID());
105 if (aStringAttr->isInitialized()) {
107 aCaseId = QString::fromStdString(aStringAttr->value());
109 aCaseId = QString::fromStdString(aDefVal.empty() ? aStringAttr->value() : aDefVal);
111 int idx = myCaseIds.indexOf(aCaseId);
113 idx = currentPageIndex();
114 setCurrentPageIndex(idx);
117 // It is added because if user edits the feature created from Python
118 // and switches his choice
119 // it will not be stored in the attribute while apply not pressed.
120 // But this button will be disabled because of not initialized attribute
121 aStringAttr->setValue(myCaseIds.at(0).toStdString());
122 setCurrentPageIndex(0);
127 void ModuleBase_PagedContainer::activateCustom()
129 // activate current page
133 bool ModuleBase_PagedContainer::storeValueCustom()
135 // A rare case when plugin was not loaded.
138 DataPtr aData = myFeature->data();
140 AttributeStringPtr aStringAttr = aData->string(attributeID());
141 std::string aWidgetValue;
143 aWidgetValue = myDefValue.empty()?
144 myCaseIds.at(currentPageIndex()).toStdString() : myDefValue;
146 aWidgetValue = myCaseIds.at(currentPageIndex()).toStdString();
147 myDefValue = aWidgetValue;
148 aStringAttr->setValue(aWidgetValue);
152 updateObject(myFeature); // for preview
157 void ModuleBase_PagedContainer::onPageChanged()
161 // focus might be changed only if the value is correcly stored
162 // if it is not stored, reentrant manager will handle by this widget
163 // after it will restart operation, the widget might be removed
164 if (myIsFocusOnCurrentPage)
168 void ModuleBase_PagedContainer::onFeatureAccepted()
171 defaultValues[myFeatureId + attributeID()] = myDefValue;