QmlJS Live Preview: Implemented "Apply changes from Qml File" button

The button is checkable and pressing it will stop/propagate changes to
the qml application being debugged.
This commit is contained in:
Lasse Holmstedt
2010-07-26 11:59:59 +02:00
parent 70f2243bde
commit c7a8d93765
7 changed files with 65 additions and 23 deletions

View File

@@ -53,6 +53,9 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
void QmlInspectorToolbar::setEnabled(bool value) void QmlInspectorToolbar::setEnabled(bool value)
{ {
m_designmodeAction->setEnabled(value); m_designmodeAction->setEnabled(value);
//m_toQmlAction->setEnabled(value);
m_fromQmlAction->setEnabled(value);
m_reloadAction->setEnabled(value); m_reloadAction->setEnabled(value);
m_playAction->setEnabled(value); m_playAction->setEnabled(value);
m_pauseAction->setEnabled(value); m_pauseAction->setEnabled(value);
@@ -60,7 +63,7 @@ void QmlInspectorToolbar::setEnabled(bool value)
m_selectMarqueeAction->setEnabled(value); m_selectMarqueeAction->setEnabled(value);
m_zoomAction->setEnabled(value); m_zoomAction->setEnabled(value);
m_colorPickerAction->setEnabled(value); m_colorPickerAction->setEnabled(value);
m_toQmlAction->setEnabled(value); //m_toQmlAction->setEnabled(value);
m_fromQmlAction->setEnabled(value); m_fromQmlAction->setEnabled(value);
} }
@@ -149,7 +152,9 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
Debugger::DebuggerUISwitcher *uiSwitcher = pluginManager->getObject<Debugger::DebuggerUISwitcher>(); Debugger::DebuggerUISwitcher *uiSwitcher = pluginManager->getObject<Debugger::DebuggerUISwitcher>();
m_fromQmlAction = new QAction(QIcon(":/qml/images/from-qml-small.png"), tr("Apply Changes to Document"), this);
m_designmodeAction = new QAction(QIcon(":/qml/images/designmode.png"), "Design Mode", this); m_designmodeAction = new QAction(QIcon(":/qml/images/designmode.png"), "Design Mode", this);
m_reloadAction = new QAction(QIcon(":/qml/images/reload.png"), "Reload", this); m_reloadAction = new QAction(QIcon(":/qml/images/reload.png"), "Reload", this);
m_playAction = new QAction(QIcon(":/qml/images/play-small.png"), tr("Play animations"), this); m_playAction = new QAction(QIcon(":/qml/images/play-small.png"), tr("Play animations"), this);
m_pauseAction = new QAction(QIcon(":/qml/images/pause-small.png"), tr("Pause animations"), this); m_pauseAction = new QAction(QIcon(":/qml/images/pause-small.png"), tr("Pause animations"), this);
@@ -158,7 +163,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
m_zoomAction = new QAction(QIcon(":/qml/images/zoom-small.png"), tr("Zoom"), this); m_zoomAction = new QAction(QIcon(":/qml/images/zoom-small.png"), tr("Zoom"), this);
m_colorPickerAction = new QAction(QIcon(":/qml/images/color-picker-small.png"), tr("Color Picker"), this); m_colorPickerAction = new QAction(QIcon(":/qml/images/color-picker-small.png"), tr("Color Picker"), this);
m_toQmlAction = new QAction(QIcon(":/qml/images/to-qml-small.png"), tr("Apply Changes to QML Viewer"), this); m_toQmlAction = new QAction(QIcon(":/qml/images/to-qml-small.png"), tr("Apply Changes to QML Viewer"), this);
m_fromQmlAction = new QAction(QIcon(":/qml/images/from-qml-small.png"), tr("Apply Changes to Document"), this);
m_designmodeAction->setCheckable(true); m_designmodeAction->setCheckable(true);
m_designmodeAction->setChecked(false); m_designmodeAction->setChecked(false);
m_playAction->setCheckable(true); m_playAction->setCheckable(true);
@@ -169,6 +174,9 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
m_zoomAction->setCheckable(true); m_zoomAction->setCheckable(true);
m_colorPickerAction->setCheckable(true); m_colorPickerAction->setCheckable(true);
m_fromQmlAction->setCheckable(true);
m_fromQmlAction->setChecked(true);
am->registerAction(m_designmodeAction, QmlJSInspector::Constants::DESIGNMODE_ACTION, context); am->registerAction(m_designmodeAction, QmlJSInspector::Constants::DESIGNMODE_ACTION, context);
am->registerAction(m_reloadAction, QmlJSInspector::Constants::RELOAD_ACTION, context); am->registerAction(m_reloadAction, QmlJSInspector::Constants::RELOAD_ACTION, context);
am->registerAction(m_playAction, QmlJSInspector::Constants::PLAY_ACTION, context); am->registerAction(m_playAction, QmlJSInspector::Constants::PLAY_ACTION, context);
@@ -219,6 +227,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action())); configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::STOP)->action())); configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::STOP)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::FROM_QML_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::DESIGNMODE_ACTION)->action())); configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::DESIGNMODE_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::RELOAD_ACTION)->action())); configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::RELOAD_ACTION)->action()));
@@ -233,8 +242,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::ZOOM_ACTION)->action())); configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::ZOOM_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::COLOR_PICKER_ACTION)->action())); configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::COLOR_PICKER_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::TO_QML_ACTION)->action())); //configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::TO_QML_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::FROM_QML_ACTION)->action()));
configBarLayout->addStretch(); configBarLayout->addStretch();
@@ -254,7 +262,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
connect(m_selectAction, SIGNAL(triggered()), SLOT(activateSelectToolOnClick())); connect(m_selectAction, SIGNAL(triggered()), SLOT(activateSelectToolOnClick()));
connect(m_selectMarqueeAction, SIGNAL(triggered()), SLOT(activateMarqueeSelectToolOnClick())); connect(m_selectMarqueeAction, SIGNAL(triggered()), SLOT(activateMarqueeSelectToolOnClick()));
connect(m_toQmlAction, SIGNAL(triggered()), SLOT(activateToQml())); //connect(m_toQmlAction, SIGNAL(triggered()), SLOT(activateToQml()));
connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml())); connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml()));
} }
@@ -299,8 +307,6 @@ void QmlInspectorToolbar::activateDesignModeOnClick()
m_selectMarqueeAction->setEnabled(checked); m_selectMarqueeAction->setEnabled(checked);
m_zoomAction->setEnabled(checked); m_zoomAction->setEnabled(checked);
m_colorPickerAction->setEnabled(checked); m_colorPickerAction->setEnabled(checked);
m_toQmlAction->setEnabled(checked);
m_fromQmlAction->setEnabled(checked);
if (m_emitSignals) if (m_emitSignals)
emit designModeSelected(checked); emit designModeSelected(checked);
@@ -388,7 +394,7 @@ void QmlInspectorToolbar::activateZoomOnClick()
void QmlInspectorToolbar::activateFromQml() void QmlInspectorToolbar::activateFromQml()
{ {
if (m_emitSignals) if (m_emitSignals)
emit applyChangesFromQmlFileSelected(); emit applyChangesFromQmlFileTriggered(m_fromQmlAction->isChecked());
} }
void QmlInspectorToolbar::activateToQml() void QmlInspectorToolbar::activateToQml()

