From 8f06cfd8a1c4e17248544174baf96f23fc99508f Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 28 Aug 2012 19:15:11 +0300 Subject: [PATCH 1/4] SANKORE-1026 Navigation palette: thumbnails isn't refeshed after application added to the page Improvement of scene update flag setting --- src/domain/UBGraphicsScene.cpp | 16 ++++------------ src/domain/UBGraphicsScene.h | 12 ------------ src/frameworks/UBCoreGraphicsScene.cpp | 4 ++++ src/frameworks/UBCoreGraphicsScene.h | 13 +++++++++++++ 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b4cbfc4e..6d1f5459 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -263,7 +263,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) , mCrossedBackground(false) , mIsDesktopMode(false) , mZoomFactor(1) - , mIsModified(true) , mBackgroundObject(0) , mPreviousWidth(0) , mInputDeviceIsPressed(false) @@ -1564,7 +1563,6 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const Q void UBGraphicsScene::addItem(QGraphicsItem* item) { - setModified(true); UBCoreGraphicsScene::addItem(item); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); @@ -1577,8 +1575,6 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) void UBGraphicsScene::addItems(const QSet& items) { - setModified(true); - foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::addItem(item); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); @@ -1591,7 +1587,6 @@ void UBGraphicsScene::addItems(const QSet& items) void UBGraphicsScene::removeItem(QGraphicsItem* item) { - setModified(true); UBCoreGraphicsScene::removeItem(item); UBApplication::boardController->freezeW3CWidget(item, true); @@ -1603,8 +1598,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) void UBGraphicsScene::removeItems(const QSet& items) { - setModified(true); - foreach(QGraphicsItem* item, items) UBCoreGraphicsScene::removeItem(item); @@ -1762,7 +1755,6 @@ void UBGraphicsScene::addRuler(QPointF center) addItem(ruler); ruler->setVisible(true); - setModified(true); } void UBGraphicsScene::addProtractor(QPointF center) @@ -1780,7 +1772,6 @@ void UBGraphicsScene::addProtractor(QPointF center) protractor->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y()); protractor->setVisible(true); - setModified(true); } void UBGraphicsScene::addTriangle(QPointF center) @@ -1798,7 +1789,6 @@ void UBGraphicsScene::addTriangle(QPointF center) triangle->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y()); triangle->setVisible(true); - setModified(true); } void UBGraphicsScene::addMagnifier(UBMagnifierParams params) @@ -1857,6 +1847,7 @@ void UBGraphicsScene::moveMagnifier() { QPoint magnifierPos = QPoint(magniferControlViewWidget->pos().x() + magniferControlViewWidget->size().width() / 2, magniferControlViewWidget->pos().y() + magniferControlViewWidget->size().height() / 2 ); moveMagnifier(magnifierPos, true); + setModified(true); } } @@ -1889,6 +1880,7 @@ void UBGraphicsScene::moveMagnifier(QPoint newPos, bool forceGrab) void UBGraphicsScene::closeMagnifier() { DisposeMagnifierQWidgets(); + setModified(true); } void UBGraphicsScene::zoomInMagnifier() @@ -1906,6 +1898,7 @@ void UBGraphicsScene::zoomOutMagnifier() { magniferControlViewWidget->setZoom(magniferControlViewWidget->params.zoom - 0.5); magniferDisplayViewWidget->setZoom(magniferDisplayViewWidget->params.zoom - 0.5); + setModified(true); } } @@ -1917,6 +1910,7 @@ void UBGraphicsScene::resizedMagnifier(qreal newPercent) magniferControlViewWidget->grabPoint(); magniferDisplayViewWidget->setSize(newPercent); magniferDisplayViewWidget->grabPoint(); + setModified(true); } } @@ -1932,7 +1926,6 @@ void UBGraphicsScene::addCompass(QPointF center) compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); compass->setVisible(true); - setModified(true); } void UBGraphicsScene::addCache() @@ -1962,7 +1955,6 @@ void UBGraphicsScene::addMask(const QPointF ¢er) curtain->setRect(rect); curtain->setVisible(true); curtain->setSelected(true); - setModified(true); } void UBGraphicsScene::setRenderingQuality(UBItem::RenderingQuality pRenderingQuality) diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 738bd429..6f8c8def 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -179,16 +179,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem bool isEmpty() const; - bool isModified() const - { - return mIsModified; - } - - void setModified(bool pModified) - { - mIsModified = pModified; - } - void setDocument(UBDocumentProxy* pDocument); UBDocumentProxy* document() const @@ -380,8 +370,6 @@ public slots: bool mIsDesktopMode; qreal mZoomFactor; - bool mIsModified; - QGraphicsItem* mBackgroundObject; QPointF mPreviousPoint; diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index fd4948ec..7caec260 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -23,6 +23,7 @@ UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) : QGraphicsScene ( parent ) + , mIsModified(true) { //NOOP } @@ -51,6 +52,8 @@ void UBCoreGraphicsScene::addItem(QGraphicsItem* item) if (item->scene() != this) QGraphicsScene::addItem(item); + + setModified(true); } @@ -63,6 +66,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete) delete item; item = 0; } + setModified(true); } bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item) diff --git a/src/frameworks/UBCoreGraphicsScene.h b/src/frameworks/UBCoreGraphicsScene.h index d518db4c..19ed9da9 100644 --- a/src/frameworks/UBCoreGraphicsScene.h +++ b/src/frameworks/UBCoreGraphicsScene.h @@ -33,8 +33,21 @@ class UBCoreGraphicsScene : public QGraphicsScene void removeItemFromDeletion(QGraphicsItem* item); void addItemToDeletion(QGraphicsItem *item); + bool isModified() const + { + return mIsModified; + } + + void setModified(bool pModified) + { + mIsModified = pModified; + } + + private: QSet mItemsToDelete; + + bool mIsModified; }; #endif /* UBCOREGRAPHICSSCENE_H_ */ From 1ce5763adc9d299041de1bb74d23e33ac9675c99 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 12:25:54 +0300 Subject: [PATCH 2/4] SANKORE-1063 --- src/domain/UBGraphicsScene.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 6d1f5459..c25b65f6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1105,9 +1105,10 @@ void UBGraphicsScene::clearItems() if (!item->parentItem()) { - UBGraphicsPolygonItem* pi = qgraphicsitem_cast(item); + bool isPolygon = qgraphicsitem_cast(item) != NULL; + bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - if(!pi && !mTools.contains(item) && !isBackgroundObject(item)) + if(!isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) { removeItem(item); removedItems << item; From e441f2c2f86fed46fd8e174f4b2929f60a09f036 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 15:10:39 +0300 Subject: [PATCH 3/4] SANKORE-1063 The annotations are erased when you select the Erase items --- src/domain/UBGraphicsScene.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index c25b65f6..86d19d34 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1103,16 +1103,14 @@ void UBGraphicsScene::clearItems() { QGraphicsItem* item = itItems.next(); - if (!item->parentItem()) - { - bool isPolygon = qgraphicsitem_cast(item) != NULL; - bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; + bool isGroup = qgraphicsitem_cast(item) != NULL; + bool isPolygon = qgraphicsitem_cast(item) != NULL; + bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - if(!isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) - { - removeItem(item); - removedItems << item; - } + if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) + { + removeItem(item); + removedItems << item; } } From 5816a17f576da8c92b32e60996bed5250724fc73 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 16:55:23 +0300 Subject: [PATCH 4/4] SANKORE-98 shutdown after emptying the trashbin --- src/document/UBDocumentController.cpp | 310 +++++++++++++------------- src/document/UBDocumentController.h | 3 + 2 files changed, 163 insertions(+), 150 deletions(-) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 4be9ee0f..af8734e6 100755 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -117,8 +117,11 @@ UBDocumentProxyTreeItem* UBDocumentController::findDocument(UBDocumentProxy* pro void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument) { - if (!proxy) + if (proxy==NULL) + { + setDocument(NULL); return; + } QTreeWidgetItemIterator it(mDocumentUI->documentTreeWidget); @@ -531,6 +534,153 @@ void UBDocumentController::duplicateSelectedItem() } } +void UBDocumentController::moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi) +{ + int index = proxyTi->parent()->indexOfChild(proxyTi); + index --; + + if (index >= 0) + { + if (proxyTi->proxy() == mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true); + } + else + proxyTi->parent()->child(index)->setSelected(true); + } + else if (proxyTi->parent()->childCount() > 1) + { + if (proxyTi->proxy() == mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true); + } + else + proxyTi->parent()->child(1)->setSelected(true); + } + else + { + if (proxyTi->proxy() == mBoardController->selectedDocument()) + { + bool documentFound = false; + for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); + UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); + if (!groupItem->isTrashFolder()) + { + for(int j=0; jchildCount(); j++) + { + if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); + documentFound = true; + break; + } + } + } + if (documentFound) + break; + } + if (!documentFound) + { + UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument(groupTi->groupName()); + selectDocument(document, true); + } + } + else + proxyTi->parent()->setSelected(true); + } + + QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); + proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); + UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); + + proxyTi->parent()->removeChild(proxyTi); + mTrashTi->addChild(proxyTi); + proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); +} + +void UBDocumentController::moveFolderToTrash(UBDocumentGroupTreeItem* groupTi) +{ + bool changeCurrentDocument = false; + for (int i = 0; i < groupTi->childCount(); i++) + { + UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); + if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument()) + { + changeCurrentDocument = true; + break; + } + } + + QList toBeDeleted; + + for (int i = 0; i < groupTi->childCount(); i++) + { + UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); + if (proxyTi && proxyTi->proxy()) + toBeDeleted << proxyTi; + } + + for (int i = 0; i < toBeDeleted.count(); i++) + { + UBDocumentProxyTreeItem* proxyTi = toBeDeleted.at(i); + + showMessage(QString("Deleting %1").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString())); + // Move document to trash + QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); + proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); + UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); + + groupTi->removeChild(proxyTi); + mTrashTi->addChild(proxyTi); + proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); + + showMessage(QString("%1 deleted").arg(groupTi->groupName())); + } + + // dont remove default group + if (!groupTi->isDefaultFolder()) + { + int index = mDocumentUI->documentTreeWidget->indexOfTopLevelItem(groupTi); + + if (index >= 0) + { + mDocumentUI->documentTreeWidget->takeTopLevelItem(index); + } + } + + if (changeCurrentDocument) + { + bool documentFound = false; + for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); + UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); + if (!groupItem->isTrashFolder() && groupItem != groupTi) + { + for(int j=0; jchildCount(); j++) + { + if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); + documentFound = true; + break; + } + } + } + if (documentFound) + break; + } + if (!documentFound) + { + UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument( UBSettings::defaultDocumentGroupName ); + selectDocument(document, true); + } + } + + reloadThumbnails(); +} void UBDocumentController::deleteSelectedItem() { @@ -553,79 +703,19 @@ void UBDocumentController::deleteSelectedItem() { if (proxyTi->parent() != mTrashTi) { - // We have to move document into Trash - // Select another document for processing - // This is for Board, where this document can be selected - int index = proxyTi->parent()->indexOfChild(proxyTi); - index --; - - if (index >= 0) - { - if (proxyTi->proxy() == mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true); - } - else - proxyTi->parent()->child(index)->setSelected(true); - } - else if (proxyTi->parent()->childCount() > 1) - { - if (proxyTi->proxy() == mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true); - } - else - proxyTi->parent()->child(1)->setSelected(true); - } - else - { - if (proxyTi->proxy() == mBoardController->selectedDocument()) - { - bool documentFound = false; - for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) - { - QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); - UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); - if (!groupItem->isTrashFolder()) - { - for(int j=0; jchildCount(); j++) - { - if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); - documentFound = true; - break; - } - } - } - if (documentFound) - break; - } - if (!documentFound) - { - UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument(groupTi->groupName()); - selectDocument(document, true); - } - } - else - proxyTi->parent()->setSelected(true); - } - - QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); - proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); - UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); - - proxyTi->parent()->removeChild(proxyTi); - mTrashTi->addChild(proxyTi); - proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); + moveDocumentToTrash(groupTi, proxyTi); } else { - // We have to physical delete document - // No action with selection required - document from Trash cant be selected in Board - + // We have to physically delete document proxyTi->parent()->removeChild(proxyTi); UBPersistenceManager::persistenceManager()->deleteDocument(proxyTi->proxy()); + + if (mTrashTi->childCount()==0) + selectDocument(NULL); + else + selectDocument(((UBDocumentProxyTreeItem*)mTrashTi->child(0))->proxy()); + reloadThumbnails(); } } } @@ -666,87 +756,7 @@ void UBDocumentController::deleteSelectedItem() if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Folder"), tr("Are you sure you want to remove the folder '%1' and all its content?").arg(groupTi->groupName()))) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - - bool changeCurrentDocument = false; - for (int i = 0; i < groupTi->childCount(); i++) - { - UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); - if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument()) - { - changeCurrentDocument = true; - break; - } - } - - QList toBeDeleted; - - for (int i = 0; i < groupTi->childCount(); i++) - { - UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); - if (proxyTi && proxyTi->proxy()) - toBeDeleted << proxyTi; - } - - for (int i = 0; i < toBeDeleted.count(); i++) - { - UBDocumentProxyTreeItem* proxyTi = toBeDeleted.at(i); - - showMessage(QString("Deleting %1").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString())); - // Move document to trash - QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); - proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); - UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); - - groupTi->removeChild(proxyTi); - mTrashTi->addChild(proxyTi); - proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); - - showMessage(QString("%1 deleted").arg(groupTi->groupName())); - } - - // dont remove default group - if (!groupTi->isDefaultFolder()) - { - int index = mDocumentUI->documentTreeWidget->indexOfTopLevelItem(groupTi); - - if (index >= 0) - { - mDocumentUI->documentTreeWidget->takeTopLevelItem(index); - } - } - - if (changeCurrentDocument) - { - bool documentFound = false; - for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) - { - QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); - UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); - if (!groupItem->isTrashFolder() && groupItem != groupTi) - { - for(int j=0; jchildCount(); j++) - { - if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); - documentFound = true; - break; - } - } - } - if (documentFound) - break; - } - if (!documentFound) - { - UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument( UBSettings::defaultDocumentGroupName ); - selectDocument(document, true); - } - } - - - reloadThumbnails(); - + moveFolderToTrash(groupTi); QApplication::restoreOverrideCursor(); } } diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index d27ca0a6..ac8a113f 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -111,6 +111,9 @@ class UBDocumentController : public UBDocumentContainer bool mToolsPalettePositionned; UBDocumentGroupTreeItem* mTrashTi; + void moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi); + void moveFolderToTrash(UBDocumentGroupTreeItem* groupTi); + private slots: void documentZoomSliderValueChanged (int value); void loadDocumentProxies();