From ccb45ab1e4872ad76455f05d21664f3e35a21227 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 28 Apr 2016 10:23:39 +0300 Subject: [PATCH] Optimization of table navigation by Tab button --- .../ParametersPlugin_WidgetParamsMgr.cpp | 42 ++++++++++++++++++- .../ParametersPlugin_WidgetParamsMgr.h | 17 +++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index a0d88f734..953a9b869 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -21,13 +21,14 @@ #include #include -#include #include #include #include #include #include #include +#include +#include enum ColumnType { Col_Name, @@ -97,6 +98,39 @@ QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent, return QStyledItemDelegate::createEditor(parent, option, index); } +///////////////////////////////////////////////////////////////////////////////////////////////// +void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint) +{ + if (theHint == QAbstractItemDelegate::EditNextItem) { + QModelIndex aCurrent = currentIndex(); + QModelIndex aParent = model()->index(0, 0); + int aNbRows = model()->rowCount(aParent); + QModelIndex aIdx; + switch (aCurrent.column()) { + case 0: + aIdx = model()->index(aCurrent.row(), 1, aParent); + break; + case 1: + if (aCurrent.row() < (aNbRows - 1)) + aIdx = model()->index(aCurrent.row() + 1, 0, aParent); + else { + QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint); + return; + } + break; + case 3: + QTreeWidget::closeEditor(theEditor, theHint); + return; + } + if (aIdx.isValid()) { + QTreeWidget::closeEditor(theEditor, QAbstractItemDelegate::NoHint); + setCurrentIndex(aIdx); + edit(aIdx); + return; + } + } + QTreeWidget::closeEditor(theEditor, theHint); +} ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -105,7 +139,7 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP { QVBoxLayout* aLayout = new QVBoxLayout(this); - myTable = new QTreeWidget(this); + myTable = new ParametersPlugin_TreeWidget(this); myTable->setColumnCount(4); QStringList aHeaders; aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment"); @@ -317,6 +351,7 @@ QList ParametersPlugin_WidgetParamsMgr:: void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex) { if (myDelegate->isEditable(theIndex)) { + myTable->setCurrentIndex(theIndex); myTable->edit(theIndex); } } @@ -455,6 +490,8 @@ void ParametersPlugin_WidgetParamsMgr::onAdd() myParametersList.append(aFeature); myTable->scrollToItem(aItem); + myTable->setCurrentItem(aItem); + myTable->editItem(aItem); } QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::selectedItem() const @@ -648,3 +685,4 @@ void ParametersPlugin_WidgetParamsMgr::onSelectionChanged() myUpBtn->setEnabled(isParameter); myDownBtn->setEnabled(isParameter); } + diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index 91c772da0..5780c4b55 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -10,13 +10,26 @@ #include #include #include +#include -class QTreeWidget; class QTreeWidgetItem; class ParametersPlugin_ItemDelegate; class QPushButton; class QToolButton; + +class ParametersPlugin_TreeWidget: public QTreeWidget +{ + Q_OBJECT +public: + ParametersPlugin_TreeWidget(QWidget* theParent = 0) : QTreeWidget(theParent) {} + +protected slots: + virtual void closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint); +}; + + + /*! * \ingroup GUI * Represent a content of the property panel to show/modify parameters of some feature. @@ -105,7 +118,7 @@ private: void updateParametersFeatures(); - QTreeWidget* myTable; + ParametersPlugin_TreeWidget* myTable; QTreeWidgetItem* myFeatures; QTreeWidgetItem* myParameters; ParametersPlugin_ItemDelegate* myDelegate; -- 2.39.2