summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-05-25 07:31:42 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-05-25 09:09:33 (GMT)
commit7f43bd48595025961989fcd51bee0271a275b475 (patch)
treec769b523eb28026dc2bd2f6e34572b495aab6c47 /tools
parentbfff04ba4fab92e1cfa57954c9df2d3b5ed807ef (diff)
downloadQt-7f43bd48595025961989fcd51bee0271a275b475.zip
Qt-7f43bd48595025961989fcd51bee0271a275b475.tar.gz
Qt-7f43bd48595025961989fcd51bee0271a275b475.tar.bz2
Add basic client/server debugging support
The canvas framerate monitor now uses this support.
Diffstat (limited to 'tools')
-rw-r--r--tools/qmldebugger/canvasframerate.cpp305
-rw-r--r--tools/qmldebugger/canvasframerate.h23
-rw-r--r--tools/qmldebugger/main.cpp103
-rw-r--r--tools/qmldebugger/qmldebugger.pro10
4 files changed, 441 insertions, 0 deletions
diff --git a/tools/qmldebugger/canvasframerate.cpp b/tools/qmldebugger/canvasframerate.cpp
new file mode 100644
index 0000000..b1f412e
--- /dev/null
+++ b/tools/qmldebugger/canvasframerate.cpp
@@ -0,0 +1,305 @@
+#include "canvasframerate.h"
+#include <QtGui/qwidget.h>
+#include <QtGui/qpainter.h>
+#include <QtGui/qscrollbar.h>
+#include <QtDeclarative/qmldebugclient.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qdatastream.h>
+#include <QtGui/qboxlayout.h>
+#include <QResizeEvent>
+#include <QShowEvent>
+#include <QTabWidget>
+#include <QPushButton>
+#include <QLineEdit>
+
+class QLineGraph : public QWidget
+{
+Q_OBJECT
+public:
+ QLineGraph(QWidget * = 0);
+
+ void setPosition(int);
+
+public slots:
+ void addSample(int, int, int, int, bool);
+
+protected:
+ virtual void paintEvent(QPaintEvent *);
+ virtual void mousePressEvent(QMouseEvent *);
+ virtual void resizeEvent(QResizeEvent *);
+ virtual void showEvent(QShowEvent *);
+
+private slots:
+ void scrollbarChanged(int);
+
+private:
+ void updateScrollbar();
+ void drawSample(QPainter *, int, const QRect &);
+ void drawTime(QPainter *, const QRect &);
+ struct Sample {
+ int sample[4];
+ bool isBreak;
+ };
+ QList<Sample> _samples;
+
+ QScrollBar sb;
+ int position;
+ int samplesPerWidth;
+ int resolutionForHeight;
+ bool ignoreScroll;
+};
+
+QLineGraph::QLineGraph(QWidget *parent)
+: QWidget(parent), sb(Qt::Horizontal, this), position(-1), samplesPerWidth(99), resolutionForHeight(50), ignoreScroll(false)
+{
+ sb.setMaximum(0);
+ sb.setMinimum(0);
+ sb.setSingleStep(1);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ setLayout(layout);
+ layout->addStretch(2);
+ layout->addWidget(&sb);
+ QObject::connect(&sb, SIGNAL(valueChanged(int)), this, SLOT(scrollbarChanged(int)));
+}
+
+void QLineGraph::scrollbarChanged(int v)
+{
+ if(ignoreScroll)
+ return;
+
+ position = v;
+ update();
+}
+
+void QLineGraph::resizeEvent(QResizeEvent *e)
+{
+ QWidget::resizeEvent(e);
+}
+
+void QLineGraph::showEvent(QShowEvent *e)
+{
+ QWidget::showEvent(e);
+}
+
+void QLineGraph::mousePressEvent(QMouseEvent *)
+{
+ if(position == -1) {
+ position = qMax(0, _samples.count() - samplesPerWidth - 1);
+ } else {
+ position = -1;
+ }
+ update();
+}
+
+void QLineGraph::updateScrollbar()
+{
+ ignoreScroll = true;
+ sb.setMaximum(qMax(0, _samples.count() - samplesPerWidth - 1));
+
+ if(position == -1) {
+ sb.setValue(sb.maximum());
+ } else {
+ sb.setValue(position);
+ }
+ ignoreScroll = false;
+}
+
+void QLineGraph::addSample(int a, int b, int c, int d, bool isBreak)
+{
+ Sample s;
+ s.isBreak = isBreak;
+ s.sample[0] = a;
+ s.sample[1] = b;
+ s.sample[2] = c;
+ s.sample[3] = d;
+ _samples << s;
+ updateScrollbar();
+ update();
+}
+
+void QLineGraph::setPosition(int p)
+{
+ scrollbarChanged(p);
+}
+
+void QLineGraph::drawTime(QPainter *p, const QRect &rect)
+{
+ if(_samples.isEmpty())
+ return;
+
+ int first = position;
+ if(first == -1)
+ first = qMax(0, _samples.count() - samplesPerWidth - 1);
+ int last = qMin(_samples.count() - 1, first + samplesPerWidth);
+
+ qreal scaleX = qreal(rect.width()) / qreal(samplesPerWidth);
+
+ int t = 0;
+
+ for(int ii = first; ii <= last; ++ii) {
+ int sampleTime = _samples.at(ii).sample[3] / 1000;
+ if(sampleTime != t) {
+
+ int xEnd = rect.left() + scaleX * (ii - first);
+ p->drawLine(xEnd, rect.bottom(), xEnd, rect.bottom() + 7);
+
+ QRect text(xEnd - 30, rect.bottom() + 10, 60, 30);
+
+ p->drawText(text, Qt::AlignHCenter | Qt::AlignTop, QString::number(_samples.at(ii).sample[3]));
+
+ t = sampleTime;
+ }
+ }
+
+}
+
+void QLineGraph::drawSample(QPainter *p, int s, const QRect &rect)
+{
+ if(_samples.isEmpty())
+ return;
+
+ int first = position;
+ if(first == -1)
+ first = qMax(0, _samples.count() - samplesPerWidth - 1);
+ int last = qMin(_samples.count() - 1, first + samplesPerWidth);
+
+ qreal scaleY = rect.height() / resolutionForHeight;
+ qreal scaleX = qreal(rect.width()) / qreal(samplesPerWidth);
+
+ int xEnd;
+ int lastXEnd = rect.left();
+
+ p->save();
+ p->setPen(Qt::NoPen);
+ for(int ii = first + 1; ii <= last; ++ii) {
+
+ xEnd = rect.left() + scaleX * (ii - first);
+ int yEnd = rect.bottom() - _samples.at(ii).sample[s] * scaleY;
+
+ if (!(s == 0 && _samples.at(ii).isBreak))
+ p->drawRect(QRect(lastXEnd, yEnd, scaleX, _samples.at(ii).sample[s] * scaleY));
+
+ lastXEnd = xEnd;
+ }
+ p->restore();
+}
+
+void QLineGraph::paintEvent(QPaintEvent *)
+{
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing);
+
+
+ QRect r(50, 10, width() - 60, height() - 60);
+ p.setBrush(QColor("lightsteelblue"));
+ drawSample(&p, 0, r);
+
+ p.setBrush(QColor("pink"));
+ drawSample(&p, 1, r);
+
+ p.setBrush(QColor("green"));
+ drawSample(&p, 2, r);
+
+ p.setBrush(Qt::NoBrush);
+ p.drawRect(r);
+
+ for(int ii = 0; ii <= resolutionForHeight; ++ii) {
+ int y = 1 + r.bottom() - ii * r.height() / resolutionForHeight;
+
+ if((ii % 10) == 0) {
+ p.drawLine(r.left() - 20, y, r.left(), y);
+ QRect text(r.left() - 20 - 53, y - 10, 50, 20);
+ p.drawText(text, Qt::AlignRight | Qt::AlignVCenter, QString::number(ii));
+ } else {
+ p.drawLine(r.left() - 7, y, r.left(), y);
+ }
+ }
+
+ drawTime(&p, r);
+}
+
+class CanvasFrameRatePlugin : public QmlDebugClientPlugin
+{
+Q_OBJECT
+public:
+ CanvasFrameRatePlugin(QmlDebugClient *client);
+
+signals:
+ void sample(int, int, int, int, bool);
+
+protected:
+ virtual void messageReceived(const QByteArray &);
+
+private:
+ int la;
+ int lb;
+ int ld;
+};
+
+CanvasFrameRatePlugin::CanvasFrameRatePlugin(QmlDebugClient *client)
+: QmlDebugClientPlugin(QLatin1String("CanvasFrameRate"), client), la(-1)
+{
+}
+
+void CanvasFrameRatePlugin::messageReceived(const QByteArray &data)
+{
+ QByteArray rwData = data;
+ QDataStream stream(&rwData, QIODevice::ReadOnly);
+
+ int a; int b; int c; int d; bool isBreak;
+ stream >> a >> b >> c >> d >> isBreak;
+
+ if (la != -1)
+ emit sample(c, lb, la, ld, isBreak);
+
+ la = a;
+ lb = b;
+ ld = d;
+}
+
+CanvasFrameRate::CanvasFrameRate(QmlDebugClient *client, QWidget *parent)
+: QWidget(parent)
+{
+ m_plugin = new CanvasFrameRatePlugin(client);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->setContentsMargins(0,0,0,0);
+ layout->setSpacing(0);
+ setLayout(layout);
+
+ m_tabs = new QTabWidget(this);
+ layout->addWidget(m_tabs);
+
+ QHBoxLayout *bottom = new QHBoxLayout;
+ layout->addLayout(bottom);
+ bottom->addStretch(2);
+
+ QPushButton *pb = new QPushButton(tr("New Tab"), this);
+ QObject::connect(pb, SIGNAL(clicked()), this, SLOT(newTab()));
+ bottom->addWidget(pb);
+
+ newTab();
+}
+
+void CanvasFrameRate::newTab()
+{
+ if (m_tabs->count()) {
+ QWidget *w = m_tabs->widget(m_tabs->count() - 1);
+ QObject::disconnect(m_plugin, SIGNAL(sample(int,int,int,int,bool)),
+ w, SLOT(addSample(int,int,int,int,bool)));
+ }
+
+ int id = m_tabs->count();
+
+ QLineGraph *graph = new QLineGraph(this);
+ QObject::connect(m_plugin, SIGNAL(sample(int,int,int,int,bool)),
+ graph, SLOT(addSample(int,int,int,int,bool)));
+
+ QString name = QLatin1String("Graph ") + QString::number(id);
+ m_tabs->addTab(graph, name);
+ m_tabs->setCurrentIndex(id);
+}
+
+#include "canvasframerate.moc"
diff --git a/tools/qmldebugger/canvasframerate.h b/tools/qmldebugger/canvasframerate.h
new file mode 100644
index 0000000..c3e88ef
--- /dev/null
+++ b/tools/qmldebugger/canvasframerate.h
@@ -0,0 +1,23 @@
+#ifndef CANVASFRAMERATE_H
+#define CANVASFRAMERATE_H
+
+#include <QWidget>
+
+class QmlDebugClient;
+class QTabWidget;
+class CanvasFrameRate : public QWidget
+{
+ Q_OBJECT
+public:
+ CanvasFrameRate(QmlDebugClient *, QWidget *parent = 0);
+
+private slots:
+ void newTab();
+
+private:
+ QTabWidget *m_tabs;
+ QObject *m_plugin;
+};
+
+#endif // CANVASFRAMERATE_H
+
diff --git a/tools/qmldebugger/main.cpp b/tools/qmldebugger/main.cpp
new file mode 100644
index 0000000..2c5be6c
--- /dev/null
+++ b/tools/qmldebugger/main.cpp
@@ -0,0 +1,103 @@
+#include <QtNetwork/qtcpsocket.h>
+#include <QtGui/qapplication.h>
+#include <QtGui/qwidget.h>
+#include <QtGui/qpainter.h>
+#include <QtGui/qscrollbar.h>
+#include <QtDeclarative/qmldebugclient.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qdatastream.h>
+#include "canvasframerate.h"
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QLineEdit>
+#include <QTabWidget>
+#include <QSpinBox>
+
+class Shell : public QWidget
+{
+Q_OBJECT
+public:
+ Shell(QWidget * = 0);
+
+private slots:
+ void connectToHost();
+ void disconnectFromHost();
+
+private:
+ QmlDebugClient client;
+
+ QLineEdit *m_host;
+ QSpinBox *m_port;
+ QPushButton *m_connectButton;
+ QPushButton *m_disconnectButton;
+};
+
+Shell::Shell(QWidget *parent)
+: QWidget(parent)
+{
+ QVBoxLayout *layout = new QVBoxLayout;
+ setLayout(layout);
+
+
+ QHBoxLayout *connectLayout = new QHBoxLayout;
+ layout->addLayout(connectLayout);
+ connectLayout->addStretch(2);
+
+ m_host = new QLineEdit(this);
+ m_host->setText("localhost");
+ connectLayout->addWidget(m_host);
+ m_port = new QSpinBox(this);
+ m_port->setMinimum(1024);
+ m_port->setMaximum(20000);
+ m_port->setValue(3768);
+ connectLayout->addWidget(m_port);
+ m_connectButton = new QPushButton(tr("Connect"), this);
+ QObject::connect(m_connectButton, SIGNAL(clicked()),
+ this, SLOT(connectToHost()));
+ connectLayout->addWidget(m_connectButton);
+ m_disconnectButton = new QPushButton(tr("Disconnect"), this);
+ QObject::connect(m_disconnectButton, SIGNAL(clicked()),
+ this, SLOT(disconnectFromHost()));
+ m_disconnectButton->setEnabled(false);
+ connectLayout->addWidget(m_disconnectButton);
+
+ QTabWidget *tabs = new QTabWidget(this);
+ layout->addWidget(tabs);
+
+ CanvasFrameRate *cfr = new CanvasFrameRate(&client, this);
+ tabs->addTab(cfr, tr("Frame Rate"));
+}
+
+void Shell::connectToHost()
+{
+ m_connectButton->setEnabled(false);
+ m_disconnectButton->setEnabled(true);
+ client.connectToHost(m_host->text(), m_port->value());
+}
+
+void Shell::disconnectFromHost()
+{
+ m_connectButton->setEnabled(true);
+ m_disconnectButton->setEnabled(false);
+ client.disconnectFromHost();
+}
+
+int main(int argc, char ** argv)
+{
+ if(argc != 3) {
+ qWarning() << "Usage:" << argv[0] << "host port";
+ return -1;
+ }
+
+ QApplication app(argc, argv);
+
+ Shell shell;
+// shell.setFixedSize(1024, 768);
+ shell.show();
+
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tools/qmldebugger/qmldebugger.pro b/tools/qmldebugger/qmldebugger.pro
new file mode 100644
index 0000000..6af2909
--- /dev/null
+++ b/tools/qmldebugger/qmldebugger.pro
@@ -0,0 +1,10 @@
+DESTDIR = ../../bin
+QT += network declarative
+# Input
+HEADERS += canvasframerate.h
+SOURCES += main.cpp canvasframerate.cpp
+
+target.path=$$[QT_INSTALL_BINS]
+INSTALLS += target
+
+CONFIG += console