1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: ParametersPlugin_WidgetParamsMgr.cpp
4 // Created: 11 Apr 2016
5 // Author: Vitaly SMETANNIKOV
7 #include "ParametersPlugin_WidgetParamsMgr.h"
8 #include "ParametersPlugin_Parameter.h"
9 #include "ParametersPlugin_Validators.h"
11 #include <Events_InfoMessage.h>
13 #include <ModelAPI_ResultParameter.h>
14 #include <ModelAPI_AttributeString.h>
15 #include <ModelAPI_AttributeRefList.h>
16 #include <ModelAPI_AttributeDouble.h>
17 #include <ModelAPI_AttributeInteger.h>
18 #include <ModelAPI_Events.h>
19 #include <ModelAPI_Session.h>
20 #include <ModelAPI_Tools.h>
21 #include <ModelAPI_Expression.h>
23 #include <ModuleBase_Tools.h>
25 #include <Events_Loop.h>
28 #include <QPushButton>
29 #include <QToolButton>
30 #include <QStyledItemDelegate>
32 #include <QMessageBox>
36 #include <QDialogButtonBox>
45 const char* NoName = "<NoName>";
46 const char* NoValue = "<NoValue>";
47 const char* NotValid = "<NotValid>";
51 * ItemDelegate object in order to redefine items behavior
53 class ParametersPlugin_ItemDelegate : public QStyledItemDelegate
57 /// \param thaParent a parent
58 ParametersPlugin_ItemDelegate(QObject* thaParent) :
59 QStyledItemDelegate(thaParent) {}
61 /// Redefinition of virtual method
62 /// \param painter a painter object
63 /// \param option the item options
64 /// \param index the current index
65 virtual void paint(QPainter* painter,
66 const QStyleOptionViewItem& option,
67 const QModelIndex& index ) const;
69 /// Redefinition of virtual method
70 /// \param parent a parent widget
71 /// \param option the item options
72 /// \param index the current index
73 virtual QWidget* createEditor(QWidget* parent,
74 const QStyleOptionViewItem& option,
75 const QModelIndex& index) const;
77 /// Returns True if the given index is editable item
78 /// \param theIndex an item index
79 bool isEditable(const QModelIndex& theIndex) const;
81 /// Returns currently editing index
82 QModelIndex editIndex() const { return myEditingIdx; }
85 mutable QModelIndex myEditingIdx;
88 bool ParametersPlugin_ItemDelegate::isEditable(const QModelIndex& theIndex) const
90 QModelIndex aParent = theIndex.parent();
91 if (aParent.isValid() && (aParent.row() == 0)) {
92 if (theIndex.column() == 2)
99 void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
100 const QStyleOptionViewItem& option,
101 const QModelIndex& index ) const
103 QBrush aBrush = painter->brush();
104 QPen aPen = painter->pen();
105 // if (!isEditable(index))
106 if (!index.parent().isValid())
107 painter->setBrush(Qt::lightGray);
109 painter->setPen(Qt::lightGray);
110 painter->drawRect(option.rect);
111 painter->setPen(aPen);
113 QStyledItemDelegate::paint(painter, option, index);
114 painter->setBrush(aBrush);
117 QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent,
118 const QStyleOptionViewItem& option,
119 const QModelIndex& index) const
121 myEditingIdx = index;
122 return QStyledItemDelegate::createEditor(parent, option, index);
125 /////////////////////////////////////////////////////////////////////////////////////////////////
126 void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor,
127 QAbstractItemDelegate::EndEditHint theHint)
129 if (theHint == QAbstractItemDelegate::EditNextItem) {
130 QModelIndex aCurrent = currentIndex();
131 QModelIndex aParent = model()->index(0, 0);
132 int aNbRows = model()->rowCount(aParent);
134 switch (aCurrent.column()) {
136 aIdx = model()->index(aCurrent.row(), 1, aParent);
139 if (aCurrent.row() < (aNbRows - 1))
140 aIdx = model()->index(aCurrent.row() + 1, 0, aParent);
142 QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint);
147 QTreeWidget::closeEditor(theEditor, theHint);
150 if (aIdx.isValid()) {
151 QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint);
152 setCurrentIndex(aIdx);
157 QTreeWidget::closeEditor(theEditor, theHint);
160 /////////////////////////////////////////////////////////////////////////////////////////////////
162 ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent,
163 const Config_WidgetAPI* theData)
164 : ModuleBase_ModelDialogWidget(theParent, theData)
166 QVBoxLayout* aLayout = new QVBoxLayout(this);
168 myTable = new ParametersPlugin_TreeWidget(this);
169 myTable->setColumnCount(4);
170 QStringList aHeaders;
171 aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment");
172 myTable->setHeaderLabels(aHeaders);
173 myTable->setColumnWidth(Col_Name, 200);
174 myTable->setColumnWidth(Col_Equation, 100);
175 myTable->setColumnWidth(Col_Result, 80);
176 myTable->setColumnWidth(Col_Comment, 200);
177 myTable->setMinimumWidth(600);
178 myTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
179 myTable->setSelectionMode(QAbstractItemView::SingleSelection);
181 connect(myTable, SIGNAL(doubleClicked(const QModelIndex&)),
182 SLOT(onDoubleClick(const QModelIndex&)));
183 connect(myTable, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChanged()));
185 myDelegate = new ParametersPlugin_ItemDelegate(myTable);
186 connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
187 SLOT(onCloseEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
189 myTable->setItemDelegate(myDelegate);
190 aLayout->addWidget(myTable);
194 aNames<<tr("Parameters");
195 myParameters = new QTreeWidgetItem(aNames);
196 myParameters->setFlags(Qt::ItemIsEnabled);
197 myTable->addTopLevelItem(myParameters);
200 aNames<<tr("Features");
201 myFeatures = new QTreeWidgetItem(aNames);
202 myFeatures->setFlags(Qt::ItemIsEnabled);
203 myTable->addTopLevelItem(myFeatures);
205 QHBoxLayout* aBtnLayout = new QHBoxLayout(this);
207 myUpBtn = new QToolButton(this);
208 myUpBtn->setArrowType(Qt::UpArrow);
209 connect(myUpBtn, SIGNAL(clicked(bool)), SLOT(onUp()));
210 aBtnLayout->addWidget(myUpBtn);
212 myDownBtn = new QToolButton(this);
213 myDownBtn->setArrowType(Qt::DownArrow);
214 connect(myDownBtn, SIGNAL(clicked(bool)), SLOT(onDown()));
215 aBtnLayout->addWidget(myDownBtn);
217 aBtnLayout->addStretch();
219 myAddBtn = new QPushButton(tr("Add"), this);
220 connect(myAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd()));
221 aBtnLayout->addWidget(myAddBtn);
223 myInsertBtn = new QPushButton(tr("Insert"), this);
224 connect(myInsertBtn, SIGNAL(clicked(bool)), SLOT(onInsert()));
225 aBtnLayout->addWidget(myInsertBtn);
227 myRemoveBtn = new QPushButton(tr("Remove"), this);
228 connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove()));
229 aBtnLayout->addWidget(myRemoveBtn);
231 aLayout->addLayout(aBtnLayout);
233 onSelectionChanged();
236 QList<QWidget*> ParametersPlugin_WidgetParamsMgr::getControls() const
238 QList<QWidget*> aList;
243 void ParametersPlugin_WidgetParamsMgr::selectItemScroll(QTreeWidgetItem* aItem)
245 myTable->clearSelection();
246 QModelIndex aParent = myTable->model()->index(0, 0);
247 int aChildIdx = myParameters->indexOfChild(aItem);
248 QModelIndex aIndex = myTable->model()->index(aChildIdx, Col_Name, aParent);
249 myTable->selectionModel()->select(aIndex,
250 QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
251 myTable->scrollToItem(aItem);
255 bool ParametersPlugin_WidgetParamsMgr::storeValueCustom()
257 ParametersPlugin_ExpressionValidator aValidator;
258 std::list<std::string> aArgs;
259 std::string aAttrId = ParametersPlugin_Parameter::VARIABLE_ID();
260 Events_InfoMessage aErr;
262 foreach(FeaturePtr aFeature, myParametersList) {
263 if (!aValidator.isValid(aFeature->attribute(aAttrId), aArgs, aErr)) {
264 // TODO(spo): translate
265 QMessageBox::warning(this, tr("Warning"), aErr.messageString().c_str());
266 selectItemScroll(myParameters->child(aId));
274 bool ParametersPlugin_WidgetParamsMgr::restoreValueCustom()
279 void ParametersPlugin_WidgetParamsMgr::activateCustom()
281 updateParametersFeatures();
282 updateParametersPart();
283 updateFeaturesPart();
285 myFeatures->setExpanded(true);
286 myParameters->setExpanded(true);
289 void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
291 myParametersList.clear();
292 FeaturePtr aFeature = feature();
293 DocumentPtr aDoc = aFeature->document();
295 FeaturePtr aParamFeature;
296 int aNbFeatures = aDoc->numInternalFeatures();
297 for (int i = 0; i < aNbFeatures; i++) {
298 aParamFeature = aDoc->internalFeature(i);
299 if (aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
300 myParametersList.append(aParamFeature);
305 void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
307 QList<FeaturePtr> aFeatureList;
308 updateItem(myFeatures, featuresItems(myParametersList, aFeatureList));
311 void ParametersPlugin_WidgetParamsMgr::updateParametersPart()
313 updateItem(myParameters, parametersItems(myParametersList));
314 bool aIsValid = isValid();
315 enableButtons(aIsValid);
319 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
320 featuresItems(const QList<FeaturePtr>& theFeatures, QList<FeaturePtr>& theFeatureList) const
322 QList<QStringList> aItemsList;
323 ResultParameterPtr aParam;
324 foreach(FeaturePtr aParameter, theFeatures) {
325 aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParameter->firstResult());
326 const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
327 std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
328 for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
329 std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
330 FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
331 if (aReferenced.get()) {
332 if (aReferenced->getKind() == ParametersPlugin_Parameter::ID()) {
333 // Find referenced feature Recursive
334 QList<FeaturePtr> aList;
335 aList.append(aReferenced);
336 QList<QStringList> aItems = featuresItems(aList, theFeatureList);
337 aItemsList.append(aItems);
339 if (!theFeatureList.contains(aReferenced)) {
340 QStringList aValNames;
341 aValNames << aReferenced->data()->name().c_str();
343 AttributeDoublePtr aDouble =
344 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
346 aValNames << aDouble->text().c_str();
347 aValNames << QString::number(aDouble->value());
349 AttributeIntegerPtr aInt =
350 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
352 aValNames << aInt->text().c_str();
353 aValNames << QString::number(aInt->value());
356 aItemsList.append(aValNames);
357 theFeatureList.append(aReferenced);
367 QList<QStringList> ParametersPlugin_WidgetParamsMgr::
368 parametersItems(const QList<FeaturePtr>& theFeatures) const
370 std::list<std::string> aArgs;
372 QList<QStringList> aItemsList;
373 foreach(FeaturePtr aParameter, theFeatures) {
374 ResultPtr aParam = aParameter->firstResult();
377 std::string aName = aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->value();
381 aValues << aName.c_str();
383 std::string aExpr = aParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value();
387 aValues << aExpr.c_str();
390 aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
392 AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
393 aValues << QString::number(aValueAttribute->value());
395 aValues << aErr.c_str();
397 aValues << aParameter->string(ParametersPlugin_Parameter::COMMENT_ID())->value().c_str();
398 aItemsList.append(aValues);
404 void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex)
406 if (myDelegate->isEditable(theIndex)) {
407 myTable->setCurrentIndex(theIndex);
408 myTable->edit(theIndex);
412 void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
413 QAbstractItemDelegate::EndEditHint theHint)
415 FeaturePtr aFeature = myParametersList.at(myDelegate->editIndex().row());
416 QTreeWidgetItem* aItem = myParameters->child(myDelegate->editIndex().row());
417 int aColumn = myDelegate->editIndex().column();
418 QString aText = aItem->text(aColumn);
419 bool isModified = false;
424 AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::VARIABLE_ID());
425 if (!aText.isEmpty()) {
426 while (aText.indexOf(" ") != -1) {
427 aText.replace(" ", "");
429 if (hasName(aText)) {
430 myMessage = tr("Name '%1' already exists.").arg(aText);
431 QTimer::singleShot(50, this, SLOT(sendWarning()));
434 aStringAttr->setValue(aText.toStdString());
441 AttributeStringPtr aStringAttr =
442 aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID());
443 if (!aText.isEmpty()) {
444 if (aText != aStringAttr->value().c_str()) {
445 aStringAttr->setValue(aText.toStdString());
454 AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::COMMENT_ID());
455 aStringAttr->setValue(aText.toStdString());
463 Events_Loop* aLoop = Events_Loop::loop();
464 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
465 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
466 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
468 if (aColumn != Col_Comment)
469 updateParametersPart();
470 updateFeaturesPart();
472 onSelectionChanged();
475 void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem,
476 const QList<QStringList>& theFeaturesList)
478 if (theFeaturesList.count() != theItem->childCount()) {
479 if (theItem->childCount() < theFeaturesList.count()) {
480 while (theItem->childCount() != theFeaturesList.count())
481 theItem->addChild(createNewItem(theItem));
483 while (theItem->childCount() != theFeaturesList.count())
484 theItem->removeChild(theItem->child(theItem->childCount() - 1));
488 foreach(QStringList aFeature, theFeaturesList) {
490 foreach(QString aText, aFeature) {
491 if (aText.length() > 0) {
492 theItem->child(i)->setText(aCol, aText);
493 theItem->child(i)->setToolTip(aCol, aText);
501 FeaturePtr ParametersPlugin_WidgetParamsMgr::createParameter() const
503 SessionPtr aMgr = ModelAPI_Session::get();
504 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
506 FeaturePtr aFeature = aDoc->addFeature(ParametersPlugin_Parameter::ID());
507 if (aFeature.get()) {
508 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
509 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
515 QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::createNewItem(QTreeWidgetItem* theParent) const
521 QTreeWidgetItem* aItem = new QTreeWidgetItem(aValues);
522 if (theParent == myParameters)
523 aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
525 aItem->setFlags(Qt::NoItemFlags);
530 void ParametersPlugin_WidgetParamsMgr::onAdd()
532 FeaturePtr aFeature = createParameter();
536 myParametersList.append(aFeature);
537 updateParametersPart();
539 QTreeWidgetItem* aItem = myParameters->child(myParameters->childCount() - 1);
541 myTable->scrollToItem(aItem);
542 myTable->setCurrentItem(aItem);
543 myTable->editItem(aItem);
545 enableButtons(false);
548 QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::selectedItem() const
550 QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
551 if (aItemsList.count() == 0)
554 QTreeWidgetItem* aCurrentItem = aItemsList.first();
555 if (aCurrentItem->parent() != myParameters)
562 void ParametersPlugin_WidgetParamsMgr::onInsert()
564 QTreeWidgetItem* aCurrentItem = selectedItem();
568 SessionPtr aMgr = ModelAPI_Session::get();
569 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
571 FeaturePtr aNewFeature = createParameter();
572 if (!aNewFeature.get())
575 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
576 if (aCurrentPos == 0) {
577 aDoc->moveFeature(aNewFeature, FeaturePtr());
579 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos - 1);
580 aDoc->moveFeature(aNewFeature, aCurFeature);
582 updateParametersFeatures();
583 updateParametersPart();
585 myTable->scrollToItem(aCurrentItem);
586 myTable->setCurrentItem(aCurrentItem);
587 myTable->editItem(aCurrentItem);
590 void ParametersPlugin_WidgetParamsMgr::onRemove()
592 QTreeWidgetItem* aCurrentItem = selectedItem();
596 SessionPtr aMgr = ModelAPI_Session::get();
597 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
599 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
600 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
602 QObjectPtrList anObjects;
603 anObjects.append(aCurFeature);
605 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
606 std::set<FeaturePtr> aFeatures;
607 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
608 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
610 std::set<FeaturePtr> aFeatureRefsToDelete;
611 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, this, aFeatureRefsToDelete)) {
612 if (!aFeatureRefsToDelete.empty())
613 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
614 ModelAPI_Tools::removeFeatures(aFeatures, false);
616 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
617 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
618 updateParametersFeatures();
619 updateFeaturesPart();
620 updateParametersPart();
624 void ParametersPlugin_WidgetParamsMgr::onUp()
626 QTreeWidgetItem* aCurrentItem = selectedItem();
630 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
631 if (aCurrentPos == 0)
633 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
635 SessionPtr aMgr = ModelAPI_Session::get();
636 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
638 if (aCurrentPos == 1)
639 aDoc->moveFeature(aCurFeature, FeaturePtr());
641 aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos - 2));
643 // add the updated also the feature that goes down
644 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
645 static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
646 ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos - 1), EVENT_UPD);
647 Events_Loop::loop()->flush(EVENT_UPD);
648 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
649 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
650 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
651 updateParametersFeatures();
652 updateParametersPart();
653 updateFeaturesPart();
655 if (aCurrentPos > 0) {
656 aCurrentItem = myParameters->child(aCurrentPos - 1);
657 myTable->setCurrentItem(aCurrentItem);
658 selectItemScroll(aCurrentItem);
662 void ParametersPlugin_WidgetParamsMgr::onDown()
664 QTreeWidgetItem* aCurrentItem = selectedItem();
668 int aCurrentPos = myParameters->indexOfChild(aCurrentItem);
669 if (aCurrentPos == (myParametersList.count() - 1))
671 FeaturePtr aCurFeature = myParametersList.at(aCurrentPos);
673 SessionPtr aMgr = ModelAPI_Session::get();
674 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
675 aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos + 1));
676 // add the updated also the feature that goes up
677 static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
678 ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos + 1), EVENT_UPD);
680 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
681 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
682 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
683 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
684 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
685 updateParametersFeatures();
686 updateParametersPart();
687 updateFeaturesPart();
689 if (aCurrentPos < myParameters->childCount() - 1) {
690 aCurrentItem = myParameters->child(aCurrentPos + 1);
691 myTable->setCurrentItem(aCurrentItem);
692 selectItemScroll(aCurrentItem);
697 bool ParametersPlugin_WidgetParamsMgr::hasName(const QString& theName) const
699 int aCurrent = myDelegate->editIndex().row();
701 foreach(FeaturePtr aFeature, myParametersList) {
702 if ((i != aCurrent) && (aFeature->data()->name() == theName.toStdString()))
709 void ParametersPlugin_WidgetParamsMgr::sendWarning()
711 QMessageBox::warning(this, tr("Warning"), myMessage);
712 QTreeWidgetItem* aItem = myTable->currentItem();
714 myTable->editItem(aItem);
717 void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
719 QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
720 bool aIsValid = isValid();
722 bool isParameter = false;
723 foreach(QTreeWidgetItem* aItem, aItemsList) {
724 if (aItem->parent() == myParameters) {
729 myInsertBtn->setEnabled(isParameter);
730 //myRemoveBtn->setEnabled(isParameter);
731 myUpBtn->setEnabled(isParameter);
732 myDownBtn->setEnabled(isParameter);
734 myInsertBtn->setEnabled(false);
735 //myRemoveBtn->setEnabled(false);
736 myUpBtn->setEnabled(false);
737 myDownBtn->setEnabled(false);
739 myRemoveBtn->setEnabled(!aItemsList.isEmpty());
742 void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
744 myAddBtn->setEnabled(theEnable);
746 onSelectionChanged();
748 myInsertBtn->setEnabled(theEnable);
749 //myRemoveBtn->setEnabled(theEnable);
750 myUpBtn->setEnabled(theEnable);
751 myDownBtn->setEnabled(theEnable);
753 myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
756 bool ParametersPlugin_WidgetParamsMgr::isValid()
758 QTreeWidgetItem* aItem;
759 bool aIsValid = true;
760 for(int i = 0; i < myParameters->childCount(); i++) {
761 aItem = myParameters->child(i);
762 if ((aItem->text(Col_Name) == NoName) ||
763 (aItem->text(Col_Equation) == NoValue) ||
764 (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {