From 9804e89207add62daeb70f9eed8bcec14705f4c8 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sun, 23 Oct 2011 14:01:56 +0200 Subject: [PATCH] Various small fixes. --- feedmodel.cpp | 2 +- mainwindow.cpp | 16 ++++++++++++++-- rssparser.cpp | 17 +++++++++++++++++ rssparser.h | 12 ++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/feedmodel.cpp b/feedmodel.cpp index 78c2f40..90f1a68 100644 --- a/feedmodel.cpp +++ b/feedmodel.cpp @@ -51,7 +51,7 @@ FeedModel::index(int row, int column, const QModelIndex &parent) const return QModelIndex(); else { - for(int i = 1; i < row; i++) + for(int i = 0; i < row; i++) { if (!query.next()) return QModelIndex(); diff --git a/mainwindow.cpp b/mainwindow.cpp index d6a97bc..3174d4a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -27,6 +27,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->newsTableView->setColumnHidden(0, true); // ID ui->newsTableView->setColumnHidden(1, true); // Feed ID ui->newsTableView->setColumnHidden(3, true); // Link + ui->newsTableView->setColumnHidden(4, true); // Description ui->newsTableView->setColumnHidden(6, true); // Read state ui->newsTableView->verticalHeader()->setHidden(true); } @@ -53,16 +54,27 @@ void Larss::MainWindow::on_feedTreeView_clicked(const QModelIndex &index) { // Trigger refresh of selected item rssParser->loadItem(index); + + // Set the active filter + quint64 feed_id; + if ((feed_id = rssParser->getFeed (index))) + { + rssParser->selectActiveFeed(feed_id); + } + } void Larss::MainWindow::on_newsTableView_clicked(const QModelIndex &index) { + // Get the number of the row, since index.row () is likely to change + // while we set the read status on the post. + quint32 row_number = index.row(); + // A row got activated, so open it in the webview. QString link = rssParser->getLink(index); ui->webView->load(link); - qDebug () << "Loading " << link; // And then mark it as read rssParser->setReadStatus(index, true); - ui->newsTableView->selectRow(index.row()); + ui->newsTableView->selectRow(row_number); } diff --git a/rssparser.cpp b/rssparser.cpp index b9d87dc..81f9ae9 100644 --- a/rssparser.cpp +++ b/rssparser.cpp @@ -207,3 +207,20 @@ Larss::RssParser::setReadStatus(const QModelIndex& index, bool read) QModelIndex read_index = createIndex(index.row(), 6, index.internalPointer()); setData(read_index, read ? 1 : 0); } + +quint64 +Larss::RssParser::getFeed(const QModelIndex &index) +{ + quint64 id = index.internalId(); + if (id < FEEDMODEL_MAX_CATEGORIES) + return 0; + else + return (id - FEEDMODEL_MAX_CATEGORIES); +} + +void +Larss::RssParser::selectActiveFeed(quint64 feed_id) +{ + // Show only the news from the given feed + setFilter(QString("feed='%1'").arg(feed_id + FEEDMODEL_MAX_CATEGORIES)); +} diff --git a/rssparser.h b/rssparser.h index 8ee69f4..1a2a732 100644 --- a/rssparser.h +++ b/rssparser.h @@ -40,6 +40,13 @@ namespace Larss { QString getLink (const QModelIndex& index); /** + * @brief Get the id of the feed pointed by the QModelIndex or + * 0 if there is no feed pointed (i.e. is a category or + * the root of the tree). + */ + quint64 getFeed (const QModelIndex& index); + + /** * @brief Set the read status on a news. */ void setReadStatus (const QModelIndex& index, bool read); @@ -49,6 +56,11 @@ namespace Larss { */ QVariant data(const QModelIndex &idx, int role) const; + /** + * @brief Set the active category to display. + */ + void selectActiveFeed (quint64 feed_id); + signals: -- 2.1.4