mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-25 13:38:44 +01:00
Some changes for category edits.
This commit is contained in:
parent
4b92cdcb39
commit
17d757f1ae
@ -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<FeedsModelCategory*>(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<FeedsModelFeed*> 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<FeedsModelFeed*>(item);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
||||
QList<FeedsModelFeed*> feeds;
|
||||
|
||||
|
@ -52,9 +52,17 @@ class FeedsModel : public QAbstractItemModel {
|
||||
// selected feeds.
|
||||
QList<FeedsModelFeed*> feedsForIndexes(const QModelIndexList &indexes);
|
||||
|
||||
// Returns feeds contained within single index.
|
||||
// Returns ALL CHILD feeds contained within single index.
|
||||
QList<FeedsModelFeed*> 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;
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
@ -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<FeedsModelFeed *> 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) {
|
||||
|
@ -27,6 +27,12 @@ class FeedsView : public QTreeView {
|
||||
QList<FeedsModelFeed*> selectedFeeds() const;
|
||||
QList<FeedsModelFeed*> 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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user