Initial impl. of adding.
This commit is contained in:
parent
b8af2d26be
commit
1b99356a9b
@ -133,6 +133,23 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
|
|||||||
return parent_item->childCount();
|
return parent_item->childCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FeedsModel::addItem(FeedsModelRootItem *item,
|
||||||
|
FeedsModelRootItem *parent) {
|
||||||
|
QModelIndex parent_index = indexForItem(parent);
|
||||||
|
|
||||||
|
beginInsertRows(parent_index, parent->childCount(), parent->childCount());
|
||||||
|
|
||||||
|
// Add item to hierarchy.
|
||||||
|
parent->appendChild(item);
|
||||||
|
|
||||||
|
// Add item to persistent storage.
|
||||||
|
item->addItself();
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool FeedsModel::removeItem(const QModelIndex &index) {
|
bool FeedsModel::removeItem(const QModelIndex &index) {
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
QModelIndex parent_index = index.parent();
|
QModelIndex parent_index = index.parent();
|
||||||
@ -329,7 +346,6 @@ void FeedsModel::loadFromDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case FeedsModelCategory::Feedly:
|
case FeedsModelCategory::Feedly:
|
||||||
case FeedsModelCategory::TinyTinyRss:
|
|
||||||
default:
|
default:
|
||||||
// NOTE: Not yet implemented.
|
// NOTE: Not yet implemented.
|
||||||
break;
|
break;
|
||||||
|
@ -46,6 +46,8 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Feed/category manipulators.
|
// Feed/category manipulators.
|
||||||
|
bool addItem(FeedsModelRootItem *item,
|
||||||
|
FeedsModelRootItem *parent);
|
||||||
bool removeItem(const QModelIndex &index);
|
bool removeItem(const QModelIndex &index);
|
||||||
|
|
||||||
// Returns (undeleted) messages for given feeds.
|
// Returns (undeleted) messages for given feeds.
|
||||||
|
@ -15,8 +15,7 @@ class FeedsModelCategory : public FeedsModelRootItem {
|
|||||||
// NOTE: This is equivavelnt to Categories(type).
|
// NOTE: This is equivavelnt to Categories(type).
|
||||||
enum Type {
|
enum Type {
|
||||||
Standard = 0,
|
Standard = 0,
|
||||||
Feedly = 1,
|
Feedly = 1
|
||||||
TinyTinyRss = 2
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Constructors and destructors
|
// Constructors and destructors
|
||||||
|
@ -57,6 +57,10 @@ class FeedsModelRootItem {
|
|||||||
virtual int countOfUnreadMessages() const;
|
virtual int countOfUnreadMessages() const;
|
||||||
virtual int countOfAllMessages() const;
|
virtual int countOfAllMessages() const;
|
||||||
|
|
||||||
|
virtual bool addItself() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// This method is used to permanently
|
// This method is used to permanently
|
||||||
// "remove" (or "unregister") this item.
|
// "remove" (or "unregister") this item.
|
||||||
// This typically removes item and its
|
// This typically removes item and its
|
||||||
|
@ -91,6 +91,39 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FeedsModelStandardCategory::addItself() {
|
||||||
|
// Children are removed, remove this standard category too.
|
||||||
|
QSqlDatabase database = DatabaseFactory::instance()->connection();
|
||||||
|
QSqlQuery query_add(database);
|
||||||
|
|
||||||
|
query_add.setForwardOnly(true);
|
||||||
|
|
||||||
|
// Remove all messages from this standard feed.
|
||||||
|
query_add.prepare("INSERT INTO Categories "
|
||||||
|
"(parent_id, title, description, date_created, icon, type) "
|
||||||
|
"VALUES (:parent_id, :title, :description, :date_created, :icon, :type);");
|
||||||
|
query_add.bindValue(":parent_id", m_parentItem->id());
|
||||||
|
query_add.bindValue(":title", m_title);
|
||||||
|
query_add.bindValue(":description", m_description);
|
||||||
|
query_add.bindValue(":date_created", m_creationDate.toMSecsSinceEpoch());
|
||||||
|
query_add.bindValue(":icon", IconFactory::toByteArray(m_icon));
|
||||||
|
query_add.bindValue(":type", (int) m_type);
|
||||||
|
|
||||||
|
if (!query_add.exec()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
query_add.prepare("SELECT id FROM Categories WHERE date_created = :date_created;");
|
||||||
|
query_add.bindValue(":date_created", m_creationDate.toMSecsSinceEpoch());
|
||||||
|
if (query_add.exec() && query_add.next()) {
|
||||||
|
setId(query_add.value(0).toInt());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool FeedsModelStandardCategory::removeItself() {
|
bool FeedsModelStandardCategory::removeItself() {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ class FeedsModelStandardCategory : public FeedsModelCategory {
|
|||||||
// Returns the actual data representation of standard category.
|
// Returns the actual data representation of standard category.
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
|
// Add itself to persistent database.
|
||||||
|
bool addItself();
|
||||||
|
|
||||||
// Removes category and all its children from persistent
|
// Removes category and all its children from persistent
|
||||||
// database.
|
// database.
|
||||||
bool removeItself();
|
bool removeItself();
|
||||||
|
@ -49,7 +49,8 @@ bool FeedsProxyModel::lessThan(const QModelIndex &left,
|
|||||||
else {
|
else {
|
||||||
// In other cases, sort by title.
|
// In other cases, sort by title.
|
||||||
// TODO: mozna pouzit QString::localeAwareCompare tady.
|
// TODO: mozna pouzit QString::localeAwareCompare tady.
|
||||||
return left_item->title() < right_item->title();
|
return QString::compare(left_item->title(),
|
||||||
|
right_item->title()) < 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (left_item->kind() == FeedsModelRootItem::Feed) {
|
else if (left_item->kind() == FeedsModelRootItem::Feed) {
|
||||||
|
@ -32,10 +32,6 @@ FeedsView::~FeedsView() {
|
|||||||
qDebug("Destroying FeedsView instance.");
|
qDebug("Destroying FeedsView instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FeedsView::setSortingEnabled(bool enable) {
|
void FeedsView::setSortingEnabled(bool enable) {
|
||||||
QTreeView::setSortingEnabled(enable);
|
QTreeView::setSortingEnabled(enable);
|
||||||
header()->setSortIndicatorShown(false);
|
header()->setSortIndicatorShown(false);
|
||||||
@ -75,7 +71,7 @@ void FeedsView::clearSelectedFeeds() {
|
|||||||
|
|
||||||
void FeedsView::addNewCategory() {
|
void FeedsView::addNewCategory() {
|
||||||
QPointer<FormCategoryDetails> form_pointer = new FormCategoryDetails(m_sourceModel, this);
|
QPointer<FormCategoryDetails> form_pointer = new FormCategoryDetails(m_sourceModel, this);
|
||||||
FormCategoryDetailsAnswer answer = form_pointer.data()->exec(NULL, NULL);
|
FormCategoryDetailsAnswer answer = form_pointer.data()->exec(NULL);
|
||||||
|
|
||||||
if (answer.m_dialogCode == QDialog::Accepted) {
|
if (answer.m_dialogCode == QDialog::Accepted) {
|
||||||
// User submitted some new category and
|
// User submitted some new category and
|
||||||
@ -104,7 +100,19 @@ void FeedsView::editSelectedItem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FeedsView::deleteSelectedItem() {
|
void FeedsView::deleteSelectedItem() {
|
||||||
m_sourceModel->removeItem(m_proxyModel->mapToSource(currentIndex()));
|
QModelIndex current_index = currentIndex();
|
||||||
|
QItemSelectionModel *selection_model = selectionModel();
|
||||||
|
|
||||||
|
if (!current_index.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selection_model->selectedRows().size() > 1) {
|
||||||
|
selection_model->clearSelection();
|
||||||
|
selection_model->select(current_index, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sourceModel->removeItem(m_proxyModel->mapToSource(current_index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
||||||
@ -218,7 +226,7 @@ void FeedsView::setupAppearance() {
|
|||||||
setIndentation(10);
|
setIndentation(10);
|
||||||
setDragDropMode(QAbstractItemView::NoDragDrop);
|
setDragDropMode(QAbstractItemView::NoDragDrop);
|
||||||
setAllColumnsShowFocus(true);
|
setAllColumnsShowFocus(true);
|
||||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
setRootIsDecorated(false);
|
setRootIsDecorated(false);
|
||||||
|
|
||||||
// Sort in ascending order, that is categories are
|
// Sort in ascending order, that is categories are
|
||||||
|
@ -3,22 +3,28 @@
|
|||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/feedsmodelrootitem.h"
|
#include "core/feedsmodelrootitem.h"
|
||||||
#include "core/feedsmodelcategory.h"
|
#include "core/feedsmodelcategory.h"
|
||||||
|
#include "core/feedsmodelstandardcategory.h"
|
||||||
#include "core/feedsmodel.h"
|
#include "core/feedsmodel.h"
|
||||||
#include "gui/iconthemefactory.h"
|
#include "gui/iconthemefactory.h"
|
||||||
#include "gui/feedsview.h"
|
#include "gui/feedsview.h"
|
||||||
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
#include "QComboBox"
|
||||||
|
|
||||||
|
|
||||||
FormCategoryDetails::FormCategoryDetails(FeedsModel *model, QWidget *parent)
|
FormCategoryDetails::FormCategoryDetails(FeedsModel *model, QWidget *parent)
|
||||||
: QDialog(parent), m_editableCategory(NULL) {
|
: QDialog(parent),
|
||||||
|
m_editableCategory(NULL),
|
||||||
|
m_feedsModel(model) {
|
||||||
initialize();
|
initialize();
|
||||||
loadCategories(model->allCategories().values(),
|
loadCategories(model->allCategories().values(),
|
||||||
model->rootItem());
|
model->rootItem());
|
||||||
|
|
||||||
setWindowTitle(tr("Add new category"));
|
connect(m_ui->m_buttonBox, SIGNAL(accepted()),
|
||||||
|
this, SLOT(apply()));
|
||||||
}
|
}
|
||||||
|
|
||||||
FormCategoryDetails::~FormCategoryDetails() {
|
FormCategoryDetails::~FormCategoryDetails() {
|
||||||
@ -35,15 +41,16 @@ void FormCategoryDetails::setEditableCategory(FeedsModelCategory *editable_categ
|
|||||||
m_ui->m_btnIcon->setIcon(editable_category->icon());
|
m_ui->m_btnIcon->setIcon(editable_category->icon());
|
||||||
}
|
}
|
||||||
|
|
||||||
FormCategoryDetailsAnswer FormCategoryDetails::exec(FeedsModelCategory *input_category,
|
FormCategoryDetailsAnswer FormCategoryDetails::exec(FeedsModelCategory *input_category) {
|
||||||
FeedsModelCategory *input_parent_category) {
|
|
||||||
FormCategoryDetailsAnswer answer;
|
FormCategoryDetailsAnswer answer;
|
||||||
|
|
||||||
if (input_category == NULL) {
|
if (input_category == NULL) {
|
||||||
// User is adding new category.
|
// User is adding new category.
|
||||||
|
setWindowTitle(tr("Add new category"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// User is editing existing category.
|
// User is editing existing category.
|
||||||
|
setWindowTitle(tr("Edit existing category"));
|
||||||
setEditableCategory(input_category);
|
setEditableCategory(input_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +59,30 @@ FormCategoryDetailsAnswer FormCategoryDetails::exec(FeedsModelCategory *input_ca
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormCategoryDetails::apply() {
|
||||||
|
if (m_editableCategory == NULL) {
|
||||||
|
// add category
|
||||||
|
FeedsModelRootItem *parent = static_cast<FeedsModelRootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
|
||||||
|
FeedsModelStandardCategory *cat = new FeedsModelStandardCategory();
|
||||||
|
|
||||||
|
cat->setTitle(m_ui->m_txtTitle->text());
|
||||||
|
cat->setCreationDate(QDateTime::currentDateTime());
|
||||||
|
cat->setDescription(m_ui->m_txtDescription->toPlainText());
|
||||||
|
cat->setIcon(m_ui->m_btnIcon->icon());
|
||||||
|
cat->setType(FeedsModelCategory::Standard);
|
||||||
|
|
||||||
|
if (m_feedsModel->addItem(cat, parent)) {
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO: hlasit chybu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// edit category
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FormCategoryDetails::initialize() {
|
void FormCategoryDetails::initialize() {
|
||||||
m_ui = new Ui::FormCategoryDetails();
|
m_ui = new Ui::FormCategoryDetails();
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
@ -74,6 +105,6 @@ void FormCategoryDetails::loadCategories(const QList<FeedsModelCategory *> categ
|
|||||||
m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX,
|
m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX,
|
||||||
Qt::DecorationRole).value<QIcon>(),
|
Qt::DecorationRole).value<QIcon>(),
|
||||||
category->title(),
|
category->title(),
|
||||||
category->id());
|
QVariant::fromValue((void*) category));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,10 @@ class FormCategoryDetails : public QDialog {
|
|||||||
// to the database.
|
// to the database.
|
||||||
// NOTE: Newly EDITED category IS COPY of its original.
|
// NOTE: Newly EDITED category IS COPY of its original.
|
||||||
// SO NO ORIGINAL MODEL DATA ARE EDITED OR CHANGED.
|
// SO NO ORIGINAL MODEL DATA ARE EDITED OR CHANGED.
|
||||||
FormCategoryDetailsAnswer exec(FeedsModelCategory *input_category,
|
FormCategoryDetailsAnswer exec(FeedsModelCategory *input_category);
|
||||||
FeedsModelCategory *input_parent_category);
|
|
||||||
|
protected slots:
|
||||||
|
void apply();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Sets the category which will be edited.
|
// Sets the category which will be edited.
|
||||||
@ -59,6 +61,7 @@ class FormCategoryDetails : public QDialog {
|
|||||||
private:
|
private:
|
||||||
Ui::FormCategoryDetails *m_ui;
|
Ui::FormCategoryDetails *m_ui;
|
||||||
FeedsModelCategory *m_editableCategory;
|
FeedsModelCategory *m_editableCategory;
|
||||||
|
FeedsModel *m_feedsModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FORMCATEGORYDETAILS_H
|
#endif // FORMCATEGORYDETAILS_H
|
||||||
|
@ -108,22 +108,6 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
|
||||||
<sender>m_buttonBox</sender>
|
|
||||||
<signal>accepted()</signal>
|
|
||||||
<receiver>FormCategoryDetails</receiver>
|
|
||||||
<slot>accept()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>248</x>
|
|
||||||
<y>254</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>157</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
<connection>
|
||||||
<sender>m_buttonBox</sender>
|
<sender>m_buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user