From d5facc505b976ae7747635f1170015db9c04d980 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 5 Dec 2017 13:56:55 +0300 Subject: [PATCH] Edit name for group --- src/CollectionPlugin/group_widget.xml | 4 ++ src/Config/Config_Keywords.h | 1 + src/ModuleBase/CMakeLists.txt | 3 ++ src/ModuleBase/ModuleBase_ModelWidget.h | 5 ++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 4 ++ src/ModuleBase/ModuleBase_WidgetLineEdit.h | 1 - .../ModuleBase_WidgetMultiSelector.cpp | 16 ++---- .../ModuleBase_WidgetMultiSelector.h | 1 + src/ModuleBase/ModuleBase_WidgetNameEdit.cpp | 46 +++++++++++++++++ src/ModuleBase/ModuleBase_WidgetNameEdit.h | 49 +++++++++++++++++++ src/XGUI/XGUI_Workshop.cpp | 16 +++--- 11 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_WidgetNameEdit.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetNameEdit.h diff --git a/src/CollectionPlugin/group_widget.xml b/src/CollectionPlugin/group_widget.xml index 31c1c3679..fab719c41 100644 --- a/src/CollectionPlugin/group_widget.xml +++ b/src/CollectionPlugin/group_widget.xml @@ -20,6 +20,10 @@ email : webmaster.salome@opencascade.com + + #include #include +#include #include #include #include @@ -317,6 +318,9 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: } else if (theType == WDG_STRINGVALUE) { std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER ); result = new ModuleBase_WidgetLineEdit( theParent, myWidgetApi, aPlaceHolder ); + } else if (theType == WDG_NAMEVALUE) { + std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER ); + result = new ModuleBase_WidgetNameEdit( theParent, myWidgetApi, aPlaceHolder ); } else if (theType == WDG_EXPR_EDITOR) { std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER ); result = new ModuleBase_WidgetExprEditor( theParent, myWidgetApi, aPlaceHolder ); diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.h b/src/ModuleBase/ModuleBase_WidgetLineEdit.h index aee98f9f4..1ce71ef22 100644 --- a/src/ModuleBase/ModuleBase_WidgetLineEdit.h +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.h @@ -63,7 +63,6 @@ protected: /// Redefinition of virtual method virtual bool restoreValueCustom(); -private: /// A line edit control QLineEdit* myLineEdit; }; diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index fd4fd7bcb..e59721ff6 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -152,19 +153,13 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen QGridLayout* aMainLay = new QGridLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); - //QLabel* aTypeLabel = new QLabel(tr("Type"), this); - //aMainLay->addWidget(aTypeLabel, 0, 0); - - //myTypeCombo = new QComboBox(this); QStringList aIconsList = getIconsList(myShapeTypes); myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList); myTypeCtrl->setLabel(tr("Type")); myTypeCtrl->setValue(0); + aMainLay->addWidget(myTypeCtrl, 0, 0, 1, 2); // There is no sense to parameterize list of types while we can not parameterize selection mode - //if (!aShapeTypes.empty()) - // myTypeCombo->addItems(aShapeTypes); - aMainLay->addWidget(myTypeCtrl, 0, 0, 1, 2); // if the xml definition contains one type, the controls to select a type should not be shown if (myShapeTypes.size() <= 1 || !myIsUseChoice) { myTypeCtrl->setVisible(false); @@ -253,7 +248,6 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom() std::string aType = anAttribute->attributeType(); if (aType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID()); - //aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString()); aSelectionListAttr->setSelectionType(myTypeCtrl->textValue().toStdString()); } return true; @@ -505,7 +499,6 @@ bool ModuleBase_WidgetMultiSelector::processDelete() QList ModuleBase_WidgetMultiSelector::getControls() const { QList result; - //result << myTypeCombo; result << myListControl; return result; } @@ -551,6 +544,9 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() true); /// hope that something is redisplayed by object updated // clear history should follow after set selected to do not increase history by setSelected clearSelectedHistory(); + + if (myWorkshop->propertyPanel()->activeWidget() != this) + myWorkshop->propertyPanel()->activateWidget(this); } //******************************************************************** @@ -670,8 +666,6 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const int theShapeType) { QString aShapeTypeName; - //for (int idx = 0; idx < myTypeCombo->count(); ++idx) { - // aShapeTypeName = myTypeCombo->itemText(idx); int idx = 0; foreach (QString aShapeTypeName, myShapeTypes) { int aRefType = ModuleBase_Tools::shapeType(aShapeTypeName); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index ca4830e67..c8dcdf66f 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -244,6 +244,7 @@ protected: /// A container of selected objects QList > > mySelectedHistoryValues; + /// Position in a container of selected values int myCurrentHistoryIndex; }; diff --git a/src/ModuleBase/ModuleBase_WidgetNameEdit.cpp b/src/ModuleBase/ModuleBase_WidgetNameEdit.cpp new file mode 100644 index 000000000..e97666f3d --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetNameEdit.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#include + +#include + +bool ModuleBase_WidgetNameEdit::storeValueCustom() +{ + if(!myFeature) + return false; + + QString aValue = myLineEdit->text(); + myFeature->data()->setName(aValue.toStdString()); + updateObject(myFeature); + return true; +} + +bool ModuleBase_WidgetNameEdit::restoreValueCustom() +{ + if(!myFeature) + return false; + + bool isBlocked = myLineEdit->blockSignals(true); + myLineEdit->setText(QString::fromStdString(myFeature->data()->name())); + myLineEdit->blockSignals(isBlocked); + + return true; +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetNameEdit.h b/src/ModuleBase/ModuleBase_WidgetNameEdit.h new file mode 100644 index 000000000..ba090c4ab --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetNameEdit.h @@ -0,0 +1,49 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#ifndef MODULEBASE_WIDGETNAMEEDIT_H_ +#define MODULEBASE_WIDGETNAMEEDIT_H_ + +#include +#include + +class ModuleBase_WidgetNameEdit : public ModuleBase_WidgetLineEdit +{ + Q_OBJECT +public: + ModuleBase_WidgetNameEdit( QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& thePlaceHolder ) + : ModuleBase_WidgetLineEdit(theParent, theData, thePlaceHolder) {} + + /// Returns True if the widget uses feature attribute. + /// If not then it means that the widget do not need attribute at all. + virtual bool usesAttribute() const { return false; } + +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom(); + + /// Redefinition of virtual method + virtual bool restoreValueCustom(); +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 17be4e530..e3e1468c2 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -598,13 +598,15 @@ void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation) FeaturePtr aFeature = aFOperation->feature(); std::string aFeatureKind = aFeature->getKind(); foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { - if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) { - std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'."; - Events_InfoMessage("XGUI_Workshop", anErrorMsg) - .arg(aFeatureKind).arg(aWidget->attributeID()) - .arg(aWidget->metaObject()->className()).send(); - myPropertyPanel->cleanContent(); - return; + if (aWidget->usesAttribute()) { + if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) { + std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'."; + Events_InfoMessage("XGUI_Workshop", anErrorMsg) + .arg(aFeatureKind).arg(aWidget->attributeID()) + .arg(aWidget->metaObject()->className()).send(); + myPropertyPanel->cleanContent(); + return; + } } } // for performance purpose, flush should be done after all controls are filled -- 2.30.2