From: vsv Date: Thu, 28 Apr 2016 07:23:39 +0000 (+0300) Subject: Optimization of table navigation by Tab button X-Git-Tag: V_2.3.0~86 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ccb45ab1e4872ad76455f05d21664f3e35a21227;p=modules%2Fshaper.git Optimization of table navigation by Tab button --- 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;