From 41c50a2c0abb694f1e402fa80a3fe20b1823e5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Tue, 18 Sep 2018 18:42:43 +0200 Subject: [PATCH] new document and new folder editable at creation + expand path if needed --- src/core/UBPersistenceManager.cpp | 4 ++-- src/document/UBDocumentController.cpp | 22 +++++++++++++--------- src/document/UBDocumentController.h | 6 +++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 6593d7e3..e6e9a7ba 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -532,8 +532,8 @@ void UBPersistenceManager::deleteDocument(UBDocumentProxy* pDocumentProxy) emit documentWillBeDeleted(pDocumentProxy); - Q_ASSERT(QFileInfo(pDocumentProxy->persistencePath()).exists()); - UBFileSystemUtils::deleteDir(pDocumentProxy->persistencePath()); + if (QFileInfo(pDocumentProxy->persistencePath()).exists()) + UBFileSystemUtils::deleteDir(pDocumentProxy->persistencePath()); mSceneCache.removeAllScenes(pDocumentProxy); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index ba94ccfc..82735532 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1109,14 +1109,14 @@ void UBDocumentTreeModel::addNewDocument(UBDocumentProxy *pProxyData, const QMod mNewDocuments << pProxyData; } -void UBDocumentTreeModel::addCatalog(const QString &pName, const QModelIndex &pParent) +QModelIndex UBDocumentTreeModel::addCatalog(const QString &pName, const QModelIndex &pParent) { if (pName.isEmpty() || !pParent.isValid()) { - return; + return QModelIndex(); } UBDocumentTreeNode *catalogNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, pName); - addNode(catalogNode, pParent); + return addNode(catalogNode, pParent); } void UBDocumentTreeModel::setNewName(const QModelIndex &index, const QString &newName) @@ -1272,7 +1272,7 @@ UBDocumentTreeView::UBDocumentTreeView(QWidget *parent) : QTreeView(parent) setRootIsDecorated(true); } -void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool pExpand) +void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool pExpand, bool pEdit) { if (!pIndex.isValid()) { return; @@ -1287,7 +1287,7 @@ void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool ? QItemSelectionModel::Select : QItemSelectionModel::Deselect; - selectionModel()->select(proxy->mapFromSource(indexCurrentDoc), QItemSelectionModel::Rows | sel); + selectionModel()->select(proxy->mapFromSource(indexCurrentDoc), QItemSelectionModel::Rows | sel); setCurrentIndex(pExpand ? indexCurrentDoc @@ -1299,6 +1299,9 @@ void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool } scrollTo(proxy->mapFromSource(pIndex), QAbstractItemView::PositionAtCenter); + + if (pEdit) + edit(proxy->mapFromSource(pIndex)); } void UBDocumentTreeView::onModelIndexChanged(const QModelIndex &pNewIndex, const QModelIndex &pOldIndex) @@ -1660,14 +1663,14 @@ void UBDocumentController::createNewDocument() : docModel->virtualDirForIndex(selectedIndex); UBDocumentProxy *document = pManager->createDocument(groupName); - selectDocument(document); + selectDocument(document, true, false, true); if (document) pManager->mDocumentTreeStructureModel->markDocumentAsNew(document); } } -void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument, const bool onImport) +void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument, const bool onImport, const bool editMode) { if (proxy==NULL) { @@ -1678,7 +1681,7 @@ void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurr if (setAsCurrentDocument) { UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel->setCurrentDocument(proxy); QModelIndex indexCurrentDoc = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel->indexForProxy(proxy); - mDocumentUI->documentTreeView->setSelectedAndExpanded(indexCurrentDoc, true); + mDocumentUI->documentTreeView->setSelectedAndExpanded(indexCurrentDoc, true, editMode); if (proxy != mBoardController->selectedDocument()) // only if wanted Document is different from document actually on Board, // ALTI/AOU - 20140217 { @@ -1705,7 +1708,8 @@ void UBDocumentController::createNewDocumentGroup() QString newFolderName = docModel->adjustNameForParentIndex(tr("New Folder"), parentIndex); - docModel->addCatalog(newFolderName, parentIndex); + QModelIndex newIndex = docModel->addCatalog(newFolderName, parentIndex); + mDocumentUI->documentTreeView->setSelectedAndExpanded(newIndex, true, true); } diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index 8647660b..2bb2c0a5 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -208,7 +208,7 @@ public: UBDocumentProxy *proxyData(const QModelIndex &index) const {return nodeFromIndex(index)->proxyData();} void addDocument(UBDocumentProxy *pProxyData, const QModelIndex &pParent = QModelIndex()); void addNewDocument(UBDocumentProxy *pProxyData, const QModelIndex &pParent = QModelIndex()); - void addCatalog(const QString &pName, const QModelIndex &pParent); + QModelIndex addCatalog(const QString &pName, const QModelIndex &pParent); QList newDocuments() {return mNewDocuments;} void markDocumentAsNew(UBDocumentProxy *pDoc) {if (indexForProxy(pDoc).isValid()) mNewDocuments << pDoc;} void setNewName(const QModelIndex &index, const QString &newName); @@ -286,7 +286,7 @@ public: QModelIndexList mapIndexesToSource(const QModelIndexList &indexes); public slots: - void setSelectedAndExpanded(const QModelIndex &pIndex, bool pExpand = true); + void setSelectedAndExpanded(const QModelIndex &pIndex, bool pExpand = true, bool pEdit = false); void onModelIndexChanged(const QModelIndex &pNewIndex, const QModelIndex &pOldIndex); void hSliderRangeChanged(int min, int max); @@ -429,7 +429,7 @@ class UBDocumentController : public UBDocumentContainer void duplicateSelectedItem(); void importFile(); void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target); - void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true, const bool onImport = false); + void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true, const bool onImport = false, const bool editMode = false); void show(); void hide(); void showMessage(const QString& message, bool showSpinningWheel = false);