only one level of sublists are allowed

This commit is contained in:
Luis Ángel San Martín
2014-12-18 21:16:09 +01:00
parent e576bebc2a
commit c55ce376b1
3 changed files with 35 additions and 14 deletions

View File

@ -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<ListItem*>(mi.internalPointer());
if(typeid(*item) == typeid(ReadingListItem))
{
ReadingListItem * readingListItem = static_cast<ReadingListItem *>(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();

View File

@ -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);

View File

@ -1560,16 +1560,18 @@ void LibraryWindow::errorDeletingFolder()
void LibraryWindow::addNewReadingList()
{
bool ok;
QString newListName = QInputDialog::getText(this, tr("Add new reading lists"),
tr("List name:"), QLineEdit::Normal,
"", &ok);
if (ok) {
QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes();
QModelIndex sourceMI;
if(!selectedLists.isEmpty())
sourceMI = listsModelProxy->mapToSource(selectedLists.at(0));
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
@ -1577,6 +1579,7 @@ void LibraryWindow::addNewReadingList()
listsModel->addReadingListAt(newListName,sourceMI); //sublist
}
}
}
}
void LibraryWindow::deleteSelectedReadingList()