From 6546a292c2f2f6a70cec950c011a27e91311867e Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 4 Feb 2015 18:29:30 +0100 Subject: [PATCH] Gerrit: Properly sort timestamps in Gerrit dialog Task-number: QTCREATORBUG-13602 Change-Id: Iba4b2d85d6b75752214b4f53684b9e90df9b1b69 Reviewed-by: Orgad Shaneh --- src/plugins/git/gerrit/gerritdialog.cpp | 1 + src/plugins/git/gerrit/gerritmodel.cpp | 11 ++++++++++- src/plugins/git/gerrit/gerritmodel.h | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/git/gerrit/gerritdialog.cpp b/src/plugins/git/gerrit/gerritdialog.cpp index 3eabebbe060..40b8fd79310 100644 --- a/src/plugins/git/gerrit/gerritdialog.cpp +++ b/src/plugins/git/gerrit/gerritdialog.cpp @@ -158,6 +158,7 @@ GerritDialog::GerritDialog(const QSharedPointer &p, m_filterModel->setSourceModel(m_model); m_filterModel->setFilterRole(GerritModel::FilterRole); + m_filterModel->setSortRole(GerritModel::SortRole); m_treeView->setRootIsDecorated(true); m_treeView->setModel(m_filterModel); m_treeView->setMinimumWidth(600); diff --git a/src/plugins/git/gerrit/gerritmodel.cpp b/src/plugins/git/gerrit/gerritmodel.cpp index bc04fa25544..d296c93112a 100644 --- a/src/plugins/git/gerrit/gerritmodel.cpp +++ b/src/plugins/git/gerrit/gerritmodel.cpp @@ -419,7 +419,14 @@ GerritModel::GerritModel(const QSharedPointer &p, QObject *par } GerritModel::~GerritModel() +{ } + +QVariant GerritModel::data(const QModelIndex &index, int role) const { + QVariant value = QStandardItemModel::data(index, role); + if (role == SortRole && value.isNull()) + return QStandardItemModel::data(index, Qt::DisplayRole); + return value; } static inline GerritChangePtr changeFromItem(const QStandardItem *item) @@ -704,7 +711,8 @@ QList GerritModel::changeToRow(const GerritChangePtr &c) const const QString dateString = c->lastUpdated.date() == QDate::currentDate() ? c->lastUpdated.time().toString(Qt::SystemLocaleShortDate) : c->lastUpdated.date().toString(Qt::SystemLocaleShortDate); - row[DateColumn]->setText(dateString); + row[DateColumn]->setData(dateString, Qt::DisplayRole); + row[DateColumn]->setData(c->lastUpdated, SortRole); QString project = c->project; if (c->branch != QLatin1String("master")) @@ -726,6 +734,7 @@ QList GerritModel::changeToRow(const GerritChangePtr &c) const for (int i = 0; i < GerritModel::ColumnCount; ++i) row[i]->setFont(font); } + return row; } diff --git a/src/plugins/git/gerrit/gerritmodel.h b/src/plugins/git/gerrit/gerritmodel.h index 166e0a99f3a..58796da460a 100644 --- a/src/plugins/git/gerrit/gerritmodel.h +++ b/src/plugins/git/gerrit/gerritmodel.h @@ -112,11 +112,14 @@ public: enum CustomModelRoles { FilterRole = Qt::UserRole + 1, - GerritChangeRole = Qt::UserRole + 2 + GerritChangeRole = Qt::UserRole + 2, + SortRole = Qt::UserRole + 3 }; GerritModel(const QSharedPointer &, QObject *parent = 0); ~GerritModel(); + QVariant data(const QModelIndex &index, int role) const; + GerritChangePtr change(const QModelIndex &index) const; QString toHtml(const QModelIndex &index) const;