QmlJsDebugger: Make DebugServer a singleton

This commit is contained in:
Kai Koehne
2010-09-01 13:42:24 +02:00
parent c6bfe05083
commit b7788bd808
4 changed files with 42 additions and 33 deletions

View File

@@ -60,7 +60,8 @@ class QMLJSDEBUGGER_EXPORT QDeclarativeDesignDebugServer : public QDeclarativeDe
{ {
Q_OBJECT Q_OBJECT
public: public:
QDeclarativeDesignDebugServer(QObject *parent = 0); QDeclarativeDesignDebugServer();
static QDeclarativeDesignDebugServer *instance();
void setDesignModeBehavior(bool inDesignMode); void setDesignModeBehavior(bool inDesignMode);
void setCurrentObjects(QList<QObject*> items); void setCurrentObjects(QList<QObject*> items);
@@ -99,7 +100,6 @@ protected:
private: private:
QHash<int, QString> m_stringIdForObjectId; QHash<int, QString> m_stringIdForObjectId;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@@ -46,11 +46,18 @@
#include <QDebug> #include <QDebug>
QDeclarativeDesignDebugServer::QDeclarativeDesignDebugServer(QObject *parent) Q_GLOBAL_STATIC(QDeclarativeDesignDebugServer, qmlDesignDebugServer)
: QDeclarativeDebugService(QLatin1String("QDeclarativeDesignMode"), parent)
QDeclarativeDesignDebugServer::QDeclarativeDesignDebugServer()
: QDeclarativeDebugService(QLatin1String("QDeclarativeDesignMode"))
{ {
} }
QDeclarativeDesignDebugServer *QDeclarativeDesignDebugServer::instance()
{
return qmlDesignDebugServer();
}
void QDeclarativeDesignDebugServer::messageReceived(const QByteArray &message) void QDeclarativeDesignDebugServer::messageReceived(const QByteArray &message)
{ {
QDataStream ds(message); QDataStream ds(message);

View File

@@ -56,8 +56,6 @@ namespace QmlViewer {
const int SceneChangeUpdateInterval = 5000; const int SceneChangeUpdateInterval = 5000;
Q_GLOBAL_STATIC(QDeclarativeDesignDebugServer, qmlDesignDebugServer)
QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate(QDeclarativeDesignView *q) : QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate(QDeclarativeDesignView *q) :
q(q), q(q),
designModeBehavior(false), designModeBehavior(false),
@@ -85,34 +83,35 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
setMouseTracking(true); setMouseTracking(true);
connect(qmlDesignDebugServer(), SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool))); data->debugServer = QDeclarativeDesignDebugServer::instance();
connect(qmlDesignDebugServer(), SIGNAL(reloadRequested()), SLOT(_q_reloadView())); connect(data->debugServer, SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool)));
connect(qmlDesignDebugServer(), connect(data->debugServer, SIGNAL(reloadRequested()), SLOT(_q_reloadView()));
connect(data->debugServer,
SIGNAL(currentObjectsChanged(QList<QObject*>)), SIGNAL(currentObjectsChanged(QList<QObject*>)),
SLOT(_q_onCurrentObjectsChanged(QList<QObject*>))); SLOT(_q_onCurrentObjectsChanged(QList<QObject*>)));
connect(qmlDesignDebugServer(), SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal))); connect(data->debugServer, SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal)));
connect(qmlDesignDebugServer(), SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool())); connect(data->debugServer, SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool()));
connect(qmlDesignDebugServer(), SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool())); connect(data->debugServer, SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool()));
connect(qmlDesignDebugServer(), SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool())); connect(data->debugServer, SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool()));
connect(qmlDesignDebugServer(), SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool())); connect(data->debugServer, SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool()));
connect(qmlDesignDebugServer(), connect(data->debugServer,
SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)), SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)),
SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString))); SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString)));
connect(qmlDesignDebugServer(), connect(data->debugServer,
SIGNAL(objectReparentRequested(QObject *, QObject *)), SIGNAL(objectReparentRequested(QObject *, QObject *)),
SLOT(_q_reparentQmlObject(QObject *, QObject *))); SLOT(_q_reparentQmlObject(QObject *, QObject *)));
connect(qmlDesignDebugServer(), SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int))); connect(data->debugServer, SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int)));
connect(qmlDesignDebugServer(), SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache())); connect(data->debugServer, SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache()));
connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status)));
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor)));
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)),
qmlDesignDebugServer(), SLOT(selectedColorChanged(QColor))); data->debugServer, SLOT(selectedColorChanged(QColor)));
connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared())); connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared()));
connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString))); connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString)));
connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped())); connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped()));
connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), qmlDesignDebugServer(), SLOT(contextPathUpdated(QStringList))); connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), data->debugServer, SLOT(contextPathUpdated(QStringList)));
data->createToolbar(); data->createToolbar();
@@ -131,7 +130,7 @@ void QDeclarativeDesignView::setInspectorContext(int contextIndex)
if (data->subcomponentEditorTool->contextIndex() != contextIndex) { if (data->subcomponentEditorTool->contextIndex() != contextIndex) {
QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex); QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex);
if (object) if (object)
qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << object); data->debugServer->setCurrentObjects(QList<QObject*>() << object);
} }
} }
@@ -202,7 +201,7 @@ void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event)
data->cursorPos = event->pos(); data->cursorPos = event->pos();
data->currentTool->mouseReleaseEvent(event); data->currentTool->mouseReleaseEvent(event);
qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems())); data->debugServer->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
} }
void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event) void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event)
@@ -335,7 +334,7 @@ void QDeclarativeDesignView::mouseDoubleClickEvent(QMouseEvent *event)
if ((event->buttons() & Qt::LeftButton) && itemToEnter) { if ((event->buttons() & Qt::LeftButton) && itemToEnter) {
QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject(); QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject();
if (objectToEnter) if (objectToEnter)
qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << objectToEnter); data->debugServer->setCurrentObjects(QList<QObject*>() << objectToEnter);
} }
} }
@@ -364,7 +363,7 @@ void QDeclarativeDesignView::setDesignModeBehavior(bool value)
emit designModeBehaviorChanged(value); emit designModeBehaviorChanged(value);
data->toolbar->setDesignModeBehavior(value); data->toolbar->setDesignModeBehavior(value);
qmlDesignDebugServer()->setDesignModeBehavior(value); data->debugServer->setDesignModeBehavior(value);
data->designModeBehavior = value; data->designModeBehavior = value;
if (data->subcomponentEditorTool) { if (data->subcomponentEditorTool) {
@@ -414,7 +413,7 @@ void QDeclarativeDesignViewPrivate::setSelectedItemsForTools(QList<QGraphicsItem
void QDeclarativeDesignViewPrivate::setSelectedItems(QList<QGraphicsItem *> items) void QDeclarativeDesignViewPrivate::setSelectedItems(QList<QGraphicsItem *> items)
{ {
setSelectedItemsForTools(items); setSelectedItemsForTools(items);
qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(items)); debugServer->setCurrentObjects(AbstractFormEditorTool::toObjectList(items));
} }
QList<QGraphicsItem *> QDeclarativeDesignViewPrivate::selectedItems() QList<QGraphicsItem *> QDeclarativeDesignViewPrivate::selectedItems()
@@ -504,7 +503,7 @@ void QDeclarativeDesignViewPrivate::_q_changeToSingleSelectTool()
changeToSelectTool(); changeToSelectTool();
emit q->selectToolActivated(); emit q->selectToolActivated();
qmlDesignDebugServer()->setCurrentTool(Constants::SelectionToolMode); debugServer->setCurrentTool(Constants::SelectionToolMode);
} }
void QDeclarativeDesignViewPrivate::changeToSelectTool() void QDeclarativeDesignViewPrivate::changeToSelectTool()
@@ -525,7 +524,7 @@ void QDeclarativeDesignViewPrivate::_q_changeToMarqueeSelectTool()
selectionTool->setRubberbandSelectionMode(true); selectionTool->setRubberbandSelectionMode(true);
emit q->marqueeSelectToolActivated(); emit q->marqueeSelectToolActivated();
qmlDesignDebugServer()->setCurrentTool(Constants::MarqueeSelectionToolMode); debugServer->setCurrentTool(Constants::MarqueeSelectionToolMode);
} }
void QDeclarativeDesignViewPrivate::_q_changeToZoomTool() void QDeclarativeDesignViewPrivate::_q_changeToZoomTool()
@@ -536,7 +535,7 @@ void QDeclarativeDesignViewPrivate::_q_changeToZoomTool()
currentTool->clear(); currentTool->clear();
emit q->zoomToolActivated(); emit q->zoomToolActivated();
qmlDesignDebugServer()->setCurrentTool(Constants::ZoomMode); debugServer->setCurrentTool(Constants::ZoomMode);
} }
void QDeclarativeDesignViewPrivate::_q_changeToColorPickerTool() void QDeclarativeDesignViewPrivate::_q_changeToColorPickerTool()
@@ -550,7 +549,7 @@ void QDeclarativeDesignViewPrivate::_q_changeToColorPickerTool()
currentTool->clear(); currentTool->clear();
emit q->colorPickerActivated(); emit q->colorPickerActivated();
qmlDesignDebugServer()->setCurrentTool(Constants::ColorPickerMode); debugServer->setCurrentTool(Constants::ColorPickerMode);
} }
void QDeclarativeDesignViewPrivate::_q_changeContextPathIndex(int index) void QDeclarativeDesignViewPrivate::_q_changeContextPathIndex(int index)
@@ -583,7 +582,7 @@ void QDeclarativeDesignView::continueExecution(qreal slowdownFactor)
data->executionPaused = false; data->executionPaused = false;
emit executionStarted(data->slowdownFactor); emit executionStarted(data->slowdownFactor);
qmlDesignDebugServer()->setAnimationSpeed(data->slowdownFactor); data->debugServer->setAnimationSpeed(data->slowdownFactor);
} }
void QDeclarativeDesignView::pauseExecution() void QDeclarativeDesignView::pauseExecution()
@@ -594,7 +593,7 @@ void QDeclarativeDesignView::pauseExecution()
data->executionPaused = true; data->executionPaused = true;
emit executionPaused(); emit executionPaused();
qmlDesignDebugServer()->setAnimationSpeed(0); data->debugServer->setAnimationSpeed(0);
} }
void QDeclarativeDesignViewPrivate::_q_applyChangesFromClient() void QDeclarativeDesignViewPrivate::_q_applyChangesFromClient()
@@ -654,7 +653,7 @@ void QDeclarativeDesignViewPrivate::_q_onStatusChanged(QDeclarativeView::Status
emit q->executionStarted(1.0f); emit q->executionStarted(1.0f);
} }
qmlDesignDebugServer()->reloaded(); debugServer->reloaded();
} }
} }
@@ -678,7 +677,7 @@ void QDeclarativeDesignViewPrivate::_q_onCurrentObjectsChanged(QList<QObject*> o
QString QDeclarativeDesignView::idStringForObject(QObject *obj) QString QDeclarativeDesignView::idStringForObject(QObject *obj)
{ {
return qmlDesignDebugServer()->idStringForObject(obj); return QDeclarativeDesignDebugServer::instance()->idStringForObject(obj);
} }
// adjusts bounding boxes on edges of screen to be visible // adjusts bounding boxes on edges of screen to be visible

View File

@@ -35,6 +35,7 @@
#include <QTimer> #include <QTimer>
#include "qdeclarativedesignview.h" #include "qdeclarativedesignview.h"
#include "qdeclarativedesigndebugserver.h"
QT_FORWARD_DECLARE_CLASS(JSDebuggerAgent) QT_FORWARD_DECLARE_CLASS(JSDebuggerAgent)
@@ -65,6 +66,8 @@ public:
~QDeclarativeDesignViewPrivate(); ~QDeclarativeDesignViewPrivate();
QDeclarativeDesignView *q; QDeclarativeDesignView *q;
QDeclarativeDesignDebugServer *debugServer;
QPointF cursorPos; QPointF cursorPos;
QList<QWeakPointer<QGraphicsObject> > currentSelection; QList<QWeakPointer<QGraphicsObject> > currentSelection;