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) {
// Load categories.
loadCategories(m_serviceRoot->allCategories().values(), m_serviceRoot, input_category);
loadCategories(m_serviceRoot->allCategories(), m_serviceRoot, input_category);
if (input_category == NULL) {
// User is adding new category.

View File

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

View File

@ -292,35 +292,15 @@ void StandardServiceRoot::loadFromDatabase(){
m_recycleBin->updateCounts(true);
}
QHash<int,StandardCategory*> StandardServiceRoot::categoriesForItem(RootItem *root) {
QHash<int,StandardCategory*> categories;
QList<RootItem*> parents;
QList<StandardCategory*> StandardServiceRoot::allCategories() {
QList<Category*> cats = getSubTreeCategories();
QList<StandardCategory*> std_cats;
parents.append(root->childItems());
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());
}
foreach (Category *category, cats) {
std_cats.append(qobject_cast<StandardCategory*>(category));
}
return categories;
}
QHash<int,StandardCategory*> StandardServiceRoot::allCategories() {
// TODO: změnit na qlist, použít getsubtree možná
return categoriesForItem(this);
return std_cats;
}
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 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
// 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.
QList<QAction*> getContextMenuForFeed(StandardFeed *feed);