Work on feeds view/model.

This commit is contained in:
Martin Rotter 2013-12-31 13:19:25 +01:00
parent 9dbbd42862
commit 7f33dfdd2e
3 changed files with 50 additions and 3 deletions

View File

@ -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.

View File

@ -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();
}

View File

@ -57,6 +57,7 @@ class FeedsView : public QTreeView {
void updateCountsOfAllFeeds(bool update_total_too = true);
protected:
// Initializes context menus.
void initializeContextMenuCategoriesFeeds();
void initializeContextMenuEmptySpace();