diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 2bfc15cbb..84680a4e8 100755 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -74,7 +74,7 @@ class FeedsModelRootItem { // Checks whether this instance is child (can be nested) // if given root item. - bool isChild(FeedsModelRootItem *root) { + bool isChildOf(FeedsModelRootItem *root) { while (root->kind() != FeedsModelRootItem::RootItem) { if (root->childItems().contains(this)) { diff --git a/src/gui/formstandardcategorydetails.cpp b/src/gui/formstandardcategorydetails.cpp index 5060b2dcd..69cd766fe 100644 --- a/src/gui/formstandardcategorydetails.cpp +++ b/src/gui/formstandardcategorydetails.cpp @@ -16,14 +16,12 @@ #include -FormStandardCategoryDetails::FormStandardCategoryDetails(FeedsModel *model, QWidget *parent) +FormStandardCategoryDetails::FormStandardCategoryDetails(FeedsModel *model, + QWidget *parent) : QDialog(parent), m_editableCategory(NULL), m_feedsModel(model) { initialize(); - loadCategories(model->allCategories().values(), - model->rootItem()); - createConnections(); // Initialize text boxes. @@ -56,14 +54,17 @@ int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category setWindowTitle(tr("Add new category")); } else { - // This item cannot have set itself as the parent. - m_ui->m_cmbParentCategory->removeItem(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) input_category))); - // User is editing existing category. setWindowTitle(tr("Edit existing category")); setEditableCategory(input_category); } + // Load categories. + loadCategories(m_feedsModel->allCategories().values(), + m_feedsModel->rootItem(), + input_category); + + // Run the dialog. return QDialog::exec(); } @@ -119,16 +120,23 @@ void FormStandardCategoryDetails::initialize() { m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } -void FormStandardCategoryDetails::loadCategories(const QList categories, - FeedsModelRootItem *root_item) { +void FormStandardCategoryDetails::loadCategories(const QList categories, + FeedsModelRootItem *root_item, + FeedsModelCategory *input_category) { m_ui->m_cmbParentCategory->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*) root_item)); - // pro ziskani root_item static_cast(itemData(i).value()) - // a stejnÄ› dole ve foreachi - foreach (FeedsModelCategory *category, categories) { + if (input_category != NULL && (category == input_category || + input_category->parent() == category || + category->isChildOf(input_category))) { + // This category cannot be selected as the new + // parent for currently edited category, so + // don't add it. + continue; + } + m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX, Qt::DecorationRole).value(), category->title(), diff --git a/src/gui/formstandardcategorydetails.h b/src/gui/formstandardcategorydetails.h index a6da853ef..9b7edd09c 100644 --- a/src/gui/formstandardcategorydetails.h +++ b/src/gui/formstandardcategorydetails.h @@ -55,9 +55,12 @@ class FormStandardCategoryDetails : public QDialog { // Initializes the dialog. void initialize(); - // Loads categories into the dialog. + // Loads categories into the dialog + give root "category" + // and make sure that no childs of input category (including) + // input category are loaded. void loadCategories(const QList categories, - FeedsModelRootItem *root_item); + FeedsModelRootItem *root_item, + FeedsModelCategory *input_category); private: Ui::FormStandardCategoryDetails *m_ui;