Commit 9e58ab2a authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlProfiler: Initial conversion from Quick 1 to Quick 2



Updated class names and functions. Fixed imports.

Change-Id: I5f12e3a108a0e60c091acc9c415ff77e52118029
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
parent 8e281fe2
......@@ -64,16 +64,18 @@ isEmpty(IDE_PACKAGE_MODE) {
contains(QT_CONFIG, declarative)|!isEmpty(QT.declarative.name) {
SUBDIRS += \
qmlprojectmanager \
qmlprofiler
qmlprojectmanager
greaterThan(QT_MAJOR_VERSION, 4):greaterThan(QT_MINOR_VERSION, 0) {
SUBDIRS += \
qmldesigner \
qmlprofiler \
welcome
} else {
warning("QmlDesigner plugin has been disabled.")
warning("The plugin needs at least Qt 5.1.")
warning("QmlProfiler plugin has been disabled.")
warning("Welcome plugin has been disabled.")
warning("These plugins need at least Qt 5.1.")
}
} else {
warning("QmlProjectManager, QmlProfiler and QmlDesigner plugins have been disabled: The plugins require QtDeclarative")
......
......@@ -35,16 +35,14 @@
QT_BEGIN_NAMESPACE
Canvas::Canvas(QDeclarativeItem *parent)
: QDeclarativeItem(parent),
Canvas::Canvas(QQuickPaintedItem *parent)
: QQuickPaintedItem(parent),
m_context(new Context2D(this)),
m_canvasWidth(0),
m_canvasHeight(0),
m_fillMode(Canvas::Stretch),
m_color(Qt::white)
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
......@@ -57,10 +55,10 @@ void Canvas::componentComplete()
connect(m_context, SIGNAL(changed()), this, SLOT(requestPaint()));
emit init();
QDeclarativeItem::componentComplete();
QQuickItem::componentComplete();
}
void Canvas::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
void Canvas::paint(QPainter *painter)
{
m_context->setInPaint(true);
emit paint();
......@@ -160,7 +158,7 @@ void Canvas::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometr
&& newGeometry.width() > 0 && newGeometry.height() > 0) {
m_context->setSize(width(), height());
}
QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
QQuickItem::geometryChanged(newGeometry, oldGeometry);
}
void Canvas::setCanvasWidth(int newWidth)
......@@ -219,24 +217,24 @@ CanvasImage *Canvas::toImage() const
return new CanvasImage(m_context->pixmap());
}
void Canvas::setTimeout(const QScriptValue &handler, long timeout)
void Canvas::setTimeout(const QJSValue &handler, long timeout)
{
if (handler.isFunction())
if (handler.isCallable())
CanvasTimer::createTimer(this, handler, timeout, true);
}
void Canvas::setInterval(const QScriptValue &handler, long interval)
void Canvas::setInterval(const QJSValue &handler, long interval)
{
if (handler.isFunction())
if (handler.isCallable())
CanvasTimer::createTimer(this, handler, interval, false);
}
void Canvas::clearTimeout(const QScriptValue &handler)
void Canvas::clearTimeout(const QJSValue &handler)
{
CanvasTimer::removeTimer(handler);
}
void Canvas::clearInterval(const QScriptValue &handler)
void Canvas::clearInterval(const QJSValue &handler)
{
CanvasTimer::removeTimer(handler);
}
......
......@@ -30,15 +30,14 @@
#ifndef QDECLARATIVECANVAS_P_H
#define QDECLARATIVECANVAS_P_H
#include <qdeclarativeitem.h>
#include <QQuickPaintedItem>
#include "qdeclarativecontext2d_p.h"
#include "qdeclarativecanvastimer_p.h"
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class Canvas : public QDeclarativeItem
class Canvas : public QQuickPaintedItem
{
Q_OBJECT
......@@ -49,11 +48,11 @@ class Canvas : public QDeclarativeItem
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
public:
Canvas(QDeclarativeItem *parent = 0);
Canvas(QQuickPaintedItem *parent = 0);
enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally };
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
void paint(QPainter *);
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
void setCanvasWidth(int newWidth);
int canvasWidth() {return m_canvasWidth;}
......@@ -78,10 +77,10 @@ public Q_SLOTS:
bool save(const QString& filename) const;
// Timers
void setInterval(const QScriptValue &handler, long timeout);
void setTimeout(const QScriptValue &handler, long timeout);
void clearInterval(const QScriptValue &handler);
void clearTimeout(const QScriptValue &handler);
void setInterval(const QJSValue &handler, long timeout);
void setTimeout(const QJSValue &handler, long timeout);
void clearInterval(const QJSValue &handler);
void clearTimeout(const QJSValue &handler);
Q_SIGNALS:
void fillModeChanged();
......
......@@ -29,28 +29,28 @@
#include "qdeclarativecanvastimer_p.h"
#include <qscriptengine.h>
#include <qscriptvalue.h>
#include <QJSEngine>
#include <QJSValue>
#include <qtimer.h>
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QList<CanvasTimer*> , activeTimers);
CanvasTimer::CanvasTimer(QObject *parent, const QScriptValue &data)
CanvasTimer::CanvasTimer(QObject *parent, const QJSValue &data)
: QTimer(parent), m_value(data)
{
}
void CanvasTimer::handleTimeout()
{
Q_ASSERT(m_value.isFunction());
Q_ASSERT(m_value.isCallable());
m_value.call();
if (isSingleShot())
removeTimer(this);
}
void CanvasTimer::createTimer(QObject *parent, const QScriptValue &val, long timeout, bool singleshot)
void CanvasTimer::createTimer(QObject *parent, const QJSValue &val, long timeout, bool singleshot)
{
CanvasTimer *timer = new CanvasTimer(parent, val);
......@@ -67,9 +67,9 @@ void CanvasTimer::removeTimer(CanvasTimer *timer)
timer->deleteLater();
}
void CanvasTimer::removeTimer(const QScriptValue &val)
void CanvasTimer::removeTimer(const QJSValue &val)
{
if (!val.isFunction())
if (!val.isCallable())
return;
for (int i = 0 ; i < activeTimers()->count() ; ++i) {
......
......@@ -30,32 +30,30 @@
#ifndef QDECLARATIVECANVASTIMER_P_H
#define QDECLARATIVECANVASTIMER_P_H
#include <qscriptvalue.h>
#include <QJSValue>
#include <qtimer.h>
#include <qlist.h>
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class CanvasTimer : public QTimer
{
Q_OBJECT
public:
CanvasTimer(QObject *parent, const QScriptValue &data);
CanvasTimer(QObject *parent, const QJSValue &data);
public Q_SLOTS:
void handleTimeout();
bool equals(const QScriptValue &value){return m_value.equals(value);}
bool equals(const QJSValue &value){return m_value.equals(value);}
public:
static void createTimer(QObject *parent, const QScriptValue &val, long timeout, bool singleshot);
static void createTimer(QObject *parent, const QJSValue &val, long timeout, bool singleshot);
static void removeTimer(CanvasTimer *timer);
static void removeTimer(const QScriptValue &);
static void removeTimer(const QJSValue &);
private:
QScriptValue m_value;
QJSValue m_value;
};
......
......@@ -39,6 +39,7 @@
#include <qgraphicseffect.h>
#include <QImage>
#include <QWidget>
QT_BEGIN_NAMESPACE
......@@ -737,8 +738,8 @@ void Context2D::strokeRect(qreal x, qreal y, qreal w, qreal h)
scheduleChange();
}
void Context2D::mouseArea(qreal x, qreal y, qreal w, qreal h, const QScriptValue &callback,
const QScriptValue &data)
void Context2D::mouseArea(qreal x, qreal y, qreal w, qreal h, const QJSValue &callback,
const QJSValue &data)
{
MouseArea a = { callback, data, QRectF(x, y, w, h), m_state.matrix };
m_mouseAreas << a;
......@@ -1103,9 +1104,14 @@ void Context2D::setPainterTranslate(const QPoint &translate)
}
void Context2D::scheduleChange()
{
QMetaObject::invokeMethod(this, "onScheduleChange", Qt::QueuedConnection, Q_ARG(int, 0));
}
void Context2D::onScheduleChange(int interval)
{
if (m_changeTimerId == -1 && !m_inPaint)
m_changeTimerId = startTimer(0);
m_changeTimerId = startTimer(interval);
}
void Context2D::timerEvent(QTimerEvent *e)
......
......@@ -38,11 +38,10 @@
#include <qmetatype.h>
#include <qcoreevent.h>
#include <qvariant.h>
#include <qscriptvalue.h>
QT_BEGIN_NAMESPACE
#include <QJSValue>
QT_MODULE(Declarative)
QT_BEGIN_NAMESPACE
QColor colorFromString(const QString &name);
......@@ -174,8 +173,8 @@ public:
void setShadowColor(const QString &str);
struct MouseArea {
QScriptValue callback;
QScriptValue data;
QJSValue callback;
QJSValue data;
QRectF rect;
QMatrix matrix;
};
......@@ -209,7 +208,7 @@ public slots:
void strokeRect(qreal x, qreal y, qreal w, qreal h);
// mouse
void mouseArea(qreal x, qreal y, qreal w, qreal h, const QScriptValue &, const QScriptValue & = QScriptValue());
void mouseArea(qreal x, qreal y, qreal w, qreal h, const QJSValue &, const QJSValue & = QJSValue());
// path API
void beginPath();
......@@ -239,6 +238,9 @@ public slots:
void putImageData(ImageData image, qreal dx, qreal dy);
void endPainting();
private slots:
void onScheduleChange(int interval);
signals:
void changed();
......
......@@ -41,9 +41,7 @@ QmlProfilerCanvas::QmlProfilerCanvas()
: m_context2d(new Context2D(this))
, m_dirty(true)
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
setAcceptedMouseButtons(Qt::LeftButton);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
void QmlProfilerCanvas::requestPaint()
......@@ -57,7 +55,7 @@ void QmlProfilerCanvas::requestRedraw()
update();
}
void QmlProfilerCanvas::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
void QmlProfilerCanvas::paint(QPainter *p)
{
if (m_context2d->size().width() != width() || m_context2d->size().height() != height()) {
m_dirty = true;
......@@ -84,7 +82,7 @@ void QmlProfilerCanvas::componentComplete()
if (p.hasNotifySignal())
QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
}
QDeclarativeItem::componentComplete();
QQuickItem::componentComplete();
}
}
......
......@@ -30,7 +30,7 @@
#ifndef QMLPROFILERCANVAS_H
#define QMLPROFILERCANVAS_H
#include <QDeclarativeItem>
#include <QQuickPaintedItem>
QT_BEGIN_NAMESPACE
class Context2D;
......@@ -39,7 +39,7 @@ QT_END_NAMESPACE
namespace QmlProfiler {
namespace Internal {
class QmlProfilerCanvas : public QDeclarativeItem
class QmlProfilerCanvas : public QQuickPaintedItem
{
Q_OBJECT
......@@ -67,7 +67,7 @@ public slots:
void requestRedraw();
protected:
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
virtual void paint(QPainter *);
virtual void componentComplete();
private:
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
Item {
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
Item {
id: labelContainer
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
Rectangle {
......@@ -502,7 +502,7 @@ Rectangle {
onPressed: {
selectionRange.pressedOnCreation();
}
onMousePositionChanged: {
onPositionChanged: {
selectionRange.movedOnCreation();
}
}
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
import "Overview.js" as Plotter
......@@ -108,7 +108,7 @@ Canvas2D {
onPressed: {
jumpTo(mouse.x);
}
onMousePositionChanged: {
onPositionChanged: {
jumpTo(mouse.x);
}
}
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
Item {
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
Rectangle {
id: rangeMover
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
Rectangle {
id: selectionRange
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
Item {
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
Canvas2D {
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0
import Monitor 1.0
Canvas2D {
......
DEFINES += QMLPROFILER_LIBRARY
QT += network script declarative
QT += network qml quick
include(../../qtcreatorplugin.pri)
include(canvas/canvas.pri)
......
......@@ -5,7 +5,7 @@ import "../QtcPlugin.qbs" as QtcPlugin
QtcPlugin {
name: "QmlProfiler"
Depends { name: "Qt"; submodules: ["widgets", "network", "script", "declarative"] }
Depends { name: "Qt"; submodules: ["widgets", "network", "qml", "quick"] }
Depends { name: "Core" }
Depends { name: "AnalyzerBase" }
Depends { name: "QmlProjectManager" }
......
......@@ -42,7 +42,7 @@
#include <utils/styledbar.h>
#include <QDeclarativeContext>
#include <QQmlContext>
#include <QToolButton>
#include <QEvent>
#include <QVBoxLayout>
......@@ -50,6 +50,7 @@
#include <QScrollBar>
#include <QSlider>
#include <QMenu>
#include <QQuickItem>
#include <math.h>
......@@ -86,23 +87,22 @@ void ZoomControl::setRange(qint64 startTime, qint64 endTime)
}
/////////////////////////////////////////////////////////
ScrollableDeclarativeView::ScrollableDeclarativeView(QWidget *parent)
: QDeclarativeView(parent)
ScrollableQuickView::ScrollableQuickView(QQuickView *parent)
: QQuickView(parent)
{
}
ScrollableDeclarativeView::~ScrollableDeclarativeView()
ScrollableQuickView::~ScrollableQuickView()
{
}
void ScrollableDeclarativeView::scrollContentsBy(int dx, int dy)
void ScrollableQuickView::scrollContentsBy(int /*dx*/, int dy)
{
// special workaround to track the scrollbar
if (rootObject()) {
int scrollY = rootObject()->property("scrollY").toInt();
rootObject()->setProperty("scrollY", QVariant(scrollY - dy));
}
QDeclarativeView::scrollContentsBy(dx,dy);
}
/////////////////////////////////////////////////////////
......@@ -110,6 +110,13 @@ class QmlProfilerTraceView::QmlProfilerTraceViewPrivate
{
public:
QmlProfilerTraceViewPrivate(QmlProfilerTraceView *qq) : q(qq) {}
~QmlProfilerTraceViewPrivate()
{
delete m_mainView;
delete m_timebar;
delete m_overview;
}
QmlProfilerTraceView *q;
QmlProfilerStateManager *m_profilerState;
......@@ -118,9 +125,9 @@ public:
QSize m_sizeHint;
ScrollableDeclarativeView *m_mainView;
QDeclarativeView *m_timebar;
QDeclarativeView *m_overview;
ScrollableQuickView *m_mainView;
QQuickView *m_timebar;
QQuickView *m_overview;
QmlProfilerModelManager *m_modelManager;
TimelineModelAggregator *m_modelProxy;
......@@ -145,40 +152,38 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, Analyzer::IAnalyzerT
groupLayout->setContentsMargins(0, 0, 0, 0);
groupLayout->setSpacing(0);
d->m_mainView = new ScrollableDeclarativeView(this);
d->m_mainView->setResizeMode(QDeclarativeView::SizeViewToRootObject);
d->m_mainView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
d->m_mainView->setBackgroundBrush(QBrush(Qt::white));
d->m_mainView->setAlignment(Qt::AlignLeft | Qt::AlignTop);
d->m_mainView->setFocus();
d->m_mainView = new ScrollableQuickView();
d->m_mainView->setResizeMode(QQuickView::SizeViewToRootObject);
QWidget *mainViewContainer = QWidget::createWindowContainer(d->m_mainView);
MouseWheelResizer *resizer = new MouseWheelResizer(this);
connect(resizer,SIGNAL(mouseWheelMoved(int,int,int)), this, SLOT(mouseWheelMoved(int,int,int)));
d->m_mainView->viewport()->installEventFilter(resizer);
QHBoxLayout *toolsLayout = new QHBoxLayout;
d->m_timebar = new QDeclarativeView(this);
d->m_timebar->setResizeMode(QDeclarativeView::SizeRootObjectToView);
d->m_timebar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
d->m_timebar->setFixedHeight(24);
d->m_timebar = new QQuickView();
d->m_timebar->setResizeMode(QQuickView::SizeRootObjectToView);
QWidget *timeBarContainer = QWidget::createWindowContainer(d->m_timebar);
timeBarContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
timeBarContainer->setFixedHeight(24);
d->m_overview = new QDeclarativeView(this);
d->m_overview->setResizeMode(QDeclarativeView::SizeRootObjectToView);
d->m_overview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
d->m_overview->setMaximumHeight(50);