From 1773c66a65336ad8fdfc914a81465a30531fb631 Mon Sep 17 00:00:00 2001 From: Jakob Leben Date: Sun, 11 Sep 2011 20:28:14 +0200 Subject: [PATCH] qt gui: QTreeView add sorting New -canSort variable and -sort( column, descending ) method. --- QtCollider/widgets/QcTreeWidget.cpp | 5 +++++ QtCollider/widgets/QcTreeWidget.h | 2 ++ SCClassLibrary/QtCollider/QTreeView.sc | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/QtCollider/widgets/QcTreeWidget.cpp b/QtCollider/widgets/QcTreeWidget.cpp index 7479e6607..304e2fe6f 100644 --- a/QtCollider/widgets/QcTreeWidget.cpp +++ b/QtCollider/widgets/QcTreeWidget.cpp @@ -186,6 +186,11 @@ void QcTreeWidget::removeItemWidget( const QcTreeWidget::ItemPtr &item, int colu if( item ) QTreeWidget::removeItemWidget( item, column ); } +void QcTreeWidget::sort( int column, bool descending ) +{ + sortItems( column, descending ? Qt::DescendingOrder : Qt::AscendingOrder ); +} + void QcTreeWidget::onCurrentItemChanged() { if( _emitAction ) Q_EMIT( action() ); diff --git a/QtCollider/widgets/QcTreeWidget.h b/QtCollider/widgets/QcTreeWidget.h index ecd8c52ae..3a28d6390 100644 --- a/QtCollider/widgets/QcTreeWidget.h +++ b/QtCollider/widgets/QcTreeWidget.h @@ -85,6 +85,8 @@ public: Q_INVOKABLE void setItemWidget( const QcTreeWidget::ItemPtr &, int column, QObjectProxy * ); Q_INVOKABLE void removeItemWidget( const QcTreeWidget::ItemPtr &, int column ); + Q_INVOKABLE void sort( int column, bool descending ); + Q_SIGNALS: void action(); diff --git a/SCClassLibrary/QtCollider/QTreeView.sc b/SCClassLibrary/QtCollider/QTreeView.sc index fd2b5616f..f3e576e86 100644 --- a/SCClassLibrary/QtCollider/QTreeView.sc +++ b/SCClassLibrary/QtCollider/QTreeView.sc @@ -30,6 +30,13 @@ QTreeView : QView { ^this.invokeMethod( \item, [QTreeViewItem(), index] ).prValidItem(this); } + canSort { ^this.getProperty( \sortingEnabled ) } + canSort_ { arg bool; this.setProperty( \sortingEnabled, bool ) } + + sort { arg column, descending = false; + this.invokeMethod( \sort, [column, descending] ) + } + /* NOTE: These methods can only operate on top level items -- 2.11.4.GIT