forked from qt-creator/qt-creator
ModelEditor: Copy selected elements to clipboard
On Copy (Ctrl+C) the selected elements on a diagram are copied as an image into the clipboard. If no element is selected all elements are copied (as it was before). Change-Id: Ia24e1cae44ea3cc7303198fe7bfd3174c7a970cc Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -300,11 +300,25 @@ void DiagramSceneModel::copyToClipboard()
|
|||||||
{
|
{
|
||||||
auto mimeData = new QMimeData();
|
auto mimeData = new QMimeData();
|
||||||
|
|
||||||
|
QSet<QGraphicsItem *> selectedItems = m_selectedItems;
|
||||||
|
QSet<QGraphicsItem *> secondarySelectedItems = m_secondarySelectedItems;
|
||||||
|
QGraphicsItem *focusItem = m_focusItem;
|
||||||
// Selections would also render to the clipboard
|
// Selections would also render to the clipboard
|
||||||
m_graphicsScene->clearSelection();
|
m_graphicsScene->clearSelection();
|
||||||
removeExtraSceneItems();
|
removeExtraSceneItems();
|
||||||
|
|
||||||
QRectF sceneBoundingRect = m_graphicsScene->itemsBoundingRect();
|
bool copyAll = selectedItems.isEmpty() && secondarySelectedItems.isEmpty();
|
||||||
|
QRectF sceneBoundingRect;
|
||||||
|
if (copyAll) {
|
||||||
|
sceneBoundingRect = m_graphicsScene->itemsBoundingRect();
|
||||||
|
} else {
|
||||||
|
foreach (QGraphicsItem *item, m_graphicsItems) {
|
||||||
|
if (selectedItems.contains(item) || secondarySelectedItems.contains(item))
|
||||||
|
sceneBoundingRect |= item->mapRectToScene(item->boundingRect());
|
||||||
|
else
|
||||||
|
item->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Create the image with the size of the shrunk scene
|
// Create the image with the size of the shrunk scene
|
||||||
@@ -384,7 +398,25 @@ void DiagramSceneModel::copyToClipboard()
|
|||||||
|
|
||||||
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
|
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
|
||||||
|
|
||||||
|
if (!copyAll) {
|
||||||
|
// TODO once an annotation item had focus the call to show() will give it focus again. Bug in Qt?
|
||||||
|
foreach (QGraphicsItem *item, m_graphicsItems)
|
||||||
|
item->show();
|
||||||
|
}
|
||||||
|
|
||||||
addExtraSceneItems();
|
addExtraSceneItems();
|
||||||
|
|
||||||
|
foreach (QGraphicsItem *item, selectedItems)
|
||||||
|
item->setSelected(true);
|
||||||
|
|
||||||
|
// reset focus item
|
||||||
|
if (focusItem) {
|
||||||
|
ISelectable *selectable = dynamic_cast<ISelectable *>(focusItem);
|
||||||
|
if (selectable) {
|
||||||
|
selectable->setFocusSelected(true);
|
||||||
|
m_focusItem = focusItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiagramSceneModel::exportPng(const QString &fileName)
|
bool DiagramSceneModel::exportPng(const QString &fileName)
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ void DocumentController::copyFromModel(const MSelection &selection)
|
|||||||
|
|
||||||
void DocumentController::copyFromDiagram(const qmt::MDiagram *diagram)
|
void DocumentController::copyFromDiagram(const qmt::MDiagram *diagram)
|
||||||
{
|
{
|
||||||
|
m_diagramsManager->diagramSceneModel(diagram)->copyToClipboard();
|
||||||
*m_diagramClipboard = m_diagramController->copyElements(m_diagramsManager->diagramSceneModel(diagram)->selectedElements(), diagram);
|
*m_diagramClipboard = m_diagramController->copyElements(m_diagramsManager->diagramSceneModel(diagram)->selectedElements(), diagram);
|
||||||
emit diagramClipboardChanged(isDiagramClipboardEmpty());
|
emit diagramClipboardChanged(isDiagramClipboardEmpty());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user