forked from qt-creator/qt-creator
QmlJSInspector: Set property values
QML property values could be set in the inspector.
Regression introduced by 7f09d0b756
.
This patch is a partial fix. Only values can be assigned currently.
For expressions, use the console.
Change-Id: I945b11109cd7788dd0f5277af206bf9658844aee
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -286,14 +286,14 @@ quint32 BaseEngineDebugClient::addWatch(const ObjectReference &object,
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 BaseEngineDebugClient::addWatch(int objectId)
|
quint32 BaseEngineDebugClient::addWatch(int objectDebugId)
|
||||||
{
|
{
|
||||||
quint32 id = 0;
|
quint32 id = 0;
|
||||||
if (status() == Enabled) {
|
if (status() == Enabled) {
|
||||||
id = getId();
|
id = getId();
|
||||||
QByteArray message;
|
QByteArray message;
|
||||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||||
ds << QByteArray("WATCH_OBJECT") << id << objectId;
|
ds << QByteArray("WATCH_OBJECT") << id << objectDebugId;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
|
@@ -56,7 +56,7 @@ public:
|
|||||||
quint32 addWatch(const PropertyReference &property);
|
quint32 addWatch(const PropertyReference &property);
|
||||||
quint32 addWatch(const ContextReference &context, const QString &id);
|
quint32 addWatch(const ContextReference &context, const QString &id);
|
||||||
quint32 addWatch(const ObjectReference &object, const QString &expr);
|
quint32 addWatch(const ObjectReference &object, const QString &expr);
|
||||||
quint32 addWatch(int objectId);
|
quint32 addWatch(int objectDebugId);
|
||||||
quint32 addWatch(const FileReference &file);
|
quint32 addWatch(const FileReference &file);
|
||||||
|
|
||||||
void removeWatch(quint32 watch);
|
void removeWatch(quint32 watch);
|
||||||
|
@@ -989,10 +989,11 @@ bool QmlEngine::setToolTipExpression(const QPoint &mousePos,
|
|||||||
void QmlEngine::assignValueInDebugger(const WatchData *data,
|
void QmlEngine::assignValueInDebugger(const WatchData *data,
|
||||||
const QString &expression, const QVariant &valueV)
|
const QString &expression, const QVariant &valueV)
|
||||||
{
|
{
|
||||||
if (!expression.isEmpty() && m_adapter.activeDebuggerClient()) {
|
if (!expression.isEmpty()) {
|
||||||
m_adapter.activeDebuggerClient()->assignValueInDebugger(data,
|
if (data->isInspect() && m_inspectorAdapter.agent())
|
||||||
expression,
|
m_inspectorAdapter.agent()->assignValue(data, expression, valueV);
|
||||||
valueV);
|
else if (m_adapter.activeDebuggerClient())
|
||||||
|
m_adapter.activeDebuggerClient()->assignValueInDebugger(data, expression, valueV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -81,6 +81,23 @@ quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
|
|||||||
m_engine.debugId());
|
m_engine.debugId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlInspectorAgent::assignValue(const WatchData *data,
|
||||||
|
const QString &expr, const QVariant &valueV)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
qDebug() << __FUNCTION__ << "(" << data->id << ")" << data->iname;
|
||||||
|
|
||||||
|
if (data->id) {
|
||||||
|
QString val(valueV.toString());
|
||||||
|
if (valueV.type() == QVariant::String) {
|
||||||
|
val = val.replace(QLatin1Char('\"'), QLatin1String("\\\""));
|
||||||
|
val = QLatin1Char('\"') + val + QLatin1Char('\"');
|
||||||
|
}
|
||||||
|
QString expression = QString(_("%1 = %2;")).arg(expr).arg(val);
|
||||||
|
queryExpressionResult(data->id, expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
@@ -269,7 +286,7 @@ bool QmlInspectorAgent::addObjectWatch(int objectDebugId)
|
|||||||
if (m_engineClient->addWatch(objectDebugId))
|
if (m_engineClient->addWatch(objectDebugId))
|
||||||
m_objectWatches.append(objectDebugId);
|
m_objectWatches.append(objectDebugId);
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlInspectorAgent::isObjectBeingWatched(int objectDebugId)
|
bool QmlInspectorAgent::isObjectBeingWatched(int objectDebugId)
|
||||||
@@ -316,6 +333,8 @@ void QmlInspectorAgent::setEngineClient(BaseEngineDebugClient *client)
|
|||||||
this, SLOT(onResult(quint32,QVariant,QByteArray)));
|
this, SLOT(onResult(quint32,QVariant,QByteArray)));
|
||||||
disconnect(m_engineClient, SIGNAL(newObject(int,int,int)),
|
disconnect(m_engineClient, SIGNAL(newObject(int,int,int)),
|
||||||
this, SLOT(newObject(int,int,int)));
|
this, SLOT(newObject(int,int,int)));
|
||||||
|
disconnect(m_engineClient, SIGNAL(valueChanged(int,QByteArray,QVariant)),
|
||||||
|
this, SLOT(onValueChanged(int,QByteArray,QVariant)));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_engineClient = client;
|
m_engineClient = client;
|
||||||
@@ -327,6 +346,8 @@ void QmlInspectorAgent::setEngineClient(BaseEngineDebugClient *client)
|
|||||||
this, SLOT(onResult(quint32,QVariant,QByteArray)));
|
this, SLOT(onResult(quint32,QVariant,QByteArray)));
|
||||||
connect(m_engineClient, SIGNAL(newObject(int,int,int)),
|
connect(m_engineClient, SIGNAL(newObject(int,int,int)),
|
||||||
this, SLOT(newObject(int,int,int)));
|
this, SLOT(newObject(int,int,int)));
|
||||||
|
connect(m_engineClient, SIGNAL(valueChanged(int,QByteArray,QVariant)),
|
||||||
|
this, SLOT(onValueChanged(int,QByteArray,QVariant)));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
@@ -418,6 +439,21 @@ void QmlInspectorAgent::newObject(int engineId, int objectId, int /*parentId*/)
|
|||||||
m_delayQueryTimer.start();
|
m_delayQueryTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyName,
|
||||||
|
const QVariant &value)
|
||||||
|
{
|
||||||
|
const QByteArray iname = m_debugIdToIname.value(debugId) +
|
||||||
|
".[properties]." + propertyName;
|
||||||
|
const WatchData *data = m_debuggerEngine->watchHandler()->findData(iname);
|
||||||
|
if (debug)
|
||||||
|
qDebug() << __FUNCTION__ << "(" << debugId << ")" << iname <<value.toString();
|
||||||
|
if (data) {
|
||||||
|
WatchData d(*data);
|
||||||
|
d.value = value.toString();
|
||||||
|
m_debuggerEngine->watchHandler()->insertData(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::reloadEngines()
|
void QmlInspectorAgent::reloadEngines()
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
@@ -660,6 +696,7 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
|
|
||||||
list.append(objWatch);
|
list.append(objWatch);
|
||||||
m_debugIdToIname.insert(objWatch.id, objWatch.iname);
|
m_debugIdToIname.insert(objWatch.id, objWatch.iname);
|
||||||
|
addObjectWatch(objWatch.id);
|
||||||
|
|
||||||
if (m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
if (m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
QList<int> childIds;
|
QList<int> childIds;
|
||||||
@@ -694,6 +731,7 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
|
|
||||||
foreach (const PropertyReference &property, obj.properties()) {
|
foreach (const PropertyReference &property, obj.properties()) {
|
||||||
WatchData propertyWatch;
|
WatchData propertyWatch;
|
||||||
|
propertyWatch.id = objWatch.id;
|
||||||
propertyWatch.exp = property.name().toLatin1();
|
propertyWatch.exp = property.name().toLatin1();
|
||||||
propertyWatch.name = property.name();
|
propertyWatch.name = property.name();
|
||||||
propertyWatch.iname = buildIName(propertiesWatch.iname, property.name());
|
propertyWatch.iname = buildIName(propertiesWatch.iname, property.name());
|
||||||
@@ -744,6 +782,9 @@ void QmlInspectorAgent::clearObjectTree()
|
|||||||
m_debugIdToIname.clear();
|
m_debugIdToIname.clear();
|
||||||
m_debugIdChildIds.clear();
|
m_debugIdChildIds.clear();
|
||||||
m_objectStack.clear();
|
m_objectStack.clear();
|
||||||
|
|
||||||
|
removeAllObjectWatches();
|
||||||
}
|
}
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Debugger
|
} // Debugger
|
||||||
|
|
||||||
|
@@ -62,6 +62,7 @@ public:
|
|||||||
void fetchObject(int debugId);
|
void fetchObject(int debugId);
|
||||||
quint32 queryExpressionResult(int debugId, const QString &expression);
|
quint32 queryExpressionResult(int debugId, const QString &expression);
|
||||||
|
|
||||||
|
void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
|
||||||
void updateWatchData(const WatchData &data);
|
void updateWatchData(const WatchData &data);
|
||||||
void selectObjectInTree(int debugId);
|
void selectObjectInTree(int debugId);
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ private slots:
|
|||||||
void updateStatus();
|
void updateStatus();
|
||||||
void onResult(quint32 queryId, const QVariant &value, const QByteArray &type);
|
void onResult(quint32 queryId, const QVariant &value, const QByteArray &type);
|
||||||
void newObject(int engineId, int objectId, int parentId);
|
void newObject(int engineId, int objectId, int parentId);
|
||||||
|
void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reloadEngines();
|
void reloadEngines();
|
||||||
|
@@ -1139,12 +1139,13 @@ Qt::ItemFlags WatchModel::flags(const QModelIndex &idx) const
|
|||||||
= Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
= Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
static const Qt::ItemFlags editable = notEditable | Qt::ItemIsEditable;
|
static const Qt::ItemFlags editable = notEditable | Qt::ItemIsEditable;
|
||||||
|
|
||||||
// Disable editing if debuggee is positively running.
|
// Disable editing if debuggee is positively running except for Inspector data
|
||||||
|
const WatchData &data = *watchItem(idx);
|
||||||
const bool isRunning = engine() && engine()->state() == InferiorRunOk;
|
const bool isRunning = engine() && engine()->state() == InferiorRunOk;
|
||||||
if (isRunning && engine() && !engine()->hasCapability(AddWatcherWhileRunningCapability))
|
if (isRunning && engine() && !engine()->hasCapability(AddWatcherWhileRunningCapability) &&
|
||||||
|
!data.isInspect())
|
||||||
return notEditable;
|
return notEditable;
|
||||||
|
|
||||||
const WatchData &data = *watchItem(idx);
|
|
||||||
if (data.isWatcher()) {
|
if (data.isWatcher()) {
|
||||||
if (idx.column() == 0 && data.iname.count('.') == 1)
|
if (idx.column() == 0 && data.iname.count('.') == 1)
|
||||||
return editable; // Watcher names are editable.
|
return editable; // Watcher names are editable.
|
||||||
@@ -1159,6 +1160,9 @@ Qt::ItemFlags WatchModel::flags(const QModelIndex &idx) const
|
|||||||
} else if (data.isLocal()) {
|
} else if (data.isLocal()) {
|
||||||
if (idx.column() == 1 && data.valueEditable)
|
if (idx.column() == 1 && data.valueEditable)
|
||||||
return editable; // Locals values are sometimes editable.
|
return editable; // Locals values are sometimes editable.
|
||||||
|
} else if (data.isInspect()) {
|
||||||
|
if (idx.column() == 1 && data.valueEditable)
|
||||||
|
return editable; // Inspector values are sometimes editable.
|
||||||
}
|
}
|
||||||
return notEditable;
|
return notEditable;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user