+//**********************************************************************************
+void CollectionPlugin_WidgetField::appendStepControls()
+{
+ QWidget* aWidget = new QWidget(myStepWgt);
+ QGridLayout* aStepLayout = new QGridLayout(aWidget);
+ aStepLayout->setContentsMargins(0, 0, 0, 0);
+
+ aStepLayout->addWidget(new QLabel(tr("Stamp"), aWidget), 0, 0);
+
+ QSpinBox* aStampSpn = new QSpinBox(aWidget);
+ aStepLayout->addWidget(aStampSpn, 0, 1);
+
+ myStampSpnList.append(aStampSpn);
+
+ // Data table
+ QTableWidget* aDataTbl = new QTableWidget(1, myCompNamesList.count() + 1, aWidget);
+ aDataTbl->installEventFilter(this);
+ aDataTbl->setItemDelegate(myDelegate);
+
+ QIntList aColWidth;
+ if (!myDataTblList.isEmpty()) {
+ QTableWidget* aFirstTable = myDataTblList.first();
+ for (int i = 0; i < aFirstTable->columnCount(); i++)
+ aColWidth.append(aFirstTable->columnWidth(i));
+ }
+ myDataTblList.append(aDataTbl);
+
+ aDataTbl->verticalHeader()->hide();
+ aDataTbl->setRowHeight(0, 25);
+ aDataTbl->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+
+ connect(aDataTbl->horizontalHeader(), SIGNAL(sectionResized(int, int, int)),
+ SLOT(onColumnResize(int, int, int)));
+
+ updateHeaders(aDataTbl);
+
+ QTableWidgetItem* aItem = new QTableWidgetItem("Default value");
+ aItem->setBackgroundColor(Qt::lightGray);
+ aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
+ aDataTbl->setItem(0, 0, aItem);
+
+ // Set default value item
+ for (int i = 0; i < myCompNamesList.count(); i++) {
+ aItem = createDefaultItem();
+ aItem->setBackgroundColor(Qt::lightGray);
+ aDataTbl->setItem(0, i + 1, aItem);
+ }
+
+ if (aColWidth.length() > 0) {
+ 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)));
+
+ myStepWgt->addWidget(aWidget);
+ aDataTbl->horizontalHeader()->viewport()->installEventFilter(this);
+}
+
+//**********************************************************************************
+void CollectionPlugin_WidgetField::deactivate()
+{
+ ModuleBase_WidgetSelector::deactivate();
+ storeValueCustom();
+}
+
+//**********************************************************************************
+//void CollectionPlugin_WidgetField::showEvent(QShowEvent* theEvent)
+//{
+// myShapeTypeCombo->setEnabled(!isEditingMode());
+// myFieldTypeCombo->setEnabled(!isEditingMode());
+// myNbComponentsSpn->setEnabled(!isEditingMode());
+//}
+
+//**********************************************************************************
+bool CollectionPlugin_WidgetField::eventFilter(QObject* theObject, QEvent* theEvent)
+{
+ QObject* aObject = 0;
+ foreach(QTableWidget* aTable, myDataTblList) {
+ if (aTable->horizontalHeader()->viewport() == theObject) {
+ aObject = theObject;
+ break;
+ }
+ }
+ if (aObject) {
+ if (theEvent->type() == QEvent::MouseButtonDblClick) {
+ if (myHeaderEditor) { //delete previous editor
+ myHeaderEditor->deleteLater();
+ myHeaderEditor = 0;
+ }
+ QMouseEvent* aMouseEvent = static_cast<QMouseEvent*>(theEvent);
+ QHeaderView* aHeader = static_cast<QHeaderView*>(aObject->parent());
+ QTableWidget* aTable = static_cast<QTableWidget*>(aHeader->parentWidget());
+
+ int aShift = aTable->horizontalScrollBar()->value();
+ int aPos = aMouseEvent->x();
+ int aIndex = aHeader->logicalIndex(aHeader->visualIndexAt(aPos));
+ if (aIndex > 0) {
+ QRect aRect;
+ aRect.setLeft(aHeader->sectionPosition(aIndex));
+ aRect.setWidth(aHeader->sectionSize(aIndex));
+ aRect.setTop(0);
+ aRect.setHeight(aHeader->height());
+ aRect.adjust(1, 1, -1, -1);
+ aRect.translate(-aShift, 0);
+
+ myHeaderEditor = new QLineEdit(aHeader->viewport());
+ myHeaderEditor->move(aRect.topLeft());
+ myHeaderEditor->resize(aRect.size());
+ myHeaderEditor->setFrame(false);
+ QString aText = aHeader->model()->
+ headerData(aIndex, aHeader->orientation()).toString();
+ myHeaderEditor->setText(aText);
+ myHeaderEditor->setFocus();
+ myEditIndex = aIndex; //save for future use
+ myHeaderEditor->installEventFilter(this); //catch focus out event
+ //if user presses Enter it should close editor
+ connect(myHeaderEditor, SIGNAL(returnPressed()), aTable, SLOT(setFocus()));
+ myHeaderEditor->show();
+ return true;
+ }
+ }
+ } else if ((theObject == myHeaderEditor) && (theEvent->type() == QEvent::FocusOut)) {
+ QString aNewTitle = myHeaderEditor->text();
+ //save item text
+ myCompNamesList.replace(myEditIndex - 1, aNewTitle);
+ myHeaderEditor->deleteLater(); //safely delete editor
+ myHeaderEditor = 0;
+ // Store into data model
+ AttributeStringArrayPtr aStringsAttr =
+ myFeature->data()->stringArray(CollectionPlugin_Field::COMPONENTS_NAMES_ID());
+ aStringsAttr->setValue(myEditIndex - 1, aNewTitle.toStdString());
+ foreach(QTableWidget* aTable, myDataTblList) {
+ updateHeaders(aTable);
+ }
+ } else if (theEvent->type() == QEvent::FocusIn) {
+ QTableWidget* aTable = dynamic_cast<QTableWidget*>(theObject);
+ if (aTable) {
+ ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel();
+ if (aPanel->activeWidget() != this) {
+ myActivation = true;
+ aPanel->activateWidget(this, false);
+ }
+ }
+ }
+ return ModuleBase_WidgetSelector::eventFilter(theObject, theEvent);
+}
+
+//**********************************************************************************
+QTableWidgetItem* CollectionPlugin_WidgetField::createDefaultItem() const
+{
+ QTableWidgetItem* aItem = new QTableWidgetItem();
+ switch (myFieldTypeCombo->currentIndex()) {
+ case ModelAPI_AttributeTables::DOUBLE:
+ case ModelAPI_AttributeTables::INTEGER:
+ aItem->setText("0");
+ break;
+ case ModelAPI_AttributeTables::BOOLEAN:
+ aItem->setText(MYFalse);
+ break;
+ case ModelAPI_AttributeTables::STRING:
+ aItem->setText("");
+ break;
+ }
+ return aItem;
+}
+
+//**********************************************************************************
+QTableWidgetItem* CollectionPlugin_WidgetField::
+ createValueItem(ModelAPI_AttributeTables::Value& theVal) const
+{
+ QTableWidgetItem* aItem = new QTableWidgetItem();
+ aItem->setText(getValueText(theVal));
+ return aItem;
+}
+
+//**********************************************************************************
+QString CollectionPlugin_WidgetField::getValueText(ModelAPI_AttributeTables::Value& theVal) const
+{
+ switch (myFieldTypeCombo->currentIndex()) {
+ case ModelAPI_AttributeTables::DOUBLE:
+ return QString::number(theVal.myDouble);
+ case ModelAPI_AttributeTables::INTEGER:
+ return QString::number(theVal.myInt);
+ case ModelAPI_AttributeTables::BOOLEAN:
+ return theVal.myBool? MYTrue : MYFalse;
+ case ModelAPI_AttributeTables::STRING:
+ return theVal.myStr.c_str();
+ }
+ return "";
+}
+
+
+//**********************************************************************************
+void CollectionPlugin_WidgetField::updateHeaders(QTableWidget* theDataTbl) const
+{
+ QStringList aHeaders;
+ aHeaders << tr(MYFirstCol);
+ aHeaders << myCompNamesList;
+ theDataTbl->setHorizontalHeaderLabels(aHeaders);
+}
+
+//**********************************************************************************
+void CollectionPlugin_WidgetField::removeStepControls()
+{
+ int aCurWgtId = myStepWgt->currentIndex();
+ QWidget* aWgt = myStepWgt->currentWidget();
+ myStepWgt->removeWidget(aWgt);
+
+ myStampSpnList.removeAt(aCurWgtId);
+ myDataTblList.removeAt(aCurWgtId);
+ aWgt->deleteLater();
+}
+
+//**********************************************************************************