summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-10-19 23:57:41 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-10-19 23:57:41 (GMT)
commit85fe2b6ece1e590199bcf7960c1a40e816e81105 (patch)
treec194a7d2f1000ba32f62acb42275b5aeda722bed
parent515cb0f40654e54384fd75c7042b9fa25d3df193 (diff)
downloadQt-85fe2b6ece1e590199bcf7960c1a40e816e81105.zip
Qt-85fe2b6ece1e590199bcf7960c1a40e816e81105.tar.gz
Qt-85fe2b6ece1e590199bcf7960c1a40e816e81105.tar.bz2
Add ExpressionQueryWidget and do some clean up.
-rw-r--r--tools/qmldebugger/expressionquerywidget.cpp181
-rw-r--r--tools/qmldebugger/expressionquerywidget.h58
-rw-r--r--tools/qmldebugger/objectpropertiesview.cpp2
-rw-r--r--tools/qmldebugger/objecttree.cpp10
-rw-r--r--tools/qmldebugger/objecttree.h6
-rw-r--r--tools/qmldebugger/qmldebugger.cpp4
-rw-r--r--tools/qmldebugger/qmldebugger.pri6
-rw-r--r--tools/qmldebugger/watchtable.cpp3
8 files changed, 259 insertions, 11 deletions
diff --git a/tools/qmldebugger/expressionquerywidget.cpp b/tools/qmldebugger/expressionquerywidget.cpp
new file mode 100644
index 0000000..90ab8ee
--- /dev/null
+++ b/tools/qmldebugger/expressionquerywidget.cpp
@@ -0,0 +1,181 @@
+#include <QtGui/qlabel.h>
+#include <QtGui/qtextedit.h>
+#include <QtGui/qlineedit.h>
+#include <QtGui/qpushbutton.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qgroupbox.h>
+#include <QtGui/qtextobject.h>
+#include <QtGui/qlayout.h>
+
+#include "expressionquerywidget.h"
+
+ExpressionQueryWidget::ExpressionQueryWidget(QmlEngineDebug *client, QWidget *parent)
+ : QWidget(parent),
+ m_style(Compact),
+ m_client(client),
+ m_query(0),
+ m_groupBox(0),
+ m_textEdit(new QTextEdit),
+ m_lineEdit(0)
+{
+ m_prompt = QLatin1String(">> ");
+
+ m_groupBox = new QGroupBox;
+ QVBoxLayout *vbox = new QVBoxLayout(m_groupBox);
+ vbox->addWidget(m_textEdit);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(m_groupBox);
+
+ updateTitle();
+
+ if (m_style == Compact) {
+ QHBoxLayout *hbox = new QHBoxLayout;
+ QPushButton *button = new QPushButton(tr("Execute"));
+ connect(button, SIGNAL(clicked()), SLOT(executeExpression()));
+ m_lineEdit = new QLineEdit;
+ connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(executeExpression()));
+ hbox->addWidget(new QLabel(tr("Expression:")));
+ hbox->addWidget(m_lineEdit);
+ hbox->addWidget(button);
+ vbox->addLayout(hbox);
+
+ m_textEdit->setReadOnly(true);
+ } else {
+ m_textEdit->installEventFilter(this);
+ }
+}
+
+void ExpressionQueryWidget::updateTitle()
+{
+ if (m_currObject.debugId() < 0) {
+ m_groupBox->setTitle(tr("Expression queries"));
+ } else {
+ QString desc = QLatin1String("<")
+ + m_currObject.className() + QLatin1String(": ")
+ + (m_currObject.name().isEmpty() ? QLatin1String("<unnamed>") : m_currObject.name())
+ + QLatin1String(">");
+ m_groupBox->setTitle(tr("Expression queries (current context: %1)"
+ , "Selected object").arg(desc));
+ }
+}
+
+void ExpressionQueryWidget::appendPrompt()
+{
+ m_textEdit->moveCursor(QTextCursor::End);
+
+ if (m_style == Compact) {
+ m_textEdit->insertPlainText("\n");
+ } else {
+ m_textEdit->setTextColor(Qt::gray);
+ m_textEdit->append(m_prompt);
+ }
+}
+
+void ExpressionQueryWidget::setCurrentObject(const QmlDebugObjectReference &obj)
+{
+ m_currObject = obj;
+ updateTitle();
+}
+
+void ExpressionQueryWidget::checkCurrentContext()
+{
+ m_textEdit->moveCursor(QTextCursor::End);
+
+ if (m_currObject.debugId() != -1 && m_currObject.debugId() != m_objectAtLastFocus.debugId())
+ showCurrentContext();
+ m_objectAtLastFocus = m_currObject;
+}
+
+void ExpressionQueryWidget::showCurrentContext()
+{
+ m_textEdit->moveCursor(QTextCursor::End);
+ m_textEdit->setTextColor(Qt::darkGreen);
+ m_textEdit->append(m_currObject.className()
+ + QLatin1String(": ")
+ + (m_currObject.name().isEmpty() ? QLatin1String("<unnamed>") : m_currObject.name()));
+ appendPrompt();
+}
+
+void ExpressionQueryWidget::executeExpression()
+{
+ if (m_style == Compact)
+ m_expr = m_lineEdit->text().trimmed();
+
+ if (!m_expr.trimmed().isEmpty() && m_currObject.debugId() != -1) {
+ checkCurrentContext();
+ if (m_query)
+ delete m_query;
+ m_query = m_client->queryExpressionResult(m_currObject.debugId(), m_expr.trimmed(), this);
+ if (!m_query->isWaiting())
+ showResult();
+ else
+ QObject::connect(m_query, SIGNAL(stateChanged(State)),
+ this, SLOT(showResult()));
+
+ if (m_lineEdit)
+ m_lineEdit->clear();
+ }
+}
+
+void ExpressionQueryWidget::showResult()
+{
+ if (m_query) {
+ m_textEdit->moveCursor(QTextCursor::End);
+ QString result = m_query->result().toString();
+ if (result.isEmpty())
+ result = QLatin1String("<no value>");
+
+ if (m_style == Compact) {
+ 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);
+ }
+ appendPrompt();
+ m_expr.clear();
+ }
+}
+
+bool ExpressionQueryWidget::eventFilter(QObject *obj, QEvent *event)
+{
+ if (obj == m_textEdit) {
+ switch (event->type()) {
+ case QEvent::KeyPress:
+ {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
+ int key = keyEvent->key();
+ if (key == Qt::Key_Return || key == Qt::Key_Enter) {
+ executeExpression();
+ return true;
+ } else if (key == Qt::Key_Backspace) {
+ // ensure m_expr doesn't contain backspace characters
+ QTextCursor cursor = m_textEdit->textCursor();
+ bool atLastLine = !(cursor.block().next().isValid());
+ if (!atLastLine)
+ return true;
+ if (cursor.columnNumber() <= m_prompt.count())
+ return true;
+ cursor.deletePreviousChar();
+ m_expr = cursor.block().text().mid(m_prompt.count());
+ return true;
+ } else {
+ m_textEdit->moveCursor(QTextCursor::End);
+ m_textEdit->setTextColor(Qt::black);
+ m_expr += keyEvent->text();
+ }
+ break;
+ }
+ case QEvent::FocusIn:
+ checkCurrentContext();
+ m_textEdit->moveCursor(QTextCursor::End);
+ break;
+ default:
+ break;
+ }
+ }
+ return QWidget::eventFilter(obj, event);
+}
diff --git a/tools/qmldebugger/expressionquerywidget.h b/tools/qmldebugger/expressionquerywidget.h
new file mode 100644
index 0000000..3ea95ac
--- /dev/null
+++ b/tools/qmldebugger/expressionquerywidget.h
@@ -0,0 +1,58 @@
+#ifndef EXPRESSIONQUERYWIDGET_H
+#define EXPRESSIONQUERYWIDGET_H
+
+#include <QWidget>
+
+#include <QtDeclarative/qmldebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGroupBox;
+class QTextEdit;
+class QLineEdit;
+
+class ExpressionQueryWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ enum Style {
+ Compact,
+ Shell
+ };
+
+ ExpressionQueryWidget(QmlEngineDebug *client, QWidget *parent = 0);
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *event);
+
+public slots:
+ void setCurrentObject(const QmlDebugObjectReference &obj);
+
+private slots:
+ void executeExpression();
+ void showResult();
+
+private:
+ void appendPrompt();
+ void checkCurrentContext();
+ void showCurrentContext();
+ void updateTitle();
+
+ Style m_style;
+
+ QmlEngineDebug *m_client;
+ QmlDebugExpressionQuery *m_query;
+ QGroupBox *m_groupBox;
+ QTextEdit *m_textEdit;
+ QLineEdit *m_lineEdit;
+ QString m_prompt;
+ QString m_expr;
+
+ QmlDebugObjectReference m_currObject;
+ QmlDebugObjectReference m_objectAtLastFocus;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/tools/qmldebugger/objectpropertiesview.cpp b/tools/qmldebugger/objectpropertiesview.cpp
index 864468c..4a2f97d 100644
--- a/tools/qmldebugger/objectpropertiesview.cpp
+++ b/tools/qmldebugger/objectpropertiesview.cpp
@@ -177,7 +177,7 @@ void ObjectPropertiesView::valueChanged(const QByteArray &name, const QVariant &
void ObjectPropertiesView::itemActivated(QTreeWidgetItem *i)
{
PropertiesViewItem *item = static_cast<PropertiesViewItem *>(i);
- if (!item->property.name().isEmpty() && item->property.hasNotifySignal())
+ if (!item->property.name().isEmpty())
emit activated(m_object, item->property);
}
diff --git a/tools/qmldebugger/objecttree.cpp b/tools/qmldebugger/objecttree.cpp
index f68e7f1..0b92ceb 100644
--- a/tools/qmldebugger/objecttree.cpp
+++ b/tools/qmldebugger/objecttree.cpp
@@ -19,8 +19,8 @@ ObjectTree::ObjectTree(QmlEngineDebug *client, QWidget *parent)
{
setHeaderHidden(true);
- connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
- this, SLOT(handleItemClicked(QTreeWidgetItem *)));
+ connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+ this, SLOT(currentItemChanged(QTreeWidgetItem *)));
}
void ObjectTree::reload(int objectDebugId)
@@ -38,7 +38,7 @@ void ObjectTree::reload(int objectDebugId)
this, SLOT(objectFetched()));
}
-void ObjectTree::selectObject(int debugId)
+void ObjectTree::setCurrentObject(int debugId)
{
QTreeWidgetItem *item = findItemByObjectId(debugId);
if (item) {
@@ -57,14 +57,14 @@ void ObjectTree::objectFetched()
m_query = 0;
}
-void ObjectTree::handleItemClicked(QTreeWidgetItem *item)
+void ObjectTree::currentItemChanged(QTreeWidgetItem *item)
{
QmlDebugObjectReference obj = item->data(0, Qt::UserRole).value<QmlDebugObjectReference>();
if (obj.debugId() < 0) {
qWarning("QML Object Tree: bad object id");
return;
}
- emit objectSelected(obj);
+ emit currentObjectChanged(obj);
}
void ObjectTree::buildTree(const QmlDebugObjectReference &obj, QTreeWidgetItem *parent)
diff --git a/tools/qmldebugger/objecttree.h b/tools/qmldebugger/objecttree.h
index bba6c08..3c0a5c6 100644
--- a/tools/qmldebugger/objecttree.h
+++ b/tools/qmldebugger/objecttree.h
@@ -20,19 +20,19 @@ public:
ObjectTree(QmlEngineDebug *client, QWidget *parent = 0);
signals:
- void objectSelected(const QmlDebugObjectReference &);
+ void currentObjectChanged(const QmlDebugObjectReference &);
void expressionWatchRequested(const QmlDebugObjectReference &, const QString &);
public slots:
void reload(int objectDebugId);
- void selectObject(int debugId);
+ void setCurrentObject(int debugId);
protected:
virtual void mousePressEvent(QMouseEvent *);
private slots:
void objectFetched();
- void handleItemClicked(QTreeWidgetItem *);
+ void currentItemChanged(QTreeWidgetItem *);
private:
QTreeWidgetItem *findItemByObjectId(int debugId) const;
diff --git a/tools/qmldebugger/qmldebugger.cpp b/tools/qmldebugger/qmldebugger.cpp
index 0f0fc03..e0a76b6 100644
--- a/tools/qmldebugger/qmldebugger.cpp
+++ b/tools/qmldebugger/qmldebugger.cpp
@@ -57,6 +57,10 @@ QmlDebugger::QmlDebugger(QWidget *parent)
QObject::connect(&client, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(connectionError(QAbstractSocket::SocketError)));
+
+
+ m_tabs->setCurrentIndex(1);
+ connectToHost();
}
void QmlDebugger::setHost(const QString &host)
diff --git a/tools/qmldebugger/qmldebugger.pri b/tools/qmldebugger/qmldebugger.pri
index ce36381..c49d334 100644
--- a/tools/qmldebugger/qmldebugger.pri
+++ b/tools/qmldebugger/qmldebugger.pri
@@ -7,7 +7,8 @@ HEADERS += $$PWD/qmldebugger.h \
$$PWD/watchtable.h \
$$PWD/engine.h \
$$PWD/objecttree.h \
- $$PWD/objectpropertiesview.h
+ $$PWD/objectpropertiesview.h \
+ $$PWD/expressionquerywidget.h
SOURCES += $$PWD/qmldebugger.cpp \
$$PWD/main.cpp \
@@ -15,7 +16,8 @@ SOURCES += $$PWD/qmldebugger.cpp \
$$PWD/watchtable.cpp \
$$PWD/engine.cpp \
$$PWD/objecttree.cpp \
- $$PWD/objectpropertiesview.cpp
+ $$PWD/objectpropertiesview.cpp \
+ $$PWD/expressionquerywidget.cpp
RESOURCES += $$PWD/qmldebugger.qrc
diff --git a/tools/qmldebugger/watchtable.cpp b/tools/qmldebugger/watchtable.cpp
index e4163dc..512bfb2 100644
--- a/tools/qmldebugger/watchtable.cpp
+++ b/tools/qmldebugger/watchtable.cpp
@@ -193,6 +193,9 @@ void WatchTableModel::addValue(int column, const QVariant &value)
void WatchTableModel::togglePropertyWatch(const QmlDebugObjectReference &object, const QmlDebugPropertyReference &property)
{
+ if (!property.hasNotifySignal())
+ return;
+
QmlDebugWatch *watch = findWatch(object.debugId(), property.name());
if (watch) {
// watch will be deleted in watchStateChanged()