Skip to content

Conversation

@cxxamz
Copy link
Contributor

@cxxamz cxxamz commented Oct 30, 2025

Type of change

  • Bug fix

Description

GraphicsView::setScene support nullptr

Testing

  • Qt version tested:
  • Existing tests still pass

Breaking changes?

None.

Related issue

None.


Please fill out the sections above to help reviewers understand your changes.

@Llcoolsouder Llcoolsouder self-assigned this Nov 12, 2025
Copy link
Collaborator

@Llcoolsouder Llcoolsouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. For clarity/brevity, I think it would be preferable to move your logic to the start of the function and then early return. This way we don't wrap everything in multiple if (scene) statements. e.g.
void GraphicsView::setScene(BasicGraphicsScene *scene)
{
    QGraphicsView::setScene(scene);
    if (!scene) {
        // Clear whatever is necessary
        return;
    }
    // Original function mostly untouched
    ...
}
  1. What does this give us? Is this just more in line with the upstream QGraphicsScene::setScene() behaviour? Does calling this with nullptr clear the scene, do nothing, or something else?

void GraphicsView::onDeleteSelectedObjects()
{
nodeScene()->undoStack().push(new DeleteCommand(nodeScene()));
if (auto scene = nodeScene()) scene->undoStack().push(new DeleteCommand(scene));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any valid configuration when scene != nodeScene?
Shouldn't we better assert this condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this acceptable?

void GraphicsView::onDeleteSelectedObjects()
{
    if (!nodeScene()) return; 

    nodeScene()->undoStack().push(new DeleteCommand(nodeScene()));
}

@cxxamz
Copy link
Contributor Author

cxxamz commented Nov 13, 2025

  1. For clarity/brevity, I think it would be preferable to move your logic to the start of the function and then early return. This way we don't wrap everything in multiple if (scene) statements. e.g.
void GraphicsView::setScene(BasicGraphicsScene *scene)
{
    QGraphicsView::setScene(scene);
    if (!scene) {
        // Clear whatever is necessary
        return;
    }
    // Original function mostly untouched
    ...
}

This approach is indeed better. I have fixed it in the next submission.

  1. What does this give us? Is this just more in line with the upstream QGraphicsScene::setScene() behaviour? Does calling this with nullptr clear the scene, do nothing, or something else?

When click "Close", the program will crash because the scene is set to nullptr.

10-08-54.mp4

Copy link
Contributor

@lsouder-ozone3d lsouder-ozone3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now. 谢谢,太棒了!

Leaving this one for @paceholder to merge when he's ready.

@paceholder paceholder merged commit 280406a into paceholder:master Nov 14, 2025
3 checks passed
@cxxamz cxxamz deleted the BUGFIX branch November 14, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants