From 5e031bc5e5a3949f8986d837db90de1280806093 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 28 Dec 2013 17:40:22 +0100 Subject: [PATCH] Work on categorie. --- src/core/feedsmodelcategory.cpp | 12 +++++++ src/core/feedsmodelcategory.h | 1 + src/core/feedsmodelrootitem.cpp | 2 +- src/core/feedsmodelrootitem.h | 2 +- src/gui/feedsview.cpp | 20 +++++++++--- src/gui/feedsview.h | 2 ++ src/gui/formcategorydetails.cpp | 57 ++++++++++++++++++++------------- src/gui/formcategorydetails.h | 31 ++++++++++++------ 8 files changed, 90 insertions(+), 37 deletions(-) diff --git a/src/core/feedsmodelcategory.cpp b/src/core/feedsmodelcategory.cpp index 4e1f2eb51..708c905de 100755 --- a/src/core/feedsmodelcategory.cpp +++ b/src/core/feedsmodelcategory.cpp @@ -11,6 +11,18 @@ FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item) m_kind = FeedsModelRootItem::Category; } +FeedsModelCategory::FeedsModelCategory(const FeedsModelCategory &other) { + m_kind = other.kind(); + m_title = other.title(); + m_id = other.id(); + m_icon = other.icon(); + m_childItems = other.childItems(); + m_parentItem = other.parent(); + m_type = other.type(); + m_creationDate = other.creationDate(); + m_description = other.description(); +} + FeedsModelCategory::~FeedsModelCategory() { } diff --git a/src/core/feedsmodelcategory.h b/src/core/feedsmodelcategory.h index 3119888e7..bfcd4e9ba 100755 --- a/src/core/feedsmodelcategory.h +++ b/src/core/feedsmodelcategory.h @@ -23,6 +23,7 @@ class FeedsModelCategory : public FeedsModelRootItem { // Constructors and destructors explicit FeedsModelCategory(FeedsModelRootItem *parent_item = NULL); + explicit FeedsModelCategory(const FeedsModelCategory &other); virtual ~FeedsModelCategory(); // Counts of messages. diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 8b8dfa3a4..3822d19bf 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -15,7 +15,7 @@ FeedsModelRootItem::~FeedsModelRootItem() { qDeleteAll(m_childItems); } -FeedsModelRootItem *FeedsModelRootItem::parent() { +FeedsModelRootItem *FeedsModelRootItem::parent() const { return m_parentItem; } diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 416ee8b6d..bbd76899a 100755 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -21,7 +21,7 @@ class FeedsModelRootItem { virtual ~FeedsModelRootItem(); // Basic operations. - virtual FeedsModelRootItem *parent(); + virtual FeedsModelRootItem *parent() const; virtual void setParent(FeedsModelRootItem *parent_item); virtual FeedsModelRootItem *child(int row); virtual void appendChild(FeedsModelRootItem *child); diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 940da5d41..f5d4f0e29 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -62,17 +62,29 @@ void FeedsView::clearSelectedFeeds() { } void FeedsView::addNewCategory() { - QPointer form_pointer = new FormCategoryDetails(this); - - if (form_pointer.data()->exec() == QDialog::Accepted) { - // User submitted some new category. + QPointer form_pointer = new FormCategoryDetails(m_sourceModel, + this); + FeedsModelCategory *output_item; + FeedsModelRootItem *parent_item; + if (form_pointer.data()->exec(NULL, + output_item, + parent_item) == QDialog::Accepted) { + // User submitted some new category and + // it now resides in output_item pointer, + // parent_item contains parent_that user selected for + // new category. + // TODO: Add new category to the model and to the database. } delete form_pointer.data(); } +void FeedsView::editSelectedCategory() { + // TODO: Implement this. +} + void FeedsView::markSelectedFeedsReadStatus(int read) { m_sourceModel->markFeedsRead(selectedFeeds(), read); updateCountsOfSelectedFeeds(false); diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 6002a0335..de8ba5993 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -7,6 +7,7 @@ class FeedsModel; class FeedsProxyModel; class FeedsModelFeed; +class FeedsModelCategory; class FeedsView : public QTreeView { Q_OBJECT @@ -38,6 +39,7 @@ class FeedsView : public QTreeView { // Category operators. void addNewCategory(); + void editSelectedCategory(); // Reloads counts for selected feeds. void updateCountsOfSelectedFeeds(bool update_total_too = true); diff --git a/src/gui/formcategorydetails.cpp b/src/gui/formcategorydetails.cpp index b0fbaeba5..f40b79648 100644 --- a/src/gui/formcategorydetails.cpp +++ b/src/gui/formcategorydetails.cpp @@ -10,41 +10,55 @@ #include -FormCategoryDetails::FormCategoryDetails(FeedsView *parent) - : QDialog(parent) { - initialize(parent); - loadCategories(parent->sourceModel()->getAllCategories().values(), - parent->sourceModel()->rootItem()); +FormCategoryDetails::FormCategoryDetails(FeedsModel *model, QWidget *parent) + : QDialog(parent), m_editableCategory(NULL) { + initialize(); + loadCategories(model->getAllCategories().values(), + model->rootItem()); setWindowTitle(tr("Add new category")); } -FormCategoryDetails::FormCategoryDetails(FeedsModelCategory *category, - FeedsView *parent) - : QDialog(parent) { - initialize(parent); - loadCategories(parent->sourceModel()->getAllCategories().values(), - parent->sourceModel()->rootItem()); - - setWindowTitle(tr("Edit existing category")); -} - FormCategoryDetails::~FormCategoryDetails() { qDebug("Destroying FormCategoryDetails instance."); } -void FormCategoryDetails::initialize(FeedsView *view) { +void FormCategoryDetails::setEditableCategory(FeedsModelCategory *editable_category) { + m_editableCategory = editable_category; + + if (m_editableCategory != NULL) { + // TODO: Setup the dialog according to new category. + // so remove this category from category combobox!! + } +} + +int FormCategoryDetails::exec(FeedsModelCategory *input_category, + FeedsModelCategory *output_item, + FeedsModelRootItem *parent_item) { + // TODO: Implement this. + setEditableCategory(input_category); + + int result = QDialog::exec(); + + if (input_category == NULL) { + // User is adding new category. + + } + else { + // User is editing existing category. + + } + + return result; +} + +void FormCategoryDetails::initialize() { m_ui = new Ui::FormCategoryDetails(); m_ui->setupUi(this); // Set flags and attributes. setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog); setWindowIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); - - // Add button for obtaining data about feed from internet. - m_btnObtainDetails = m_ui->m_buttonBox->addButton(tr("Get details via internet"), - QDialogButtonBox::ActionRole); - m_btnObtainDetails->setIcon(IconThemeFactory::getInstance()->fromTheme("document-save")); } void FormCategoryDetails::loadCategories(const QList categories, @@ -59,5 +73,4 @@ void FormCategoryDetails::loadCategories(const QList categ category->title(), category->id()); } - } diff --git a/src/gui/formcategorydetails.h b/src/gui/formcategorydetails.h index 9b2a52c3e..c1cac9305 100644 --- a/src/gui/formcategorydetails.h +++ b/src/gui/formcategorydetails.h @@ -11,8 +11,8 @@ namespace Ui { } class FeedsModelCategory; +class FeedsModel; class FeedsModelRootItem; -class FeedsView; class FormCategoryDetails : public QDialog { Q_OBJECT @@ -20,17 +20,31 @@ class FormCategoryDetails : public QDialog { 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); + explicit FormCategoryDetails(FeedsModel *model, QWidget *parent = 0); // Destructor. virtual ~FormCategoryDetails(); + public slots: + // Start dialog execution. If result is QDialog::Accepted, + // then output_item contains added or edited category + // and parent_item contains parent item of newly + // created or edited category. + // NOTE: Newly ADDED category is NOT added to the model NOR + // in the database. + // NOTE: Newly EDITED category IS COPY of its original. + // SO NO ORIGINAL MODEL DATA ARE EDITED OR CHANGED. + int exec(FeedsModelCategory *input_category, + FeedsModelCategory *output_item, + FeedsModelRootItem *parent_item); + protected: - void initialize(FeedsView *view); + // Sets the category which will be edited. + // NOTE: This is used for editing categories. + void setEditableCategory(FeedsModelCategory *editable_category); + + // Initializes the dialog. + void initialize(); // Loads categories into the dialog. void loadCategories(const QList categories, @@ -38,8 +52,7 @@ class FormCategoryDetails : public QDialog { private: Ui::FormCategoryDetails *m_ui; - QPushButton *m_btnObtainDetails; - + FeedsModelCategory *m_editableCategory; }; #endif // FORMCATEGORYDETAILS_H