View File

@@ -52,7 +52,7 @@ signals:
void zoomToolSelected(); void zoomToolSelected();
void applyChangesToQmlFileSelected(); void applyChangesToQmlFileSelected();
void applyChangesFromQmlFileSelected(); void applyChangesFromQmlFileTriggered(bool isChecked);
private slots: private slots:
void activateDesignModeOnClick(); void activateDesignModeOnClick();

View File

@@ -636,3 +636,13 @@ bool Inspector::addQuotesForData(const QVariant &value) const
return false; return false;
} }
void Inspector::setApplyChangesToQmlObserver(bool applyChanges)
{
QHashIterator<QString, QmlJSLiveTextPreview *> iter(m_textPreviews);
while(iter.hasNext()) {
iter.next();
iter.value()->setApplyChangesToQmlObserver(applyChanges);
}
}

View File

@@ -92,7 +92,6 @@ public:
QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, const QString &objectId, QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, const QString &objectId,
const QString &propertyName, const QVariant &value, const QString &propertyName, const QVariant &value,
bool isLiteralValue); bool isLiteralValue);
signals: signals:
void statusMessage(const QString &text); void statusMessage(const QString &text);
@@ -100,6 +99,7 @@ public slots:
void setSimpleDockWidgetArrangement(); void setSimpleDockWidgetArrangement();
void reloadQmlViewer(); void reloadQmlViewer();
void serverReloaded(); void serverReloaded();
void setApplyChangesToQmlObserver(bool applyChanges);
private slots: private slots:
void gotoObjectReferenceDefinition(const QDeclarativeDebugObjectReference &obj); void gotoObjectReferenceDefinition(const QDeclarativeDebugObjectReference &obj);

View File

@@ -166,6 +166,7 @@ void InspectorPlugin::extensionsInitialized()
connect(m_toolbar, SIGNAL(zoomToolSelected()), _clientProxy, SLOT(changeToZoomTool())); connect(m_toolbar, SIGNAL(zoomToolSelected()), _clientProxy, SLOT(changeToZoomTool()));
connect(m_toolbar, SIGNAL(selectToolSelected()), _clientProxy, SLOT(changeToSelectTool())); connect(m_toolbar, SIGNAL(selectToolSelected()), _clientProxy, SLOT(changeToSelectTool()));
connect(m_toolbar, SIGNAL(marqueeSelectToolSelected()), _clientProxy, SLOT(changeToSelectMarqueeTool())); connect(m_toolbar, SIGNAL(marqueeSelectToolSelected()), _clientProxy, SLOT(changeToSelectMarqueeTool()));
connect(m_toolbar, SIGNAL(applyChangesFromQmlFileTriggered(bool)), _inspector, SLOT(setApplyChangesToQmlObserver(bool)));
connect(_clientProxy, SIGNAL(colorPickerActivated()), m_toolbar, SLOT(activateColorPicker())); connect(_clientProxy, SIGNAL(colorPickerActivated()), m_toolbar, SLOT(activateColorPicker()));
connect(_clientProxy, SIGNAL(selectToolActivated()), m_toolbar, SLOT(activateSelectTool())); connect(_clientProxy, SIGNAL(selectToolActivated()), m_toolbar, SLOT(activateSelectTool()));

