summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-10-28 05:50:11 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-10-28 05:50:11 (GMT)
commit25f87fede4b5fd367242be80f314310e7be6e0a5 (patch)
treecd4f0411959eba5cb93f8fe425cbf2f2931c6790
parent37314eb9ff900780b8bb952c8fa87f278a634f3a (diff)
downloadQt-25f87fede4b5fd367242be80f314310e7be6e0a5.zip
Qt-25f87fede4b5fd367242be80f314310e7be6e0a5.tar.gz
Qt-25f87fede4b5fd367242be80f314310e7be6e0a5.tar.bz2
Show contents of list properties within the debugger (like the Creator
debugger). Also add Mode arg to ExpressionQueryWidget constructor.
-rw-r--r--src/declarative/debugger/qmldebug.cpp5
-rw-r--r--src/declarative/qml/qmlenginedebug.cpp67
-rw-r--r--src/declarative/qml/qmlenginedebug_p.h4
-rw-r--r--src/declarative/qml/qmlwatcher.cpp2
-rw-r--r--src/declarative/qml/qmlwatcher_p.h3
-rw-r--r--tools/qmldebugger/standalone/engine.cpp2
-rw-r--r--tools/qmldebugger/standalone/expressionquerywidget.cpp34
-rw-r--r--tools/qmldebugger/standalone/expressionquerywidget.h10
-rw-r--r--tools/qmldebugger/standalone/objectpropertiesview.cpp76
-rw-r--r--tools/qmldebugger/standalone/objectpropertiesview.h2
10 files changed, 129 insertions, 76 deletions
diff --git a/src/declarative/debugger/qmldebug.cpp b/src/declarative/debugger/qmldebug.cpp
index 6e541a9..5a8cda0 100644
--- a/src/declarative/debugger/qmldebug.cpp
+++ b/src/declarative/debugger/qmldebug.cpp
@@ -122,9 +122,10 @@ void QmlEngineDebugPrivate::decode(QDataStream &ds, QmlDebugObjectReference &o,
prop.m_binding = data.binding;
prop.m_hasNotifySignal = data.hasNotifySignal;
prop.m_valueTypeName = data.valueTypeName;
- if (data.type == QmlEngineDebugServer::QmlObjectProperty::Basic)
+ if (data.type == QmlEngineDebugServer::QmlObjectProperty::Basic
+ || data.type == QmlEngineDebugServer::QmlObjectProperty::List) {
prop.m_value = data.value;
- else if (data.type == QmlEngineDebugServer::QmlObjectProperty::Object) {
+ } else if (data.type == QmlEngineDebugServer::QmlObjectProperty::Object) {
QmlDebugObjectReference obj;
obj.m_debugId = prop.m_value.toInt();
prop.m_value = qVariantFromValue(obj);
diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp
index 664ca3f..63be6b0 100644
--- a/src/declarative/qml/qmlenginedebug.cpp
+++ b/src/declarative/qml/qmlenginedebug.cpp
@@ -57,8 +57,8 @@ QmlEngineDebugServer::QmlEngineDebugServer(QObject *parent)
: QmlDebugService(QLatin1String("QmlEngine"), parent),
m_watch(new QmlWatcher(this))
{
- QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QByteArray,QVariant)),
- this, SLOT(propertyChanged(int,int,QByteArray,QVariant)));
+ QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)),
+ this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant)));
}
QDataStream &operator<<(QDataStream &ds,
@@ -110,9 +110,11 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx)
if (binding)
rv.binding = binding->expression();
+ QVariant value = prop.read(obj);
+ rv.value = valueContents(value);
+
if (prop.type() < QVariant::UserType) {
rv.type = QmlObjectProperty::Basic;
- rv.value = prop.read(obj);
} else if (QmlMetaType::isObject(prop.userType())) {
rv.type = QmlObjectProperty::Object;
} else if (QmlMetaType::isList(prop.userType()) ||
@@ -123,6 +125,32 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx)
return rv;
}
+QVariant QmlEngineDebugServer::valueContents(const QVariant &value) const
+{
+ if (value.type() < QVariant::UserType)
+ return value;
+
+ int userType = value.userType();
+
+ if (QmlMetaType::isList(userType) || QmlMetaType::isQmlList(userType)) {
+ int count = QmlMetaType::listCount(value);
+ QVariantList contents;
+ for (int i=0; i<count; i++)
+ contents << valueContents(QmlMetaType::listAt(value, i));
+ return contents;
+ } else if (QmlMetaType::isObject(userType)) {
+ QObject *o = QmlMetaType::toQObject(value);
+ if (o) {
+ QString name = o->objectName();
+ if (name.isEmpty())
+ name = QLatin1String("<unnamed>");
+ return name;
+ }
+ }
+
+ return QLatin1String("<unknown value>");
+}
+
void QmlEngineDebugServer::buildObjectDump(QDataStream &message,
QObject *object, bool recur)
{
@@ -188,32 +216,6 @@ void QmlEngineDebugServer::buildObjectList(QDataStream &message,
}
}
-QVariant QmlEngineDebugServer::serializableVariant(const QVariant &value)
-{
- if (value.type() < QVariant::UserType)
- return value;
-
- if (!value.toString().isEmpty())
- return value.toString();
-
- QVariant v;
- if (value.type() == QVariant::UserType || QmlMetaType::isObject(value.userType())) {
- QObject *o = QmlMetaType::toQObject(value);
- if (o) {
- QString objectName = o->objectName();
- if (objectName.isEmpty())
- objectName = QLatin1String("<unnamed>");
- v = QString::fromUtf8(o->metaObject()->className()) +
- QLatin1String(": ") + objectName;
- }
- }
-
- if (v.isNull())
- v = QString::fromUtf8(value.typeName());
-
- return v;
-}
-
QmlEngineDebugServer::QmlObjectData
QmlEngineDebugServer::objectData(QObject *object)
{
@@ -357,7 +359,7 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message)
if (undefined)
result = QLatin1String("<undefined>");
else
- result = serializableVariant(value);
+ result = valueContents(value);
delete exprObj;
} else {
result = QLatin1String("<unknown context>");
@@ -371,13 +373,12 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message)
}
}
-void QmlEngineDebugServer::propertyChanged(int id, int objectId, const QByteArray &property, const QVariant &value)
+void QmlEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value)
{
QByteArray reply;
- QVariant v = serializableVariant(value);
QDataStream rs(&reply, QIODevice::WriteOnly);
- rs << QByteArray("UPDATE_WATCH") << id << objectId << property << v;
+ rs << QByteArray("UPDATE_WATCH") << id << objectId << QString::fromUtf8(property.name()) << valueContents(value);
sendMessage(reply);
}
diff --git a/src/declarative/qml/qmlenginedebug_p.h b/src/declarative/qml/qmlenginedebug_p.h
index 075a711..a8572eb 100644
--- a/src/declarative/qml/qmlenginedebug_p.h
+++ b/src/declarative/qml/qmlenginedebug_p.h
@@ -97,14 +97,14 @@ protected:
virtual void messageReceived(const QByteArray &);
private Q_SLOTS:
- void propertyChanged(int id, int objectId, const QByteArray &property, const QVariant &value);
+ void propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value);
private:
void buildObjectList(QDataStream &, QmlContext *);
void buildObjectDump(QDataStream &, QObject *, bool);
QmlObjectData objectData(QObject *);
QmlObjectProperty propertyData(QObject *, int);
- QVariant serializableVariant(const QVariant &value);
+ QVariant valueContents(const QVariant &defaultValue) const;
static QList<QmlEngine *> m_engines;
QmlWatcher *m_watch;
diff --git a/src/declarative/qml/qmlwatcher.cpp b/src/declarative/qml/qmlwatcher.cpp
index ca99472..8cd51e0 100644
--- a/src/declarative/qml/qmlwatcher.cpp
+++ b/src/declarative/qml/qmlwatcher.cpp
@@ -112,7 +112,7 @@ void QmlWatchProxy::notifyValueChanged()
else
v = m_property.read(m_object);
- emit m_watch->propertyChanged(m_id, m_debugId, QByteArray(m_property.name()), v);
+ emit m_watch->propertyChanged(m_id, m_debugId, m_property, v);
}
diff --git a/src/declarative/qml/qmlwatcher_p.h b/src/declarative/qml/qmlwatcher_p.h
index 99cae88..0bfcd71 100644
--- a/src/declarative/qml/qmlwatcher_p.h
+++ b/src/declarative/qml/qmlwatcher_p.h
@@ -65,6 +65,7 @@ QT_BEGIN_NAMESPACE
class QmlWatchProxy;
class QmlExpression;
class QmlContext;
+class QMetaProperty;
class QmlWatcher : public QObject
{
@@ -79,7 +80,7 @@ public:
void removeWatch(int id);
Q_SIGNALS:
- void propertyChanged(int id, int objectId, const QByteArray &property, const QVariant &value);
+ void propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value);
private:
friend class QmlWatchProxy;
diff --git a/tools/qmldebugger/standalone/engine.cpp b/tools/qmldebugger/standalone/engine.cpp
index a1fd009..f1eada8 100644
--- a/tools/qmldebugger/standalone/engine.cpp
+++ b/tools/qmldebugger/standalone/engine.cpp
@@ -86,7 +86,7 @@ EnginePane::EnginePane(QmlDebugConnection *conn, QWidget *parent)
connect(m_watchTableView, SIGNAL(objectActivated(int)),
m_objTree, SLOT(setCurrentObject(int)));
- m_exprQueryWidget = new ExpressionQueryWidget(m_client);
+ m_exprQueryWidget = new ExpressionQueryWidget(ExpressionQueryWidget::SeparateEntryMode, m_client);
connect(m_objTree, SIGNAL(currentObjectChanged(QmlDebugObjectReference)),
m_exprQueryWidget, SLOT(setCurrentObject(QmlDebugObjectReference)));
diff --git a/tools/qmldebugger/standalone/expressionquerywidget.cpp b/tools/qmldebugger/standalone/expressionquerywidget.cpp
index f8f5aef..3c4296d 100644
--- a/tools/qmldebugger/standalone/expressionquerywidget.cpp
+++ b/tools/qmldebugger/standalone/expressionquerywidget.cpp
@@ -11,9 +11,9 @@
#include "expressionquerywidget.h"
-ExpressionQueryWidget::ExpressionQueryWidget(QmlEngineDebug *client, QWidget *parent)
+ExpressionQueryWidget::ExpressionQueryWidget(Mode mode, QmlEngineDebug *client, QWidget *parent)
: QWidget(parent),
- m_style(Compact),
+ m_mode(mode),
m_client(client),
m_query(0),
m_textEdit(new QTextEdit),
@@ -28,7 +28,7 @@ ExpressionQueryWidget::ExpressionQueryWidget(QmlEngineDebug *client, QWidget *pa
updateTitle();
- if (m_style == Compact) {
+ if (m_mode == SeparateEntryMode) {
m_lineEdit = new QLineEdit;
connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(executeExpression()));
QHBoxLayout *hbox = new QHBoxLayout;
@@ -53,7 +53,8 @@ void ExpressionQueryWidget::setEngineDebug(QmlEngineDebug *client)
void ExpressionQueryWidget::clear()
{
m_textEdit->clear();
- m_lineEdit->clear();
+ if (m_lineEdit)
+ m_lineEdit->clear();
}
void ExpressionQueryWidget::updateTitle()
@@ -73,7 +74,7 @@ void ExpressionQueryWidget::appendPrompt()
{
m_textEdit->moveCursor(QTextCursor::End);
- if (m_style == Compact) {
+ if (m_mode == SeparateEntryMode) {
m_textEdit->insertPlainText("\n");
} else {
m_textEdit->setTextColor(Qt::gray);
@@ -111,7 +112,7 @@ void ExpressionQueryWidget::executeExpression()
if (!m_client)
return;
- if (m_style == Compact)
+ if (m_mode == SeparateEntryMode)
m_expr = m_lineEdit->text().trimmed();
else
m_expr = m_expr.trimmed();
@@ -136,20 +137,31 @@ void ExpressionQueryWidget::showResult()
{
if (m_query) {
m_textEdit->moveCursor(QTextCursor::End);
+ QVariant value = m_query->result();
QString result;
- if (m_query->result().isNull())
+
+ if (value.isNull()) {
result = QLatin1String("<no value>");
- else
- result = m_query->result().toString();
+ } else {
+ if (value.canConvert(QVariant::String)) {
+ result = value.toString();
+ } else {
+ QDebug debug(&result);
+ debug << value;
+ }
+ }
- if (m_style == Compact) {
+ if (m_mode == SeparateEntryMode) {
m_textEdit->setTextColor(Qt::black);
m_textEdit->setFontWeight(QFont::Bold);
m_textEdit->insertPlainText(m_expr + " : ");
m_textEdit->setFontWeight(QFont::Normal);
m_textEdit->insertPlainText(result);
} else {
- m_textEdit->append(result);
+ m_textEdit->setTextColor(Qt::darkGreen);
+ m_textEdit->insertPlainText(" => ");
+ m_textEdit->setTextColor(Qt::black);
+ m_textEdit->insertPlainText(result);
}
appendPrompt();
m_expr.clear();
diff --git a/tools/qmldebugger/standalone/expressionquerywidget.h b/tools/qmldebugger/standalone/expressionquerywidget.h
index 6fab059..3fe0295 100644
--- a/tools/qmldebugger/standalone/expressionquerywidget.h
+++ b/tools/qmldebugger/standalone/expressionquerywidget.h
@@ -16,12 +16,12 @@ class ExpressionQueryWidget : public QWidget
{
Q_OBJECT
public:
- enum Style {
- Compact,
- Shell
+ enum Mode {
+ SeparateEntryMode,
+ ShellMode
};
- ExpressionQueryWidget(QmlEngineDebug *client = 0, QWidget *parent = 0);
+ ExpressionQueryWidget(Mode mode = SeparateEntryMode, QmlEngineDebug *client = 0, QWidget *parent = 0);
void setEngineDebug(QmlEngineDebug *client);
void clear();
@@ -42,7 +42,7 @@ private:
void showCurrentContext();
void updateTitle();
- Style m_style;
+ Mode m_mode;
QmlEngineDebug *m_client;
QmlDebugExpressionQuery *m_query;
diff --git a/tools/qmldebugger/standalone/objectpropertiesview.cpp b/tools/qmldebugger/standalone/objectpropertiesview.cpp
index f86a69e..d6fefa0 100644
--- a/tools/qmldebugger/standalone/objectpropertiesview.cpp
+++ b/tools/qmldebugger/standalone/objectpropertiesview.cpp
@@ -16,19 +16,25 @@ class PropertiesViewItem : public QObject, public QTreeWidgetItem
{
Q_OBJECT
public:
- PropertiesViewItem(QTreeWidget *widget);
- PropertiesViewItem(QTreeWidgetItem *parent);
+ enum Type {
+ BindingType,
+ OtherType
+ };
+
+ PropertiesViewItem(QTreeWidget *widget, Type type = OtherType);
+ PropertiesViewItem(QTreeWidgetItem *parent, Type type = OtherType);
QmlDebugPropertyReference property;
+ Type type;
};
-PropertiesViewItem::PropertiesViewItem(QTreeWidget *widget)
- : QTreeWidgetItem(widget)
+PropertiesViewItem::PropertiesViewItem(QTreeWidget *widget, Type type)
+ : QTreeWidgetItem(widget), type(type)
{
}
-PropertiesViewItem::PropertiesViewItem(QTreeWidgetItem *parent)
- : QTreeWidgetItem(parent)
+PropertiesViewItem::PropertiesViewItem(QTreeWidgetItem *parent, Type type)
+ : QTreeWidgetItem(parent), type(type)
{
}
@@ -109,6 +115,42 @@ void ObjectPropertiesView::queryFinished()
setObject(obj);
}
+void ObjectPropertiesView::setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool makeGray)
+{
+ if (value.type() == QVariant::List || value.type() == QVariant::StringList) {
+ PropertiesViewItem *bindingItem = static_cast<PropertiesViewItem*>(item->takeChild(item->childCount() - 1));
+ if (bindingItem && bindingItem->type != PropertiesViewItem::BindingType) {
+ delete bindingItem;
+ bindingItem = 0;
+ }
+
+ qDeleteAll(item->takeChildren());
+
+ QVariantList variants = value.toList();
+ item->setText(1, tr("<%1 items>", "%1 = number of items").arg(variants.count()));
+ item->setText(2, QString::fromUtf8(value.typeName()));
+
+ PropertiesViewItem *child;
+ for (int i=0; i<variants.count(); i++) {
+ child = new PropertiesViewItem(item);
+ setPropertyValue(child, variants[i], makeGray);
+ }
+
+ if (bindingItem)
+ item->addChild(bindingItem);
+
+ item->setExpanded(false);
+ } else {
+ item->setText(1, (value.isNull() ? QLatin1String("<null>") : value.toString()));
+ item->setExpanded(true);
+ }
+
+ if (makeGray) {
+ for (int i=0; i<m_tree->columnCount(); i++)
+ item->setForeground(i, Qt::gray);
+ }
+}
+
void ObjectPropertiesView::setObject(const QmlDebugObjectReference &object)
{
m_object = object;
@@ -123,20 +165,17 @@ void ObjectPropertiesView::setObject(const QmlDebugObjectReference &object)
item->setText(0, p.name());
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- if (!p.hasNotifySignal()) {
- item->setForeground(0, Qt::gray);
- item->setForeground(1, Qt::gray);
- }
+
+ setPropertyValue(item, p.value(), !p.hasNotifySignal());
+ item->setText(2, p.valueTypeName());
+ // binding is set after property value to ensure it is added to the end of the
+ // list, if the value is a list
if (!p.binding().isEmpty()) {
- PropertiesViewItem *binding = new PropertiesViewItem(item);
+ PropertiesViewItem *binding = new PropertiesViewItem(item, PropertiesViewItem::BindingType);
binding->setText(1, p.binding());
binding->setForeground(1, Qt::darkGreen);
}
-
- item->setText(2, p.valueTypeName());
-
- item->setExpanded(true);
}
}
@@ -177,11 +216,8 @@ void ObjectPropertiesView::valueChanged(const QByteArray &name, const QVariant &
for (int i=0; i<m_tree->topLevelItemCount(); i++) {
PropertiesViewItem *item = static_cast<PropertiesViewItem *>(m_tree->topLevelItem(i));
if (item->property.name() == name) {
- if (value.isNull()) {
- item->setText(1, QLatin1String("<null>"));
- } else {
- item->setText(1, value.toString());
- }
+ setPropertyValue(item, value, !item->property.hasNotifySignal());
+ return;
}
}
}
diff --git a/tools/qmldebugger/standalone/objectpropertiesview.h b/tools/qmldebugger/standalone/objectpropertiesview.h
index 6a1fc03..306e5b9 100644
--- a/tools/qmldebugger/standalone/objectpropertiesview.h
+++ b/tools/qmldebugger/standalone/objectpropertiesview.h
@@ -10,6 +10,7 @@ QT_BEGIN_NAMESPACE
class QTreeWidget;
class QTreeWidgetItem;
class QmlDebugConnection;
+class PropertiesViewItem;
class ObjectPropertiesView : public QWidget
{
@@ -36,6 +37,7 @@ private slots:
private:
void setObject(const QmlDebugObjectReference &object);
void setWatched(const QString &property, bool watched);
+ void setPropertyValue(PropertiesViewItem *item, const QVariant &value, bool makeGray);
QmlEngineDebug *m_client;
QmlDebugObjectQuery *m_query;