Advances in category management implementation.
This commit is contained in:
parent
8d070db0ed
commit
04218ca1ae
@ -74,7 +74,7 @@ class FeedsModelRootItem {
|
|||||||
|
|
||||||
// Checks whether this instance is child (can be nested)
|
// Checks whether this instance is child (can be nested)
|
||||||
// if given root item.
|
// if given root item.
|
||||||
bool isChild(FeedsModelRootItem *root) {
|
bool isChildOf(FeedsModelRootItem *root) {
|
||||||
|
|
||||||
while (root->kind() != FeedsModelRootItem::RootItem) {
|
while (root->kind() != FeedsModelRootItem::RootItem) {
|
||||||
if (root->childItems().contains(this)) {
|
if (root->childItems().contains(this)) {
|
||||||
|
@ -16,14 +16,12 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
|
||||||
FormStandardCategoryDetails::FormStandardCategoryDetails(FeedsModel *model, QWidget *parent)
|
FormStandardCategoryDetails::FormStandardCategoryDetails(FeedsModel *model,
|
||||||
|
QWidget *parent)
|
||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
m_editableCategory(NULL),
|
m_editableCategory(NULL),
|
||||||
m_feedsModel(model) {
|
m_feedsModel(model) {
|
||||||
initialize();
|
initialize();
|
||||||
loadCategories(model->allCategories().values(),
|
|
||||||
model->rootItem());
|
|
||||||
|
|
||||||
createConnections();
|
createConnections();
|
||||||
|
|
||||||
// Initialize text boxes.
|
// Initialize text boxes.
|
||||||
@ -56,14 +54,17 @@ int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category
|
|||||||
setWindowTitle(tr("Add new category"));
|
setWindowTitle(tr("Add new category"));
|
||||||
}
|
}
|
||||||
else {
|
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.
|
// User is editing existing category.
|
||||||
setWindowTitle(tr("Edit existing category"));
|
setWindowTitle(tr("Edit existing category"));
|
||||||
setEditableCategory(input_category);
|
setEditableCategory(input_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load categories.
|
||||||
|
loadCategories(m_feedsModel->allCategories().values(),
|
||||||
|
m_feedsModel->rootItem(),
|
||||||
|
input_category);
|
||||||
|
|
||||||
|
// Run the dialog.
|
||||||
return QDialog::exec();
|
return QDialog::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,16 +120,23 @@ void FormStandardCategoryDetails::initialize() {
|
|||||||
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormStandardCategoryDetails::loadCategories(const QList<FeedsModelCategory *> categories,
|
void FormStandardCategoryDetails::loadCategories(const QList<FeedsModelCategory*> categories,
|
||||||
FeedsModelRootItem *root_item) {
|
FeedsModelRootItem *root_item,
|
||||||
|
FeedsModelCategory *input_category) {
|
||||||
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
|
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
|
||||||
root_item->title(),
|
root_item->title(),
|
||||||
QVariant::fromValue((void*) root_item));
|
QVariant::fromValue((void*) root_item));
|
||||||
// pro ziskani root_item static_cast<FeedsModelRootItem*>(itemData(i).value<void*>())
|
|
||||||
// a stejně dole ve foreachi
|
|
||||||
|
|
||||||
|
|
||||||
foreach (FeedsModelCategory *category, categories) {
|
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,
|
m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX,
|
||||||
Qt::DecorationRole).value<QIcon>(),
|
Qt::DecorationRole).value<QIcon>(),
|
||||||
category->title(),
|
category->title(),
|
||||||
|
@ -55,9 +55,12 @@ class FormStandardCategoryDetails : public QDialog {
|
|||||||
// Initializes the dialog.
|
// Initializes the dialog.
|
||||||
void initialize();
|
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<FeedsModelCategory*> categories,
|
void loadCategories(const QList<FeedsModelCategory*> categories,
|
||||||
FeedsModelRootItem *root_item);
|
FeedsModelRootItem *root_item,
|
||||||
|
FeedsModelCategory *input_category);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FormStandardCategoryDetails *m_ui;
|
Ui::FormStandardCategoryDetails *m_ui;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user