From 319671eeab480504ebd23d0a932eaaf1f7a9a3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Wed, 18 Jul 2018 16:22:02 +0200 Subject: [PATCH] deleted Models Folder and code related + redesign of Documents UI --- resources/forms/documents.ui | 79 ++++--------------- src/adaptors/UBExportAdaptor.cpp | 17 +++-- src/adaptors/UBExportDocument.cpp | 11 +++ src/adaptors/UBExportDocument.h | 4 +- src/adaptors/UBExportDocumentSetAdaptor.cpp | 2 +- src/document/UBDocumentController.cpp | 85 ++++----------------- src/document/UBDocumentController.h | 4 - src/gui/UBDocumentTreeWidget.cpp | 9 +-- 8 files changed, 57 insertions(+), 154 deletions(-) diff --git a/resources/forms/documents.ui b/resources/forms/documents.ui index 90dc4476..49aa1ed9 100644 --- a/resources/forms/documents.ui +++ b/resources/forms/documents.ui @@ -54,49 +54,23 @@ - - - - 0 - 0 - - - - Collapse All - - - - - - - :/images/collapse-all.png:/images/collapse-all.png - - - true - - - - - + - 0 + 2 0 - - Expand All - - - - - - - :/images/expand-all.png:/images/expand-all.png - - - true - + + + Ascending order + + + + + Descending order + + @@ -107,11 +81,6 @@ 0 - - - Select a sort - - Creation date @@ -129,26 +98,6 @@ - - - - - 2 - 0 - - - - - Ascending order - - - - - Descending order - - - - @@ -344,8 +293,6 @@
document/UBDocumentController.h
- - - + diff --git a/src/adaptors/UBExportAdaptor.cpp b/src/adaptors/UBExportAdaptor.cpp index 7d985eaa..c4ac4896 100644 --- a/src/adaptors/UBExportAdaptor.cpp +++ b/src/adaptors/UBExportAdaptor.cpp @@ -55,22 +55,25 @@ UBExportAdaptor::~UBExportAdaptor() // NOOP } - QString UBExportAdaptor::askForFileName(UBDocumentProxy* pDocument, const QString& pDialogTitle) { QString defaultName; - if (pDocument->metaData(UBSettings::documentGroupName).toString().length() > 0) - { - defaultName += pDocument->metaData(UBSettings::documentGroupName).toString() + QString(" "); - } - defaultName += pDocument->metaData(UBSettings::documentName).toString() + exportExtention(); defaultName = UBFileSystemUtils::cleanName(defaultName); + QString defaultPath = UBSettings::settings()->lastExportFilePath->get().toString() + "/" + defaultName; - QString filename = QFileDialog::getSaveFileName(UBApplication::mainWindow, pDialogTitle, defaultPath); + bool useNativeDialog = true; +#ifdef Q_OS_MAC + int versionMac = qMacVersion(); + if (versionMac == QSysInfo::MV_Unknown || versionMac >= 11){ // version 11 is MacOSX 10.9 Mavericks + useNativeDialog = false; + } +#endif + + QString filename = QFileDialog::getSaveFileName(UBApplication::mainWindow, pDialogTitle, defaultPath, QString(), 0, useNativeDialog?(QFileDialog::Option)0:QFileDialog::DontUseNativeDialog); if (filename.size() == 0) { diff --git a/src/adaptors/UBExportDocument.cpp b/src/adaptors/UBExportDocument.cpp index 63928615..b13fcf5b 100644 --- a/src/adaptors/UBExportDocument.cpp +++ b/src/adaptors/UBExportDocument.cpp @@ -35,6 +35,7 @@ #include "core/UBApplication.h" #include "document/UBDocumentProxy.h" +#include "document/UBDocumentController.h" #include "globals/UBGlobals.h" @@ -111,3 +112,13 @@ QString UBExportDocument::exportName() { return tr("Export to OpenBoard Format"); } + +bool UBExportDocument::associatedActionactionAvailableFor(const QModelIndex &selectedIndex) +{ + const UBDocumentTreeModel *docModel = qobject_cast(selectedIndex.model()); + if (!selectedIndex.isValid() || docModel->isCatalog(selectedIndex)) { + return false; + } + + return true; +} diff --git a/src/adaptors/UBExportDocument.h b/src/adaptors/UBExportDocument.h index a0e55287..6555ebd6 100644 --- a/src/adaptors/UBExportDocument.h +++ b/src/adaptors/UBExportDocument.h @@ -41,7 +41,7 @@ class UBDocumentProxy; class UBExportDocument : public UBExportAdaptor, public UBProcessingProgressListener { - Q_OBJECT; + Q_OBJECT public: UBExportDocument(QObject *parent = 0); @@ -54,6 +54,8 @@ class UBExportDocument : public UBExportAdaptor, public UBProcessingProgressList virtual bool persistsDocument(UBDocumentProxy* pDocument, const QString& filename); virtual void processing(const QString& pObjectName, int pCurrent, int pTotal); + + virtual bool associatedActionactionAvailableFor(const QModelIndex &selectedIndex); }; #endif /* UBEXPORTDOCUMENT_H_ */ diff --git a/src/adaptors/UBExportDocumentSetAdaptor.cpp b/src/adaptors/UBExportDocumentSetAdaptor.cpp index 87738391..eb56c691 100644 --- a/src/adaptors/UBExportDocumentSetAdaptor.cpp +++ b/src/adaptors/UBExportDocumentSetAdaptor.cpp @@ -142,7 +142,7 @@ QString UBExportDocumentSetAdaptor::exportExtention() QString UBExportDocumentSetAdaptor::exportName() { - return tr("Export to Sankore UBX Format"); + return tr("Export to OpenBoard UBX Format"); } bool UBExportDocumentSetAdaptor::addDocumentToZip(const QModelIndex &pIndex, UBDocumentTreeModel *model, QuaZip &zip) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 82b0dc37..186a9655 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -347,8 +347,8 @@ UBDocumentTreeModel::UBDocumentTreeModel(QObject *parent) : UBDocumentTreeNode *myDocsNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, UBPersistenceManager::myDocumentsName, tr("My documents")); rootNode->addChild(myDocsNode); - UBDocumentTreeNode *modelsNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, UBPersistenceManager::modelsName, tr("Models")); - rootNode->addChild(modelsNode); + //UBDocumentTreeNode *modelsNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, UBPersistenceManager::modelsName, tr("Models")); + //rootNode->addChild(modelsNode); UBDocumentTreeNode *trashNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, trashName, tr("Trash")); rootNode->addChild(trashNode); UBDocumentTreeNode *untitledDocumentsNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, UBPersistenceManager::untitledDocumentsName, tr("Untitled documents")); @@ -358,8 +358,7 @@ UBDocumentTreeModel::UBDocumentTreeModel(QObject *parent) : mRoot = index(0, 0, QModelIndex()); mMyDocuments = index(0, 0, QModelIndex()); - mModels = index(1, 0, QModelIndex()); - mTrash = index(2, 0, QModelIndex()); + mTrash = index(1, 0, QModelIndex()); mUntitledDocuments = index(0, 0, mMyDocuments); mAscendingOrder = true; } @@ -711,13 +710,8 @@ bool UBDocumentTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction act QList incomingIndexes = mimeData->indexes(); - foreach (QModelIndex curIndex, incomingIndexes) { -#ifdef Q_WS_MAC - if (inModel(curIndex)) { - return true; - } -#endif - + foreach (QModelIndex curIndex, incomingIndexes) + { //Issue N/C - NNE - 20140528 : use just the index on the first column if(curIndex.column() == 0){ QModelIndex clonedTopLevel = copyIndexToNewParent(curIndex, parent, action == Qt::MoveAction ? aReference : aContentCopy); @@ -1070,11 +1064,6 @@ bool UBDocumentTreeModel::inTrash(const QModelIndex &index) const return isDescendantOf(index, trashIndex()); } -bool UBDocumentTreeModel::inModel(const QModelIndex &index) const -{ - return isDescendantOf(index, modelsIndex()); -} - bool UBDocumentTreeModel::inUntitledDocuments(const QModelIndex &index) const { return isDescendantOf(index, untitledDocumentsIndex()); @@ -1409,11 +1398,11 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event) bool isUBPage = event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage); - bool inModel = docModel->inModel(targetIndex) || targetIndex == docModel->modelsIndex(); + bool inModel = false; //just check the first index, because the selection is exclusive between //myDocuments, Model and Tash - bool isSourceAModel = docModel->inModel(dropIndex.first()); + bool isSourceAModel = false; //issue 1629 - NNE - 20131212 bool targetIsInTrash = docModel->inTrash(targetIndex) || docModel->trashIndex() == targetIndex; @@ -1502,27 +1491,12 @@ bool UBDocumentTreeView::isAcceptable(const QModelIndex &dragIndex, const QModel return false; } - if (fullModel() && fullModel()->inModel(dragIndexSource)) { - if (atIndexSource == fullModel()->modelsIndex() || fullModel()->inModel(atIndexSource)) { - return false; //do not accept drop from model to itself - } - } - return true; } Qt::DropAction UBDocumentTreeView::acceptableAction(const QModelIndex &dragIndex, const QModelIndex &atIndex) -{ - if (fullModel()->inModel(dragIndex)) { - if (atIndex == fullModel()->trashIndex() || fullModel()->inTrash(atIndex)) { - return Qt::MoveAction; //do not accept drop from model to trash, only "delete" command accepted - } - return Qt::CopyAction; - } else { - return Qt::MoveAction; - } - - return Qt::IgnoreAction; +{ + return Qt::MoveAction; } void UBDocumentTreeView::updateIndexEnvirons(const QModelIndex &index) @@ -1844,9 +1818,7 @@ void UBDocumentController::TreeViewSelectionChanged(const QItemSelection &select UBDocumentTreeModel *model = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; - bool sameFolder = (model->inModel(sourceIndex1) && model->inModel(sourceIndex2)); - - sameFolder |= (model->inTrash(sourceIndex1) && model->inTrash(sourceIndex2)); + bool sameFolder = (model->inTrash(sourceIndex1) && model->inTrash(sourceIndex2)); sameFolder |= (model->inMyDocuments(sourceIndex1) && model->inMyDocuments(sourceIndex2)); @@ -2022,15 +1994,9 @@ void UBDocumentController::setupViews() mDocumentUI->documentTreeView->hideColumn(1); mDocumentUI->documentTreeView->hideColumn(2); - mDocumentUI->sortOrder->hide(); - connect(mDocumentUI->sortKind, SIGNAL(activated(int)), this, SLOT(onSortKindChanged(int))); connect(mDocumentUI->sortOrder, SIGNAL(activated(int)), this, SLOT(onSortOrderChanged(int))); - connect(mDocumentUI->collapseAll, SIGNAL(clicked()), this, SLOT(collapseAll())); - - connect(mDocumentUI->expandAll, SIGNAL(clicked()), this, SLOT(expandAll())); - connect(mDocumentUI->documentTreeView->itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint) ), mDocumentUI->documentTreeView, SLOT(adjustSize())); connect(mDocumentUI->documentTreeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(TreeViewSelectionChanged(QItemSelection,QItemSelection))); connect(UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel, SIGNAL(indexChanged(QModelIndex,QModelIndex)) @@ -2083,22 +2049,12 @@ void UBDocumentController::sortDocuments(int kind, int order) if(kind == UBDocumentController::CreationDate){ mSortFilterProxyModel->setSortRole(UBDocumentTreeModel::CreationDate); mSortFilterProxyModel->sort(1, sortOrder); - - mDocumentUI->documentTreeView->showColumn(1); - mDocumentUI->documentTreeView->hideColumn(2); }else if(kind == UBDocumentController::UpdateDate){ mSortFilterProxyModel->setSortRole(UBDocumentTreeModel::UpdateDate); mSortFilterProxyModel->sort(2, sortOrder); - - mDocumentUI->documentTreeView->hideColumn(1); - mDocumentUI->documentTreeView->showColumn(2); }else{ mSortFilterProxyModel->setSortRole(Qt::DisplayRole); mSortFilterProxyModel->sort(0, sortOrder); - - //alphabetical order or nothing - mDocumentUI->documentTreeView->hideColumn(1); - mDocumentUI->documentTreeView->hideColumn(2); } } @@ -2115,11 +2071,6 @@ void UBDocumentController::onSortKindChanged(int index) { int orderIndex = mDocumentUI->sortOrder->currentIndex(); - if(index == -1 || index == 0) - mDocumentUI->sortOrder->hide(); - else - mDocumentUI->sortOrder->show(); - sortDocuments(index, orderIndex); } //N/C - NNE - 20140403 : END @@ -2762,10 +2713,7 @@ void UBDocumentController::thumbnailPageDoubleClicked(QGraphicsItem* item, int i QModelIndex selectedIndex = firstSelectedTreeIndex(); if (selectedIndex.isValid()) { - if (docModel->inModel(selectedIndex)) { - UBApplication::showMessage(tr("The model documents are not editable. Copy it to \"My documents\" to be able to work with")); - return; - } else if (docModel->inTrash(selectedIndex)) { + if (docModel->inTrash(selectedIndex)) { return; } } @@ -3070,9 +3018,8 @@ void UBDocumentController::updateActions() } bool trashSelected = docModel->inTrash(selectedIndex) || selectedIndex == docModel->trashIndex() ? true : false; - bool modelSelected = docModel->inModel(selectedIndex) || selectedIndex == docModel->modelsIndex() ? true : false; - mMainWindow->actionNewDocument->setEnabled(docModel->newNodeAllowed(selectedIndex) && !modelSelected); + mMainWindow->actionNewDocument->setEnabled(docModel->newNodeAllowed(selectedIndex)); mMainWindow->actionNewFolder->setEnabled(docModel->newNodeAllowed(selectedIndex)); mMainWindow->actionExport->setEnabled((docSelected || pageSelected || groupSelected) && !trashSelected); updateExportSubActions(selectedIndex); @@ -3080,7 +3027,7 @@ void UBDocumentController::updateActions() bool firstSceneSelected = false; if (docSelected) { - mMainWindow->actionDuplicate->setEnabled(!trashSelected && !modelSelected); + mMainWindow->actionDuplicate->setEnabled(!trashSelected); } else if (pageSelected) { QList selection = mDocumentUI->thumbnailWidget->selectedItems(); @@ -3104,7 +3051,7 @@ void UBDocumentController::updateActions() mMainWindow->actionDuplicate->setEnabled(false); } - mMainWindow->actionOpen->setEnabled((docSelected || pageSelected) && !trashSelected && !modelSelected); + mMainWindow->actionOpen->setEnabled((docSelected || pageSelected) && !trashSelected); mMainWindow->actionRename->setEnabled(docModel->isOkToRename(selectedIndex)); mMainWindow->actionAddToWorkingDocument->setEnabled(pageSelected @@ -3133,7 +3080,7 @@ void UBDocumentController::updateActions() break; } - mMainWindow->actionDocumentAdd->setEnabled((docSelected || pageSelected) && !trashSelected && !modelSelected); + mMainWindow->actionDocumentAdd->setEnabled((docSelected || pageSelected) && !trashSelected); mMainWindow->actionImport->setEnabled(!trashSelected); } @@ -3344,7 +3291,7 @@ void UBDocumentController::refreshDocumentThumbnailsView(UBDocumentContainer*) mDocumentUI->thumbnailWidget->setGraphicsItems(items, itemsPath, labels, UBApplication::mimeTypeUniboardPage); - if (docModel->inTrash(current) || docModel->inModel(current)) { + if (docModel->inTrash(current)) { mDocumentUI->thumbnailWidget->setDragEnabled(false); } else { mDocumentUI->thumbnailWidget->setDragEnabled(true); diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index 796242c8..dea703bc 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -199,7 +199,6 @@ public: bool newNodeAllowed(const QModelIndex &pSelectedIndex) const; QModelIndex goTo(const QString &dir); bool inTrash(const QModelIndex &index) const; - bool inModel(const QModelIndex &index) const; bool inUntitledDocuments(const QModelIndex &index) const; bool isCatalog(const QModelIndex &index) const {return nodeFromIndex(index)->nodeType() == UBDocumentTreeNode::Catalog;} bool isDocument(const QModelIndex &index) const {return nodeFromIndex(index)->nodeType() == UBDocumentTreeNode::Document;} @@ -216,7 +215,6 @@ public: QString adjustNameForParentIndex(const QString &pName, const QModelIndex &pIndex); QPersistentModelIndex myDocumentsIndex() const {return mMyDocuments;} - QPersistentModelIndex modelsIndex() const {return mModels;} QPersistentModelIndex trashIndex() const {return mTrash;} QPersistentModelIndex untitledDocumentsIndex() const {return mUntitledDocuments;} UBDocumentTreeNode *nodeFromIndex(const QModelIndex &pIndex) const; @@ -251,7 +249,6 @@ private: void updateIndexNameBindings(UBDocumentTreeNode *nd); QPersistentModelIndex mRoot; QPersistentModelIndex mMyDocuments; - QPersistentModelIndex mModels; QPersistentModelIndex mTrash; QPersistentModelIndex mUntitledDocuments; QList mNewDocuments; @@ -360,7 +357,6 @@ class UBDocumentController : public UBDocumentContainer enum SortKind { - Reset = 0, CreationDate, UpdateDate, Alphabetical diff --git a/src/gui/UBDocumentTreeWidget.cpp b/src/gui/UBDocumentTreeWidget.cpp index 2339e120..e4bf4683 100644 --- a/src/gui/UBDocumentTreeWidget.cpp +++ b/src/gui/UBDocumentTreeWidget.cpp @@ -72,12 +72,9 @@ void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int col if (column == 0) { - - - - UBDocumentGroupTreeItem* group = dynamic_cast(item); - if(group) - { + UBDocumentGroupTreeItem* group = dynamic_cast(item); + if(group) + { QString name = group->text(0); for(int i = 0; i < topLevelItemCount (); i++)