Refactored some code.

This commit is contained in:
Martin Rotter 2015-12-10 13:57:40 +01:00
parent c6576ea799
commit 32e1374921
4 changed files with 10 additions and 35 deletions

View file

@ -76,7 +76,7 @@ void FormStandardCategoryDetails::setEditableCategory(StandardCategory *editable
int FormStandardCategoryDetails::exec(StandardCategory *input_category, RootItem *parent_to_select) { int FormStandardCategoryDetails::exec(StandardCategory *input_category, RootItem *parent_to_select) {
// Load categories. // Load categories.
loadCategories(m_serviceRoot->allCategories().values(), m_serviceRoot, input_category); loadCategories(m_serviceRoot->allCategories(), m_serviceRoot, input_category);
if (input_category == NULL) { if (input_category == NULL) {
// User is adding new category. // User is adding new category.

View file

@ -61,7 +61,7 @@ FormStandardFeedDetails::~FormStandardFeedDetails() {
int FormStandardFeedDetails::exec(StandardFeed *input_feed, RootItem *parent_to_select) { int FormStandardFeedDetails::exec(StandardFeed *input_feed, RootItem *parent_to_select) {
// Load categories. // Load categories.
loadCategories(m_serviceRoot->allCategories().values(), m_serviceRoot); loadCategories(m_serviceRoot->allCategories(), m_serviceRoot);
if (input_feed == NULL) { if (input_feed == NULL) {
// User is adding new category. // User is adding new category.
@ -491,8 +491,7 @@ void FormStandardFeedDetails::loadCategories(const QList<StandardCategory*> cate
QVariant::fromValue((void*) root_item)); QVariant::fromValue((void*) root_item));
foreach (StandardCategory *category, categories) { foreach (StandardCategory *category, categories) {
m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX, m_ui->m_cmbParentCategory->addItem(category->icon(),
Qt::DecorationRole).value<QIcon>(),
category->title(), category->title(),
QVariant::fromValue((void*) category)); QVariant::fromValue((void*) category));
} }

View file

@ -292,35 +292,15 @@ void StandardServiceRoot::loadFromDatabase(){
m_recycleBin->updateCounts(true); m_recycleBin->updateCounts(true);
} }
QHash<int,StandardCategory*> StandardServiceRoot::categoriesForItem(RootItem *root) { QList<StandardCategory*> StandardServiceRoot::allCategories() {
QHash<int,StandardCategory*> categories; QList<Category*> cats = getSubTreeCategories();
QList<RootItem*> parents; QList<StandardCategory*> std_cats;
parents.append(root->childItems()); foreach (Category *category, cats) {
std_cats.append(qobject_cast<StandardCategory*>(category));
while (!parents.isEmpty()) {
RootItem *item = parents.takeFirst();
if (item->kind() == RootItemKind::Category) {
// This item is category, add it to the output list and
// scan its children.
int category_id = item->id();
StandardCategory *category = static_cast<StandardCategory*>(item);
if (!categories.contains(category_id)) {
categories.insert(category_id, category);
} }
parents.append(category->childItems()); return std_cats;
}
}
return categories;
}
QHash<int,StandardCategory*> StandardServiceRoot::allCategories() {
// TODO: změnit na qlist, použít getsubtree možná
return categoriesForItem(this);
} }
QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) { QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) {

View file

@ -75,13 +75,9 @@ class StandardServiceRoot : public ServiceRoot {
bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages); bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages); bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
// Returns all standard categories which are lying under given root node.
// This does NOT include the root node even if the node is category.
QHash<int,StandardCategory*> categoriesForItem(RootItem *root);
// Returns all categories from this root, each pair // Returns all categories from this root, each pair
// consists of ID of parent item and pointer to category. // consists of ID of parent item and pointer to category.
QHash<int,StandardCategory*> allCategories(); QList<StandardCategory*> allCategories();
// Returns context specific menu actions for given feed. // Returns context specific menu actions for given feed.
QList<QAction*> getContextMenuForFeed(StandardFeed *feed); QList<QAction*> getContextMenuForFeed(StandardFeed *feed);