From 9b55161eb57c03200f038c41d319b57691380e21 Mon Sep 17 00:00:00 2001 From: larry Date: Tue, 27 Jul 2021 08:22:52 +0200 Subject: [PATCH] Fix #304642: inspector update on subtype change - its not enough to only track element-type change when to consider if update inspector. - use Qt deleteLater which is more safe if we have signals roaming to old deleted widgets. Duplicate of #8721 --- mscore/inspector/inspector.cpp | 15 ++++++++++++--- mscore/inspector/inspector.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mscore/inspector/inspector.cpp b/mscore/inspector/inspector.cpp index c9e387038e911..b951f235d578d 100644 --- a/mscore/inspector/inspector.cpp +++ b/mscore/inspector/inspector.cpp @@ -120,6 +120,7 @@ Inspector::Inspector(QWidget* parent) ie = 0; oe = 0; oSameTypes = true; + oSameSubtypes = true; _score = 0; // retranslate(); setWindowTitle(tr("Inspector")); @@ -201,11 +202,13 @@ void Inspector::update(Score* s) sameSubtypes = false; } } - if (oe != element() || oSameTypes != sameTypes || (sameTypes && !sameSubtypes)) { - delete ie; + if (oe != element() || + (oSameTypes != sameTypes) || + (oSameSubtypes != sameSubtypes)) { ie = 0; oe = element(); oSameTypes = sameTypes; + oSameSubtypes = sameSubtypes; if (!element()) ie = new InspectorEmpty(this); else if (!sameTypes) @@ -324,6 +327,7 @@ void Inspector::update(Score* s) else ie = new InspectorBreak(this); #endif + //FIX: it looks as we might end up with ie = 0 break; case ElementType::BEND: ie = new InspectorBend(this); @@ -399,8 +403,13 @@ void Inspector::update(Score* s) break; } } + Q_ASSERT(ie); connect(ie, &InspectorBase::elementChanged, this, QOverload<>::of(&Inspector::update), Qt::QueuedConnection); - sa->setWidget(ie); // will destroy previous set widget + if (sa->widget()) { // If old inspector exist + QWidget *q = sa->takeWidget(); + q->deleteLater(); + } + sa->setWidget(ie); // will destroy previous set widget, unless takeWidget() call //focus policies were set by hand in each inspector_*.ui. this code just helps keeping them like they are //also fixes mac problem. on Mac Qt::TabFocus doesn't work, but Qt::StrongFocus works diff --git a/mscore/inspector/inspector.h b/mscore/inspector/inspector.h index d5e50a396bfd0..8bb848c7f3954 100644 --- a/mscore/inspector/inspector.h +++ b/mscore/inspector/inspector.h @@ -392,6 +392,7 @@ class Inspector : public QDockWidget { // within the inspector itself Element* oe; bool oSameTypes; + bool oSameSubtypes; public slots: void update();