| 1833 | } |
| 1834 | |
| 1835 | void UBBoardController::ClearUndoStack() |
| 1836 | { |
| 1837 | QSet<QGraphicsItem*> uniqueItems; |
| 1838 | // go through all stack command |
| 1839 | for (int i = 0; i < UBApplication::undoStack->count(); i++) { |
| 1840 | findUniquesItems(UBApplication::undoStack->command(i), uniqueItems); |
| 1841 | } |
| 1842 | |
| 1843 | // Get items from clipboard in order not to delete an item that was cut |
| 1844 | // (using source URL of graphics items as a surrogate for equality testing) |
| 1845 | // This ensures that we can cut and paste a media item, widget, etc. from one page to the next. |
| 1846 | QClipboard *clipboard = QApplication::clipboard(); |
| 1847 | const QMimeData* data = clipboard->mimeData(); |
| 1848 | QList<QUrl> sourceURLs; |
| 1849 | |
| 1850 | if (data && data->hasFormat(UBApplication::mimeTypeUniboardPageItem)) { |
| 1851 | const UBMimeDataGraphicsItem* mimeDataGI = qobject_cast <const UBMimeDataGraphicsItem*>(data); |
| 1852 | |
| 1853 | if (mimeDataGI) { |
| 1854 | foreach (UBItem* sourceItem, mimeDataGI->items()) { |
| 1855 | sourceURLs << sourceItem->sourceUrl(); |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | // go through all unique items, and check, if they are on scene, or not. |
| 1861 | // if not on scene, than item can be deleted |
| 1862 | QSetIterator<QGraphicsItem*> itUniq(uniqueItems); |
| 1863 | while (itUniq.hasNext()) |
| 1864 | { |
| 1865 | QGraphicsItem* item = itUniq.next(); |
| 1866 | UBGraphicsScene* scene = nullptr; |
| 1867 | if (item->scene()) { |
| 1868 | scene = dynamic_cast<UBGraphicsScene*>(item->scene()); |
| 1869 | } |
| 1870 | |
| 1871 | bool inClipboard = false; |
| 1872 | UBItem* ubi = dynamic_cast<UBItem*>(item); |
| 1873 | if (ubi && sourceURLs.contains(ubi->sourceUrl())) |
| 1874 | inClipboard = true; |
| 1875 | |
| 1876 | if(!scene && !inClipboard) |
| 1877 | { |
| 1878 | if (!mActiveScene->deleteItem(item)){ |
| 1879 | delete item; |
| 1880 | item = 0; |
| 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | // clear stack, and command list |
| 1886 | UBApplication::undoStack->clear(); |
| 1887 | } |
| 1888 | |
| 1889 | void UBBoardController::adjustDisplayViews() |
| 1890 | { |
no test coverage detected