Work on feeds model/view.
This commit is contained in:
parent
5742c60051
commit
f85de2c819
@ -36,6 +36,17 @@ CREATE TABLE IF NOT EXISTS Feeds (
|
|||||||
type INTEGER NOT NULL
|
type INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
-- !
|
-- !
|
||||||
|
DROP TABLE IF EXISTS FeedsData;
|
||||||
|
-- !
|
||||||
|
CREATE TABLE IF NOT EXISTS FeedsData (
|
||||||
|
id INTEGER NOT NULL,
|
||||||
|
key TEXT NOT NULL,
|
||||||
|
value TEXT,
|
||||||
|
|
||||||
|
PRIMARY KEY (id, key),
|
||||||
|
FOREIGN KEY (id) REFERENCES Feeds (id)
|
||||||
|
);
|
||||||
|
-- !
|
||||||
DROP TABLE IF EXISTS Messages;
|
DROP TABLE IF EXISTS Messages;
|
||||||
-- !
|
-- !
|
||||||
CREATE TABLE IF NOT EXISTS Messages (
|
CREATE TABLE IF NOT EXISTS Messages (
|
||||||
|
@ -64,13 +64,9 @@
|
|||||||
#define MSG_DB_DUPDATED_INDEX 9
|
#define MSG_DB_DUPDATED_INDEX 9
|
||||||
#define MSG_DB_CONTENTS_INDEX 10
|
#define MSG_DB_CONTENTS_INDEX 10
|
||||||
|
|
||||||
// Indexes of columns as they are USED IN THE MODEL for MESSAGES.
|
// Indexes of columns for feed models.
|
||||||
#define MSG_MODEL_READ_INDEX 0
|
#define FDS_TITLE_INDEX 0
|
||||||
#define MSG_MODEL_IMPORTANT_INDEX 1
|
#define FDS_COUNTS_INDEX 1
|
||||||
#define MSG_MODEL_TITLE_INDEX 2
|
|
||||||
#define MSG_MODEL_AUTHOR_INDEX 3
|
|
||||||
#define MSG_MODEL_DCREATED_INDEX 4
|
|
||||||
#define MSG_MODEL_DUPDATED_INDEX 5
|
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
#define APP_DESKTOP_ENTRY_PATH "@DESKTOP_ENTRY_PATH@"
|
#define APP_DESKTOP_ENTRY_PATH "@DESKTOP_ENTRY_PATH@"
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
#include "core/feedsmodel.h"
|
#include "core/feedsmodel.h"
|
||||||
#include "core/feedsmodelstandardcategory.h"
|
#include "core/feedsmodelstandardcategory.h"
|
||||||
#include "core/feedsmodelstandardfeed.h"
|
#include "core/feedsmodelstandardfeed.h"
|
||||||
|
#include "core/defs.h"
|
||||||
|
#include "gui/iconthemefactory.h"
|
||||||
|
|
||||||
|
|
||||||
FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
|
FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
|
||||||
m_rootItem = new FeedsModelRootItem(NULL);
|
m_rootItem = new FeedsModelRootItem();
|
||||||
|
m_countsIcon = IconThemeFactory::getInstance()->fromTheme("mail-mark-unread");
|
||||||
|
|
||||||
FeedsModelStandardCategory *cat1 = new FeedsModelStandardCategory(m_rootItem);
|
m_headerData << tr("Title");
|
||||||
FeedsModelStandardCategory *cat2 = new FeedsModelStandardCategory(cat1);
|
|
||||||
FeedsModelStandardFeed *feed1 = new FeedsModelStandardFeed(cat1);
|
FeedsModelStandardCategory *cat1 = new FeedsModelStandardCategory();
|
||||||
FeedsModelStandardFeed *feed2 = new FeedsModelStandardFeed(cat1);
|
FeedsModelStandardCategory *cat2 = new FeedsModelStandardCategory();
|
||||||
FeedsModelStandardFeed *feed3 = new FeedsModelStandardFeed(m_rootItem);
|
FeedsModelStandardFeed *feed1 = new FeedsModelStandardFeed();
|
||||||
FeedsModelStandardFeed *feed4 = new FeedsModelStandardFeed(cat2);
|
FeedsModelStandardFeed *feed2 = new FeedsModelStandardFeed();
|
||||||
FeedsModelStandardFeed *feed5 = new FeedsModelStandardFeed(cat2);
|
FeedsModelStandardFeed *feed3 = new FeedsModelStandardFeed();
|
||||||
|
FeedsModelStandardFeed *feed4 = new FeedsModelStandardFeed();
|
||||||
|
FeedsModelStandardFeed *feed5 = new FeedsModelStandardFeed();
|
||||||
|
|
||||||
cat1->appendChild(feed1);
|
cat1->appendChild(feed1);
|
||||||
cat1->appendChild(feed2);
|
cat1->appendChild(feed2);
|
||||||
@ -35,30 +40,41 @@ QVariant FeedsModel::data(const QModelIndex &index, int role) const {
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role != Qt::DisplayRole) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
FeedsModelRootItem *item = static_cast<FeedsModelRootItem*>(index.internalPointer());
|
FeedsModelRootItem *item = static_cast<FeedsModelRootItem*>(index.internalPointer());
|
||||||
|
return item->data(index.column(), role);
|
||||||
return item->data(index.column(), Qt::DisplayRole);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FeedsModel::headerData(int section,
|
QVariant FeedsModel::headerData(int section,
|
||||||
Qt::Orientation orientation,
|
Qt::Orientation orientation,
|
||||||
int role) const {
|
int role) const {
|
||||||
if (orientation == Qt::Horizontal) {
|
if (orientation != Qt::Horizontal) {
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
return "aaa";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
if (section == FDS_TITLE_INDEX) {
|
||||||
|
return m_headerData.at(FDS_TITLE_INDEX);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::DecorationRole:
|
||||||
|
if (section == FDS_COUNTS_INDEX) {
|
||||||
|
return m_countsIcon;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex FeedsModel::index(int row, int column, const QModelIndex &parent) const {
|
QModelIndex FeedsModel::index(int row, int column, const QModelIndex &parent) const {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define FEEDSMODEL_H
|
#define FEEDSMODEL_H
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
|
|
||||||
class FeedsModelRootItem;
|
class FeedsModelRootItem;
|
||||||
@ -25,6 +26,8 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
FeedsModelRootItem *m_rootItem;
|
FeedsModelRootItem *m_rootItem;
|
||||||
|
QList<QString> m_headerData;
|
||||||
|
QIcon m_countsIcon;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,5 +6,4 @@ FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelCategory::~FeedsModelCategory() {
|
FeedsModelCategory::~FeedsModelCategory() {
|
||||||
qDebug("Destroying BaseFeedsModelCategory instance.");
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
class FeedsModelCategory : public FeedsModelRootItem {
|
class FeedsModelCategory : public FeedsModelRootItem {
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors
|
// Constructors and destructors
|
||||||
explicit FeedsModelCategory(FeedsModelRootItem *parent_item);
|
explicit FeedsModelCategory(FeedsModelRootItem *parent_item = NULL);
|
||||||
virtual ~FeedsModelCategory();
|
virtual ~FeedsModelCategory();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,6 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelFeed::~FeedsModelFeed() {
|
FeedsModelFeed::~FeedsModelFeed() {
|
||||||
qDebug("Destroying FeedsModelFeed instance.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FeedsModelFeed::childCount() const {
|
int FeedsModelFeed::childCount() const {
|
||||||
|
@ -9,8 +9,16 @@
|
|||||||
class FeedsModelFeed : public FeedsModelRootItem
|
class FeedsModelFeed : public FeedsModelRootItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// Describes possible types of feeds.
|
||||||
|
// NOTE: This is equivalent to attribute Feeds(type).
|
||||||
|
enum Type {
|
||||||
|
StandardRss = 0,
|
||||||
|
StandardRdf = 1,
|
||||||
|
StandardAtom = 2
|
||||||
|
};
|
||||||
|
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit FeedsModelFeed(FeedsModelRootItem *parent_item);
|
explicit FeedsModelFeed(FeedsModelRootItem *parent_item = NULL);
|
||||||
virtual ~FeedsModelFeed();
|
virtual ~FeedsModelFeed();
|
||||||
|
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
|
@ -16,12 +16,17 @@ FeedsModelRootItem *FeedsModelRootItem::parent() {
|
|||||||
return m_parentItem;
|
return m_parentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FeedsModelRootItem::setParent(FeedsModelRootItem *parent_item) {
|
||||||
|
m_parentItem = parent_item;
|
||||||
|
}
|
||||||
|
|
||||||
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
|
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
|
||||||
return m_childItems.value(row);
|
return m_childItems.value(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
|
void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
|
||||||
m_childItems.append(child);
|
m_childItems.append(child);
|
||||||
|
child->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FeedsModelRootItem::columnCount() const {
|
int FeedsModelRootItem::columnCount() const {
|
||||||
|
@ -13,9 +13,10 @@ class FeedsModelRootItem {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit FeedsModelRootItem(FeedsModelRootItem *parent_item);
|
explicit FeedsModelRootItem(FeedsModelRootItem *parent_item = NULL);
|
||||||
virtual ~FeedsModelRootItem();
|
virtual ~FeedsModelRootItem();
|
||||||
|
|
||||||
|
virtual void setParent(FeedsModelRootItem *parent_item);
|
||||||
virtual FeedsModelRootItem *parent();
|
virtual FeedsModelRootItem *parent();
|
||||||
virtual FeedsModelRootItem *child(int row);
|
virtual FeedsModelRootItem *child(int row);
|
||||||
virtual void appendChild(FeedsModelRootItem *child);
|
virtual void appendChild(FeedsModelRootItem *child);
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
class FeedsModelStandardCategory : public FeedsModelCategory {
|
class FeedsModelStandardCategory : public FeedsModelCategory {
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit FeedsModelStandardCategory(FeedsModelRootItem *parent_item);
|
explicit FeedsModelStandardCategory(FeedsModelRootItem *parent_item = NULL);
|
||||||
virtual ~FeedsModelStandardCategory();
|
virtual ~FeedsModelStandardCategory();
|
||||||
|
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "feedsmodelstandardfeed.h"
|
#include "core/defs.h"
|
||||||
|
#include "gui/iconthemefactory.h"
|
||||||
|
#include "core/feedsmodelstandardfeed.h"
|
||||||
|
|
||||||
|
|
||||||
FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item)
|
FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item)
|
||||||
@ -12,10 +14,29 @@ FeedsModelStandardFeed::~FeedsModelStandardFeed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariant FeedsModelStandardFeed::data(int column, int role) const {
|
QVariant FeedsModelStandardFeed::data(int column, int role) const {
|
||||||
if (role == Qt::DisplayRole) {
|
switch (role) {
|
||||||
return "bbb";
|
case Qt::DisplayRole:
|
||||||
}
|
if (column == FDS_TITLE_INDEX) {
|
||||||
else {
|
return m_title;
|
||||||
return QVariant();
|
}
|
||||||
|
else if (column == FDS_COUNTS_INDEX) {
|
||||||
|
return QString("(%1)").arg(QString::number(m_unreadCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
case Qt::DecorationRole:
|
||||||
|
return column == FDS_TITLE_INDEX ?
|
||||||
|
m_icon :
|
||||||
|
QVariant();
|
||||||
|
|
||||||
|
case Qt::TextAlignmentRole:
|
||||||
|
if (column == FDS_COUNTS_INDEX) {
|
||||||
|
return Qt::AlignRight;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,33 @@
|
|||||||
#ifndef FEEDSMODELSTANDARDFEED_H
|
#ifndef FEEDSMODELSTANDARDFEED_H
|
||||||
#define FEEDSMODELSTANDARDFEED_H
|
#define FEEDSMODELSTANDARDFEED_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "core/feedsmodelfeed.h"
|
#include "core/feedsmodelfeed.h"
|
||||||
|
|
||||||
|
|
||||||
// Represents STANDARD RSS/RDF/ATOM feed with no
|
// Represents STANDARD RSS/RDF/ATOM feed with no
|
||||||
// online synchronization services (NO TT-RSS, NO FEEDLY).
|
// online synchronization services (NO TT-RSS, NO FEEDLY).
|
||||||
|
// So, parent item is either root item or category.
|
||||||
class FeedsModelStandardFeed : public FeedsModelFeed {
|
class FeedsModelStandardFeed : public FeedsModelFeed {
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit FeedsModelStandardFeed(FeedsModelRootItem *parent_item);
|
explicit FeedsModelStandardFeed(FeedsModelRootItem *parent_item = NULL);
|
||||||
virtual ~FeedsModelStandardFeed();
|
virtual ~FeedsModelStandardFeed();
|
||||||
|
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_title;
|
||||||
|
QDateTime m_creationDate;
|
||||||
|
QString m_encoding;
|
||||||
|
QString m_url;
|
||||||
|
QString m_description;
|
||||||
|
QString m_language;
|
||||||
|
|
||||||
|
int m_totalCount;
|
||||||
|
int m_unreadCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FEEDSMODELSTANDARDFEED_H
|
#endif // FEEDSMODELSTANDARDFEED_H
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
#include <QHeaderView>
|
||||||
|
|
||||||
#include "gui/feedsview.h"
|
#include "gui/feedsview.h"
|
||||||
#include "core/feedsmodel.h"
|
#include "core/feedsmodel.h"
|
||||||
#include "core/feedsproxymodel.h"
|
#include "core/feedsproxymodel.h"
|
||||||
|
#include "core/defs.h"
|
||||||
|
|
||||||
|
|
||||||
FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) {
|
FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) {
|
||||||
@ -8,6 +11,24 @@ FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) {
|
|||||||
m_sourceModel = m_proxyModel->sourceModel();
|
m_sourceModel = m_proxyModel->sourceModel();
|
||||||
|
|
||||||
setModel(m_proxyModel);
|
setModel(m_proxyModel);
|
||||||
|
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
// Setup column resize strategies.
|
||||||
|
header()->setSectionResizeMode(FDS_TITLE_INDEX, QHeaderView::Interactive);
|
||||||
|
header()->setSectionResizeMode(FDS_COUNTS_INDEX, QHeaderView::ResizeToContents);
|
||||||
|
#else
|
||||||
|
// Setup column resize strategies.
|
||||||
|
header()->setResizeMode(FDS_TITLE_INDEX, QHeaderView::Interactive);
|
||||||
|
header()->setResizeMode(FDS_COUNTS_INDEX, QHeaderView::ResizeToContents);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
header()->setStretchLastSection(false);
|
||||||
|
setUniformRowHeights(true);
|
||||||
|
setAcceptDrops(false);
|
||||||
|
setDragEnabled(false);
|
||||||
|
setDragDropMode(QAbstractItemView::NoDragDrop);
|
||||||
|
setAllColumnsShowFocus(true);
|
||||||
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedsView::~FeedsView() {
|
FeedsView::~FeedsView() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user