OSDN Git Service

Fixed crash when QML app shuts down itself in debugging mode
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
Tue, 15 Mar 2011 14:56:46 +0000 (15:56 +0100)
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
Tue, 15 Mar 2011 15:45:28 +0000 (16:45 +0100)
The QDeclarativeViewObserverPrivate could end up referencing the tool bar
when it was already destroyed.

Reviewed-by: Kai Koehne
share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp
share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h

index 8734552..0d169b8 100644 (file)
@@ -63,24 +63,56 @@ const char * const KEY_TOOLBOX_GEOMETRY = "toolBox/geometry";
 
 const int SceneChangeUpdateInterval = 5000;
 
+
+class ToolBox : public QWidget
+{
+    Q_OBJECT
+
+public:
+    ToolBox(QWidget *parent = 0);
+    ~ToolBox();
+
+    QmlToolBar *toolBar() const { return m_toolBar; }
+
+private:
+    QSettings m_settings;
+    QmlToolBar *m_toolBar;
+};
+
+ToolBox::ToolBox(QWidget *parent)
+    : QWidget(parent, Qt::Tool)
+    , m_settings(QLatin1String("Nokia"), QLatin1String("QmlObserver"), this)
+    , m_toolBar(new QmlToolBar)
+{
+    setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::CustomizeWindowHint);
+    setWindowTitle(tr("Qt Quick Toolbox"));
+
+    QVBoxLayout *verticalLayout = new QVBoxLayout;
+    verticalLayout->setMargin(0);
+    verticalLayout->addWidget(m_toolBar);
+    setLayout(verticalLayout);
+
+    restoreGeometry(m_settings.value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray());
+}
+
+ToolBox::~ToolBox()
+{
+    m_settings.setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY), saveGeometry());
+}
+
+
 QDeclarativeViewObserverPrivate::QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *q) :
     q(q),
     designModeBehavior(false),
     showAppOnTop(false),
     executionPaused(false),
     slowdownFactor(1.0f),
-    toolBar(0),
-    toolBox(0),
-    settings(0)
+    toolBox(0)
 {
 }
 
 QDeclarativeViewObserverPrivate::~QDeclarativeViewObserverPrivate()
 {
-    if (toolBar) {
-        settings->setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY),
-                           toolBar->window()->saveGeometry());
-    }
 }
 
 QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent) :
@@ -96,9 +128,6 @@ QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObje
     data->boundingRectHighlighter = new BoundingRectHighlighter(this);
     data->subcomponentEditorTool = new SubcomponentEditorTool(this);
     data->currentTool = data->selectionTool;
-    data->settings = new QSettings(QLatin1String("Nokia"),
-                                   QLatin1String("QmlObserver"),
-                                   this);
 
     // to capture ChildRemoved event when viewport changes
     data->view->installEventFilter(this);
@@ -481,8 +510,8 @@ void QDeclarativeViewObserver::setDesignModeBehavior(bool value)
 {
     emit designModeBehaviorChanged(value);
 
-    if (data->toolBar)
-        data->toolBar->setDesignModeBehavior(value);
+    if (data->toolBox)
+        data->toolBox->toolBar()->setDesignModeBehavior(value);
     data->debugService->setDesignModeBehavior(value);
 
     data->designModeBehavior = value;
@@ -878,7 +907,10 @@ QRectF QDeclarativeViewObserver::adjustToScreenBoundaries(const QRectF &bounding
 
 void QDeclarativeViewObserverPrivate::createToolBox()
 {
-    toolBar = new QmlToolBar;
+    toolBox = new ToolBox(q->declarativeView());
+
+    QmlToolBar *toolBar = toolBox->toolBar();
+
     QObject::connect(q, SIGNAL(selectedColorChanged(QColor)),
                      toolBar, SLOT(setColorBoxColor(QColor)));
 
@@ -912,18 +944,8 @@ void QDeclarativeViewObserverPrivate::createToolBox()
     QObject::connect(q, SIGNAL(zoomToolActivated()), toolBar, SLOT(activateZoom()));
     QObject::connect(q, SIGNAL(marqueeSelectToolActivated()),
                      toolBar, SLOT(activateMarqueeSelectTool()));
-
-    QVBoxLayout *verticalLayout = new QVBoxLayout;
-    verticalLayout->setMargin(0);
-    verticalLayout->addWidget(toolBar);
-
-    toolBox = new QWidget(q->declarativeView(), Qt::Tool);
-    toolBox->setWindowFlags((toolBox->windowFlags() & ~Qt::WindowCloseButtonHint)
-                            | Qt::CustomizeWindowHint);
-    toolBox->setWindowTitle(tr("Qt Quick Toolbox"));
-    toolBox->setLayout(verticalLayout);
-
-    toolBox->restoreGeometry(settings->value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray());
 }
 
-} //namespace QmlJSDebugger
+} // namespace QmlJSDebugger
+
+#include "qdeclarativeviewobserver.moc"
index 4219eee..fc15a2d 100644 (file)
@@ -40,8 +40,6 @@
 #include "qdeclarativeviewobserver.h"
 #include "qdeclarativeobserverservice.h"
 
-QT_FORWARD_DECLARE_CLASS(QSettings)
-
 namespace QmlJSDebugger {
 
 class JSDebuggerAgent;
@@ -52,7 +50,7 @@ class ColorPickerTool;
 class LiveLayerItem;
 class BoundingRectHighlighter;
 class SubcomponentEditorTool;
-class QmlToolBar;
+class ToolBox;
 class CrumblePath;
 class AbstractLiveEditTool;
 
@@ -93,9 +91,7 @@ public:
     bool executionPaused;
     qreal slowdownFactor;
 
-    QmlToolBar *toolBar;
-    QWidget *toolBox;
-    QSettings *settings;
+    ToolBox *toolBox;
 
     void setViewport(QWidget *widget);