From d3e739dbd0889d27e230d33ff54ce82b2c6b9a13 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 30 Dec 2016 14:18:04 +0300 Subject: [PATCH] Store content of table item when user presses Ok button --- .../CollectionPlugin_WidgetField.cpp | 23 ++++++++++--------- .../CollectionPlugin_WidgetField.h | 3 +++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp b/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp index bdb55bdf3..7d091f00c 100644 --- a/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp +++ b/src/CollectionPlugin/CollectionPlugin_WidgetField.cpp @@ -89,20 +89,21 @@ QWidget* DataTableItemDelegate::createEditor(QWidget* theParent, aEditor = QStyledItemDelegate::createEditor(theParent, theOption, theIndex); } } - QObject* aThat = (QObject*) this; - aEditor->installEventFilter(aThat); + 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; } -//bool DataTableItemDelegate::eventFilter(QObject* theObj, QEvent* theEvent) -//{ -// qDebug("### Type = %i", theEvent->type()); -// if (theEvent->type() == QEvent::Close) { -// QWidget* aWgt = dynamic_cast(theObj); -// commitData(aWgt); -// } -// return QStyledItemDelegate::eventFilter(theObj, theEvent); -//} +void DataTableItemDelegate::onEditItem(const QString& theText) +{ + QWidget* aWgt = dynamic_cast(sender()); + commitData(aWgt); +} + //********************************************************************************** diff --git a/src/CollectionPlugin/CollectionPlugin_WidgetField.h b/src/CollectionPlugin/CollectionPlugin_WidgetField.h index 515a442aa..f56f6431b 100644 --- a/src/CollectionPlugin/CollectionPlugin_WidgetField.h +++ b/src/CollectionPlugin/CollectionPlugin_WidgetField.h @@ -49,6 +49,9 @@ public: //protected: // bool eventFilter(QObject* theObj, QEvent* theEvent); +private slots: + void onEditItem(const QString& theText); + private: ModelAPI_AttributeTables::ValueType myType; }; -- 2.39.2