Fixed duplicate feeds in feed selections.
This commit is contained in:
parent
494ef47ead
commit
a19ba25137
@ -255,6 +255,7 @@ set(APP_SOURCES
|
|||||||
src/gui/messagesview.cpp
|
src/gui/messagesview.cpp
|
||||||
src/gui/statusbar.cpp
|
src/gui/statusbar.cpp
|
||||||
src/gui/iconfactory.cpp
|
src/gui/iconfactory.cpp
|
||||||
|
src/gui/formcategorydetails.cpp
|
||||||
|
|
||||||
# CORE sources.
|
# CORE sources.
|
||||||
src/core/debugging.cpp
|
src/core/debugging.cpp
|
||||||
@ -316,6 +317,7 @@ set(APP_HEADERS
|
|||||||
src/gui/feedsview.h
|
src/gui/feedsview.h
|
||||||
src/gui/messagesview.h
|
src/gui/messagesview.h
|
||||||
src/gui/statusbar.h
|
src/gui/statusbar.h
|
||||||
|
src/gui/formcategorydetails.h
|
||||||
|
|
||||||
# CORE headers.
|
# CORE headers.
|
||||||
src/core/settings.h
|
src/core/settings.h
|
||||||
|
@ -294,12 +294,25 @@ QList<FeedsModelFeed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
|
|||||||
return getFeeds(item);
|
return getFeeds(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FeedsModel::isUnequal(FeedsModelFeed *lhs, FeedsModelFeed *rhs) {
|
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
||||||
return !isEqual(lhs, rhs);
|
QList<FeedsModelFeed*> feeds;
|
||||||
}
|
|
||||||
|
|
||||||
bool FeedsModel::isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs) {
|
// Get selected feeds for each index.
|
||||||
return lhs->id() == rhs->id();
|
foreach (const QModelIndex &index, indexes) {
|
||||||
|
feeds.append(feedsForIndex(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we obtained all feeds from corresponding indexes.
|
||||||
|
if (indexes.size() != feeds.size()) {
|
||||||
|
// Selection contains duplicate feeds (for
|
||||||
|
// example situation where feed and its parent category are both
|
||||||
|
// selected). So, remove duplicates from the list.
|
||||||
|
qSort(feeds.begin(), feeds.end(), FeedsModelRootItem::lessThan);
|
||||||
|
feeds.erase(std::unique(feeds.begin(), feeds.end(), FeedsModelRootItem::isEqual),
|
||||||
|
feeds.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
return feeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
|
bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
|
||||||
@ -370,28 +383,6 @@ bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed *> &feeds,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
|
||||||
QList<FeedsModelFeed*> feeds;
|
|
||||||
|
|
||||||
// Get selected feeds for each index.
|
|
||||||
foreach (const QModelIndex &index, indexes) {
|
|
||||||
feeds.append(feedsForIndex(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we obtained all feeds from corresponding indexes.
|
|
||||||
if (indexes.size() != feeds.size()) {
|
|
||||||
// Selection contains duplicate feeds (for
|
|
||||||
// example situation where feed and its parent category are both
|
|
||||||
// selected). So, remove duplicates from the list.
|
|
||||||
qSort(feeds.begin(), feeds.end(), isUnequal);
|
|
||||||
feeds.erase(std::unique(feeds.begin(), feeds.end(), isEqual),
|
|
||||||
feeds.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
return feeds;
|
|
||||||
}
|
|
||||||
|
|
||||||
QHash<int, FeedsModelCategory*> FeedsModel::getAllCategories() {
|
QHash<int, FeedsModelCategory*> FeedsModel::getAllCategories() {
|
||||||
return getCategories(m_rootItem);
|
return getCategories(m_rootItem);
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,6 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
// Returns feeds contained within single index.
|
// Returns feeds contained within single index.
|
||||||
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
|
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
|
||||||
|
|
||||||
// Equality "operators" used for identifying duplicate feeds.
|
|
||||||
static bool isUnequal(FeedsModelFeed *lhs, FeedsModelFeed *rhs);
|
|
||||||
static bool isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool markFeedsRead(const QList<FeedsModelFeed*> &feeds, int read);
|
bool markFeedsRead(const QList<FeedsModelFeed*> &feeds, int read);
|
||||||
bool markFeedsDeleted(const QList<FeedsModelFeed*> &feeds, int deleted);
|
bool markFeedsDeleted(const QList<FeedsModelFeed*> &feeds, int deleted);
|
||||||
|
@ -98,3 +98,18 @@ QList<FeedsModelRootItem *> FeedsModelRootItem::childItems() const {
|
|||||||
void FeedsModelRootItem::clearChilds() {
|
void FeedsModelRootItem::clearChilds() {
|
||||||
m_childItems.clear();
|
m_childItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs,
|
||||||
|
FeedsModelRootItem *rhs) {
|
||||||
|
return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FeedsModelRootItem::lessThan(FeedsModelRootItem *lhs,
|
||||||
|
FeedsModelRootItem *rhs) {
|
||||||
|
if (lhs->kind() == rhs->kind()) {
|
||||||
|
return lhs->id() < rhs->id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -54,6 +54,10 @@ class FeedsModelRootItem {
|
|||||||
// Removes all childs from this item.
|
// Removes all childs from this item.
|
||||||
void clearChilds();
|
void clearChilds();
|
||||||
|
|
||||||
|
// Compares two model items.
|
||||||
|
static bool isEqual(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs);
|
||||||
|
static bool lessThan(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Kind m_kind;
|
Kind m_kind;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
|
@ -185,6 +185,8 @@ void FeedMessageViewer::createConnections() {
|
|||||||
SIGNAL(triggered()), this, SLOT(updateSelectedFeeds()));
|
SIGNAL(triggered()), this, SLOT(updateSelectedFeeds()));
|
||||||
connect(FormMain::getInstance()->m_ui->m_actionUpdateAllFeeds,
|
connect(FormMain::getInstance()->m_ui->m_actionUpdateAllFeeds,
|
||||||
SIGNAL(triggered()), this, SLOT(updateAllFeeds()));
|
SIGNAL(triggered()), this, SLOT(updateAllFeeds()));
|
||||||
|
connect(FormMain::getInstance()->m_ui->m_actionAddNewCategory,
|
||||||
|
SIGNAL(triggered()), m_feedsView, SLOT(addNewCategory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::initialize() {
|
void FeedMessageViewer::initialize() {
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
#include "core/feedsproxymodel.h"
|
#include "core/feedsproxymodel.h"
|
||||||
#include "core/feedsmodelrootitem.h"
|
#include "core/feedsmodelrootitem.h"
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
|
#include "gui/formcategorydetails.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
|
||||||
FeedsView::FeedsView(QWidget *parent) : QTreeView(parent), m_contextMenu(NULL) {
|
FeedsView::FeedsView(QWidget *parent) : QTreeView(parent), m_contextMenu(NULL) {
|
||||||
@ -51,6 +53,18 @@ void FeedsView::clearSelectedFeeds() {
|
|||||||
setSelectedFeedsClearStatus(1);
|
setSelectedFeedsClearStatus(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FeedsView::addNewCategory() {
|
||||||
|
QPointer<FormCategoryDetails> form_pointer = new FormCategoryDetails(this);
|
||||||
|
|
||||||
|
if (form_pointer.data()->exec() == QDialog::Accepted) {
|
||||||
|
// User submitted some new category.
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
delete form_pointer.data();
|
||||||
|
}
|
||||||
|
|
||||||
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
||||||
m_sourceModel->markFeedsRead(selectedFeeds(), read);
|
m_sourceModel->markFeedsRead(selectedFeeds(), read);
|
||||||
updateCountsOfSelectedFeeds(false);
|
updateCountsOfSelectedFeeds(false);
|
||||||
|
@ -33,6 +33,9 @@ class FeedsView : public QTreeView {
|
|||||||
void setSelectedFeedsClearStatus(int clear);
|
void setSelectedFeedsClearStatus(int clear);
|
||||||
void clearSelectedFeeds();
|
void clearSelectedFeeds();
|
||||||
|
|
||||||
|
// Category operators.
|
||||||
|
void addNewCategory();
|
||||||
|
|
||||||
// Reloads counts for selected feeds.
|
// Reloads counts for selected feeds.
|
||||||
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
||||||
|
|
||||||
|
25
src/gui/formcategorydetails.cpp
Normal file
25
src/gui/formcategorydetails.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "gui/formcategorydetails.h"
|
||||||
|
|
||||||
|
#include "gui/iconthemefactory.h"
|
||||||
|
#include "gui/feedsview.h"
|
||||||
|
|
||||||
|
|
||||||
|
FormCategoryDetails::FormCategoryDetails(FeedsView *parent)
|
||||||
|
: QDialog(parent) {
|
||||||
|
// Set flags and attributes.
|
||||||
|
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
|
||||||
|
setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new"));
|
||||||
|
}
|
||||||
|
|
||||||
|
FormCategoryDetails::FormCategoryDetails(FeedsModelCategory *category,
|
||||||
|
FeedsView *parent)
|
||||||
|
:QDialog(parent) {
|
||||||
|
// Set flags and attributes.
|
||||||
|
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
|
||||||
|
setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
FormCategoryDetails::~FormCategoryDetails() {
|
||||||
|
qDebug("Destroying FormCategoryDetails instance.");
|
||||||
|
}
|
31
src/gui/formcategorydetails.h
Normal file
31
src/gui/formcategorydetails.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef FORMCATEGORYDETAILS_H
|
||||||
|
#define FORMCATEGORYDETAILS_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
|
||||||
|
class FeedsModelCategory;
|
||||||
|
class FeedsView;
|
||||||
|
|
||||||
|
class FormCategoryDetails : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructors and destructors.
|
||||||
|
// This constructor is supposed to create new categories.
|
||||||
|
explicit FormCategoryDetails(FeedsView *parent = 0);
|
||||||
|
|
||||||
|
// This constructor is supposed to edit existing categories.
|
||||||
|
explicit FormCategoryDetails(FeedsModelCategory *category,
|
||||||
|
FeedsView *parent = 0);
|
||||||
|
|
||||||
|
// Destructor.
|
||||||
|
virtual ~FormCategoryDetails();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FORMCATEGORYDETAILS_H
|
Loading…
x
Reference in New Issue
Block a user