X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FCollectionPlugin%2FCollectionPlugin_WidgetField.cpp;h=f1a5109eff7776b5efcb25e149698b1e29a4e433;hb=refs%2Fheads%2FCR35150;hp=80f3e3d683e9f15afc10c6255e5f21b050c4689a;hpb=d1c3a1eb0a508414fbf1876787f522efb43700c5;p=modules%2Fshaper.git diff --git a/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp b/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp index 80f3e3d68..f1a5109ef 100644 --- a/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp +++ b/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp @@ -1,19 +1,30 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: CollectionPlugin_WidgetField.cpp -// Created: 16 Nov 2016 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-2023 CEA, EDF +// +// 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 "CollectionPlugin_WidgetField.h" #include "CollectionPlugin_Field.h" #include #include +#include #include - -#include -#include -#include +#include #include #include @@ -32,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -43,36 +53,22 @@ const char* MYFirstCol = "Shape"; const char* MYTrue = "True"; const char* MYFalse = "False"; -class DataTableItemDelegate : public QStyledItemDelegate +DataTableItemDelegate::DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType) + : QStyledItemDelegate(), myType(theType) { -public: - DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType) : - QStyledItemDelegate() { myType = theType; } - - virtual QWidget* createEditor(QWidget* theParent, - const QStyleOptionViewItem & theOption, - const QModelIndex& theIndex) const; - - ModelAPI_AttributeTables::ValueType dataType() const { return myType; } - - void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; } - -signals: - void startEditing(); +} -private: - ModelAPI_AttributeTables::ValueType myType; -}; QWidget* DataTableItemDelegate::createEditor(QWidget* theParent, const QStyleOptionViewItem & theOption, const QModelIndex& theIndex ) const { + QWidget* aEditor = 0; if ((theIndex.column() == 0) && (theIndex.row() > 0)) { QWidget* aWgt = QStyledItemDelegate::createEditor(theParent, theOption, theIndex); QLineEdit* aEdt = static_cast(aWgt); aEdt->setReadOnly(true); - return aEdt; + aEditor = aEdt; } else { QLineEdit* aLineEdt = 0; switch (myType) { @@ -82,7 +78,7 @@ QWidget* DataTableItemDelegate::createEditor(QWidget* theParent, theIndex)); if (aLineEdt) { aLineEdt->setValidator(new QDoubleValidator(aLineEdt)); - return aLineEdt; + aEditor = aLineEdt; } break; case ModelAPI_AttributeTables::INTEGER: @@ -91,7 +87,7 @@ QWidget* DataTableItemDelegate::createEditor(QWidget* theParent, theIndex)); if (aLineEdt) { aLineEdt->setValidator(new QIntValidator(aLineEdt)); - return aLineEdt; + aEditor = aLineEdt; } break; case ModelAPI_AttributeTables::BOOLEAN: @@ -99,11 +95,26 @@ QWidget* DataTableItemDelegate::createEditor(QWidget* theParent, QComboBox* aBox = new QComboBox(theParent); aBox->addItem(MYFalse); aBox->addItem(MYTrue); - return aBox; + aEditor = aBox; } + break; + default: + aEditor = QStyledItemDelegate::createEditor(theParent, theOption, theIndex); } } - return QStyledItemDelegate::createEditor(theParent, theOption, theIndex); + if (myType == ModelAPI_AttributeTables::BOOLEAN) + connect(aEditor, SIGNAL(currentTextChanged(const QString&)), + SLOT(onEditItem(const QString&))); + else + connect(aEditor, SIGNAL(textEdited(const QString&)), + SLOT(onEditItem(const QString&))); + return aEditor; +} + +void DataTableItemDelegate::onEditItem(const QString& theText) +{ + QWidget* aWgt = dynamic_cast(sender()); + commitData(aWgt); } @@ -184,6 +195,11 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), myCompNamesList << "Comp 1"; myStepWgt = new QStackedWidget(aStepFrame); aStepLayout->addWidget(myStepWgt, 2, 0, 1, 2); + + myDelegate = + new DataTableItemDelegate((ModelAPI_AttributeTables::ValueType) + myFieldTypeCombo->currentIndex()); + appendStepControls(); // Buttons below @@ -228,12 +244,7 @@ void CollectionPlugin_WidgetField::appendStepControls() // Data table QTableWidget* aDataTbl = new QTableWidget(1, myCompNamesList.count() + 1, aWidget); aDataTbl->installEventFilter(this); - DataTableItemDelegate* aDelegate = 0; - if (myDataTblList.isEmpty()) - aDelegate = new DataTableItemDelegate( - (ModelAPI_AttributeTables::ValueType) myFieldTypeCombo->currentIndex()); - else - aDelegate = dynamic_cast(myDataTblList.first()->itemDelegate()); + aDataTbl->setItemDelegate(myDelegate); QIntList aColWidth; if (!myDataTblList.isEmpty()) { @@ -241,7 +252,6 @@ void CollectionPlugin_WidgetField::appendStepControls() for (int i = 0; i < aFirstTable->columnCount(); i++) aColWidth.append(aFirstTable->columnWidth(i)); } - aDataTbl->setItemDelegate(aDelegate); myDataTblList.append(aDataTbl); aDataTbl->verticalHeader()->hide(); @@ -266,13 +276,14 @@ void CollectionPlugin_WidgetField::appendStepControls() } if (aColWidth.length() > 0) { - for (int i = 0; i < aDataTbl->columnCount(); i++) + for (int i = 0; i < aDataTbl->columnCount(); i++) { + if (i < aColWidth.size()) aDataTbl->setColumnWidth(i, aColWidth.at(i)); + } } aStepLayout->addWidget(aDataTbl, 1, 0, 1, 2); connect(aDataTbl, SIGNAL(cellChanged(int, int)), SLOT(onTableEdited(int, int))); - QAbstractItemDelegate* aDel = aDataTbl->itemDelegate(); myStepWgt->addWidget(aWidget); aDataTbl->horizontalHeader()->viewport()->installEventFilter(this); } @@ -356,8 +367,7 @@ bool CollectionPlugin_WidgetField::eventFilter(QObject* theObject, QEvent* theEv } else if (theEvent->type() == QEvent::FocusIn) { QTableWidget* aTable = dynamic_cast(theObject); if (aTable) { - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); - XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); + ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel(); if (aPanel->activeWidget() != this) { myActivation = true; aPanel->activateWidget(this, false); @@ -438,9 +448,14 @@ QList CollectionPlugin_WidgetField::getControls() const { QList aControls; // this control will accept focus and will be highlighted in the Property Panel - aControls.push_back(myShapeTypeCombo); - aControls.push_back(myFieldTypeCombo); - aControls.push_back(myNbComponentsSpn); + aControls.append(myShapeTypeCombo); + aControls.append(myFieldTypeCombo); + aControls.append(myNbComponentsSpn); + if (myStampSpnList.size() > 0) + aControls.append(myStampSpnList.first()); + if (myDataTblList.size() > 0) + aControls.append(myDataTblList.first()); + return aControls; } @@ -483,7 +498,6 @@ bool CollectionPlugin_WidgetField::storeValueCustom() } } } - updateObject(myFeature); return true; } @@ -497,7 +511,9 @@ bool CollectionPlugin_WidgetField::restoreValueCustom() std::string aTypeStr = aSelList->selectionType(); if (aTypeStr == "") return false; // The attribute is not initialized + isBlocked = myShapeTypeCombo->blockSignals(true); myShapeTypeCombo->setCurrentIndex(getSelectionType(aTypeStr)); + myShapeTypeCombo->blockSignals(isBlocked); // Get number of components AttributeStringArrayPtr aStringsAttr = @@ -534,6 +550,7 @@ bool CollectionPlugin_WidgetField::restoreValueCustom() isBlocked = myFieldTypeCombo->blockSignals(true); myFieldTypeCombo->setCurrentIndex(aTablesAttr->type()); myFieldTypeCombo->blockSignals(isBlocked); + myDelegate->setDataType(aTablesAttr->type()); AttributeIntArrayPtr aStampsAttr = aData->intArray(CollectionPlugin_Field::STAMPS_ID()); // Fill data table @@ -552,6 +569,8 @@ bool CollectionPlugin_WidgetField::restoreValueCustom() QTableWidget* aTable = myDataTblList.at(i); isBlocked = aTable->blockSignals(true); aTable->setRowCount(aRows); + aTable->setColumnCount(aCols + 1); + updateHeaders(aTable); for (int j = 0; j < aCols + 1; j++) { for (int k = 0; k < aRows; k++) { aItem = aTable->item(k, j); @@ -559,9 +578,9 @@ bool CollectionPlugin_WidgetField::restoreValueCustom() // Add selection names AttributeSelectionPtr aAttr = aSelList->value(k - 1); if (aItem) { - aItem->setText(aAttr->namingName().c_str()); + aItem->setText(QString::fromStdWString(aAttr->namingName())); } else { - aItem = new QTableWidgetItem(aAttr->namingName().c_str()); + aItem = new QTableWidgetItem(QString::fromStdWString(aAttr->namingName())); aTable->setItem(k, j, aItem); } } else if (j > 0) { @@ -579,8 +598,10 @@ bool CollectionPlugin_WidgetField::restoreValueCustom() } } // Restore columns width - for (int i = 0; i < aTable->columnCount(); i++) - aTable->setColumnWidth(i, aColWidth.at(i)); + for (int col = 0; col < aTable->columnCount(); col++) { + if (col < aColWidth.size()) + aTable->setColumnWidth(col, aColWidth.at(col)); + } aTable->blockSignals(isBlocked); } @@ -748,8 +769,8 @@ void CollectionPlugin_WidgetField::onAddStep() aTable->setItem(j, i, aItem); } AttributeSelectionPtr aAttr = aSelList->value(j - 1); - aItem->setText(aAttr->namingName().c_str()); - aItem->setToolTip(aAttr->namingName().c_str()); + aItem->setText(QString::fromStdWString(aAttr->namingName())); + aItem->setToolTip(QString::fromStdWString(aAttr->namingName())); } } else { QString aDefVal = aTable->item(0, i)->text(); @@ -763,6 +784,7 @@ void CollectionPlugin_WidgetField::onAddStep() } } } + emit valuesChanged(); } //********************************************************************************** @@ -774,8 +796,9 @@ void CollectionPlugin_WidgetField::onRemoveStep() removeStepControls(); myStepSlider->setMaximum(aMax); - AttributeTablesPtr aTablesAttr = myFeature->data()->tables(CollectionPlugin_Field::VALUES_ID()); - aTablesAttr->setSize(aTablesAttr->rows(), aTablesAttr->columns(), myDataTblList.size()); + //AttributeTablesPtr aTablesAttr = myFeature->data()->tables(CollectionPlugin_Field::VALUES_ID()); + //aTablesAttr->setSize(aTablesAttr->rows(), aTablesAttr->columns(), myDataTblList.size()); + emit valuesChanged(); } //********************************************************************************** @@ -801,21 +824,29 @@ bool CollectionPlugin_WidgetField:: } //********************************************************************************** -void CollectionPlugin_WidgetField::onSelectionChanged() +bool CollectionPlugin_WidgetField:: + setSelection(QList>& theValues, const bool theToValidate) { - //if (isEditingMode()) - // return; - if (myActivation) { myActivation = false; - return; + return false; } // Ignore selection for Parts mode if (myShapeTypeCombo->currentIndex() == 5) - return; - - QList aSelected = getFilteredSelected(); - + return false; + + QList aSelected; + QList::const_iterator anIt; + for (anIt = theValues.begin(); anIt != theValues.end(); anIt++) { + ModuleBase_ViewerPrsPtr aValue = *anIt; + ResultPtr aRes = std::dynamic_pointer_cast(aValue->object()); + if (theToValidate && aRes.get()) { + if (myShapeTypeCombo->currentIndex() > 3) + aSelected.append(aValue); + else if (acceptSubShape(aValue->shape(), aRes)) + aSelected.append(aValue); + } + } AttributeSelectionListPtr aSelList = myFeature->data()->selectionList(CollectionPlugin_Field::SELECTED_ID()); aSelList->setSelectionType(getSelectionType(myShapeTypeCombo->currentIndex())); @@ -854,8 +885,8 @@ void CollectionPlugin_WidgetField::onSelectionChanged() aTable->setItem(j, i, aItem); } AttributeSelectionPtr aAttr = aSelList->value(j - 1); - aItem->setText(aAttr->namingName().c_str()); - aItem->setToolTip(aAttr->namingName().c_str()); + aItem->setText(QString::fromStdWString(aAttr->namingName())); + aItem->setToolTip(QString::fromStdWString(aAttr->namingName())); } } else { QString aDefVal = aTable->item(0, i)->text(); @@ -873,48 +904,41 @@ void CollectionPlugin_WidgetField::onSelectionChanged() // Update only selection name for(int j = 1; j < aNewRows - 1; j++) { AttributeSelectionPtr aAttr = aSelList->value(j); - aTable->item(j, 0)->setText(aAttr->namingName().c_str()); - aTable->item(j, 0)->setToolTip(aAttr->namingName().c_str()); + aTable->item(j, 0)->setText(QString::fromStdWString(aAttr->namingName())); + aTable->item(j, 0)->setToolTip(QString::fromStdWString(aAttr->namingName())); } } } - emit valuesChanged(); + return true; } //********************************************************************************** void CollectionPlugin_WidgetField::onFieldTypeChanged(int theIdx) { - DataTableItemDelegate* aDelegate = 0; - aDelegate = dynamic_cast(myDataTblList.first()->itemDelegate()); - if (aDelegate) { - ModelAPI_AttributeTables::ValueType aOldType = aDelegate->dataType(); - if (aOldType != theIdx) { - aDelegate->setDataType((ModelAPI_AttributeTables::ValueType)theIdx); - int aColumns = myDataTblList.first()->columnCount(); - int aRows = myDataTblList.first()->rowCount(); - foreach(QTableWidget* aTable, myDataTblList) { - for(int i = 1; i < aColumns; i++) { - for(int j = 0; j < aRows; j++) { - switch (theIdx) { - case ModelAPI_AttributeTables::DOUBLE: - case ModelAPI_AttributeTables::INTEGER: - if ((aOldType == ModelAPI_AttributeTables::BOOLEAN) || - (aOldType == ModelAPI_AttributeTables::STRING)) { - aTable->item(j, i)->setText("0"); - } - break; - case ModelAPI_AttributeTables::BOOLEAN: - aTable->item(j, i)->setText(MYFalse); - break; - case ModelAPI_AttributeTables::STRING: - aTable->item(j, i)->setText(""); - break; - } + ModelAPI_AttributeTables::ValueType aOldType = myDelegate->dataType(); + if (aOldType != theIdx) { + myDelegate->setDataType((ModelAPI_AttributeTables::ValueType)theIdx); + int aColumns = myDataTblList.first()->columnCount(); + int aRows = myDataTblList.first()->rowCount(); + foreach(QTableWidget* aTable, myDataTblList) { + for(int i = 1; i < aColumns; i++) { + for(int j = 0; j < aRows; j++) { + switch (theIdx) { + case ModelAPI_AttributeTables::DOUBLE: + case ModelAPI_AttributeTables::INTEGER: + aTable->item(j, i)->setText("0"); + break; + case ModelAPI_AttributeTables::BOOLEAN: + aTable->item(j, i)->setText(MYFalse); + break; + case ModelAPI_AttributeTables::STRING: + aTable->item(j, i)->setText(""); + break; } } } - emit valuesChanged(); } + emit valuesChanged(); } } @@ -942,7 +966,7 @@ void CollectionPlugin_WidgetField::onTableEdited(int theRow, int theCol) //********************************************************************************** void CollectionPlugin_WidgetField::onShapeTypeChanged(int theType) { - activateSelectionAndFilters(theType == 5? false:true); + updateSelectionModesAndFilters(theType == 5? false:true); AttributeSelectionListPtr aSelList = myFeature->data()->selectionList(CollectionPlugin_Field::SELECTED_ID()); @@ -951,12 +975,16 @@ void CollectionPlugin_WidgetField::onShapeTypeChanged(int theType) if (aTypeName == aSelList->selectionType()) return; aSelList->setSelectionType(aTypeName); + // Updated event has to be sent here in case if type of shapes + // was changed from Part to any other in order to updater Apply button status + myFeature->data()->sendAttributeUpdated(aSelList.get()); //Clear old selection clearData(); aSelList->clear(); AttributeTablesPtr aTablesAttr = myFeature->data()->tables(CollectionPlugin_Field::VALUES_ID()); aTablesAttr->setSize(1, myNbComponentsSpn->value(), myDataTblList.size()); + updateObject(myFeature); emit valuesChanged(); } @@ -967,6 +995,16 @@ bool CollectionPlugin_WidgetField::processEnter() myIsTabEdit = false; return true; } + QWidget* aCurrWgt = qApp->focusWidget(); + int aCurWgtId = myStepWgt->currentIndex(); + if ((aCurrWgt == myShapeTypeCombo) || + (aCurrWgt == myFieldTypeCombo) || + (aCurrWgt == myNbComponentsSpn) || + (aCurrWgt == myStampSpnList[aCurWgtId]) || + (aCurrWgt == myDataTblList[aCurWgtId])) { + setFocus(); + return true; + } return false; } @@ -995,3 +1033,24 @@ void CollectionPlugin_WidgetField::onColumnResize(int theIndex, int theOld, int aTable->setColumnWidth(theIndex, theNew); } } + +//********************************************************************************** +QList> + CollectionPlugin_WidgetField::getAttributeSelection() const +{ + QList> aList; + if(myFeature) { + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelList = + aData->selectionList(CollectionPlugin_Field::SELECTED_ID()); + AttributeSelectionPtr aAttr; + ObjectPtr anObject; + for (int i = 0; i < aSelList->size(); i++) { + aAttr = aSelList->value(i); + ModuleBase_ViewerPrsPtr + aPrs(new ModuleBase_ViewerPrs(aAttr->context(), aAttr->value(), NULL)); + aList.append(aPrs); + } + } + return aList; +} \ No newline at end of file