From 1f5fa55bc01760d85025a19e6f6c425f55c16ff3 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 1 Mar 2014 15:09:10 +0100 Subject: [PATCH] Performance enhancements for message list.. --- src/core/messagesmodel.cpp | 25 ++++++++++++++----------- src/core/messagesmodel.h | 1 - src/core/textfactory.h | 4 +--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index 8757c075b..7de7140cb 100644 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -93,7 +93,7 @@ QStringList MessagesModel::textualFeeds() const { } int MessagesModel::messageId(int row_index) const { - return record(row_index).value(MSG_DB_ID_INDEX).toInt(); + return data(row_index, MSG_DB_ID_INDEX).toInt(); } Message MessagesModel::messageAt(int row_index) const { @@ -140,24 +140,26 @@ QVariant MessagesModel::data(int row, int column, int role) const { return data(index(row, column), role); } -QVariant MessagesModel::data(const QModelIndex &index, int role) const { +QVariant MessagesModel::data(const QModelIndex &idx, int role) const { switch (role) { // Human readable data for viewing. case Qt::DisplayRole: { - int index_column = index.column(); + int index_column = idx.column(); if (index_column == MSG_DB_DCREATED_INDEX) { - return TextFactory::parseDateTime(QSqlTableModel::data(index, + // TODO: toLocalTime() may be unnecessary here + // because parseDateTime already returns localtime. + return TextFactory::parseDateTime(QSqlTableModel::data(idx, role).value()).toLocalTime().toString(Qt::DefaultLocaleShortDate); } else if (index_column == MSG_DB_AUTHOR_INDEX) { - QString author_name = QSqlTableModel::data(index, role).toString(); + QString author_name = QSqlTableModel::data(idx, role).toString(); return author_name.isEmpty() ? "-" : author_name; } else if (index_column != MSG_DB_IMPORTANT_INDEX && index_column != MSG_DB_READ_INDEX) { - return QSqlTableModel::data(index, role); + return QSqlTableModel::data(idx, role); } else { return QVariant(); @@ -165,23 +167,24 @@ QVariant MessagesModel::data(const QModelIndex &index, int role) const { } case Qt::EditRole: - return QSqlTableModel::data(index, role); + return QSqlTableModel::data(idx, role); case Qt::FontRole: - return record(index.row()).value(MSG_DB_READ_INDEX).toInt() == 1 ? + return QSqlTableModel::data(index(idx.row(), + MSG_DB_READ_INDEX)).toInt() == 1 ? m_normalFont : m_boldFont; case Qt::DecorationRole: { - int index_column = index.column(); + int index_column = idx.column(); if (index_column == MSG_DB_READ_INDEX) { - return record(index.row()).value(MSG_DB_READ_INDEX).toInt() == 1 ? + return QSqlTableModel::data(idx).toInt() == 1 ? m_readIcon : m_unreadIcon; } else if (index_column == MSG_DB_IMPORTANT_INDEX) { - return record(index.row()).value(MSG_DB_IMPORTANT_INDEX).toInt() == 1 ? + return QSqlTableModel::data(idx).toInt() == 1 ? m_favoriteIcon : QVariant(); } diff --git a/src/core/messagesmodel.h b/src/core/messagesmodel.h index c1bccb6b5..1b4b2d04d 100644 --- a/src/core/messagesmodel.h +++ b/src/core/messagesmodel.h @@ -72,7 +72,6 @@ class MessagesModel : public QSqlTableModel { // To disable persistent changes submissions. inline bool submitAll() { qFatal("Submitting changes via model is not allowed."); - return false; } diff --git a/src/core/textfactory.h b/src/core/textfactory.h index 8abfa31c1..a1bbe8dfa 100644 --- a/src/core/textfactory.h +++ b/src/core/textfactory.h @@ -40,9 +40,7 @@ class TextFactory { static QDateTime parseDateTime(const QString &date_time); // Converts 1970-epoch miliseconds to date/time. - // NOTE: This method returns date/time local-time - // which is calculated from the system settings. - // NOTE: On Windows UTC is known to be broken. + // NOTE: This apparently returns date/time in localtime. static QDateTime parseDateTime(qint64 milis_from_epoch); // Strips "<....>" (HTML, XML) tags from given text.