From a35b1e7a436e3436d4fb0a4618b86e81220d04d8 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Fri, 1 Jun 2012 13:31:15 -0300 Subject: The method createIndex is the peferred way to create valid QModelIndex objects. So says the Qt documentation, plus one less warning from QSortFilterProxyModel. For the healthly curious the warning was: "inconsistent changes reported by source model". And it happened when removing from top sites one item that was not the last. Reviewed-by: Luciano Wolf --- src/core/BookmarkModel.cpp | 10 +++++----- src/core/HistoryModel.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/BookmarkModel.cpp b/src/core/BookmarkModel.cpp index 280a85e..0f3542c 100644 --- a/src/core/BookmarkModel.cpp +++ b/src/core/BookmarkModel.cpp @@ -79,14 +79,14 @@ void BookmarkModel::remove(const QString& url) sqlQuery.first(); int indexToDelete = -1; for (int row = 0; row < rowCount(); ++row) { - if (index(row, 0).data(Qt::DisplayRole).toInt() == sqlQuery.value(0).toInt()) { + if (createIndex(row, 0).data(Qt::DisplayRole).toInt() == sqlQuery.value(0).toInt()) { indexToDelete = row; break; } } if (indexToDelete >= 0) { - beginRemoveRows(QModelIndex(), indexToDelete, indexToDelete); + beginRemoveRows(createIndex(indexToDelete, 0), indexToDelete, indexToDelete); removeRow(indexToDelete); submitAll(); endRemoveRows(); @@ -103,8 +103,8 @@ void BookmarkModel::togglePin(const QString& url) void BookmarkModel::update(int index, const QString& name, const QString& url) { - setData(this->index(index, 1), name); - setData(this->index(index, 2), url); + setData(createIndex(index, 1), name); + setData(createIndex(index, 2), url); } bool BookmarkModel::contains(const QString& url) @@ -123,7 +123,7 @@ QVariant BookmarkModel::data(const QModelIndex& index, int role) const value = QSqlQueryModel::data(index, role); else { const int columnId = role - Qt::UserRole; - const QModelIndex modelIndex = this->index(index.row(), columnId); + const QModelIndex modelIndex = createIndex(index.row(), columnId); value = QSqlTableModel::data(modelIndex, Qt::DisplayRole); } return value; diff --git a/src/core/HistoryModel.cpp b/src/core/HistoryModel.cpp index d9ec14d..830e7c6 100644 --- a/src/core/HistoryModel.cpp +++ b/src/core/HistoryModel.cpp @@ -84,7 +84,7 @@ QVariant HistoryModel::data(const QModelIndex& index, int role) const return QVariant(); const int columnId = role - Qt::UserRole; - const QModelIndex modelIndex = this->index(index.row(), columnId); + const QModelIndex modelIndex = createIndex(index.row(), columnId); return QSqlTableModel::data(modelIndex, Qt::DisplayRole); } -- cgit v1.2.3