Skip to content

Commit 6b192c8

Browse files
broccoli-97claude
andcommitted
fix(themes): re-measure nodes on level change and theme swap
The new Whimsy theme (6682cb2) exposed a latent node-sizing bug. NodeItem measured itself on ItemSceneHasChanged, but MindMapScene::addNode (and AddNodeCommand::redo) set the parent *after* addItem — so level() was 0 at measurement time and every node briefly got sized with rootStyle. With themes whose rootStyle barely differs from nodeStyle (default, tinted, ...) the effect was invisible, but Whimsy's Georgia 22pt rootStyle made every child take on root dimensions, producing oversized rectangles. - setParentNode now re-measures on level change, so the existing addItem-then-addChild order produces correct sizes. - setThemeId re-measures every node (new public refreshGeometry) and refreshes edges, so a theme swap picks up padding/font/min-max width changes instead of keeping the previous theme's dimensions. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 6682cb2 commit 6b192c8

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/scene/MindMapScene.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,17 @@ void MindMapScene::setThemeId(const QString& id) {
180180
m_themeId = id;
181181
// Force every node to drop its device-coord cache so a theme swap repaints
182182
// with the new fill/border/edge style instead of the stale cached pixmap.
183+
// Also re-measure each node — themes differ in padding/font/min-width, and
184+
// without a refresh the m_rect stays at the previous theme's dimensions.
183185
const auto items = this->items();
184186
for (auto* it : items) {
185187
it->setCacheMode(QGraphicsItem::NoCache);
188+
if (auto* node = dynamic_cast<NodeItem*>(it))
189+
node->refreshGeometry();
186190
it->update();
187191
}
192+
for (auto* e : m_edges)
193+
e->updatePath();
188194
for (auto* v : views())
189195
v->viewport()->update();
190196
}

src/scene/NodeItem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,13 @@ NodeItem* NodeItem::parentNode() const {
508508
}
509509

510510
void NodeItem::setParentNode(NodeItem* parent) {
511+
if (m_parentNode == parent)
512+
return;
511513
m_parentNode = parent;
514+
// Level changed → re-measure. Themes whose rootStyle overrides padding or
515+
// font (e.g. Whimsy: Georgia 22pt) would otherwise leave a child sized
516+
// for level=0 when it was added to the scene before being parented.
517+
updateGeometry();
512518
}
513519

514520
QList<NodeItem*> NodeItem::childNodes() const {
@@ -600,6 +606,10 @@ QRectF NodeItem::nodeRect() const {
600606
return m_rect;
601607
}
602608

609+
void NodeItem::refreshGeometry() {
610+
updateGeometry();
611+
}
612+
603613
void NodeItem::moveSubtree(const QPointF& delta) {
604614
moveBy(delta.x(), delta.y());
605615
for (auto* child : m_children) {

src/scene/NodeItem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class NodeItem : public QGraphicsObject {
4747
QRectF nodeRect() const;
4848
void moveSubtree(const QPointF& delta);
4949

50+
// Re-measure this node against the current theme/template. Call after a
51+
// theme swap so existing nodes pick up new padding/font/min-max widths.
52+
void refreshGeometry();
53+
5054
void showAddButton();
5155
void hideAddButton();
5256

0 commit comments

Comments
 (0)