From de26ea6a7ff921995b6229f1f683821adb95e973 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 10 Aug 2019 18:21:59 +0200 Subject: QTree/TableView: allow to reset the sort order to natural sorting QTreeView allowed to set the sort column to -1 which shows the data in it's natural order (when the model supports it). This functionality was removed during the porting away from the deprecated sortByColumn(int) functionality done in d0f909f8dbdd8594b0d950822f0e7ab8728da513 Readd the functionality and also allow it for QTableView. Fixes: QTBUG-77419 Change-Id: I96b0c09ab9da36ca0a9de58fe0f37e2c56b1d51b Reviewed-by: Samuel Gaist Reviewed-by: David Faure --- src/widgets/itemviews/qtableview.cpp | 8 ++++++-- src/widgets/itemviews/qtreeview.cpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index d4a6433c4d..b05662f6bc 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3187,14 +3187,18 @@ void QTableView::sortByColumn(int column) /*! \since 4.2 - Sorts the model by the values in the given \a column in the given \a order. + Sorts the model by the values in the given \a column and \a order. + + \a column may be -1, in which case no sort indicator will be shown + and the model will return to its natural, unsorted order. Note that not + all models support this and may even crash in this case. \sa sortingEnabled */ void QTableView::sortByColumn(int column, Qt::SortOrder order) { Q_D(QTableView); - if (column < 0) + if (column < -1) return; // If sorting is enabled it will emit a signal connected to // _q_sortIndicatorChanged, which then actually sorts diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 55b10d13c1..e9228edcda 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -2618,7 +2618,7 @@ void QTreeView::sortByColumn(int column) /*! \since 4.2 - Sets the model up for sorting by the values in the given \a column and \a order. + Sorts the model by the values in the given \a column and \a order. \a column may be -1, in which case no sort indicator will be shown and the model will return to its natural, unsorted order. Note that not @@ -2629,7 +2629,7 @@ void QTreeView::sortByColumn(int column) void QTreeView::sortByColumn(int column, Qt::SortOrder order) { Q_D(QTreeView); - if (column < 0) + if (column < -1) return; // If sorting is enabled it will emit a signal connected to // _q_sortIndicatorChanged, which then actually sorts -- cgit v1.2.3