diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 62a4e524..72dcc042 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -29,6 +29,7 @@ #include "UBSvgSubsetAdaptor.h" +#include #include #include #include @@ -239,6 +240,7 @@ QString UBSvgSubsetAdaptor::uniboardDocumentNamespaceUriFromVersion(int mFileVer UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int pageIndex) { + UBApplication::showMessage(QObject::tr("Loading scene (%1/%2)").arg(pageIndex+1).arg(proxy->pageCount())); QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex); qDebug() << fileName; QFile file(fileName); diff --git a/src/adaptors/UBThumbnailAdaptor.cpp b/src/adaptors/UBThumbnailAdaptor.cpp index b73f9e57..0dedef4f 100644 --- a/src/adaptors/UBThumbnailAdaptor.cpp +++ b/src/adaptors/UBThumbnailAdaptor.cpp @@ -54,6 +54,7 @@ void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy) for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo) { + UBApplication::showMessage(tr("check generateMissingThumbnails (%1/%2)").arg(iPageNo).arg(existingPageCount)); QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo); QFile thumbFile(thumbFileName); @@ -83,8 +84,9 @@ void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy) } } -const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex) +QPixmap UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex) { + UBApplication::showMessage(tr("Loading thumbnail (%1/%2)").arg(pageIndex+1).arg(proxy->pageCount())); QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); QFile file(fileName); @@ -93,30 +95,21 @@ const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex) generateMissingThumbnails(proxy); } - QPixmap* pix = new QPixmap(); + QPixmap pix; if (file.exists()) { - //Warning. Works only with modified Qt -#ifdef Q_OS_LINUX - pix->load(fileName, 0, Qt::AutoColor); -#else - pix->load(fileName, 0, Qt::AutoColor); -#endif + pix.load(fileName, 0, Qt::AutoColor); } return pix; } -void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList& list) +void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList>& list) { - generateMissingThumbnails(proxy); - - foreach(const QPixmap* pm, list){ - delete pm; - pm = NULL; - } list.clear(); for(int i=0; ipageCount(); i++) - list.append(get(proxy, i)); + { + list.append(std::make_shared(get(proxy, i))); + } } void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified) diff --git a/src/adaptors/UBThumbnailAdaptor.h b/src/adaptors/UBThumbnailAdaptor.h index 8c36b724..47f8be17 100644 --- a/src/adaptors/UBThumbnailAdaptor.h +++ b/src/adaptors/UBThumbnailAdaptor.h @@ -45,8 +45,8 @@ public: static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false); - static const QPixmap* get(UBDocumentProxy* proxy, int index); - static void load(UBDocumentProxy* proxy, QList& list); + static QPixmap get(UBDocumentProxy* proxy, int index); + static void load(UBDocumentProxy* proxy, QList>& list); private: static void generateMissingThumbnails(UBDocumentProxy* proxy); diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index ffe0f639..480afb65 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -354,7 +354,7 @@ void UBApplicationController::showBoard() int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex(); if (selectedSceneIndex != -1) { - UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex, true); + UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex); } } diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index a53342a4..0642f63d 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -809,7 +809,7 @@ void UBPersistenceManager::copyDocumentScene(UBDocumentProxy *from, int fromInde Q_ASSERT(QFileInfo(thumbTmp).exists()); Q_ASSERT(QFileInfo(thumbTo).exists()); - const QPixmap *pix = new QPixmap(thumbTmp); + auto pix = std::make_shared(thumbTmp); UBDocumentController *ctrl = UBApplication::documentController; ctrl->addPixmapAt(pix, toIndex); ctrl->TreeViewSelectionChanged(ctrl->firstSelectedTreeIndex(), QModelIndex()); @@ -820,10 +820,13 @@ void UBPersistenceManager::copyDocumentScene(UBDocumentProxy *from, int fromInde UBGraphicsScene* UBPersistenceManager::createDocumentSceneAt(UBDocumentProxy* proxy, int index, bool useUndoRedoStack) { - int count = sceneCount(proxy); + int count = proxy->pageCount(); for(int i = count - 1; i >= index; i--) + { + UBApplication::showMessage(tr("renaming pages (%1/%2)").arg(i).arg(count)); renamePage(proxy, i , i + 1); + } mSceneCache.shiftUpScenes(proxy, index, count -1); diff --git a/src/core/UBSceneCache.cpp b/src/core/UBSceneCache.cpp index c5a110d1..a3c92bc6 100644 --- a/src/core/UBSceneCache.cpp +++ b/src/core/UBSceneCache.cpp @@ -222,6 +222,7 @@ void UBSceneCache::shiftUpScenes(UBDocumentProxy* proxy, int startIncIndex, int { for(int i = endIncIndex; i >= startIncIndex; i--) { + UBApplication::showMessage(QObject::tr("moving cached scenes (%1/%2)").arg(i).arg(endIncIndex)); internalMoveScene(proxy, i, i + 1); } } diff --git a/src/document/UBDocumentContainer.cpp b/src/document/UBDocumentContainer.cpp index 481a415a..2609158b 100644 --- a/src/document/UBDocumentContainer.cpp +++ b/src/document/UBDocumentContainer.cpp @@ -40,10 +40,7 @@ UBDocumentContainer::UBDocumentContainer(QObject * parent) UBDocumentContainer::~UBDocumentContainer() { - foreach(const QPixmap* pm, mDocumentThumbs){ - delete pm; - pm = NULL; - } + } void UBDocumentContainer::setDocument(UBDocumentProxy* document, bool forceReload) @@ -52,6 +49,8 @@ void UBDocumentContainer::setDocument(UBDocumentProxy* document, bool forceReloa { mCurrentDocument = document; + //qDebug() << documentThumbs(); + clearThumbPage(); reloadThumbnails(); emit documentSet(mCurrentDocument); } @@ -103,15 +102,14 @@ void UBDocumentContainer::addPage(int index) } -void UBDocumentContainer::addPixmapAt(const QPixmap *pix, int index) +void UBDocumentContainer::addPixmapAt(std::shared_ptr pix, int index) { - mDocumentThumbs.insert(index, pix); + documentThumbs().insert(index, pix); } void UBDocumentContainer::clearThumbPage() { - qDeleteAll(mDocumentThumbs); mDocumentThumbs.clear(); } @@ -126,7 +124,6 @@ void UBDocumentContainer::initThumbPage() void UBDocumentContainer::updatePage(int index) { updateThumbPage(index); - emit documentThumbnailsUpdated(this); } void UBDocumentContainer::deleteThumbPage(int index) @@ -138,8 +135,9 @@ void UBDocumentContainer::updateThumbPage(int index) { if (mDocumentThumbs.size() > index) { - mDocumentThumbs[index] = UBThumbnailAdaptor::get(mCurrentDocument, index); - emit documentPageUpdated(index); + QPixmap pixmap = UBThumbnailAdaptor::get(mCurrentDocument, index); + mDocumentThumbs[index] = std::make_shared(pixmap); + emit documentPageUpdated(index); //refresh specific thumbnail in board } else { @@ -149,15 +147,24 @@ void UBDocumentContainer::updateThumbPage(int index) void UBDocumentContainer::insertThumbPage(int index) { - mDocumentThumbs.insert(index, UBThumbnailAdaptor::get(mCurrentDocument, index)); + QPixmap newPixmap = UBThumbnailAdaptor::get(mCurrentDocument, index); + if (index < documentThumbs().size()) + { + *documentThumbs().at(index) = newPixmap; + } + else + { + documentThumbs().insert(index, std::make_shared(newPixmap)); + } +} + +void UBDocumentContainer::insertExistingThumbPage(int index, std::shared_ptr thumbnailPixmap) +{ + documentThumbs().insert(index, thumbnailPixmap); } void UBDocumentContainer::reloadThumbnails() { - if (mCurrentDocument) - { - UBThumbnailAdaptor::load(mCurrentDocument, mDocumentThumbs); - } emit documentThumbnailsUpdated(this); } @@ -173,6 +180,5 @@ int UBDocumentContainer::sceneIndexFromPage(int page) void UBDocumentContainer::addEmptyThumbPage() { - const QPixmap* pThumb = new QPixmap(); - mDocumentThumbs.append(pThumb); + mDocumentThumbs.append(std::shared_ptr()); } diff --git a/src/document/UBDocumentContainer.h b/src/document/UBDocumentContainer.h index 7be279e0..abf7ab1f 100644 --- a/src/document/UBDocumentContainer.h +++ b/src/document/UBDocumentContainer.h @@ -45,8 +45,9 @@ class UBDocumentContainer : public QObject void pureSetDocument(UBDocumentProxy *document) {mCurrentDocument = document;} UBDocumentProxy* selectedDocument(){return mCurrentDocument;} + QList>& documentThumbs() { return mDocumentThumbs; } int pageCount() const{return mCurrentDocument->pageCount();} - const QPixmap* pageAt(int index) + std::shared_ptr pageAt(int index) { if (index < mDocumentThumbs.size()) return mDocumentThumbs[index]; @@ -65,16 +66,17 @@ class UBDocumentContainer : public QObject void clearThumbPage(); void initThumbPage(); void addPage(int index); - void addPixmapAt(const QPixmap *pix, int index); + void addPixmapAt(std::shared_ptr pix, int index); void updatePage(int index); void addEmptyThumbPage(); - void reloadThumbnails(); + virtual void reloadThumbnails(); void insertThumbPage(int index); + void insertExistingThumbPage(int index, std::shared_ptr thumbnailPixmap); private: UBDocumentProxy* mCurrentDocument; - QList mDocumentThumbs; + QList> mDocumentThumbs; protected: diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index cc9c1412..3f5791d0 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1555,7 +1555,7 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event) Q_ASSERT(QFileInfo(thumbTmp).exists()); Q_ASSERT(QFileInfo(thumbTo).exists()); - const QPixmap *pix = new QPixmap(thumbTmp); + auto pix = std::make_shared(thumbTmp); UBDocumentController *ctrl = UBApplication::documentController; ctrl->addPixmapAt(pix, toIndex); } @@ -2238,7 +2238,6 @@ void UBDocumentController::sortDocuments(int kind, int order) } } - void UBDocumentController::onSortOrderChanged(bool order) { int kindIndex = mDocumentUI->sortKind->currentIndex(); @@ -2297,9 +2296,6 @@ void UBDocumentController::show() { selectDocument(mBoardController->selectedDocument()); - //to be sure thumbnails will be up-to-date - reloadThumbnails(); - updateActions(); if(!mToolsPalette) @@ -3061,6 +3057,11 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source, } } +void UBDocumentController::updateThumbnailPixmap(int index, const QPixmap& newThumbnail) +{ + mDocumentUI->thumbnailWidget->updateThumbnailPixmap(index, newThumbnail); +} + void UBDocumentController::thumbnailViewResized() { @@ -3182,7 +3183,7 @@ void UBDocumentController::addToDocument() UBMetadataDcSubsetAdaptor::persist(mBoardController->selectedDocument()); mBoardController->reloadThumbnails(); - emit UBApplication::boardController->documentThumbnailsUpdated(this); + emit mBoardController->documentThumbnailsUpdated(this); UBApplication::applicationController->showBoard(); mBoardController->setActiveDocumentScene(newActiveSceneIndex); @@ -3583,7 +3584,7 @@ void UBDocumentController::deletePages(QList itemsToDelete) } } UBDocumentContainer::deletePages(sceneIndexes); - emit UBApplication::boardController->documentThumbnailsUpdated(this); + emit mBoardController->documentThumbnailsUpdated(this); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(proxy); @@ -3724,7 +3725,7 @@ bool UBDocumentController::firstAndOnlySceneSelected() const return false; } -void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer*) +void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer* source) { UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; UBDocumentProxy *currentDocumentProxy = selectedDocument(); @@ -3740,11 +3741,9 @@ void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer*) return; } - QList thumbs; - if (currentDocumentProxy) { - UBThumbnailAdaptor::load(currentDocumentProxy, thumbs); + UBThumbnailAdaptor::load(currentDocumentProxy, documentThumbs()); } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -3760,7 +3759,9 @@ void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer*) { for (int i = 0; i < currentDocumentProxy->pageCount(); i++) { - const QPixmap* pix = thumbs.at(i); + UBApplication::showMessage(tr("Refreshing Document Thumbnails View (%1/%2)").arg(i+1).arg(source->selectedDocument()->pageCount())); + + auto pix = documentThumbs().at(i); QGraphicsPixmapItem *pixmapItem = new UBSceneThumbnailPixmap(*pix, currentDocumentProxy, i); // deleted by the tree widget if (currentDocumentProxy == mBoardController->selectedDocument() && mBoardController->activeSceneIndex() == i) @@ -3792,9 +3793,9 @@ void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer*) if (selection) { disconnect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); - UBSceneThumbnailPixmap *currentScene = dynamic_cast(selection); - if (currentScene) - mDocumentUI->thumbnailWidget->hightlightItem(currentScene->sceneIndex()); + UBSceneThumbnailPixmap *currentSceneThumbnailPixmap = dynamic_cast(selection); + if (currentSceneThumbnailPixmap) + mDocumentUI->thumbnailWidget->hightlightItem(currentSceneThumbnailPixmap->sceneIndex()); connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); } diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index 6c673097..7fbd555a 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -501,6 +501,8 @@ class UBDocumentController : public UBDocumentContainer void collapseAll(); void expandAll(); + void updateThumbnailPixmap(int index, const QPixmap& newThumbnail); + protected: virtual void setupViews(); virtual void setupToolbar(); diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index 1fa0a6db..7a6ccf51 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -133,12 +133,31 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source) for(int i = 0; i < source->selectedDocument()->pageCount(); i++) { - //claudio This is a very bad hack and shows a architectural problem - // source->selectedDocument()->pageCount() != source->pageCount() - if(i>=source->pageCount() || !source->pageAt(i)) - source->insertThumbPage(i); + UBApplication::showMessage(tr("generating thumbnails for board (%1/%2)").arg(i+1).arg(source->selectedDocument()->pageCount())); - const QPixmap* pix = source->pageAt(i); + bool found = false; + if (UBApplication::documentController) + { + if (UBApplication::documentController->selectedDocument() == source->selectedDocument()) + { + if (UBApplication::documentController->pageAt(i)) + { + found = true; + //thumbnail has already been loaded on the documentController so we don't need to do it again + source->insertExistingThumbPage(i, UBApplication::documentController->pageAt(i)); + } + } + } + + if (!found) + { + //claudio This is a very bad hack and shows a architectural problem + // source->selectedDocument()->pageCount() != source->pageCount() + if(i>=source->pageCount() || !source->pageAt(i)) + source->insertThumbPage(i); + } + + auto pix = source->pageAt(i); Q_ASSERT(!pix->isNull()); int pageIndex = UBDocumentContainer::pageFromSceneIndex(i); @@ -193,12 +212,12 @@ void UBDocumentNavigator::onScrollToSelectedPage(int index) */ void UBDocumentNavigator::updateSpecificThumbnail(int iPage) { - const QPixmap* pix = UBApplication::boardController->pageAt(iPage); + auto pix = UBApplication::boardController->pageAt(iPage); UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), iPage); // Get the old thumbnail UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail(); - if(NULL != oldItem) + if(oldItem) { mScene->removeItem(oldItem); mScene->addItem(newItem); @@ -209,6 +228,18 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage) oldItem = NULL; } + ensureVisible(0, 0, 10, 10); + + refreshScene(); + + if (UBApplication::documentController) + { + if (UBApplication::documentController->selectedDocument() == UBApplication::boardController->selectedDocument()) + { + //update the pixmap in document mode + UBApplication::documentController->updateThumbnailPixmap(iPage, *pix); + } + } } /** diff --git a/src/gui/UBDocumentNavigator.h b/src/gui/UBDocumentNavigator.h index 9e29a2c9..ffe5a447 100644 --- a/src/gui/UBDocumentNavigator.h +++ b/src/gui/UBDocumentNavigator.h @@ -58,7 +58,7 @@ public: public slots: void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); } void generateThumbnails(UBDocumentContainer* source); - void updateSpecificThumbnail(int iPage); + void updateSpecificThumbnail(int iPage); void longPressTimeout(); void mousePressAndHoldEvent(); diff --git a/src/gui/UBDocumentThumbnailWidget.cpp b/src/gui/UBDocumentThumbnailWidget.cpp index 44cf9ebe..4f37beb5 100644 --- a/src/gui/UBDocumentThumbnailWidget.cpp +++ b/src/gui/UBDocumentThumbnailWidget.cpp @@ -297,6 +297,18 @@ bool UBDocumentThumbnailWidget::dragEnabled() const return mDragEnabled; } +void UBDocumentThumbnailWidget::updateThumbnailPixmap(int index, const QPixmap& newThumbnail) +{ + if (index >= 0 && index < mGraphicItems.length()) + { + UBSceneThumbnailPixmap *thumbnail = dynamic_cast(mGraphicItems.at(index)); + if (thumbnail) + { + thumbnail->setPixmap(newThumbnail); + } + } +} + void UBDocumentThumbnailWidget::hightlightItem(int index) { if (0 <= index && index < mLabelsItems.length()) diff --git a/src/gui/UBDocumentThumbnailWidget.h b/src/gui/UBDocumentThumbnailWidget.h index e08b464d..a7e36da3 100644 --- a/src/gui/UBDocumentThumbnailWidget.h +++ b/src/gui/UBDocumentThumbnailWidget.h @@ -48,9 +48,8 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget void hightlightItem(int index); public slots: - virtual void setGraphicsItems(const QList& pGraphicsItems, - const QList& pItemPaths, const QStringList pLabels = QStringList(), - const QString& pMimeType = QString("")); + void updateThumbnailPixmap(int index, const QPixmap& newThumbnail); + virtual void setGraphicsItems(const QList& pGraphicsItems, const QList& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString("")); signals: void sceneDropped(UBDocumentProxy* proxy, int source, int target);