From c55ce376b11eac20935d1a0b3ec6f0c9e78f07d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 18 Dec 2014 21:16:09 +0100 Subject: [PATCH] only one level of sublists are allowed --- YACReaderLibrary/db/reading_list_model.cpp | 17 ++++++++++++ YACReaderLibrary/db/reading_list_model.h | 1 + YACReaderLibrary/library_window.cpp | 31 ++++++++++++---------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index 18c62e45..8a825e96 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -369,6 +369,23 @@ bool ReadingListModel::isReadingList(const QModelIndex &mi) return typeid(*item) == typeid(ReadingListItem); } +bool ReadingListModel::isReadingSubList(const QModelIndex &mi) +{ + if(!mi.isValid()) + return false; + ListItem * item = static_cast(mi.internalPointer()); + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * readingListItem = static_cast(item); + if(readingListItem->parent == rootItem) + return false; + else + return true; + } + else + return false; +} + QString ReadingListModel::name(const QModelIndex &mi) { return data(mi,Qt::DisplayRole).toString(); diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h index 6f379548..3f332c17 100644 --- a/YACReaderLibrary/db/reading_list_model.h +++ b/YACReaderLibrary/db/reading_list_model.h @@ -48,6 +48,7 @@ public: void addReadingListAt(const QString & name, const QModelIndex & mi); bool isEditable(const QModelIndex & mi); bool isReadingList(const QModelIndex & mi); + bool isReadingSubList(const QModelIndex & mi); QString name(const QModelIndex & mi); void rename(const QModelIndex & mi, const QString & name); void deleteItem(const QModelIndex & mi); diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index eaf91cb8..e713b40d 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1560,21 +1560,24 @@ void LibraryWindow::errorDeletingFolder() void LibraryWindow::addNewReadingList() { - bool ok; - QString newListName = QInputDialog::getText(this, tr("Add new reading lists"), - tr("List name:"), QLineEdit::Normal, - "", &ok); + QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); + QModelIndex sourceMI; + if(!selectedLists.isEmpty()) + sourceMI = listsModelProxy->mapToSource(selectedLists.at(0)); - if (ok) { - QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); - QModelIndex sourceMI; - if(!selectedLists.isEmpty()) - sourceMI = listsModelProxy->mapToSource(selectedLists.at(0)); - if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI)) - listsModel->addReadingList(newListName); //top level - else - { - listsModel->addReadingListAt(newListName,sourceMI); //sublist + if(selectedLists.isEmpty() || !listsModel->isReadingSubList(sourceMI) ) + { + bool ok; + QString newListName = QInputDialog::getText(this, tr("Add new reading lists"), + tr("List name:"), QLineEdit::Normal, + "", &ok); + if (ok) { + if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI)) + listsModel->addReadingList(newListName); //top level + else + { + listsModel->addReadingListAt(newListName,sourceMI); //sublist + } } } }