From 7f33dfdd2e7c7c49c5dee6cf4b1cd72437af2240 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 31 Dec 2013 13:19:25 +0100 Subject: [PATCH] Work on feeds view/model. --- src/core/feedsmodel.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ src/gui/feedsview.cpp | 6 +++--- src/gui/feedsview.h | 1 + 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index cf15f1b45..1447daffd 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -168,6 +168,52 @@ FeedsModelCategory *FeedsModel::categoryForIndex(const QModelIndex &index) const } } +/* +QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { + if (item->kind() == FeedsModelRootItem::RootItem) { + // Root item lies on invalid index. + return QModelIndex(); + } + + // TODO: Rewrite for better performance. + + QModelIndexList parents; + + // Start with invalid index (so that we start from the root + // item). + parents << QModelIndex(); + + while (!parents.isEmpty()) { + QModelIndex active_index = parents.takeFirst(); + int row_count = rowCount(active_index); + + if (row_count > 0) { + // This index has children. + // Lets take a look if our target item is among them. + FeedsModelRootItem *active_item = itemForIndex(active_index); + int candidate_index = active_item->childItems().indexOf(item); + + if (candidate_index >= 0) { + // We found our item. + return index(candidate_index, 0, active_index); + } + else { + // Item is not found, add all "categories" from active_item. + for (int i = 0; i < row_count; i++) { + FeedsModelRootItem *possible_category = active_item->child(i); + + if (possible_category->kind() == FeedsModelRootItem::Category) { + parents << index(i, 0, active_index); + } + } + } + } + } + + return QModelIndex(); +} +*/ + QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { if (item->kind() == FeedsModelRootItem::RootItem) { // Root item lies on invalid index. diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 1f305c014..bcaf1c1f7 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -195,9 +195,6 @@ void FeedsView::setupAppearance() { setDragDropMode(QAbstractItemView::NoDragDrop); setAllColumnsShowFocus(true); setSelectionMode(QAbstractItemView::ExtendedSelection); - - // TODO: Check if stylesheets or drawBranches(...) reimplementation - // is better for hiding the branches of the view. setRootIsDecorated(false); } @@ -208,6 +205,9 @@ void FeedsView::selectionChanged(const QItemSelection &selected, m_selectedFeeds.clear(); foreach (FeedsModelFeed *feed, selectedFeeds()) { + QModelIndex id = m_sourceModel->indexForItem(feed); + qDebug("INDEX %d, %d", id.row(), id.column()); + m_selectedFeeds << feed->id(); } diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index ab0409d4d..4f65f9160 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -57,6 +57,7 @@ class FeedsView : public QTreeView { void updateCountsOfAllFeeds(bool update_total_too = true); protected: + // Initializes context menus. void initializeContextMenuCategoriesFeeds(); void initializeContextMenuEmptySpace();