diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 2d4bb8acc..cf15f1b45 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -157,12 +157,25 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) const { } } +FeedsModelCategory *FeedsModel::categoryForIndex(const QModelIndex &index) const { + FeedsModelRootItem *item = itemForIndex(index); + + if (item->kind() == FeedsModelRootItem::Category) { + return static_cast(item); + } + else { + return NULL; + } +} + 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 @@ -311,6 +324,17 @@ QList FeedsModel::feedsForIndex(const QModelIndex &index) { return getFeeds(item); } +FeedsModelFeed *FeedsModel::feedForIndex(const QModelIndex &index) { + FeedsModelRootItem *item = itemForIndex(index); + + if (item->kind() == FeedsModelRootItem::Feed) { + return static_cast(item); + } + else { + return NULL; + } +} + QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { QList feeds; diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 259b050d1..1aa58af5d 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -52,9 +52,17 @@ class FeedsModel : public QAbstractItemModel { // selected feeds. QList feedsForIndexes(const QModelIndexList &indexes); - // Returns feeds contained within single index. + // Returns ALL CHILD feeds contained within single index. QList feedsForIndex(const QModelIndex &index); + // Returns pointer to feed if it lies in given index + // or NULL if no feed lies in given index. + FeedsModelFeed *feedForIndex(const QModelIndex &index); + + // Returns pointer to category if it lies in given index + // or NULL if no category lies in given index. + FeedsModelCategory *categoryForIndex(const QModelIndex &index) const; + // Returns feed/category which lies at the specified index or // null if index is invalid. FeedsModelRootItem *itemForIndex(const QModelIndex &index) const; diff --git a/src/core/feedsmodelcategory.cpp b/src/core/feedsmodelcategory.cpp index 708c905de..638b6b653 100755 --- a/src/core/feedsmodelcategory.cpp +++ b/src/core/feedsmodelcategory.cpp @@ -11,7 +11,8 @@ FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item) m_kind = FeedsModelRootItem::Category; } -FeedsModelCategory::FeedsModelCategory(const FeedsModelCategory &other) { +FeedsModelCategory::FeedsModelCategory(const FeedsModelCategory &other) + : FeedsModelRootItem(NULL) { m_kind = other.kind(); m_title = other.title(); m_id = other.id(); diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 8ca418f76..de7d09e6c 100644 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -187,6 +187,8 @@ void FeedMessageViewer::createConnections() { SIGNAL(triggered()), this, SLOT(updateAllFeeds())); connect(FormMain::getInstance()->m_ui->m_actionAddNewCategory, SIGNAL(triggered()), m_feedsView, SLOT(addNewCategory())); + connect(FormMain::getInstance()->m_ui->m_actionEditSelectedFeed, + SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem())); } void FeedMessageViewer::initialize() { diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 42a1e1446..a45894df6 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -5,6 +5,8 @@ #include "core/feedsmodel.h" #include "core/feedsproxymodel.h" #include "core/feedsmodelrootitem.h" +#include "core/feedsmodelcategory.h" +#include "core/feedsmodelstandardcategory.h" #include "gui/formmain.h" #include "gui/formcategorydetails.h" @@ -51,6 +53,16 @@ QList FeedsView::allFeeds() const { return m_sourceModel->getAllFeeds(); } +FeedsModelCategory *FeedsView::isCurrentIndexCategory() const { + QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); + return m_sourceModel->categoryForIndex(current_mapped); +} + +FeedsModelFeed *FeedsView::isCurrentIndexFeed() const { + QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); + return m_sourceModel->feedForIndex(current_mapped); +} + void FeedsView::setSelectedFeedsClearStatus(int clear) { m_sourceModel->markFeedsDeleted(selectedFeeds(), clear); updateCountsOfSelectedFeeds(); @@ -82,8 +94,18 @@ void FeedsView::addNewCategory() { delete form_pointer.data(); } -void FeedsView::editSelectedCategory() { +void FeedsView::editSelectedItem() { // TODO: Implement this. + FeedsModelCategory *category; + FeedsModelFeed *feed; + + if ((category = isCurrentIndexCategory()) != NULL) { + // Category is selected. + } + else if ((feed = isCurrentIndexFeed()) != NULL) { + // Feed is selected. + } + } void FeedsView::markSelectedFeedsReadStatus(int read) { diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 2b0a8aefa..c8248e908 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -27,6 +27,12 @@ class FeedsView : public QTreeView { QList selectedFeeds() const; QList allFeeds() const; + // Return true if current index contains category/feed and + // stores category/feed in the parameter pointer, + // otherwise false. + FeedsModelCategory *isCurrentIndexCategory() const; + FeedsModelFeed *isCurrentIndexFeed() const; + public slots: // Feed read/unread manipulators. void markSelectedFeedsReadStatus(int read); @@ -39,7 +45,7 @@ class FeedsView : public QTreeView { // Category operators. void addNewCategory(); - void editSelectedCategory(); + void editSelectedItem(); // Reloads counts for selected feeds. void updateCountsOfSelectedFeeds(bool update_total_too = true); @@ -60,7 +66,10 @@ class FeedsView : public QTreeView { // Show custom context menu. void contextMenuEvent(QContextMenuEvent *event); - void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const; + // Don't draw branches at all. + void drawBranches(QPainter *painter, + const QRect &rect, + const QModelIndex &index) const; signals: // Emitted if currently selected feeds needs to be reloaded. diff --git a/src/gui/formcategorydetails.cpp b/src/gui/formcategorydetails.cpp index a2262ba21..f6a3581f4 100644 --- a/src/gui/formcategorydetails.cpp +++ b/src/gui/formcategorydetails.cpp @@ -38,8 +38,6 @@ void FormCategoryDetails::setEditableCategory(FeedsModelCategory *editable_categ int FormCategoryDetails::exec(FeedsModelCategory *input_category, FeedsModelCategory *output_item, FeedsModelRootItem *parent_item) { - int result = QDialog::exec(); - if (input_category == NULL) { // User is adding new category. } @@ -48,6 +46,8 @@ int FormCategoryDetails::exec(FeedsModelCategory *input_category, setEditableCategory(input_category); } + int result = QDialog::exec(); + return result; }