]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
0023342: [CEA 1947] When we add a text option, the tab key doesn't allow to write...
authorvsr <vsr@opencascade.com>
Tue, 7 Feb 2017 13:37:53 +0000 (16:37 +0300)
committervsr <vsr@opencascade.com>
Tue, 7 Feb 2017 13:53:32 +0000 (16:53 +0300)
src/GUI/BLSURFPluginGUI_AdvWidget.cxx
src/GUI/BLSURFPluginGUI_AdvWidget_QTD.ui
src/GUI/BLSURFPluginGUI_TreeWidget.cxx [new file with mode: 0644]
src/GUI/BLSURFPluginGUI_TreeWidget.h [new file with mode: 0644]
src/GUI/CMakeLists.txt

index 8bd1296b22004d62d9bea7758fb9e918f7294fe4..7816edaee8afa70c51a7b28a35c5db4fe30cbed8 100644 (file)
@@ -67,10 +67,11 @@ BLSURFPluginGUI_AdvWidget::~BLSURFPluginGUI_AdvWidget()
 void BLSURFPluginGUI_AdvWidget::onChooseGMFFile()
 {
   QString fileName = QFileDialog::getSaveFileName(0, tr("BLSURF_GMF_FILE_DIALOG"), myGMFFileName->text(), tr("BLSURF_GMF_FILE_FORMAT"));
-  std::cout << "fileName: " << fileName.toStdString() << std::endl;
-  if (!fileName.endsWith(".mesh") && !fileName.endsWith(".meshb"))
-    fileName.append(".mesh");
-  myGMFFileName->setText(fileName);
+  if ( !fileName.isEmpty() ) {
+    if (!fileName.endsWith(".mesh") && !fileName.endsWith(".meshb"))
+      fileName.append(".mesh");
+    myGMFFileName->setText(fileName);
+  }
 }
 
 void BLSURFPluginGUI_AdvWidget::AddOption( int iTable, const char* option )
@@ -107,6 +108,7 @@ void BLSURFPluginGUI_AdvWidget::AddOption( int iTable, const char* option )
     if ( !option )
     {
       myOptionTable->scrollToItem( row );
+      myOptionTable->setCurrentItem( row );
       myOptionTable->editItem( row, NAME_COL );
     }
   }
index c2f05dfc7a3c2c254b63de496563d92223ee89fd..43f0876d49dd56f4bdd36d8edeba245d21bea33c 100644 (file)
   </property>
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0" colspan="3">
-    <widget class="QTreeWidget" name="myOptionTable">
+    <widget class="BLSURFPluginGUI_TreeWidget" name="myOptionTable">
      <property name="editTriggers">
-      <set>QAbstractItemView::DoubleClicked</set>
+      <set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
+     </property>
+     <property name="tabKeyNavigation">
+      <bool>true</bool>
      </property>
      <column>
       <property name="text">
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>BLSURFPluginGUI_TreeWidget</class>
+   <extends>QTreeWidget</extends>
+   <header location="global">BLSURFPluginGUI_TreeWidget.h</header>
+  </customwidget>
+ </customwidgets>
  <tabstops>
   <tabstop>addBtn</tabstop>
   <tabstop>myVerbosity</tabstop>
diff --git a/src/GUI/BLSURFPluginGUI_TreeWidget.cxx b/src/GUI/BLSURFPluginGUI_TreeWidget.cxx
new file mode 100644 (file)
index 0000000..ed121c6
--- /dev/null
@@ -0,0 +1,91 @@
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "BLSURFPluginGUI_TreeWidget.h"
+#include <QKeyEvent>
+
+namespace
+{
+  bool isEditable( const QModelIndex& index )
+  {
+    return index.isValid() &&
+      index.flags() & Qt::ItemIsEditable && 
+      index.flags() & Qt::ItemIsEnabled &&
+      ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
+  }
+}
+
+BLSURFPluginGUI_TreeWidget::BLSURFPluginGUI_TreeWidget( QWidget* parent )
+  : QTreeWidget( parent )
+{
+}
+
+QModelIndex BLSURFPluginGUI_TreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
+{
+  QModelIndex current = currentIndex();
+  int column = current.column();
+  if ( action == MoveNext ) {
+    if ( column < columnCount()-1 ) {
+      QModelIndex next = current.sibling( current.row(), column+1 );
+      if ( isEditable( next ) )
+        return next;
+    }
+    else {
+      QModelIndex next = current.sibling( current.row()+1, 0 );
+      if ( isEditable( next ) )
+        return next;
+    }
+  }
+  else if ( action == MovePrevious ) {
+    if ( column == 0 ) {
+      QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
+      if ( isEditable( next ) )
+        return next;
+    }
+    else {
+      QModelIndex next = current.sibling( current.row(), column-1 );
+      if ( isEditable( next ) )
+        return next;
+    }
+  }
+  return QTreeWidget::moveCursor( action, modifiers );
+}
+
+void BLSURFPluginGUI_TreeWidget::keyPressEvent( QKeyEvent* e )
+{
+  switch ( e->key() ) {
+  case Qt::Key_F2:
+    {
+      QModelIndex index = currentIndex();
+      if ( !isEditable( index ) ) {
+        for ( int i = 0; i < columnCount(); i++ ) {
+          QModelIndex sibling = index.sibling( index.row(), i );
+          if ( isEditable( sibling ) ) {
+            if ( !edit( sibling, EditKeyPressed, e ) )
+              e->ignore();
+          }
+        }
+      }
+    }
+    break;
+  default:
+    break;
+  }
+  QTreeWidget::keyPressEvent( e );
+}
diff --git a/src/GUI/BLSURFPluginGUI_TreeWidget.h b/src/GUI/BLSURFPluginGUI_TreeWidget.h
new file mode 100644 (file)
index 0000000..7581cb1
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#if !defined(BLSURFPluginGUI_TreeWidget_H)
+#define BLSURFPluginGUI_TreeWidget_H
+
+#include <QTreeWidget>
+
+class BLSURFPluginGUI_TreeWidget : public QTreeWidget
+{
+  Q_OBJECT
+public:
+  BLSURFPluginGUI_TreeWidget( QWidget* );
+
+protected:
+  QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers );
+  void keyPressEvent( QKeyEvent* );
+};
+
+#endif // BLSURFPluginGUI_TreeWidget_H
index b42d57eef2141b3c611f1c3aa030748443f3fdfb..4a13b7de9825dcfffa411acd0be0297603486ed2 100644 (file)
@@ -36,6 +36,7 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_BINARY_DIR}
   ${PROJECT_BINARY_DIR}/idl
   ${PROJECT_SOURCE_DIR}/src/BLSURFPlugin
+  ${PROJECT_SOURCE_DIR}/src/GUI
 )
 
 # additional preprocessor / compiler flags
@@ -73,6 +74,7 @@ SET(_link_LIBRARIES
 SET(BLSURFPluginGUI_HEADERS
   BLSURFPluginGUI_HypothesisCreator.h
   BLSURFPluginGUI_Dlg.h
+  BLSURFPluginGUI_TreeWidget.h
 )
 
 # --- sources ---
@@ -86,6 +88,7 @@ SET(_other_SOURCES
   BLSURFPluginGUI_StdWidget.cxx
   BLSURFPluginGUI_AdvWidget.cxx
   BLSURFPluginGUI_HypothesisCreator.cxx
+  BLSURFPluginGUI_TreeWidget.cxx
 )
 
 # --- resources ---