Commit f5761c92 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Fixed crash when QML app shuts down itself in debugging mode

The QDeclarativeViewObserverPrivate could end up referencing the tool bar
when it was already destroyed.

Reviewed-by: Kai Koehne
parent bc5c462d
......@@ -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"
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment