diff options
author | Albert Astals Cid <aacid@kde.org> | 2010-11-25 15:21:29 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2010-11-25 15:21:29 (GMT) |
commit | 9d80633e7dea2e054b4b748032879dc302b36a23 (patch) | |
tree | b605b577aba1d07267934ba050db1142b907064d /src/gui/itemviews/qheaderview.cpp | |
parent | dcaa2b69af5d242248c8e12355539b6e8349f5d5 (diff) | |
download | Qt-9d80633e7dea2e054b4b748032879dc302b36a23.zip Qt-9d80633e7dea2e054b4b748032879dc302b36a23.tar.gz Qt-9d80633e7dea2e054b4b748032879dc302b36a23.tar.bz2 |
Add a way to set QHeaderView initial sort order
Merge-request: 814
Reviewed-by: Thierry Bastian <thierry.bastian@nokia.com>
Diffstat (limited to 'src/gui/itemviews/qheaderview.cpp')
-rw-r--r-- | src/gui/itemviews/qheaderview.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index 7eb3ddc..754e8b5 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -3274,9 +3274,17 @@ void QHeaderViewPrivate::clear() void QHeaderViewPrivate::flipSortIndicator(int section) { Q_Q(QHeaderView); - bool ascending = (sortIndicatorSection != section - || sortIndicatorOrder == Qt::DescendingOrder); - q->setSortIndicator(section, ascending ? Qt::AscendingOrder : Qt::DescendingOrder); + Qt::SortOrder sortOrder; + if (sortIndicatorSection == section) { + sortOrder = (sortIndicatorOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; + } else { + const QVariant value = model->headerData(section, orientation, Qt::InitialSortOrderRole); + if (value.canConvert(QVariant::Int)) + sortOrder = static_cast<Qt::SortOrder>(value.toInt()); + else + sortOrder = Qt::AscendingOrder; + } + q->setSortIndicator(section, sortOrder); } void QHeaderViewPrivate::cascadingResize(int visual, int newSize) |