Some optimizations for feedsmodel.

This commit is contained in:
Martin Rotter 2013-12-31 14:25:49 +01:00
parent 7f33dfdd2e
commit e7a313fd77
4 changed files with 14 additions and 17 deletions

View file

@ -19,7 +19,6 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
virtual void loadSettings(); virtual void loadSettings();
protected: protected:
QNetworkReply *createRequest(Operation op, QNetworkReply *createRequest(Operation op,
const QNetworkRequest &request, const QNetworkRequest &request,
QIODevice *outgoingData); QIODevice *outgoingData);

View file

@ -35,19 +35,13 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
FeedsModel::~FeedsModel() { FeedsModel::~FeedsModel() {
qDebug("Destroying FeedsModel instance."); qDebug("Destroying FeedsModel instance.");
delete m_rootItem; delete m_rootItem;
DatabaseFactory::getInstance()->removeConnection(objectName()); DatabaseFactory::getInstance()->removeConnection(objectName());
} }
QVariant FeedsModel::data(const QModelIndex &index, int role) const { QVariant FeedsModel::data(const QModelIndex &index, int role) const {
FeedsModelRootItem *item = itemForIndex(index); return itemForIndex(index)->data(index.column(), role);
if (item != NULL) {
return item->data(index.column(), role);
}
else {
return QVariant();
}
} }
QVariant FeedsModel::headerData(int section, QVariant FeedsModel::headerData(int section,
@ -153,7 +147,7 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) const {
return static_cast<FeedsModelRootItem*>(index.internalPointer()); return static_cast<FeedsModelRootItem*>(index.internalPointer());
} }
else { else {
return NULL; return m_rootItem;
} }
} }
@ -168,9 +162,9 @@ FeedsModelCategory *FeedsModel::categoryForIndex(const QModelIndex &index) const
} }
} }
/*
QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const {
if (item->kind() == FeedsModelRootItem::RootItem) { if (item == NULL || item->kind() == FeedsModelRootItem::RootItem) {
// Root item lies on invalid index. // Root item lies on invalid index.
return QModelIndex(); return QModelIndex();
} }
@ -212,8 +206,8 @@ QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const {
return QModelIndex(); return QModelIndex();
} }
*/
/*
QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const {
if (item->kind() == FeedsModelRootItem::RootItem) { if (item->kind() == FeedsModelRootItem::RootItem) {
// Root item lies on invalid index. // Root item lies on invalid index.
@ -255,7 +249,7 @@ QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const {
} }
return QModelIndex(); return QModelIndex();
} }*/
void FeedsModel::reloadChangedLayout(QModelIndexList list) { void FeedsModel::reloadChangedLayout(QModelIndexList list) {
while (!list.isEmpty()) { while (!list.isEmpty()) {

View file

@ -64,7 +64,7 @@ class FeedsModel : public QAbstractItemModel {
FeedsModelCategory *categoryForIndex(const QModelIndex &index) const; FeedsModelCategory *categoryForIndex(const QModelIndex &index) const;
// Returns feed/category which lies at the specified index or // Returns feed/category which lies at the specified index or
// null if index is invalid. // root item if index is invalid.
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const; FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
// Returns QModelIndex on which lies given item. // Returns QModelIndex on which lies given item.

View file

@ -205,8 +205,12 @@ void FeedsView::selectionChanged(const QItemSelection &selected,
m_selectedFeeds.clear(); m_selectedFeeds.clear();
foreach (FeedsModelFeed *feed, selectedFeeds()) { foreach (FeedsModelFeed *feed, selectedFeeds()) {
QModelIndex id = m_sourceModel->indexForItem(feed); #if defined(DEBUG)
qDebug("INDEX %d, %d", id.row(), id.column()); QModelIndex index_for_feed = m_sourceModel->indexForItem(feed);
qDebug("Selecting feed '%s' (source index [%d, %d]).",
qPrintable(feed->title()), index_for_feed.row(), index_for_feed.column());
#endif
m_selectedFeeds << feed->id(); m_selectedFeeds << feed->id();
} }