Ability to obtain index for item in feeds model. Added one feed.

This commit is contained in:
Martin Rotter 2013-12-28 21:20:34 +01:00
parent 5e031bc5e5
commit ef6721feee
5 changed files with 55 additions and 7 deletions

View file

@ -72,6 +72,8 @@ INSERT INTO Feeds (title, description, date_created, category, encoding, url, ty
-- ! -- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LinuxInsider', 'LinuxInsider: Linux News & Information from Around the World.', '2013-12-20T08:00:00-05:00', 1, 'UTF-8', 'http://www.linuxinsider.com/perl/syndication/rssfull.pl', 2); INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LinuxInsider', 'LinuxInsider: Linux News & Information from Around the World.', '2013-12-20T08:00:00-05:00', 1, 'UTF-8', 'http://www.linuxinsider.com/perl/syndication/rssfull.pl', 2);
-- ! -- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LXer: Linux News', 'The world is talking about GNU/Linux and Free/Open Source Software.', '2013-12-20T08:00:00-05:00', 1, 'UTF-8', 'http://lxer.com/module/newswire/headlines.rss', 2);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Recent Commits', 'Recent commits for RSS Guard project.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/commits/master.atom', 3); INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Recent Commits', 'Recent commits for RSS Guard project.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/commits/master.atom', 3);
-- ! -- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Releases', 'Releases for RSS Guard.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/releases.atom', 3); INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Releases', 'Releases for RSS Guard.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/releases.atom', 3);

View file

@ -157,6 +157,47 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) const {
} }
} }
QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const {
if (item->kind() == FeedsModelRootItem::RootItem) {
// Root item lies on invalid index.
return QModelIndex();
}
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);
// Iterate all childs of this parent.
for (int i = 0; i < row_count; i++) {
QModelIndex candidate_index = index(i, 0, active_index);
// This index could be our target item.
FeedsModelRootItem *target_item = itemForIndex(candidate_index);
if (target_item != NULL) {
if (FeedsModelRootItem::isEqual(target_item, item)) {
// We found our target index, it's good.
return candidate_index;
}
else if (hasChildren(candidate_index)) {
// This is not our target index but it has children,
// scan them too.
parents << candidate_index;
}
}
}
}
return QModelIndex();
}
void FeedsModel::reloadChangedLayout(QModelIndexList list) { void FeedsModel::reloadChangedLayout(QModelIndexList list) {
while (!list.isEmpty()) { while (!list.isEmpty()) {
QModelIndex ix = list.takeLast(); QModelIndex ix = list.takeLast();

View file

@ -48,12 +48,20 @@ class FeedsModel : public QAbstractItemModel {
// Returns list of feeds which belong to given indexes. // Returns list of feeds which belong to given indexes.
// NOTE: If index is "category", then all child feeds are contained in the // NOTE: If index is "category", then all child feeds are contained in the
// result. // result.
// NOTE: This is particularly useful for displaying messages of selected feeds. // NOTE: This is particularly useful for displaying messages of
// selected feeds.
QList<FeedsModelFeed*> feedsForIndexes(const QModelIndexList &indexes); QList<FeedsModelFeed*> feedsForIndexes(const QModelIndexList &indexes);
// Returns feeds contained within single index. // Returns feeds contained within single index.
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index); QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
// Returns feed/category which lies at the specified index or
// null if index is invalid.
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
// Returns QModelIndex on which lies given item.
QModelIndex indexForItem(FeedsModelRootItem *item) const;
// Access to root item. // Access to root item.
FeedsModelRootItem *rootItem() const; FeedsModelRootItem *rootItem() const;
@ -72,10 +80,6 @@ class FeedsModel : public QAbstractItemModel {
protected: protected:
QStringList textualFeedIds(const QList<FeedsModelFeed*> &feeds); QStringList textualFeedIds(const QList<FeedsModelFeed*> &feeds);
// Returns feed/category which lies at the specified index or
// null if index is invalid.
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
// Loads feed/categories from the database. // Loads feed/categories from the database.
void loadFromDatabase(); void loadFromDatabase();

View file

@ -141,7 +141,10 @@ void FeedsView::setupAppearance() {
setUniformRowHeights(true); setUniformRowHeights(true);
setAcceptDrops(false); setAcceptDrops(false);
setDragEnabled(false); setDragEnabled(false);
setAnimated(true);
setSortingEnabled(true); setSortingEnabled(true);
setItemsExpandable(true);
setExpandsOnDoubleClick(true);
setIndentation(10); setIndentation(10);
sortByColumn(0, Qt::AscendingOrder); sortByColumn(0, Qt::AscendingOrder);
setDragDropMode(QAbstractItemView::NoDragDrop); setDragDropMode(QAbstractItemView::NoDragDrop);

View file

@ -42,11 +42,9 @@ int FormCategoryDetails::exec(FeedsModelCategory *input_category,
if (input_category == NULL) { if (input_category == NULL) {
// User is adding new category. // User is adding new category.
} }
else { else {
// User is editing existing category. // User is editing existing category.
} }
return result; return result;