View File

@@ -164,7 +164,7 @@ void QmlJSLiveTextPreview::unassociateEditor(Core::IEditor *oldEditor)
} }
QmlJSLiveTextPreview::QmlJSLiveTextPreview(const QmlJS::Document::Ptr &doc, const QmlJS::Document::Ptr &initDoc, QObject* parent) : QmlJSLiveTextPreview::QmlJSLiveTextPreview(const QmlJS::Document::Ptr &doc, const QmlJS::Document::Ptr &initDoc, QObject* parent) :
QObject(parent), m_previousDoc(doc), m_initialDoc(initDoc) QObject(parent), m_previousDoc(doc), m_initialDoc(initDoc), m_applyChangesToQmlObserver(true)
{ {
Q_ASSERT(doc->fileName() == initDoc->fileName()); Q_ASSERT(doc->fileName() == initDoc->fileName());
ClientProxy *clientProxy = ClientProxy::instance(); ClientProxy *clientProxy = ClientProxy::instance();
@@ -184,6 +184,7 @@ void QmlJSLiveTextPreview::resetInitialDoc(const QmlJS::Document::Ptr &doc)
m_previousDoc = doc; m_previousDoc = doc;
m_createdObjects.clear(); m_createdObjects.clear();
m_debugIds.clear(); m_debugIds.clear();
m_docWithUnappliedChanges.clear();
} }
@@ -462,20 +463,38 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
if (!core->hasContext(dbgcontext)) if (!core->hasContext(dbgcontext))
return; return;
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName() if (m_applyChangesToQmlObserver) {
&& doc->qmlProgram() && m_previousDoc->qmlProgram()) m_docWithUnappliedChanges.clear();
{
UpdateObserver delta;
m_debugIds = delta(m_previousDoc, doc, m_debugIds);
if (delta.referenceRefreshRequired) if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()
ClientProxy::instance()->refreshObjectTree(); && doc->qmlProgram() && m_previousDoc->qmlProgram())
{
UpdateObserver delta;
m_debugIds = delta(m_previousDoc, doc, m_debugIds);
m_previousDoc = doc; if (delta.referenceRefreshRequired)
if (!delta.newObjects.isEmpty()) ClientProxy::instance()->refreshObjectTree();
m_createdObjects[doc] += delta.newObjects;
m_previousDoc = doc;
if (!delta.newObjects.isEmpty())
m_createdObjects[doc] += delta.newObjects;
}
} else {
m_docWithUnappliedChanges = doc;
} }
} }
void QmlJSLiveTextPreview::setApplyChangesToQmlObserver(bool applyChanges)
{
if (applyChanges && !m_applyChangesToQmlObserver) {
if (m_docWithUnappliedChanges) {
m_applyChangesToQmlObserver = true;
documentChanged(m_docWithUnappliedChanges);
}
}
m_applyChangesToQmlObserver = applyChanges;
}
} // namespace Internal } // namespace Internal
} // namespace QmlJSInspector } // namespace QmlJSInspector

View File

@@ -75,11 +75,14 @@ public:
signals: signals:
void selectedItemsChanged(const QList<QDeclarativeDebugObjectReference> &objects); void selectedItemsChanged(const QList<QDeclarativeDebugObjectReference> &objects);
public slots:
void setApplyChangesToQmlObserver(bool applyChanges);
void updateDebugIds(const QDeclarativeDebugObjectReference &rootReference);
private slots: private slots:
void changeSelectedElements(QList<int> offsets, const QString &wordAtCursor); void changeSelectedElements(QList<int> offsets, const QString &wordAtCursor);
void documentChanged(QmlJS::Document::Ptr doc); void documentChanged(QmlJS::Document::Ptr doc);
public slots:
void updateDebugIds(const QDeclarativeDebugObjectReference &rootReference);
private: private:
QList<int> objectReferencesForOffset(quint32 offset) const; QList<int> objectReferencesForOffset(quint32 offset) const;
@@ -95,6 +98,9 @@ private:
QList<QWeakPointer<QmlJSEditor::Internal::QmlJSTextEditor> > m_editors; QList<QWeakPointer<QmlJSEditor::Internal::QmlJSTextEditor> > m_editors;
bool m_applyChangesToQmlObserver;
QmlJS::Document::Ptr m_docWithUnappliedChanges;
}; };
} // namespace Internal } // namespace Internal