Salome HOME
bos #32216 [CEA] GUI ergonomic: fix horizontal scrollbar position.
[modules/gui.git] / src / Qtx / QtxTreeView.cxx
index 9de54fd2436a963a92c55d0ad508ae029b8e0f0f..17e2dfab1dc3d8e16c3031762d75caf1f0beaa81 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
 #include <QHeaderView>
 #include <QMenu>
 #include <QMouseEvent>
+#include <QScrollBar>
 
 /*!
   \class QtxTreeView::Header
@@ -107,10 +108,10 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e )
     QVariant appropriate = model()->headerData( i, orientation(), Qtx::AppropriateRole );
     QIcon icon;
     if ( iconData.isValid() ) {
-      if ( qVariantCanConvert<QIcon>( iconData ) )
-        icon = qVariantValue<QIcon>( iconData );
-      else if ( qVariantCanConvert<QPixmap>( iconData ) )
-        icon = qVariantValue<QPixmap>( iconData );
+      if ( iconData.canConvert( QMetaType::QIcon ) )
+        icon = iconData.value<QIcon>();
+      else if ( iconData.canConvert( QMetaType::QPixmap ) )
+        icon = iconData.value<QPixmap>();
     }
     if( ( !lab.isEmpty() || !icon.isNull() ) && 
             appropriate.isValid() ? appropriate.toInt()==Qtx::Toggled : true )
@@ -136,7 +137,7 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e )
     }
     else if ( a && a == sortAction ) {
       setSortIndicatorShown( a->isChecked() );
-      setClickable( a->isChecked() );
+      setSectionsClickable( a->isChecked() );
       QtxTreeView* view = qobject_cast<QtxTreeView*>( parent() );
       if ( view ) {
         view->emitSortingEnabled( a->isChecked() );
@@ -181,7 +182,7 @@ QtxTreeView::QtxTreeView( QWidget* parent )
 : QTreeView( parent )
 {
   setHeader( new Header( false, this ) );
-  header()->setMovable( true );
+  header()->setSectionsMovable( true );
 }
 
 /*!
@@ -193,7 +194,7 @@ QtxTreeView::QtxTreeView( const bool enableSortMenu, QWidget* parent )
 : QTreeView( parent )
 {
   setHeader( new Header( enableSortMenu, this ) );
-  header()->setMovable( true );
+  header()->setSectionsMovable( true );
 }
 
 /*!
@@ -390,6 +391,21 @@ void QtxTreeView::setModel( QAbstractItemModel* m )
              this, SLOT( onAppropriate( Qt::Orientation, int, int ) ) );
 }
 
+// This method fixes problem with Object Browser horizontal scrollbar automatic scrolling to the right
+void QtxTreeView::scrollTo(const QModelIndex &index,
+                           QAbstractItemView::ScrollHint hint)
+{
+  QScrollBar* aScrollBar = horizontalScrollBar();
+  if (aScrollBar) {
+    int horPos = aScrollBar->value();
+    QTreeView::scrollTo(index, hint);
+    aScrollBar->setValue(horPos);
+  }
+  else {
+    QTreeView::scrollTo(index, hint);
+  }
+}
+
 void QtxTreeView::onAppropriate( Qt::Orientation orient, int first, int last )
 {
   if( orient==Qt::Horizontal )