From dc124b27dec5077aa387de5330153ef7c1bb771e Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 7 Feb 2017 16:37:53 +0300 Subject: [PATCH] 0023342: [CEA 1947] When we add a text option, the tab key doesn't allow to write the value --- src/GUI/BLSURFPluginGUI_AdvWidget.cxx | 10 +-- src/GUI/BLSURFPluginGUI_AdvWidget_QTD.ui | 14 +++- src/GUI/BLSURFPluginGUI_TreeWidget.cxx | 91 ++++++++++++++++++++++++ src/GUI/BLSURFPluginGUI_TreeWidget.h | 36 ++++++++++ src/GUI/CMakeLists.txt | 3 + 5 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 src/GUI/BLSURFPluginGUI_TreeWidget.cxx create mode 100644 src/GUI/BLSURFPluginGUI_TreeWidget.h diff --git a/src/GUI/BLSURFPluginGUI_AdvWidget.cxx b/src/GUI/BLSURFPluginGUI_AdvWidget.cxx index 8bd1296..7816eda 100644 --- a/src/GUI/BLSURFPluginGUI_AdvWidget.cxx +++ b/src/GUI/BLSURFPluginGUI_AdvWidget.cxx @@ -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 ); } } diff --git a/src/GUI/BLSURFPluginGUI_AdvWidget_QTD.ui b/src/GUI/BLSURFPluginGUI_AdvWidget_QTD.ui index c2f05df..43f0876 100644 --- a/src/GUI/BLSURFPluginGUI_AdvWidget_QTD.ui +++ b/src/GUI/BLSURFPluginGUI_AdvWidget_QTD.ui @@ -12,9 +12,12 @@ - + - QAbstractItemView::DoubleClicked + QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + true @@ -122,6 +125,13 @@ + + + BLSURFPluginGUI_TreeWidget + QTreeWidget +
BLSURFPluginGUI_TreeWidget.h
+
+
addBtn myVerbosity diff --git a/src/GUI/BLSURFPluginGUI_TreeWidget.cxx b/src/GUI/BLSURFPluginGUI_TreeWidget.cxx new file mode 100644 index 0000000..ed121c6 --- /dev/null +++ b/src/GUI/BLSURFPluginGUI_TreeWidget.cxx @@ -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 + +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 index 0000000..7581cb1 --- /dev/null +++ b/src/GUI/BLSURFPluginGUI_TreeWidget.h @@ -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 + +class BLSURFPluginGUI_TreeWidget : public QTreeWidget +{ + Q_OBJECT +public: + BLSURFPluginGUI_TreeWidget( QWidget* ); + +protected: + QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers ); + void keyPressEvent( QKeyEvent* ); +}; + +#endif // BLSURFPluginGUI_TreeWidget_H diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index b42d57e..4a13b7d 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -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 --- -- 2.39.2