From e0790bb6a2ebac94998302d08c7248c8929543fe Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 25 Sep 2017 15:18:04 +0200 Subject: [PATCH] Some simplifications in construcotrs of std. category. --- src/services/abstract/category.cpp | 2 ++ src/services/abstract/category.h | 1 + src/services/abstract/rootitem.cpp | 8 ++++- src/services/standard/standardcategory.cpp | 40 +++++----------------- src/services/standard/standardcategory.h | 17 ++------- 5 files changed, 22 insertions(+), 46 deletions(-) diff --git a/src/services/abstract/category.cpp b/src/services/abstract/category.cpp index 4bc7047cd..707cea38c 100755 --- a/src/services/abstract/category.cpp +++ b/src/services/abstract/category.cpp @@ -34,6 +34,8 @@ Category::Category(RootItem* parent) : RootItem(parent) { } } +Category::Category(const Category& other) : RootItem(other) {} + Category::Category(const QSqlRecord& record) : Category(nullptr) { setId(record.value(CAT_DB_ID_INDEX).toInt()); setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toString()); diff --git a/src/services/abstract/category.h b/src/services/abstract/category.h index e7c38d8cd..e8d372fce 100755 --- a/src/services/abstract/category.h +++ b/src/services/abstract/category.h @@ -26,6 +26,7 @@ class Category : public RootItem { public: explicit Category(RootItem* parent = nullptr); + explicit Category(const Category& other); explicit Category(const QSqlRecord& record); virtual ~Category(); diff --git a/src/services/abstract/rootitem.cpp b/src/services/abstract/rootitem.cpp index bae6d5aa2..d40b229e1 100755 --- a/src/services/abstract/rootitem.cpp +++ b/src/services/abstract/rootitem.cpp @@ -146,7 +146,13 @@ QVariant RootItem::data(int column, int role) const { switch (role) { case Qt::ToolTipRole: if (column == FDS_MODEL_TITLE_INDEX) { - return m_title; + QString tool_tip = m_title; + + if (!m_description.isEmpty()) { + tool_tip += QL1S("\n\n") + m_description; + } + + return tool_tip; } else if (column == FDS_MODEL_COUNTS_INDEX) { //: Tooltip for "unread" column of feed list. diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index da1d42526..a39b5e6b8 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -35,16 +35,7 @@ StandardCategory::StandardCategory(RootItem* parent_item) : Category(parent_item) {} StandardCategory::StandardCategory(const StandardCategory& other) - : StandardCategory(nullptr) { - setId(other.id()); - setCustomId(other.customId()); - setTitle(other.title()); - setDescription(other.description()); - setIcon(other.icon()); - setCreationDate(other.creationDate()); - setChildItems(other.childItems()); - setParent(other.parent()); -} + : Category(other) {} StandardCategory::~StandardCategory() { qDebug("Destroying Category instance."); @@ -54,27 +45,6 @@ StandardServiceRoot* StandardCategory::serviceRoot() const { return qobject_cast(getParentServiceRoot()); } -QVariant StandardCategory::data(int column, int role) const { - switch (role) { - case Qt::ToolTipRole: - if (column == FDS_MODEL_TITLE_INDEX) { - //: Tooltip for standard feed. - return tr("%1 (category)" - "%2%3").arg(title(), - description().isEmpty() ? QString() : QSL("\n") + description(), - childCount() == 0 ? - tr("\nThis category does not contain any nested items.") : - QString()); - } - else { - return Category::data(column, role); - } - - default: - return Category::data(column, role); - } -} - Qt::ItemFlags StandardCategory::additionalFlags() const { return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; } @@ -96,6 +66,14 @@ bool StandardCategory::performDragDropChange(RootItem* target_item) { } } +bool StandardCategory::canBeEdited() const { + return true; +} + +bool StandardCategory::canBeDeleted() const { + return true; +} + bool StandardCategory::editViaGui() { QScopedPointer form_pointer(new FormStandardCategoryDetails(serviceRoot(), qApp->mainFormWidget())); form_pointer.data()->addEditCategory(this, nullptr); diff --git a/src/services/standard/standardcategory.h b/src/services/standard/standardcategory.h index 42df36d68..5f9d389b7 100755 --- a/src/services/standard/standardcategory.h +++ b/src/services/standard/standardcategory.h @@ -34,8 +34,6 @@ class StandardCategory : public Category { Q_OBJECT public: - - // Constructors and destructors explicit StandardCategory(RootItem* parent_item = nullptr); explicit StandardCategory(const StandardCategory& other); explicit StandardCategory(const QSqlRecord& record); @@ -44,27 +42,18 @@ class StandardCategory : public Category { StandardServiceRoot* serviceRoot() const; // Returns the actual data representation of standard category. - QVariant data(int column, int role) const; Qt::ItemFlags additionalFlags() const; bool performDragDropChange(RootItem* target_item); - bool canBeEdited() const { - return true; - } - - bool canBeDeleted() const { - return true; - } + bool canBeEdited() const; + bool canBeDeleted() const; bool editViaGui(); bool deleteViaGui(); - // Removes category and all its children from persistent - // database. - bool removeItself(); - bool addItself(RootItem* parent); bool editItself(StandardCategory* new_category_data); + bool removeItself(); }; #endif // FEEDSMODELCLASSICCATEGORY_H