1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: CollectionPlugin_WidgetField.cpp
4 // Created: 16 Nov 2016
5 // Author: Vitaly SMETANNIKOV
7 #include "CollectionPlugin_WidgetField.h"
8 #include "CollectionPlugin_Field.h"
10 #include <ModuleBase_Tools.h>
11 #include <ModuleBase_IWorkshop.h>
12 #include <ModuleBase_ISelection.h>
14 #include <ModelAPI_AttributeSelectionList.h>
15 #include <ModelAPI_AttributeStringArray.h>
16 #include <ModelAPI_AttributeInteger.h>
17 #include <ModelAPI_AttributeIntArray.h>
21 #include <QFormLayout>
26 #include <QTableWidget>
27 #include <QPushButton>
28 #include <QHeaderView>
29 #include <QStackedWidget>
31 #include <QStyledItemDelegate>
34 #include <QMouseEvent>
37 const char* MYFirstCol = "Shape";
38 const char* MYTrue = "True";
39 const char* MYFalse = "False";
41 class DataTableItemDelegate : public QStyledItemDelegate
44 DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType) : QStyledItemDelegate() { myType = theType; }
46 virtual QWidget* createEditor(QWidget* theParent,
47 const QStyleOptionViewItem & theOption,
48 const QModelIndex& theIndex) const;
50 ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
52 void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
55 ModelAPI_AttributeTables::ValueType myType;
58 QWidget* DataTableItemDelegate::createEditor(QWidget* theParent,
59 const QStyleOptionViewItem & theOption,
60 const QModelIndex& theIndex ) const
62 if ((theIndex.column() == 0) && (theIndex.row() > 0)) {
63 QWidget* aWgt = QStyledItemDelegate::createEditor(theParent, theOption, theIndex);
64 QLineEdit* aEdt = static_cast<QLineEdit*>(aWgt);
65 aEdt->setReadOnly(true);
68 QLineEdit* aLineEdt = 0;
70 case ModelAPI_AttributeTables::DOUBLE:
71 aLineEdt = dynamic_cast<QLineEdit*>(QStyledItemDelegate::createEditor(theParent,
75 aLineEdt->setValidator(new QDoubleValidator(aLineEdt));
79 case ModelAPI_AttributeTables::INTEGER:
80 aLineEdt = dynamic_cast<QLineEdit*>(QStyledItemDelegate::createEditor(theParent,
84 aLineEdt->setValidator(new QIntValidator(aLineEdt));
88 case ModelAPI_AttributeTables::BOOLEAN:
90 QComboBox* aBox = new QComboBox(theParent);
91 aBox->addItem(MYFalse);
92 aBox->addItem(MYTrue);
97 return QStyledItemDelegate::createEditor(theParent, theOption, theIndex);
101 //**********************************************************************************
102 //**********************************************************************************
103 //**********************************************************************************
104 CollectionPlugin_WidgetField::
105 CollectionPlugin_WidgetField(QWidget* theParent,
106 ModuleBase_IWorkshop* theWorkshop,
107 const Config_WidgetAPI* theData):
108 ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0)
110 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
112 // Types definition controls
113 QWidget* aTypesWgt = new QWidget(this);
114 QFormLayout* aTypesLayout = new QFormLayout(aTypesWgt);
115 aTypesLayout->setContentsMargins(0, 0, 0, 0);
116 aMainLayout->addWidget(aTypesWgt);
119 myShapeTypeCombo = new QComboBox(aTypesWgt);
120 QStringList aShapeTypes;
121 aShapeTypes << tr("Vertices") << tr("Edges") << tr("Faces")
122 << tr("Solids") << tr("Objects") << tr("Parts");
123 myShapeTypeCombo->addItems(aShapeTypes);
124 aTypesLayout->addRow(tr("Type of shapes"), myShapeTypeCombo);
127 myFieldTypeCombo = new QComboBox(aTypesWgt);
128 QStringList aFieldTypes;
129 aFieldTypes << tr("Boolean") << tr("Integer") << tr("Double")
131 myFieldTypeCombo->addItems(aFieldTypes);
132 myFieldTypeCombo->setCurrentIndex(2);
133 aTypesLayout->addRow(tr("Type of field"), myFieldTypeCombo);
135 // Number of components
136 myNbComponentsSpn = new QSpinBox(aTypesWgt);
137 myNbComponentsSpn->setMinimum(1);
138 aTypesLayout->addRow(tr("Nb. of components"), myNbComponentsSpn);
141 QFrame* aStepFrame = new QFrame(this);
142 aStepFrame->setFrameShape(QFrame::Box);
143 aStepFrame->setFrameStyle(QFrame::StyledPanel);
144 QGridLayout* aStepLayout = new QGridLayout(aStepFrame);
145 aMainLayout->addWidget(aStepFrame);
147 // Current step label
148 aStepLayout->addWidget(new QLabel(tr("Current step"), aStepFrame), 0, 0);
149 myCurStepLbl = new QLabel("1", aStepFrame);
150 QFont aFont = myCurStepLbl->font();
152 myCurStepLbl->setFont(aFont);
153 aStepLayout->addWidget(myCurStepLbl, 0, 1);
156 QWidget* aSliderWidget = new QWidget(aStepFrame);
157 aStepLayout->addWidget(aSliderWidget, 1, 0, 1, 2);
158 QHBoxLayout* aSliderLayout = new QHBoxLayout(aSliderWidget);
159 aSliderLayout->setContentsMargins(0, 0, 0, 0);
161 aSliderLayout->addWidget(new QLabel("1", aSliderWidget));
163 myStepSlider = new QSlider(Qt::Horizontal, aSliderWidget);
164 myStepSlider->setTickPosition(QSlider::TicksBelow);
165 myStepSlider->setRange(1, 1);
166 myStepSlider->setPageStep(myStepSlider->singleStep());
167 aSliderLayout->addWidget(myStepSlider, 1);
169 myMaxLbl = new QLabel("1", aSliderWidget);
170 aSliderLayout->addWidget(myMaxLbl);
173 myCompNamesList << "Comp 1";
174 myStepWgt = new QStackedWidget(aStepFrame);
175 aStepLayout->addWidget(myStepWgt, 2, 0, 1, 2);
176 appendStepControls();
179 QWidget* aBtnWgt = new QWidget(this);
180 aMainLayout->addWidget(aBtnWgt);
181 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
182 aBtnLayout->setContentsMargins(0, 0, 0, 0);
184 QPushButton* aAddBtn = new QPushButton(tr("Add step"), aBtnWgt);
185 aBtnLayout->addWidget(aAddBtn);
187 aBtnLayout->addStretch(1);
189 myRemoveBtn = new QPushButton(tr("Remove step"), aBtnWgt);
190 aBtnLayout->addWidget(myRemoveBtn);
191 myRemoveBtn->setEnabled(false);
193 connect(myNbComponentsSpn, SIGNAL(valueChanged(int)), SLOT(onNbCompChanged(int)));
194 connect(aAddBtn, SIGNAL(clicked(bool)), SLOT(onAddStep()));
195 connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemoveStep()));
196 connect(myStepSlider, SIGNAL(valueChanged(int)), SLOT(onStepMove(int)));
197 connect(myFieldTypeCombo, SIGNAL(currentIndexChanged(int)), SLOT(onFieldTypeChanged(int)));
198 connect(myShapeTypeCombo, SIGNAL(currentIndexChanged(int)), SLOT(onShapeTypeChanged(int)));
201 //**********************************************************************************
202 void CollectionPlugin_WidgetField::appendStepControls()
204 QWidget* aWidget = new QWidget(myStepWgt);
205 QGridLayout* aStepLayout = new QGridLayout(aWidget);
206 aStepLayout->setContentsMargins(0, 0, 0, 0);
208 aStepLayout->addWidget(new QLabel(tr("Stamp"), aWidget), 0, 0);
210 QSpinBox* aStampSpn = new QSpinBox(aWidget);
211 aStepLayout->addWidget(aStampSpn, 0, 1);
213 myStampSpnList.append(aStampSpn);
216 QTableWidget* aDataTbl = new QTableWidget(1, myCompNamesList.count() + 1, aWidget);
217 DataTableItemDelegate* aDelegate = 0;
218 if (myDataTblList.isEmpty())
219 aDelegate = new DataTableItemDelegate(
220 (ModelAPI_AttributeTables::ValueType) myFieldTypeCombo->currentIndex());
222 aDelegate = dynamic_cast<DataTableItemDelegate*>(myDataTblList.first()->itemDelegate());
224 aDataTbl->setItemDelegate(aDelegate);
225 myDataTblList.append(aDataTbl);
227 aDataTbl->verticalHeader()->hide();
228 aDataTbl->setRowHeight(0, 25);
229 aDataTbl->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
231 updateHeaders(aDataTbl);
233 QTableWidgetItem* aItem = new QTableWidgetItem("Default value");
234 aItem->setBackgroundColor(Qt::lightGray);
235 aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
236 aDataTbl->setItem(0, 0, aItem);
238 // Set default value item
239 for (int i = 0; i < myCompNamesList.count(); i++) {
240 aItem = createDefaultItem();
241 aItem->setBackgroundColor(Qt::lightGray);
242 aDataTbl->setItem(0, i + 1, aItem);
244 aStepLayout->addWidget(aDataTbl, 1, 0, 1, 2);
245 connect(aDataTbl, SIGNAL(cellChanged(int, int)), SLOT(onTableEdited(int, int)));
247 QAbstractItemDelegate* aDel = aDataTbl->itemDelegate();
248 myStepWgt->addWidget(aWidget);
249 aDataTbl->horizontalHeader()->viewport()->installEventFilter(this);
252 //**********************************************************************************
253 bool CollectionPlugin_WidgetField::eventFilter(QObject* theObject, QEvent* theEvent)
255 QObject* aObject = 0;
256 foreach(QTableWidget* aTable, myDataTblList) {
257 if (aTable->horizontalHeader()->viewport() == theObject) {
263 if (theEvent->type() == QEvent::MouseButtonDblClick) {
264 if (myHeaderEditor) { //delete previous editor
265 myHeaderEditor->deleteLater();
268 QMouseEvent* aMouseEvent = static_cast<QMouseEvent*>(theEvent);
269 QHeaderView* aHeader = static_cast<QHeaderView*>(aObject->parent());
270 QTableWidget* aTable = static_cast<QTableWidget*>(aHeader->parentWidget());
272 int aShift = aTable->horizontalScrollBar()->value();
273 int aPos = aMouseEvent->x();
274 int aIndex = aHeader->logicalIndex(aHeader->visualIndexAt(aPos));
277 aRect.setLeft(aHeader->sectionPosition(aIndex));
278 aRect.setWidth(aHeader->sectionSize(aIndex));
280 aRect.setHeight(aHeader->height());
281 aRect.adjust(1, 1, -1, -1);
282 aRect.translate(-aShift, 0);
284 myHeaderEditor = new QLineEdit(aHeader->viewport());
285 myHeaderEditor->move(aRect.topLeft());
286 myHeaderEditor->resize(aRect.size());
287 myHeaderEditor->setFrame(false);
288 QString aText = aHeader->model()->
289 headerData(aIndex, aHeader->orientation()).toString();
290 myHeaderEditor->setText(aText);
291 myHeaderEditor->setFocus();
292 myEditIndex = aIndex; //save for future use
293 myHeaderEditor->installEventFilter(this); //catch focus out event
294 //if user presses Enter it should close editor
295 connect(myHeaderEditor, SIGNAL(returnPressed()), aTable, SLOT(setFocus()));
296 myHeaderEditor->show();
300 } else if ((theObject == myHeaderEditor) && (theEvent->type() == QEvent::FocusOut)) {
301 QHeaderView* aHeader =
302 static_cast<QHeaderView*>(myHeaderEditor->parentWidget()->parentWidget());
303 QString aNewTitle = myHeaderEditor->text();
305 aHeader->model()->setHeaderData(myEditIndex, aHeader->orientation(), aNewTitle);
306 myCompNamesList.replace(myEditIndex - 1, aNewTitle);
307 myHeaderEditor->deleteLater(); //safely delete editor
309 // Store into data model
310 AttributeStringArrayPtr aStringsAttr =
311 myFeature->data()->stringArray(CollectionPlugin_Field::COMPONENTS_NAMES_ID());
312 aStringsAttr->setValue(myEditIndex - 1, aNewTitle.toStdString());
314 return ModuleBase_WidgetSelector::eventFilter(theObject, theEvent);
317 //**********************************************************************************
318 QTableWidgetItem* CollectionPlugin_WidgetField::createDefaultItem() const
320 QTableWidgetItem* aItem = new QTableWidgetItem();
321 switch (myFieldTypeCombo->currentIndex()) {
322 case ModelAPI_AttributeTables::DOUBLE:
323 case ModelAPI_AttributeTables::INTEGER:
326 case ModelAPI_AttributeTables::BOOLEAN:
327 aItem->setText(MYFalse);
333 //**********************************************************************************
334 QTableWidgetItem* CollectionPlugin_WidgetField::
335 createValueItem(ModelAPI_AttributeTables::Value& theVal) const
337 QTableWidgetItem* aItem = new QTableWidgetItem();
338 switch (myFieldTypeCombo->currentIndex()) {
339 case ModelAPI_AttributeTables::DOUBLE:
340 aItem->setText(QString::number(theVal.myDouble));
342 case ModelAPI_AttributeTables::INTEGER:
343 aItem->setText(QString::number(theVal.myInt));
345 case ModelAPI_AttributeTables::BOOLEAN:
346 aItem->setText(theVal.myBool? MYTrue : MYFalse);
348 case ModelAPI_AttributeTables::STRING:
349 aItem->setText(theVal.myStr.c_str());
354 //**********************************************************************************
355 void CollectionPlugin_WidgetField::updateHeaders(QTableWidget* theDataTbl) const
357 QStringList aHeaders;
358 aHeaders << tr(MYFirstCol);
359 aHeaders << myCompNamesList;
360 theDataTbl->setHorizontalHeaderLabels(aHeaders);
363 //**********************************************************************************
364 void CollectionPlugin_WidgetField::removeStepControls()
366 int aCurWgtId = myStepWgt->currentIndex();
367 QWidget* aWgt = myStepWgt->currentWidget();
368 myStepWgt->removeWidget(aWgt);
370 myStampSpnList.removeAt(aCurWgtId);
371 myDataTblList.removeAt(aCurWgtId);
375 //**********************************************************************************
376 QList<QWidget*> CollectionPlugin_WidgetField::getControls() const
378 QList<QWidget*> aControls;
379 // this control will accept focus and will be highlighted in the Property Panel
380 aControls.push_back(myShapeTypeCombo);
381 //aControls.push_back(myFieldTypeCombo);
382 //aControls.push_back(myNbComponentsSpn);
386 //**********************************************************************************
387 bool CollectionPlugin_WidgetField::storeValueCustom()
389 DataPtr aData = myFeature->data();
390 // Store number of components
391 AttributeStringArrayPtr aStringsAttr =
392 aData->stringArray(CollectionPlugin_Field::COMPONENTS_NAMES_ID());
393 int aNbComps = myCompNamesList.size();
394 aStringsAttr->setSize(aNbComps);
395 for ( int i = 0; i < aNbComps; i++)
396 aStringsAttr->setValue(i, myCompNamesList.at(i).toStdString());
398 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
399 // Store number of steps
400 int aNbSteps = myDataTblList.size();
402 // Store Type of the field values
403 int aFldType = myFieldTypeCombo->currentIndex();
405 AttributeIntArrayPtr aStampsAttr = aData->intArray(CollectionPlugin_Field::STAMPS_ID());
406 aStampsAttr->setSize(aNbSteps);
408 QTableWidget* aTable = myDataTblList.first();
409 int aRows = aTable->rowCount();
410 // first column contains selected names which should not be stored
411 int aColumns = aTable->columnCount() - 1;
413 aTablesAttr->setSize(aRows, aColumns, aNbSteps);
414 aTablesAttr->setType((ModelAPI_AttributeTables::ValueType)aFldType);
415 for (int i = 0; i < aNbSteps; i++) {
416 aStampsAttr->setValue(i, myStampSpnList.at(i)->value());
417 aTable = myDataTblList.at(i);
418 for (int j = 0; j < aColumns; j++) {
419 for (int k = 0; k < aRows; k++) {
420 QString aTblVal = aTable->item(k, j + 1)->text();
421 aTablesAttr->setValue(getValue(aTblVal), k, j, i);
425 updateObject(myFeature);
429 //**********************************************************************************
430 bool CollectionPlugin_WidgetField::restoreValueCustom()
432 DataPtr aData = myFeature->data();
434 AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID());
435 if (!aSelList->isInitialized())
437 std::string aTypeStr = aSelList->selectionType();
438 myShapeTypeCombo->setCurrentIndex(getSelectionType(aTypeStr));
440 // Get number of components
441 AttributeStringArrayPtr aStringsAttr =
442 aData->stringArray(CollectionPlugin_Field::COMPONENTS_NAMES_ID());
444 if (!aStringsAttr->isInitialized())
447 myCompNamesList.clear();
448 for (int i = 0; i < aStringsAttr->size(); i++) {
449 myCompNamesList.append(aStringsAttr->value(i).c_str());
451 myNbComponentsSpn->setValue(myCompNamesList.size());
453 AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID());
454 // Get number of steps
455 int aNbSteps = aTablesAttr->tables();
456 myStepSlider->setMaximum(aNbSteps);
457 //myStepSlider->setValue(1);
459 myStampSpnList.clear();
460 myDataTblList.clear();
461 while (myStepWgt->count()) {
462 QWidget* aWgt = myStepWgt->widget(myStepWgt->count() - 1);
463 myStepWgt->removeWidget(aWgt);
467 while (myStepWgt->count() < aNbSteps)
468 appendStepControls();
469 //myStepWgt->setCurrentIndex(myStepSlider->value() - 1);
471 // Get Type of the field values
472 myFieldTypeCombo->setCurrentIndex(aTablesAttr->type());
474 AttributeIntArrayPtr aStampsAttr = aData->intArray(CollectionPlugin_Field::STAMPS_ID());
476 int aRows = aTablesAttr->rows();
477 int aCols = aTablesAttr->columns();
479 QTableWidgetItem* aItem = 0;
480 for (int i = 0; i < aNbSteps; i++) {
481 myStampSpnList.at(i)->setValue(aStampsAttr->value(i));
482 QTableWidget* aTable = myDataTblList.at(i);
483 bool isBlocked = aTable->blockSignals(true);
484 aTable->setRowCount(aRows);
485 for (int j = 0; j < aCols + 1; j++) {
486 for (int k = 0; k < aRows; k++) {
487 if ((j == 0) && (k > 0)) {
488 // Add selection names
489 AttributeSelectionPtr aAttr = aSelList->value(k - 1);
490 aItem = new QTableWidgetItem(aAttr->namingName().c_str());
491 aTable->setItem(k, j, aItem);
494 ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j - 1, i);
495 aItem = createValueItem(aVal);
497 aItem->setBackgroundColor(Qt::lightGray);
498 aTable->setItem(k, j, aItem);
503 aTable->blockSignals(isBlocked);
508 //**********************************************************************************
509 int CollectionPlugin_WidgetField::getSelectionType(const std::string& theStr) const
511 if (theStr == "vertex")
513 else if (theStr == "edge")
515 else if (theStr == "face")
517 else if (theStr == "solid")
519 else if (theStr == "object")
521 else if (theStr == "part")
527 //**********************************************************************************
528 std::string CollectionPlugin_WidgetField::getSelectionType(int theType) const
547 //**********************************************************************************
548 QIntList CollectionPlugin_WidgetField::shapeTypes() const
551 switch (myShapeTypeCombo->currentIndex()) {
553 aRes.append(ModuleBase_Tools::shapeType("vertex"));
556 aRes.append(ModuleBase_Tools::shapeType("edge"));
559 aRes.append(ModuleBase_Tools::shapeType("face"));
562 aRes.append(ModuleBase_Tools::shapeType("solid"));
565 aRes.append(ModuleBase_Tools::shapeType("object"));
568 // TODO: Selection mode for Parts
574 //**********************************************************************************
575 ModelAPI_AttributeTables::Value CollectionPlugin_WidgetField::getValue(QString theStrVal) const
577 ModelAPI_AttributeTables::Value aVal;
578 switch (myFieldTypeCombo->currentIndex()) {
579 case ModelAPI_AttributeTables::BOOLEAN:
580 aVal.myBool = (theStrVal == MYTrue)? true : false;
582 case ModelAPI_AttributeTables::DOUBLE:
583 aVal.myDouble = theStrVal.toDouble();
585 case ModelAPI_AttributeTables::INTEGER:
586 aVal.myInt = theStrVal.toInt();
588 case ModelAPI_AttributeTables::STRING:
589 aVal.myStr = theStrVal.toStdString();
595 //**********************************************************************************
596 void CollectionPlugin_WidgetField::onNbCompChanged(int theVal)
598 int aOldCol = myCompNamesList.count();
599 int aNbRows = myDataTblList.first()->rowCount();
600 int aDif = theVal - aOldCol;
601 QTableWidgetItem* aItem = 0;
603 while (myCompNamesList.count() != theVal) {
605 myCompNamesList.append(QString("Comp %1").arg(myCompNamesList.count() + 1));
607 myCompNamesList.removeLast();
610 foreach(QTableWidget* aDataTbl, myDataTblList) {
611 aDataTbl->setColumnCount(theVal + 1);
612 updateHeaders(aDataTbl);
613 for (int i = aOldCol; i < myCompNamesList.count(); i++) {
614 for (int j = 0; j < aNbRows; j++) {
615 aItem = createDefaultItem();
617 aItem->setBackgroundColor(Qt::lightGray);
618 aDataTbl->setItem(j, i + 1, aItem);
622 emit valuesChanged();
625 //**********************************************************************************
626 void CollectionPlugin_WidgetField::onAddStep()
628 int aMax = myStepSlider->maximum();
630 myStepSlider->setMaximum(aMax);
631 myMaxLbl->setText(QString::number(aMax));
632 appendStepControls();
633 myStepSlider->setValue(aMax);
634 myRemoveBtn->setEnabled(aMax > 1);
637 //**********************************************************************************
638 void CollectionPlugin_WidgetField::onRemoveStep()
640 int aMax = myStepSlider->maximum();
642 myMaxLbl->setText(QString::number(aMax));
643 removeStepControls();
644 myStepSlider->setMaximum(aMax);
645 myRemoveBtn->setEnabled(aMax > 1);
648 //**********************************************************************************
649 void CollectionPlugin_WidgetField::clearData()
651 foreach(QTableWidget* aDataTbl, myDataTblList) {
652 aDataTbl->setRowCount(1);
656 //**********************************************************************************
657 void CollectionPlugin_WidgetField::onStepMove(int theStep)
659 myCurStepLbl->setText(QString::number(theStep));
660 myStepWgt->setCurrentIndex(theStep - 1);
663 //**********************************************************************************
664 bool CollectionPlugin_WidgetField::
665 isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
670 //**********************************************************************************
671 void CollectionPlugin_WidgetField::onSelectionChanged()
673 QList<ModuleBase_ViewerPrsPtr> aSelected =
674 myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls);
677 AttributeSelectionListPtr aSelList =
678 myFeature->data()->selectionList(CollectionPlugin_Field::SELECTED_ID());
681 switch (myShapeTypeCombo->currentIndex()) {
683 aSelList->setSelectionType("vertex");
686 aSelList->setSelectionType("edge");
689 aSelList->setSelectionType("face");
692 aSelList->setSelectionType("solid");
695 aSelList->setSelectionType("object");
698 // TODO: Selection mode for Parts
705 foreach(ModuleBase_ViewerPrsPtr aPrs, aSelected) {
706 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
707 aShape = aPrs->shape();
708 if (!aResult.get() && !aShape.get())
710 if (!aSelList->isInList(aResult, aShape)) {
711 aSelList->append(aResult, aShape);
715 int aColumns = myDataTblList.first()->columnCount();
716 int aRows = myDataTblList.first()->rowCount();
717 AttributeTablesPtr aTablesAttr = myFeature->data()->tables(CollectionPlugin_Field::VALUES_ID());
718 aTablesAttr->setSize(aRows + aNbData, aColumns - 1, myDataTblList.size());
720 QTableWidgetItem* aItem = 0;
721 foreach(QTableWidget* aTable, myDataTblList) {
722 aTable->setRowCount(aRows + aNbData);
723 for(int i = 0; i < aColumns; i++) {
724 QString aDefVal = aTable->item(0, i)->text();
725 for(int j = 1; j < aRows + aNbData; j++) {
726 aItem = new QTableWidgetItem();
728 AttributeSelectionPtr aAttr = aSelList->value(j - 1);
729 aItem->setText(aAttr->namingName().c_str());
730 aItem->setToolTip(aAttr->namingName().c_str());
732 aItem->setText(aDefVal);
734 aTable->setItem(j, i, aItem);
738 emit valuesChanged();
741 //**********************************************************************************
742 void CollectionPlugin_WidgetField::onFieldTypeChanged(int theIdx)
744 DataTableItemDelegate* aDelegate = 0;
745 aDelegate = dynamic_cast<DataTableItemDelegate*>(myDataTblList.first()->itemDelegate());
747 ModelAPI_AttributeTables::ValueType aOldType = aDelegate->dataType();
748 if (aOldType != theIdx) {
749 aDelegate->setDataType((ModelAPI_AttributeTables::ValueType)theIdx);
750 int aColumns = myDataTblList.first()->columnCount();
751 int aRows = myDataTblList.first()->rowCount();
752 foreach(QTableWidget* aTable, myDataTblList) {
753 for(int i = 1; i < aColumns; i++) {
754 for(int j = 0; j < aRows; j++) {
756 case ModelAPI_AttributeTables::DOUBLE:
757 case ModelAPI_AttributeTables::INTEGER:
758 if ((aOldType == ModelAPI_AttributeTables::BOOLEAN) ||
759 (aOldType == ModelAPI_AttributeTables::STRING)) {
760 aTable->item(j, i)->setText("0");
763 case ModelAPI_AttributeTables::BOOLEAN:
764 aTable->item(j, i)->setText(MYFalse);
770 emit valuesChanged();
775 void CollectionPlugin_WidgetField::onTableEdited(int theRow, int theCol)
777 // Do not store here column of names
780 if (!myFeature.get())
782 QTableWidget* aTable = static_cast<QTableWidget*>(sender());
783 int aNb = myDataTblList.indexOf(aTable);
786 ModelAPI_AttributeTables::Value aVal = getValue(aTable->item(theRow, theCol)->text());
788 AttributeTablesPtr aTablesAttr = myFeature->data()->tables(CollectionPlugin_Field::VALUES_ID());
789 if (aTablesAttr->isInitialized())
790 aTablesAttr->setValue(aVal,theRow, theCol - 1, aNb);
792 emit valuesChanged();
795 void CollectionPlugin_WidgetField::onShapeTypeChanged(int theType)
797 AttributeSelectionListPtr aSelList =
798 myFeature->data()->selectionList(CollectionPlugin_Field::SELECTED_ID());
799 if (!aSelList->isInitialized())
801 std::string aTypeName = getSelectionType(theType);
802 if (aTypeName == aSelList->selectionType())
805 //Clear old selection
808 AttributeTablesPtr aTablesAttr = myFeature->data()->tables(CollectionPlugin_Field::VALUES_ID());
809 aTablesAttr->setSize(1, myNbComponentsSpn->value(), myDataTblList.size());