diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-28 05:50:11 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-28 05:50:11 (GMT) |
commit | 25f87fede4b5fd367242be80f314310e7be6e0a5 (patch) | |
tree | cd4f0411959eba5cb93f8fe425cbf2f2931c6790 /tools | |
parent | 37314eb9ff900780b8bb952c8fa87f278a634f3a (diff) | |
download | Qt-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.
Diffstat (limited to 'tools')
5 files changed, 87 insertions, 37 deletions
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; |