+ 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;