X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_WidgetParamsMgr.cpp;h=96e10edb14c720706a7f03058c5e5c9059301d4f;hb=f6bd0f4e080b833c0de7ef25822ebee641073445;hp=485ad91297a7ccd2b0ec05679ff71631389c9a6b;hpb=30c051954fe28016ee74f7aaf851dbdec4249d8c;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 485ad9129..96e10edb1 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: ParametersPlugin_WidgetParamsMgr.cpp -// Created: 11 Apr 2016 -// Author: Vitaly SMETANNIKOV +// 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 "ParametersPlugin_WidgetParamsMgr.h" #include "ParametersPlugin_Parameter.h" @@ -55,23 +69,23 @@ class ParametersPlugin_ItemDelegate : public QStyledItemDelegate public: /// Constructor /// \param thaParent a parent - ParametersPlugin_ItemDelegate(QObject* thaParent) : + ParametersPlugin_ItemDelegate(QObject* thaParent) : QStyledItemDelegate(thaParent) {} /// Redefinition of virtual method /// \param painter a painter object /// \param option the item options /// \param index the current index - virtual void paint(QPainter* painter, - const QStyleOptionViewItem& option, + virtual void paint(QPainter* painter, + const QStyleOptionViewItem& option, const QModelIndex& index ) const; - + /// Redefinition of virtual method /// \param parent a parent widget /// \param option the item options /// \param index the current index - virtual QWidget* createEditor(QWidget* parent, - const QStyleOptionViewItem& option, + virtual QWidget* createEditor(QWidget* parent, + const QStyleOptionViewItem& option, const QModelIndex& index) const; /// Returns True if the given index is editable item @@ -96,13 +110,14 @@ bool ParametersPlugin_ItemDelegate::isEditable(const QModelIndex& theIndex) cons return true; } -void ParametersPlugin_ItemDelegate::paint(QPainter* painter, - const QStyleOptionViewItem& option, +void ParametersPlugin_ItemDelegate::paint(QPainter* painter, + const QStyleOptionViewItem& option, const QModelIndex& index ) const { QBrush aBrush = painter->brush(); QPen aPen = painter->pen(); -// if (!isEditable(index)) + //if (!isEditable(index)) + // painter->setBrush(Qt::lightGray); if (!index.parent().isValid()) painter->setBrush(Qt::lightGray); @@ -114,8 +129,8 @@ void ParametersPlugin_ItemDelegate::paint(QPainter* painter, painter->setBrush(aBrush); } -QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent, - const QStyleOptionViewItem& option, +QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent, + const QStyleOptionViewItem& option, const QModelIndex& index) const { myEditingIdx = index; @@ -123,7 +138,7 @@ QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent, } ///////////////////////////////////////////////////////////////////////////////////////////////// -void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, +void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint) { if (theHint == QAbstractItemDelegate::EditNextItem) { @@ -159,7 +174,7 @@ void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, ///////////////////////////////////////////////////////////////////////////////////////////////// -ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, +ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelDialogWidget(theParent, theData) { @@ -168,7 +183,7 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP myTable = new ParametersPlugin_TreeWidget(this); myTable->setColumnCount(4); QStringList aHeaders; - aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment"); + aHeaders << tr("Name") << tr("Expression") << tr("Result") << tr("Comment"); myTable->setHeaderLabels(aHeaders); myTable->setColumnWidth(Col_Name, 200); myTable->setColumnWidth(Col_Equation, 100); @@ -183,7 +198,7 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP connect(myTable, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChanged())); myDelegate = new ParametersPlugin_ItemDelegate(myTable); - connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), + connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), SLOT(onCloseEditor(QWidget*, QAbstractItemDelegate::EndEditHint))); myTable->setItemDelegate(myDelegate); @@ -246,7 +261,7 @@ void ParametersPlugin_WidgetParamsMgr::selectItemScroll(QTreeWidgetItem* aItem) QModelIndex aParent = myTable->model()->index(0, 0); int aChildIdx = myParameters->indexOfChild(aItem); QModelIndex aIndex = myTable->model()->index(aChildIdx, Col_Name, aParent); - myTable->selectionModel()->select(aIndex, + myTable->selectionModel()->select(aIndex, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); myTable->scrollToItem(aItem); } @@ -296,7 +311,7 @@ void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures() int aNbFeatures = aDoc->numInternalFeatures(); for (int i = 0; i < aNbFeatures; i++) { aParamFeature = aDoc->internalFeature(i); - if (aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) { + if (aParamFeature && aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) { myParametersList.append(aParamFeature); } } @@ -328,7 +343,7 @@ QList ParametersPlugin_WidgetParamsMgr:: for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) { std::shared_ptr aAttr = (*aIt); FeaturePtr aReferenced = std::dynamic_pointer_cast(aAttr->owner()); - if (aReferenced.get()) { + if (aReferenced.get() && (aReferenced != aParameter)) { if (aReferenced->getKind() == ParametersPlugin_Parameter::ID()) { // Find referenced feature Recursive QList aList; @@ -409,7 +424,7 @@ void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex } } -void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, +void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint) { FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row()); @@ -433,12 +448,12 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, } aStringAttr->setValue(aText.toStdString()); isModified = true; - } + } } break; case Col_Equation: { - AttributeStringPtr aStringAttr = + AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID()); if (!aText.isEmpty()) { if (aText != aStringAttr->value().c_str()) { @@ -468,19 +483,19 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, if (aColumn != Col_Comment) updateParametersPart(); updateFeaturesPart(); - + onSelectionChanged(); } -void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem, +void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem, const QList& theFeaturesList) { if (theFeaturesList.count() != theItem->childCount()) { if (theItem->childCount() < theFeaturesList.count()) { - while (theItem->childCount() != theFeaturesList.count()) + while (theItem->childCount() != theFeaturesList.count()) theItem->addChild(createNewItem(theItem)); } else { - while (theItem->childCount() != theFeaturesList.count()) + while (theItem->childCount() != theFeaturesList.count()) theItem->removeChild(theItem->child(theItem->childCount() - 1)); } } @@ -519,9 +534,10 @@ QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem aValues << NoValue; QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues); - if (theParent == myParameters) + if (theParent == myParameters) { aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); - else + aItem->setForeground(2, Qt::darkGray); + } else aItem->setFlags(Qt::NoItemFlags); return aItem; } @@ -534,7 +550,7 @@ void ParametersPlugin_WidgetParamsMgr::onAdd() return; myParametersList.append(aFeature); - updateParametersPart(); + updateParametersPart(); QTreeWidgetItem* aItem = myParameters->child(myParameters->childCount() - 1); @@ -742,7 +758,7 @@ void ParametersPlugin_WidgetParamsMgr::onSelectionChanged() void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable) { myAddBtn->setEnabled(theEnable); - if (theEnable) + if (theEnable) onSelectionChanged(); else { myInsertBtn->setEnabled(theEnable); @@ -756,16 +772,14 @@ void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable) bool ParametersPlugin_WidgetParamsMgr::isValid() { QTreeWidgetItem* aItem; - bool aIsValid = true; for(int i = 0; i < myParameters->childCount(); i++) { aItem = myParameters->child(i); - if ((aItem->text(Col_Name) == NoName) || + if ((aItem->text(Col_Name) == NoName) || (aItem->text(Col_Equation) == NoValue) || (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) { - aIsValid = false; - break; + return false; } } - return aIsValid; + return true; }