summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2010-11-25 15:21:29 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2010-11-25 15:21:29 (GMT)
commit9d80633e7dea2e054b4b748032879dc302b36a23 (patch)
treeb605b577aba1d07267934ba050db1142b907064d /src
parentdcaa2b69af5d242248c8e12355539b6e8349f5d5 (diff)
downloadQt-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')
-rw-r--r--src/corelib/global/qnamespace.h1
-rw-r--r--src/corelib/global/qnamespace.qdoc28
-rw-r--r--src/gui/itemviews/qheaderview.cpp14
3 files changed, 27 insertions, 16 deletions
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index 3ed6291..830d35b 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -1617,6 +1617,7 @@ public:
AccessibleDescriptionRole = 12,
// More general purpose
SizeHintRole = 13,
+ InitialSortOrderRole = 14,
// Internal UiLib roles. Start worrying when public roles go that high.
DisplayPropertyRole = 27,
DecorationPropertyRole = 28,
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index f097f2a..c923a41 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2679,19 +2679,21 @@
Roles describing appearance and meta data (with associated types):
- \value FontRole The font used for items rendered with the default
- delegate. (QFont)
- \value TextAlignmentRole The alignment of the text for items rendered with the
- default delegate. (Qt::AlignmentFlag)
- \value BackgroundRole The background brush used for items rendered with
- the default delegate. (QBrush)
- \value BackgroundColorRole This role is obsolete. Use BackgroundRole instead.
- \value ForegroundRole The foreground brush (text color, typically)
- used for items rendered with the default delegate.
- (QBrush)
- \value TextColorRole This role is obsolete. Use ForegroundRole instead.
- \value CheckStateRole This role is used to obtain the checked state of
- an item. (Qt::CheckState)
+ \value FontRole The font used for items rendered with the default
+ delegate. (QFont)
+ \value TextAlignmentRole The alignment of the text for items rendered with the
+ default delegate. (Qt::AlignmentFlag)
+ \value BackgroundRole The background brush used for items rendered with
+ the default delegate. (QBrush)
+ \value BackgroundColorRole This role is obsolete. Use BackgroundRole instead.
+ \value ForegroundRole The foreground brush (text color, typically)
+ used for items rendered with the default delegate.
+ (QBrush)
+ \value TextColorRole This role is obsolete. Use ForegroundRole instead.
+ \value CheckStateRole This role is used to obtain the checked state of
+ an item. (Qt::CheckState)
+ \value InitialSortOrderRole This role is used to obtain the initial sort order
+ of a header view section. (Qt::SortOrder)
Accessibility roles (with associated types):
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)