-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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.
//
-// 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.
+// 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.
//
-// 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
//
-// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// File: QtxTreeView.cxx
// Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
//
QIcon icon;
if ( iconData.isValid() ) {
if ( qVariantCanConvert<QIcon>( iconData ) )
- icon = qVariantValue<QIcon>( iconData );
+ icon = qVariantValue<QIcon>( iconData );
else if ( qVariantCanConvert<QPixmap>( iconData ) )
- icon = qVariantValue<QPixmap>( iconData );
+ icon = qVariantValue<QPixmap>( iconData );
}
if( ( !lab.isEmpty() || !icon.isNull() ) &&
- appropriate.isValid() ? appropriate.toInt()==Qtx::Toggled : true )
- {
+ appropriate.isValid() ? appropriate.toInt()==Qtx::Toggled : true )
+ {
QAction* a = menu.addAction( icon, lab );
a->setCheckable( true );
a->setChecked( !isSectionHidden( i ) );
QAction* sortAction = 0;
if ( count() > 0 && myEnableSortMenu ) {
menu.addSeparator();
- sortAction = menu.addAction( tr( "Enable sorting" ) );
+ sortAction = menu.addAction( QtxTreeView::tr( "Enable sorting" ) );
sortAction->setCheckable( true );
sortAction->setChecked( isSortIndicatorShown() );
}
setClickable( a->isChecked() );
QtxTreeView* view = qobject_cast<QtxTreeView*>( parent() );
if ( view ) {
- view->emitSortingEnabled( a->isChecked() );
- if ( a->isChecked() ) {
- connect( this, SIGNAL( sectionClicked( int ) ), view, SLOT( onHeaderClicked( int ) ) );
- view->sortByColumn( sortIndicatorSection(), sortIndicatorOrder() );
- }
- else {
- disconnect( this, SIGNAL( sectionClicked( int ) ), view, SLOT( onHeaderClicked( int ) ) );
- view->sortByColumn( 0, Qt::AscendingOrder );
- }
+ view->emitSortingEnabled( a->isChecked() );
+ if ( a->isChecked() ) {
+ connect( this, SIGNAL( sectionClicked( int ) ), view, SLOT( onHeaderClicked( int ) ) );
+ setSortIndicator( 0, Qt::AscendingOrder );
+ view->sortByColumn( sortIndicatorSection(), sortIndicatorOrder() );
+ }
+ else {
+ disconnect( this, SIGNAL( sectionClicked( int ) ), view, SLOT( onHeaderClicked( int ) ) );
+ view->sortByColumn( 0, Qt::AscendingOrder );
+ }
}
}
}
\param deselected previous selection
*/
void QtxTreeView::selectionChanged( const QItemSelection& selected,
- const QItemSelection& deselected )
+ const QItemSelection& deselected )
{
QTreeView::selectionChanged( selected, deselected );
emit( selectionChanged() );
*/
void QtxTreeView::rowsAboutToBeRemoved( const QModelIndex& parent, int start, int end )
{
- setCurrentIndex( QModelIndex() );
+ QModelIndex curIndex = currentIndex();
+ while ( curIndex.isValid() && curIndex.parent() != parent )
+ curIndex = curIndex.parent();
+ if ( curIndex.isValid() && curIndex.row() >= start && curIndex.row() <= end )
+ setCurrentIndex( QModelIndex() );
QTreeView::rowsAboutToBeRemoved( parent, start, end );
}
QTreeView::setModel( m );
if ( model() )
connect( model(), SIGNAL( headerDataChanged( Qt::Orientation, int, int ) ),
- this, SLOT( onAppropriate( Qt::Orientation, int, int ) ) );
+ this, SLOT( onAppropriate( Qt::Orientation, int, int ) ) );
}
void QtxTreeView::onAppropriate( Qt::Orientation orient, int first, int last )
{
if( orient==Qt::Horizontal )
for( int i=first; i<=last; i++ )
- {
- int appr = model()->headerData( i, orient, Qtx::AppropriateRole ).toInt();
- header()->setSectionHidden( i, appr==Qtx::Hidden );
- }
+ {
+ int appr = model()->headerData( i, orient, Qtx::AppropriateRole ).toInt();
+ header()->setSectionHidden( i, appr==Qtx::Hidden );
+ }
}