1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HexoticPluginGUI_TreeWidget.h"
25 bool isEditable( const QModelIndex& index )
27 return index.isValid() &&
28 index.flags() & Qt::ItemIsEditable &&
29 index.flags() & Qt::ItemIsEnabled &&
30 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
34 HexoticPluginGUI_TreeWidget::HexoticPluginGUI_TreeWidget( QWidget* parent )
35 : QTreeWidget( parent )
39 QModelIndex HexoticPluginGUI_TreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
41 QModelIndex current = currentIndex();
42 int column = current.column();
43 if ( action == MoveNext ) {
44 if ( column < columnCount()-1 ) {
45 QModelIndex next = current.sibling( current.row(), column+1 );
46 if ( isEditable( next ) )
50 QModelIndex next = current.sibling( current.row()+1, 0 );
51 if ( isEditable( next ) )
55 else if ( action == MovePrevious ) {
57 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
58 if ( isEditable( next ) )
62 QModelIndex next = current.sibling( current.row(), column-1 );
63 if ( isEditable( next ) )
67 return QTreeWidget::moveCursor( action, modifiers );
70 void HexoticPluginGUI_TreeWidget::keyPressEvent( QKeyEvent* e )
75 QModelIndex index = currentIndex();
76 if ( !isEditable( index ) ) {
77 for ( int i = 0; i < columnCount(); i++ ) {
78 QModelIndex sibling = index.sibling( index.row(), i );
79 if ( isEditable( sibling ) ) {
80 if ( !edit( sibling, EditKeyPressed, e ) )
90 QTreeWidget::keyPressEvent( e );