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); 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) QString ReadingListModel::name(const QModelIndex &mi)
{ {
return data(mi,Qt::DisplayRole).toString(); return data(mi,Qt::DisplayRole).toString();

View File

@ -48,6 +48,7 @@ public:
void addReadingListAt(const QString & name, const QModelIndex & mi); void addReadingListAt(const QString & name, const QModelIndex & mi);
bool isEditable(const QModelIndex & mi); bool isEditable(const QModelIndex & mi);
bool isReadingList(const QModelIndex & mi); bool isReadingList(const QModelIndex & mi);
bool isReadingSubList(const QModelIndex & mi);
QString name(const QModelIndex & mi); QString name(const QModelIndex & mi);
void rename(const QModelIndex & mi, const QString & name); void rename(const QModelIndex & mi, const QString & name);
void deleteItem(const QModelIndex & mi); void deleteItem(const QModelIndex & mi);

View File

@ -1560,21 +1560,24 @@ void LibraryWindow::errorDeletingFolder()
void LibraryWindow::addNewReadingList() void LibraryWindow::addNewReadingList()
{ {
bool ok; QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes();
QString newListName = QInputDialog::getText(this, tr("Add new reading lists"), QModelIndex sourceMI;
tr("List name:"), QLineEdit::Normal, if(!selectedLists.isEmpty())
"", &ok); sourceMI = listsModelProxy->mapToSource(selectedLists.at(0));
if (ok) { if(selectedLists.isEmpty() || !listsModel->isReadingSubList(sourceMI) )
QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); {
QModelIndex sourceMI; bool ok;
if(!selectedLists.isEmpty()) QString newListName = QInputDialog::getText(this, tr("Add new reading lists"),
sourceMI = listsModelProxy->mapToSource(selectedLists.at(0)); tr("List name:"), QLineEdit::Normal,
if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI)) "", &ok);
listsModel->addReadingList(newListName); //top level if (ok) {
else if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI))
{ listsModel->addReadingList(newListName); //top level
listsModel->addReadingListAt(newListName,sourceMI); //sublist else
{
listsModel->addReadingListAt(newListName,sourceMI); //sublist
}
} }
} }
} }