From e9a487db5e560c890d4f920f49a5eb68c55e47b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Wed, 22 Oct 2014 21:16:43 +0200 Subject: [PATCH] new folders are selected automatically after creation fixed a couple of bugs in TreeModel::addFolderAtParent --- YACReaderLibrary/db/treemodel.cpp | 10 +++++++--- YACReaderLibrary/db/treemodel.h | 2 +- YACReaderLibrary/library_window.cpp | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/YACReaderLibrary/db/treemodel.cpp b/YACReaderLibrary/db/treemodel.cpp index bb5e571f..16aecd03 100644 --- a/YACReaderLibrary/db/treemodel.cpp +++ b/YACReaderLibrary/db/treemodel.cpp @@ -622,7 +622,7 @@ void TreeModel::fetchMoreFromDB(const QModelIndex &parent) QSqlDatabase::removeDatabase(_databasePath); } -void TreeModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent) +QModelIndex TreeModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent) { TreeItem * parentItem; @@ -645,8 +645,8 @@ void TreeModel::addFolderAtParent(const QString &folderName, const QModelIndex & QList data; data << newFolder.name; data << newFolder.path; - data << false; - data << false; + data << false; //finished + data << true; //completed TreeItem * item = new TreeItem(data); item->id = newFolder.id; @@ -656,6 +656,10 @@ void TreeModel::addFolderAtParent(const QString &folderName, const QModelIndex & beginInsertRows(parent,destRow,destRow); endInsertRows(); + + items.insert(item->id,item); + + return index(destRow,0,parent); } void TreeModel::deleteFolder(const QModelIndex &mi) diff --git a/YACReaderLibrary/db/treemodel.h b/YACReaderLibrary/db/treemodel.h index b15119d6..0242dba2 100644 --- a/YACReaderLibrary/db/treemodel.h +++ b/YACReaderLibrary/db/treemodel.h @@ -89,7 +89,7 @@ public: void fetchMoreFromDB(const QModelIndex & parent); - void addFolderAtParent(const QString & folderName, const QModelIndex & parent); + QModelIndex addFolderAtParent(const QString & folderName, const QModelIndex & parent); enum Columns { Name = 0, diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index c65bbfc8..676dfe7f 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1484,7 +1484,10 @@ void LibraryWindow::addFolderToCurrentIndex() QDir parentDir(parentPath); QDir newFolder(parentPath+"/"+newFolderName); if(parentDir.mkdir(newFolderName) || newFolder.exists()) - foldersModel->addFolderAtParent(newFolderName,currentIndex); + { + foldersView->setCurrentIndex(foldersModel->addFolderAtParent(newFolderName,currentIndex)); + reloadCovers(); + } } void LibraryWindow::deleteSelectedFolder()