]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Optimization of table navigation by Tab button
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 28 Apr 2016 07:23:39 +0000 (10:23 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 28 Apr 2016 07:24:00 +0000 (10:24 +0300)
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h

index a0d88f734ee51265ee2c33fa6c151e463e8f2133..953a9b869ac92191978dd3008eec03dce8218d91 100644 (file)
 #include <Events_Loop.h>
 
 #include <QLayout>
-#include <QTreeWidget>
 #include <QPushButton>
 #include <QToolButton>
 #include <QStyledItemDelegate>
 #include <QPainter>
 #include <QMessageBox>
 #include <QTimer>
+#include <QEvent>
+#include <QKeyEvent>
 
 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<QStringList> 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);
 }
+
index 91c772da0c073bba2dd39b9b039e0ff180e88c7c..5780c4b557f83dd96693cbb33299c6bbb4b8f381 100644 (file)
 #include <ModuleBase_ModelWidget.h>
 #include <QModelIndex>
 #include <QAbstractItemDelegate>
+#include <QTreeWidget>
 
-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;