From b943a0d79d4a9f994069b9d89b6dc54cab95e10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Wed, 9 Mar 2022 11:24:24 +0100 Subject: [PATCH] cherry-picked 670d772 + b944207c --- src/core/UBPersistenceManager.cpp | 89 ++++++++++++++++----------- src/core/UBPersistenceManager.h | 2 +- src/document/UBDocumentController.cpp | 2 + src/gui/UBBoardThumbnailsView.cpp | 4 +- 4 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 37c22054..e826a7ba 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -123,36 +123,65 @@ UBPersistenceManager::~UBPersistenceManager() { } -void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) +void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &contentInfoList, bool interactive) { - mDocumentRepositoryPath = UBSettings::userDocumentDirectory(); - - QDir rootDir(mDocumentRepositoryPath); - rootDir.mkpath(rootDir.path()); - - QFileInfoList contentList = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time | QDir::Reversed); - - mProgress.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); - mProgress.setLabelText(QString("retrieving all your documents (found %1)").arg(contentList.size())); - mProgress.setCancelButton(nullptr); - // Create a QFutureWatcher and connect signals and slots. - QFutureWatcher futureWatcher; + QFutureWatcher futureWatcher; QObject::connect(&futureWatcher, &QFutureWatcher::finished, &mProgress, &QProgressDialog::reset); QObject::connect(&futureWatcher, &QFutureWatcher::progressRangeChanged, &mProgress, &QProgressDialog::setRange); QObject::connect(&futureWatcher, &QFutureWatcher::progressValueChanged, &mProgress, &QProgressDialog::setValue); // Start the computation. - futureWatcher.setFuture(QtConcurrent::map(contentList, [=] (QFileInfo& contentInfo) - { - createDocumentProxyStructure(contentInfo); - })); + std::function createDocumentProxyLambda = [=](QFileInfo contentInfo) { + return createDocumentProxyStructure(contentInfo); + }; + + QFuture proxiesFuture = QtConcurrent::mapped(contentInfoList, createDocumentProxyLambda); + futureWatcher.setFuture(proxiesFuture); // Display the dialog and start the event loop. mProgress.exec(); futureWatcher.waitForFinished(); + QList proxies = futureWatcher.future().results(); + + for (auto&& proxy : qAsConst(proxies)) + { + if (proxy) + { + QString docGroupName = proxy->metaData(UBSettings::documentGroupName).toString(); + QModelIndex parentIndex = mDocumentTreeStructureModel->goTo(docGroupName); + if (parentIndex.isValid()) + { + if (!interactive) + mDocumentTreeStructureModel->addDocument(proxy, parentIndex); + else + processInteractiveReplacementDialog(proxy); + } + else + { + qDebug() << "something went wrong"; + } + } + } +} + +void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) +{ + mDocumentRepositoryPath = UBSettings::userDocumentDirectory(); + + QDir rootDir(mDocumentRepositoryPath); + rootDir.mkpath(rootDir.path()); + + QFileInfoList contentInfoList = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time | QDir::Reversed); + + mProgress.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); + mProgress.setLabelText(QString("retrieving all your documents (found %1)").arg(contentInfoList.size())); + mProgress.setCancelButton(nullptr); + + createDocumentProxiesStructure(contentInfoList, interactive); + if (QFileInfo(mFoldersXmlStorageName).exists()) { QDomDocument xmlDom; QFile inFile(mFoldersXmlStorageName); @@ -178,15 +207,7 @@ void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) } } -void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &contentInfoList, bool interactive) -{ - foreach(QFileInfo contentInfo, contentInfoList) - { - createDocumentProxyStructure(contentInfo, interactive); - } -} - -void UBPersistenceManager::createDocumentProxyStructure(const QFileInfo &contentInfo, bool interactive) +UBDocumentProxy* UBPersistenceManager::createDocumentProxyStructure(QFileInfo& contentInfo) { QString fullPath = contentInfo.absoluteFilePath(); QDir dir(fullPath); @@ -199,12 +220,7 @@ void UBPersistenceManager::createDocumentProxyStructure(const QFileInfo &content if (docName.isEmpty()) { qDebug() << "Group name and document name are empty in UBPersistenceManager::createDocumentProxiesStructure()"; - return; - } - - QModelIndex parentIndex = mDocumentTreeStructureModel->goTo(docGroupName); - if (!parentIndex.isValid()) { - return; + return nullptr; } UBDocumentProxy* docProxy = new UBDocumentProxy(fullPath); // managed in UBDocumentTreeNode @@ -214,11 +230,12 @@ void UBPersistenceManager::createDocumentProxyStructure(const QFileInfo &content docProxy->setPageCount(sceneCount(docProxy)); - if (!interactive) - mDocumentTreeStructureModel->addDocument(docProxy, parentIndex); - else - processInteractiveReplacementDialog(docProxy); + docProxy->moveToThread(UBApplication::instance()->thread()); + + return docProxy; } + + return nullptr; }; QDialog::DialogCode UBPersistenceManager::processInteractiveReplacementDialog(UBDocumentProxy *pProxy) diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 9d27dc80..18353b0b 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -132,7 +132,7 @@ class UBPersistenceManager : public QObject void createDocumentProxiesStructure(bool interactive = false); void createDocumentProxiesStructure(const QFileInfoList &contentInfoList, bool interactive = false); - void createDocumentProxyStructure(const QFileInfo& contentInfo, bool interactive = false); + UBDocumentProxy* createDocumentProxyStructure(QFileInfo &contentInfo); QDialog::DialogCode processInteractiveReplacementDialog(UBDocumentProxy *pProxy); QStringList documentSubDirectories() diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index d69e12bf..e76c7ecd 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -3781,6 +3781,8 @@ void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer* s , QList() , QStringList() , UBApplication::mimeTypeUniboardPage); + + QApplication::restoreOverrideCursor(); return; } diff --git a/src/gui/UBBoardThumbnailsView.cpp b/src/gui/UBBoardThumbnailsView.cpp index fe10ecca..a6f9ba4e 100644 --- a/src/gui/UBBoardThumbnailsView.cpp +++ b/src/gui/UBBoardThumbnailsView.cpp @@ -307,7 +307,7 @@ void UBBoardThumbnailsView::dragMoveEvent(QDragMoveEvent *event) { y = item->pos().y() - UBSettings::thumbnailSpacing / 2; if (mDropBar->y() != y) - mDropBar->setRect(QRectF(item->pos().x(), y, mThumbnailWidth-verticalScrollBar()->width(), 3)); + mDropBar->setRect(QRectF(item->pos().x(), y, (item->boundingRect().width()-verticalScrollBar()->width())*scale, 3)); } } else @@ -316,7 +316,7 @@ void UBBoardThumbnailsView::dragMoveEvent(QDragMoveEvent *event) { y = item->pos().y() + item->boundingRect().height() * scale + UBSettings::thumbnailSpacing / 2; if (mDropBar->y() != y) - mDropBar->setRect(QRectF(item->pos().x(), y, mThumbnailWidth-verticalScrollBar()->width(), 3)); + mDropBar->setRect(QRectF(item->pos().x(), y, (item->boundingRect().width()-verticalScrollBar()->width())*scale, 3)); } } }