-
Notifications
You must be signed in to change notification settings - Fork 937
BUGFIX: GraphicsView::setScene(nullptr) #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,75 +78,113 @@ void GraphicsView::setScene(BasicGraphicsScene *scene) | |
|
|
||
| { | ||
| // setup actions | ||
| delete _clearSelectionAction; | ||
| _clearSelectionAction = new QAction(QStringLiteral("Clear Selection"), this); | ||
| _clearSelectionAction->setShortcut(Qt::Key_Escape); | ||
|
|
||
| connect(_clearSelectionAction, &QAction::triggered, scene, &QGraphicsScene::clearSelection); | ||
|
|
||
| addAction(_clearSelectionAction); | ||
| if (_clearSelectionAction) | ||
| { | ||
| delete _clearSelectionAction; | ||
| _clearSelectionAction = {}; | ||
| } | ||
| if (scene) | ||
| { | ||
| _clearSelectionAction = new QAction(QStringLiteral("Clear Selection"), this); | ||
| _clearSelectionAction->setShortcut(Qt::Key_Escape); | ||
|
|
||
| connect(_clearSelectionAction, &QAction::triggered, scene, &QGraphicsScene::clearSelection); | ||
|
|
||
| addAction(_clearSelectionAction); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| delete _deleteSelectionAction; | ||
| _deleteSelectionAction = new QAction(QStringLiteral("Delete Selection"), this); | ||
| _deleteSelectionAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _deleteSelectionAction->setShortcut(QKeySequence(QKeySequence::Delete)); | ||
| _deleteSelectionAction->setAutoRepeat(false); | ||
| connect(_deleteSelectionAction, | ||
| &QAction::triggered, | ||
| this, | ||
| &GraphicsView::onDeleteSelectedObjects); | ||
|
|
||
| addAction(_deleteSelectionAction); | ||
| if (_deleteSelectionAction) | ||
| { | ||
| delete _deleteSelectionAction; | ||
| _deleteSelectionAction = {}; | ||
| } | ||
| if (scene) | ||
| { | ||
| _deleteSelectionAction = new QAction(QStringLiteral("Delete Selection"), this); | ||
| _deleteSelectionAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _deleteSelectionAction->setShortcut(QKeySequence(QKeySequence::Delete)); | ||
| _deleteSelectionAction->setAutoRepeat(false); | ||
| connect(_deleteSelectionAction, | ||
| &QAction::triggered, | ||
| this, | ||
| &GraphicsView::onDeleteSelectedObjects); | ||
|
|
||
| addAction(_deleteSelectionAction); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| delete _duplicateSelectionAction; | ||
| _duplicateSelectionAction = new QAction(QStringLiteral("Duplicate Selection"), this); | ||
| _duplicateSelectionAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _duplicateSelectionAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D)); | ||
| _duplicateSelectionAction->setAutoRepeat(false); | ||
| connect(_duplicateSelectionAction, | ||
| &QAction::triggered, | ||
| this, | ||
| &GraphicsView::onDuplicateSelectedObjects); | ||
|
|
||
| addAction(_duplicateSelectionAction); | ||
| if (_duplicateSelectionAction) | ||
| { | ||
| delete _duplicateSelectionAction; | ||
| _duplicateSelectionAction = {}; | ||
| } | ||
| if (scene) | ||
| { | ||
| _duplicateSelectionAction = new QAction(QStringLiteral("Duplicate Selection"), this); | ||
| _duplicateSelectionAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _duplicateSelectionAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D)); | ||
| _duplicateSelectionAction->setAutoRepeat(false); | ||
| connect(_duplicateSelectionAction, | ||
| &QAction::triggered, | ||
| this, | ||
| &GraphicsView::onDuplicateSelectedObjects); | ||
|
|
||
| addAction(_duplicateSelectionAction); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| delete _copySelectionAction; | ||
| _copySelectionAction = new QAction(QStringLiteral("Copy Selection"), this); | ||
| _copySelectionAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _copySelectionAction->setShortcut(QKeySequence(QKeySequence::Copy)); | ||
| _copySelectionAction->setAutoRepeat(false); | ||
| connect(_copySelectionAction, | ||
| &QAction::triggered, | ||
| this, | ||
| &GraphicsView::onCopySelectedObjects); | ||
|
|
||
| addAction(_copySelectionAction); | ||
| if (_copySelectionAction) | ||
| { | ||
| delete _copySelectionAction; | ||
| _copySelectionAction = {}; | ||
| } | ||
| if (scene) | ||
| { | ||
| _copySelectionAction = new QAction(QStringLiteral("Copy Selection"), this); | ||
| _copySelectionAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _copySelectionAction->setShortcut(QKeySequence(QKeySequence::Copy)); | ||
| _copySelectionAction->setAutoRepeat(false); | ||
| connect(_copySelectionAction, | ||
| &QAction::triggered, | ||
| this, | ||
| &GraphicsView::onCopySelectedObjects); | ||
|
|
||
| addAction(_copySelectionAction); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| delete _pasteAction; | ||
| _pasteAction = new QAction(QStringLiteral("Paste Selection"), this); | ||
| _pasteAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _pasteAction->setShortcut(QKeySequence(QKeySequence::Paste)); | ||
| _pasteAction->setAutoRepeat(false); | ||
| connect(_pasteAction, &QAction::triggered, this, &GraphicsView::onPasteObjects); | ||
|
|
||
| addAction(_pasteAction); | ||
| if (_pasteAction) | ||
| { | ||
| delete _pasteAction; | ||
| _pasteAction = {}; | ||
| } | ||
| if (scene) | ||
| { | ||
| _pasteAction = new QAction(QStringLiteral("Paste Selection"), this); | ||
| _pasteAction->setShortcutContext(Qt::ShortcutContext::WidgetShortcut); | ||
| _pasteAction->setShortcut(QKeySequence(QKeySequence::Paste)); | ||
| _pasteAction->setAutoRepeat(false); | ||
| connect(_pasteAction, &QAction::triggered, this, &GraphicsView::onPasteObjects); | ||
|
|
||
| addAction(_pasteAction); | ||
| } | ||
| } | ||
|
|
||
| auto undoAction = scene->undoStack().createUndoAction(this, tr("&Undo")); | ||
| undoAction->setShortcuts(QKeySequence::Undo); | ||
| addAction(undoAction); | ||
|
|
||
| auto redoAction = scene->undoStack().createRedoAction(this, tr("&Redo")); | ||
| redoAction->setShortcuts(QKeySequence::Redo); | ||
| addAction(redoAction); | ||
| if (scene) | ||
| { | ||
| auto undoAction = scene->undoStack().createUndoAction(this, tr("&Undo")); | ||
| undoAction->setShortcuts(QKeySequence::Undo); | ||
| addAction(undoAction); | ||
|
|
||
| auto redoAction = scene->undoStack().createRedoAction(this, tr("&Redo")); | ||
| redoAction->setShortcuts(QKeySequence::Redo); | ||
| addAction(redoAction); | ||
| } | ||
| } | ||
|
|
||
| void GraphicsView::centerScene() | ||
|
|
@@ -173,10 +211,13 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event) | |
|
|
||
| auto const scenePos = mapToScene(event->pos()); | ||
|
|
||
| QMenu *menu = nodeScene()->createSceneMenu(scenePos); | ||
|
|
||
| if (menu) { | ||
| menu->exec(event->globalPos()); | ||
| if (auto scene = nodeScene()) | ||
| { | ||
| QMenu *menu = scene->createSceneMenu(scenePos); | ||
|
|
||
| if (menu) { | ||
| menu->exec(event->globalPos()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -274,27 +315,29 @@ void GraphicsView::setupScale(double scale) | |
|
|
||
| void GraphicsView::onDeleteSelectedObjects() | ||
| { | ||
| nodeScene()->undoStack().push(new DeleteCommand(nodeScene())); | ||
| if (auto scene = nodeScene()) scene->undoStack().push(new DeleteCommand(scene)); | ||
|
||
| } | ||
|
|
||
| void GraphicsView::onDuplicateSelectedObjects() | ||
| { | ||
| qDebug() << "ON DUPLICATE"; | ||
Llcoolsouder marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| QPointF const pastePosition = scenePastePosition(); | ||
|
|
||
| nodeScene()->undoStack().push(new CopyCommand(nodeScene())); | ||
| nodeScene()->undoStack().push(new PasteCommand(nodeScene(), pastePosition)); | ||
| if (auto scene = nodeScene()) | ||
| { | ||
| scene->undoStack().push(new CopyCommand(scene)); | ||
| scene->undoStack().push(new PasteCommand(scene, pastePosition)); | ||
| } | ||
| } | ||
|
|
||
| void GraphicsView::onCopySelectedObjects() | ||
| { | ||
| nodeScene()->undoStack().push(new CopyCommand(nodeScene())); | ||
| if (auto scene = nodeScene()) scene->undoStack().push(new CopyCommand(scene)); | ||
| } | ||
|
|
||
| void GraphicsView::onPasteObjects() | ||
| { | ||
| QPointF const pastePosition = scenePastePosition(); | ||
| nodeScene()->undoStack().push(new PasteCommand(nodeScene(), pastePosition)); | ||
| if (auto scene = nodeScene()) scene->undoStack().push(new PasteCommand(scene, pastePosition)); | ||
| } | ||
|
|
||
| void GraphicsView::keyPressEvent(QKeyEvent *event) | ||
|
|
@@ -335,7 +378,7 @@ void GraphicsView::mousePressEvent(QMouseEvent *event) | |
| void GraphicsView::mouseMoveEvent(QMouseEvent *event) | ||
| { | ||
| QGraphicsView::mouseMoveEvent(event); | ||
| if (scene()->mouseGrabberItem() == nullptr && event->buttons() == Qt::LeftButton) { | ||
| if (scene() && scene()->mouseGrabberItem() == nullptr && event->buttons() == Qt::LeftButton) { | ||
| // Make sure shift is not being pressed | ||
| if ((event->modifiers() & Qt::ShiftModifier) == 0) { | ||
| QPointF difference = _clickPos - mapToScene(event->pos()); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.