summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-05-24 23:58:54 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-05-24 23:58:54 (GMT)
commit19038ba0847d3b8ed476d8c3c1d29332d4f80677 (patch)
tree0374a25291e47d576dc9c45ef43acd7d830195cc /src/declarative
parent641c7cbdc52f84c07cf5bb628840bd6072e64764 (diff)
parentbfff04ba4fab92e1cfa57954c9df2d3b5ed807ef (diff)
downloadQt-19038ba0847d3b8ed476d8c3c1d29332d4f80677.zip
Qt-19038ba0847d3b8ed476d8c3c1d29332d4f80677.tar.gz
Qt-19038ba0847d3b8ed476d8c3c1d29332d4f80677.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/canvas/monitor/main.cpp287
-rw-r--r--src/declarative/canvas/monitor/monitor.pro8
-rw-r--r--src/declarative/canvas/qsimplecanvasserver.cpp31
-rw-r--r--src/declarative/canvas/qsimplecanvasserver_p.h4
-rw-r--r--src/declarative/debugger/qmlcanvasdebugger.cpp4
-rw-r--r--src/declarative/debugger/qmldebugger.cpp20
-rw-r--r--src/declarative/debugger/qmlobjecttree.cpp4
-rw-r--r--src/declarative/debugger/qmlpropertyview.cpp2
-rw-r--r--src/declarative/fx/qfxanchors.cpp52
-rw-r--r--src/declarative/fx/qfxanchors.h5
-rw-r--r--src/declarative/fx/qfxanchors_p.h1
-rw-r--r--src/declarative/fx/qfxitem.cpp57
-rw-r--r--src/declarative/fx/qfxitem.h2
-rw-r--r--src/declarative/fx/qfxitem_p.h1
-rw-r--r--src/declarative/fx/qfxpathview.cpp1
-rw-r--r--src/declarative/fx/qfxtext.cpp5
-rw-r--r--src/declarative/fx/qfxvisualitemmodel.cpp2
-rw-r--r--src/declarative/qml/qmlcompiler.cpp4
-rw-r--r--src/declarative/qml/qmlcompositetypemanager.cpp4
-rw-r--r--src/declarative/qml/qmlcontext.cpp2
-rw-r--r--src/declarative/qml/qmlcustomparser.cpp1
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp16
-rw-r--r--src/declarative/qml/qmlmetatype.cpp14
-rw-r--r--src/declarative/qml/qmlmetatype.h24
-rw-r--r--src/declarative/qml/qmlprivate.h96
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp13
-rw-r--r--src/declarative/qml/qmlvme.cpp3
-rw-r--r--src/declarative/qml/script/qmlbasicscript.cpp9
-rw-r--r--src/declarative/util/qmlpackage.cpp2
-rw-r--r--src/declarative/util/qmlpackage.h3
30 files changed, 551 insertions, 126 deletions
diff --git a/src/declarative/canvas/monitor/main.cpp b/src/declarative/canvas/monitor/main.cpp
new file mode 100644
index 0000000..f5f40bd
--- /dev/null
+++ b/src/declarative/canvas/monitor/main.cpp
@@ -0,0 +1,287 @@
+#include <QApplication>
+#include <QWidget>
+#include <QPainter>
+#include <QTcpSocket>
+#include <QScrollBar>
+
+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 positionScrollbar();
+ 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);
+
+ QObject::connect(&sb, SIGNAL(valueChanged(int)), this, SLOT(scrollbarChanged(int)));
+}
+
+void QLineGraph::scrollbarChanged(int v)
+{
+ if(ignoreScroll)
+ return;
+
+ position = v;
+ update();
+}
+
+void QLineGraph::positionScrollbar()
+{
+ sb.setFixedWidth(width());
+ sb.move(0, height() - sb.height());
+}
+
+void QLineGraph::resizeEvent(QResizeEvent *e)
+{
+ QWidget::resizeEvent(e);
+ positionScrollbar();
+}
+
+void QLineGraph::showEvent(QShowEvent *e)
+{
+ QWidget::showEvent(e);
+ positionScrollbar();
+}
+
+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::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 MyReader : public QObject
+{
+Q_OBJECT
+public:
+ MyReader(const QString &host, int port);
+
+signals:
+ void sample(int, int, int, int, bool);
+
+private slots:
+ void readyRead();
+
+private:
+ QTcpSocket *socket;
+
+ int la;
+ int lb;
+ int ld;
+};
+
+MyReader::MyReader(const QString &host, int port)
+: socket(0), la(-1)
+{
+ socket = new QTcpSocket(this);
+ QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ socket->connectToHost(host, port);
+ socket->waitForConnected();
+}
+
+void MyReader::readyRead()
+{
+ static int la = -1;
+ static int lb;
+ static int ld;
+
+ if(socket->canReadLine()) {
+ QString line = socket->readLine();
+
+ int a;
+ int b;
+ int c;
+ int d;
+ int isBreak;
+ sscanf(line.toLatin1().constData(), "%d %d %d %d %d", &a, &b, &c, &d, &isBreak);
+
+ if (la != -1)
+ emit sample(c, lb, la, ld, isBreak);
+
+ la = a;
+ lb = b;
+ ld = d;
+ }
+}
+
+int main(int argc, char ** argv)
+{
+ if(argc != 3) {
+ qWarning() << "Usage:" << argv[0] << "host port";
+ return -1;
+ }
+
+ QApplication app(argc, argv);
+
+ MyReader reader(argv[1], atoi(argv[2]));
+
+ QLineGraph graph;
+ QObject::connect(&reader, SIGNAL(sample(int,int,int,int,bool)), &graph, SLOT(addSample(int,int,int,int,bool)));
+ graph.setFixedSize(800, 600);
+ graph.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/src/declarative/canvas/monitor/monitor.pro b/src/declarative/canvas/monitor/monitor.pro
new file mode 100644
index 0000000..e3b0a29
--- /dev/null
+++ b/src/declarative/canvas/monitor/monitor.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += network
+
+# Input
+SOURCES += main.cpp
diff --git a/src/declarative/canvas/qsimplecanvasserver.cpp b/src/declarative/canvas/qsimplecanvasserver.cpp
index 4d4adda..ed781b8 100644
--- a/src/declarative/canvas/qsimplecanvasserver.cpp
+++ b/src/declarative/canvas/qsimplecanvasserver.cpp
@@ -44,17 +44,37 @@
#ifndef Q_OS_WIN32
#include <arpa/inet.h>
#endif
+#include <QtCore/qabstractanimation.h>
QT_BEGIN_NAMESPACE
+class FrameBreakAnimation : public QAbstractAnimation
+{
+public:
+ FrameBreakAnimation(QSimpleCanvasServer *s)
+ : QAbstractAnimation(s), server(s)
+ {
+ start();
+ }
+
+ virtual int duration() const { return -1; }
+ virtual void updateCurrentTime(int msecs) {
+ server->frameBreak();
+ }
+
+private:
+ QSimpleCanvasServer *server;
+};
+
QSimpleCanvasServer::QSimpleCanvasServer(int port, QObject *parent)
-: QObject(parent), _tcpServer(new QTcpServer(this))
+: QObject(parent), _breaks(0), _tcpServer(new QTcpServer(this))
{
QObject::connect(_tcpServer, SIGNAL(newConnection()),
this, SLOT(newConnection()));
_time.start();
+ new FrameBreakAnimation(this);
if (!_tcpServer->listen(QHostAddress::Any, port)) {
qWarning() << "QSimpleCanvasServer: Cannot listen on port" << port;
return;
@@ -80,8 +100,10 @@ void QSimpleCanvasServer::addTiming(quint32 paint,
data[2] = ::htonl(timeBetweenFrames);
*/
+ bool isFrameBreak = _breaks > 1;
+ _breaks = 0;
int e = _time.elapsed();
- QString d = QString::number(paint) + QLatin1String(" ") + QString::number(repaint) + QLatin1String(" ") + QString::number(timeBetweenFrames) + QLatin1String(" ") + QString::number(e) + QLatin1String("\n");
+ QString d = QString::number(paint) + QLatin1String(" ") + QString::number(repaint) + QLatin1String(" ") + QString::number(timeBetweenFrames) + QLatin1String(" ") + QString::number(e) + QLatin1String(" ") + QString::number(isFrameBreak) + QLatin1String("\n");
QByteArray ba = d.toLatin1();
// XXX
@@ -90,6 +112,11 @@ void QSimpleCanvasServer::addTiming(quint32 paint,
_tcpClients.at(ii)->write(ba.constData(), ba.length());
}
+void QSimpleCanvasServer::frameBreak()
+{
+ _breaks++;
+}
+
void QSimpleCanvasServer::disconnected()
{
QTcpSocket *socket = static_cast<QTcpSocket *>(sender());
diff --git a/src/declarative/canvas/qsimplecanvasserver_p.h b/src/declarative/canvas/qsimplecanvasserver_p.h
index 7d53357..ce04e8d 100644
--- a/src/declarative/canvas/qsimplecanvasserver_p.h
+++ b/src/declarative/canvas/qsimplecanvasserver_p.h
@@ -62,6 +62,10 @@ private Q_SLOTS:
void disconnected();
private:
+ friend class FrameBreakAnimation;
+ void frameBreak();
+ int _breaks;
+
QTcpServer *_tcpServer;
QList<QTcpSocket *> _tcpClients;
QTime _time;
diff --git a/src/declarative/debugger/qmlcanvasdebugger.cpp b/src/declarative/debugger/qmlcanvasdebugger.cpp
index fe57bf4..21abd2d 100644
--- a/src/declarative/debugger/qmlcanvasdebugger.cpp
+++ b/src/declarative/debugger/qmlcanvasdebugger.cpp
@@ -76,7 +76,7 @@ QmlCanvasDebugger::QmlCanvasDebugger(QmlWatches *w, QWidget *parent)
QObject::connect(y, SIGNAL(valueChanged(int)), this, SLOT(setY(int)));
hlayout->addWidget(x);
hlayout->addWidget(y);
- QPushButton *pb = new QPushButton("Refresh", this);
+ QPushButton *pb = new QPushButton(tr("Refresh"), this);
QObject::connect(pb, SIGNAL(clicked()), this, SLOT(refresh()));
hlayout->addWidget(pb);
@@ -233,7 +233,7 @@ void QmlCanvasDebugger::setCanvas(QSimpleCanvas *canvas)
return;
QTreeWidgetItem *root = new QmlCanvasDebuggerItem(m_tree);
- root->setText(0, "Root");
+ root->setText(0, tr("Root"));
root->setExpanded(true);
clone(root, m_canvasRoot, m_debugCanvas->root());
}
diff --git a/src/declarative/debugger/qmldebugger.cpp b/src/declarative/debugger/qmldebugger.cpp
index 49ad8d9..0bbcb2c 100644
--- a/src/declarative/debugger/qmldebugger.cpp
+++ b/src/declarative/debugger/qmldebugger.cpp
@@ -85,7 +85,7 @@ QmlDebugger::QmlDebugger(QWidget *parent)
QObject::connect(m_tree, SIGNAL(addWatch(QObject*,QString)), this, SLOT(addWatch(QObject*,QString)));
vlayout->addWidget(m_tree);
- QPushButton *pb = new QPushButton("Refresh", treeWid);
+ QPushButton *pb = new QPushButton(tr("Refresh"), treeWid);
QObject::connect(pb, SIGNAL(clicked()), this, SLOT(refresh()));
vlayout->addWidget(pb);
@@ -93,28 +93,28 @@ QmlDebugger::QmlDebugger(QWidget *parent)
m_text = new QPlainTextEdit(this);
m_text->setReadOnly(true);
- tabs->addTab(m_text, "File");
+ tabs->addTab(m_text, tr("File"));
m_warnings = new QTreeWidget(this);
m_warnings->setHeaderHidden(true);
- tabs->addTab(m_warnings, "Warnings");
+ tabs->addTab(m_warnings, tr("Warnings"));
m_watches = new QmlWatches(this);
m_watchTable = new QTableView(this);
m_watchTable->setSelectionMode(QTableWidget::NoSelection);
m_watchTable->setModel(m_watches);
- tabs->addTab(m_watchTable, "Watches");
+ tabs->addTab(m_watchTable, tr("Watches"));
m_properties = new QmlPropertyView(m_watches, this);
QObject::connect(m_properties, SIGNAL(objectClicked(quint32)),
this, SLOT(highlightObject(quint32)));
- tabs->addTab(m_properties, "Properties");
+ tabs->addTab(m_properties, tr("Properties"));
tabs->setCurrentWidget(m_properties);
m_canvas = new QmlCanvasDebugger(m_watches, this);
QObject::connect(m_canvas, SIGNAL(objectClicked(quint32)),
this, SLOT(highlightObject(quint32)));
- tabs->addTab(m_canvas, "Canvas");
+ tabs->addTab(m_canvas, tr("Canvas"));
splitter->addWidget(tabs);
splitter->setStretchFactor(1, 2);
@@ -229,7 +229,7 @@ bool QmlDebugger::makeItem(QObject *obj, QmlDebuggerItem *item)
if(QmlBindableValue *bv = qobject_cast<QmlBindableValue *>(obj)) {
QmlExpressionPrivate *p = bv->d;
- text = bv->property().name() + ": " + bv->expression();
+ text = bv->property().name() + QLatin1String(": ") + bv->expression();
item->setForeground(0, Qt::green);
item->bindableValue = bv;
@@ -281,13 +281,13 @@ bool QmlDebugger::makeItem(QObject *obj, QmlDebuggerItem *item)
QString toolTipString;
if(!p->url.toString().isEmpty()) {
item->url = p->url;
- toolTipString = "URL: " + p->url.toString();
+ toolTipString = QLatin1String("URL: ") + p->url.toString();
}
if(!p->typeName.isEmpty()) {
if(!toolTipString.isEmpty())
- toolTipString.prepend("\n");
- toolTipString.prepend("Root type: " + text);
+ toolTipString.prepend(QLatin1Char('\n'));
+ toolTipString.prepend(tr("Root type: ") + text);
text = p->typeName;
}
diff --git a/src/declarative/debugger/qmlobjecttree.cpp b/src/declarative/debugger/qmlobjecttree.cpp
index fb6825a..27dc000 100644
--- a/src/declarative/debugger/qmlobjecttree.cpp
+++ b/src/declarative/debugger/qmlobjecttree.cpp
@@ -57,7 +57,7 @@ void QmlObjectTree::mousePressEvent(QMouseEvent *me)
{
QTreeWidget::mousePressEvent(me);
if(me->button() == Qt::RightButton && me->type() == QEvent::MouseButtonPress) {
- QAction action("Add watch...", 0);
+ QAction action(tr("Add watch..."), 0);
QList<QAction *> actions;
actions << &action;
QmlDebuggerItem *item = static_cast<QmlDebuggerItem *>(currentItem());
@@ -65,7 +65,7 @@ void QmlObjectTree::mousePressEvent(QMouseEvent *me)
QMenu::exec(actions, me->globalPos())) {
bool ok = false;
- QString watch = QInputDialog::getText(this, "Watch expression", "Expression:", QLineEdit::Normal, QString(), &ok);
+ QString watch = QInputDialog::getText(this, tr("Watch expression"), tr("Expression:"), QLineEdit::Normal, QString(), &ok);
if(ok && !watch.isEmpty())
emit addWatch(item->object, watch);
diff --git a/src/declarative/debugger/qmlpropertyview.cpp b/src/declarative/debugger/qmlpropertyview.cpp
index e32393c..0d34fd9 100644
--- a/src/declarative/debugger/qmlpropertyview.cpp
+++ b/src/declarative/debugger/qmlpropertyview.cpp
@@ -56,7 +56,7 @@ QmlPropertyView::QmlPropertyView(QmlWatches *watches, QWidget *parent)
setLayout(layout);
m_tree = new QTreeWidget(this);
- m_tree->setHeaderLabels(QStringList() << "Property" << "Value");
+ m_tree->setHeaderLabels(QStringList() << tr("Property") << tr("Value"));
QObject::connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
this, SLOT(itemDoubleClicked(QTreeWidgetItem *)));
QObject::connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp
index 235511f..681a9fa 100644
--- a/src/declarative/fx/qfxanchors.cpp
+++ b/src/declarative/fx/qfxanchors.cpp
@@ -146,6 +146,7 @@ QFxAnchors::~QFxAnchors()
d->remDepend(d->bottom.item);
d->remDepend(d->vCenter.item);
d->remDepend(d->hCenter.item);
+ d->remDepend(d->baseline.item);
}
void QFxAnchorsPrivate::fillChanged()
@@ -210,6 +211,10 @@ void QFxAnchorsPrivate::clearItem(QFxItem *item)
hCenter.item = 0;
usedAnchors &= ~QFxAnchors::HasHCenterAnchor;
}
+ if (baseline.item == item) {
+ baseline.item = 0;
+ usedAnchors &= ~QFxAnchors::HasBaselineAnchor;
+ }
}
void QFxAnchorsPrivate::addDepend(QFxItem *item)
@@ -430,8 +435,6 @@ void QFxAnchorsPrivate::updateVerticalAnchors()
} else if (bottom.item->itemParent() == item->itemParent()) {
setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin);
}
-
-
} else if (usedAnchors & QFxAnchors::HasVCenterAnchor) {
//(stetching handled above)
@@ -442,6 +445,11 @@ void QFxAnchorsPrivate::updateVerticalAnchors()
} else if (vCenter.item->itemParent() == item->itemParent()) {
setItemY(position(vCenter.item, vCenter.anchorLine) - item->height()/2 + vCenterOffset);
}
+ } else if (usedAnchors & QFxAnchors::HasBaselineAnchor) {
+ //Handle baseline
+ if (baseline.item->itemParent() == item->itemParent()) {
+ setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset());
+ }
}
updatingVerticalAnchor = false;
} else {
@@ -599,6 +607,36 @@ void QFxAnchors::resetVerticalCenter()
setVerticalCenter(QFxAnchorLine());
}
+QFxAnchorLine QFxAnchors::baseline() const
+{
+ Q_D(const QFxAnchors);
+ return d->baseline;
+}
+
+void QFxAnchors::setBaseline(const QFxAnchorLine &edge)
+{
+ Q_D(QFxAnchors);
+ if (!d->checkVAnchorValid(edge))
+ return;
+
+ if (edge.item)
+ d->usedAnchors |= HasBaselineAnchor;
+ else
+ d->usedAnchors &= ~HasBaselineAnchor;
+
+ d->checkVValid();
+
+ d->remDepend(d->baseline.item);
+ d->baseline = edge;
+ d->addDepend(d->baseline.item);
+ d->updateVerticalAnchors();
+}
+
+void QFxAnchors::resetBaseline()
+{
+ setBaseline(QFxAnchorLine());
+}
+
QFxAnchorLine QFxAnchors::left() const
{
Q_D(const QFxAnchors);
@@ -797,7 +835,7 @@ bool QFxAnchorsPrivate::checkHValid() const
if (usedAnchors & QFxAnchors::HasLeftAnchor &&
usedAnchors & QFxAnchors::HasRightAnchor &&
usedAnchors & QFxAnchors::HasHCenterAnchor) {
- qmlInfo(item) << "Can't specify left, right, and hcenter anchors";
+ qmlInfo(item) << "Can't specify left, right, and hcenter anchors.";
return false;
}
@@ -822,7 +860,13 @@ bool QFxAnchorsPrivate::checkVValid() const
if (usedAnchors & QFxAnchors::HasTopAnchor &&
usedAnchors & QFxAnchors::HasBottomAnchor &&
usedAnchors & QFxAnchors::HasVCenterAnchor) {
- qmlInfo(item) << "Can't specify top, bottom, and vcenter anchors";
+ qmlInfo(item) << "Can't specify top, bottom, and vcenter anchors.";
+ return false;
+ } else if (usedAnchors & QFxAnchors::HasBaselineAnchor &&
+ (usedAnchors & QFxAnchors::HasTopAnchor ||
+ usedAnchors & QFxAnchors::HasBottomAnchor ||
+ usedAnchors & QFxAnchors::HasVCenterAnchor)) {
+ qmlInfo(item) << "Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors.";
return false;
}
diff --git a/src/declarative/fx/qfxanchors.h b/src/declarative/fx/qfxanchors.h
index 9d776ab..3f142c4 100644
--- a/src/declarative/fx/qfxanchors.h
+++ b/src/declarative/fx/qfxanchors.h
@@ -91,6 +91,7 @@ class Q_DECLARATIVE_EXPORT QFxAnchors : public QObject
Q_PROPERTY(QFxAnchorLine top READ top WRITE setTop RESET resetTop);
Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom);
Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter);
+ Q_PROPERTY(QFxAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline);
Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged);
Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged);
Q_PROPERTY(int horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged());
@@ -141,6 +142,10 @@ public:
void setVerticalCenter(const QFxAnchorLine &edge);
void resetVerticalCenter();
+ QFxAnchorLine baseline() const;
+ void setBaseline(const QFxAnchorLine &edge);
+ void resetBaseline();
+
int leftMargin() const;
void setLeftMargin(int);
diff --git a/src/declarative/fx/qfxanchors_p.h b/src/declarative/fx/qfxanchors_p.h
index b90380a..32d8b75 100644
--- a/src/declarative/fx/qfxanchors_p.h
+++ b/src/declarative/fx/qfxanchors_p.h
@@ -117,6 +117,7 @@ public:
QFxAnchorLine bottom;
QFxAnchorLine vCenter;
QFxAnchorLine hCenter;
+ QFxAnchorLine baseline;
int leftMargin;
int rightMargin;
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 17fe36a..3e29f13 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -261,24 +261,10 @@ void QFxContents::setItem(QFxItem *item)
*/
/*!
- \fn void QFxItem::baselineChanged()
-
- This signal is emitted when the baseline of the item changes.
-
- The baseline may change in response to a change to the baselineOffset
- property or due to the geometry of the item changing.
-*/
-
-/*!
\fn void QFxItem::baselineOffsetChanged()
- This signal is emitted when the baseline of the item is changed
- via the baselineOffset property.
-
- The baseline corresponds to the baseline of the text contained in
- the item. It is useful for aligning the text in items placed
- beside each other. The default baseline is positioned at
- 2/3 of the height of the item.
+ This signal is emitted when the baseline offset of the item
+ is changed.
*/
/*!
@@ -288,24 +274,12 @@ void QFxContents::setItem(QFxItem *item)
*/
/*!
- \fn void QFxItem::rightChanged()
-
- This signal is emitted when the right coordinate of the item changes.
-*/
-
-/*!
\fn void QFxItem::topChanged()
This signal is emitted when the top coordinate of the item changes.
*/
/*!
- \fn void QFxItem::bottomChanged()
-
- This signal is emitted when the bottom coordinate of the item changes.
-*/
-
-/*!
\fn void QFxItem::widthChanged()
This signal is emitted when the width of the item changes.
@@ -1284,6 +1258,15 @@ QFxAnchorLine QFxItem::verticalCenter() const
}
/*!
+ \internal
+*/
+QFxAnchorLine QFxItem::baseline() const
+{
+ Q_D(const QFxItem);
+ return d->anchorLines()->baseline;
+}
+
+/*!
\property QFxItem::top
One of the anchor lines of the item.
@@ -1338,6 +1321,7 @@ QFxAnchorLine QFxItem::verticalCenter() const
\qmlproperty AnchorLine Item::right
\qmlproperty AnchorLine Item::horizontalCenter
\qmlproperty AnchorLine Item::verticalCenter
+ \qmlproperty AnchorLine Item::baseline
The anchor lines of the item.
@@ -1351,6 +1335,7 @@ QFxAnchorLine QFxItem::verticalCenter() const
\qmlproperty AnchorLine Item::anchors.right
\qmlproperty AnchorLine Item::anchors.horizontalCenter
\qmlproperty AnchorLine Item::anchors.verticalCenter
+ \qmlproperty AnchorLine Item::anchors.baseline
\qmlproperty Item Item::anchors.fill
@@ -1410,20 +1395,19 @@ QFxAnchorLine QFxItem::verticalCenter() const
/*!
\property QFxItem::baselineOffset
- \brief The position of the item's baseline in global (scene) coordinates.
+ \brief The position of the item's baseline in local coordinates.
The baseline of a Text item is the imaginary line on which the text
sits. Controls containing text usually set their baseline to the
baseline of their text.
- For non-text items, a default baseline offset of two-thirds of the
- item's height is used to determine the baseline.
+ For non-text items, a default baseline offset of 0 is used.
*/
int QFxItem::baselineOffset() const
{
Q_D(const QFxItem);
if (!d->_baselineOffset.isValid()) {
- return height()*2/3; //### default baseline is 2/3 of the way to the bottom of the item
+ return 0;
} else
return d->_baselineOffset;
}
@@ -1439,6 +1423,11 @@ void QFxItem::setBaselineOffset(int offset)
d->_baselineOffset = offset;
emit baselineOffsetChanged();
+
+ for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) {
+ QFxAnchors *anchor = d->dependantAnchors.at(ii);
+ anchor->d_func()->updateVerticalAnchors();
+ }
}
/*!
@@ -1674,6 +1663,7 @@ void QFxItem::setKeepMouseGrab(bool keep)
*/
void QFxItem::activeFocusChanged(bool flag)
{
+ Q_UNUSED(flag);
emit activeFocusChanged();
}
@@ -1683,6 +1673,7 @@ void QFxItem::activeFocusChanged(bool flag)
*/
void QFxItem::focusChanged(bool flag)
{
+ Q_UNUSED(flag);
emit focusChanged();
}
@@ -2102,6 +2093,8 @@ QFxItemPrivate::AnchorLines::AnchorLines(QFxItem *q)
bottom.anchorLine = QFxAnchorLine::Bottom;
vCenter.item = q;
vCenter.anchorLine = QFxAnchorLine::VCenter;
+ baseline.item = q;
+ baseline.anchorLine = QFxAnchorLine::Baseline;
}
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index d34a9fb..0b4f897 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -127,6 +127,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserS
Q_PROPERTY(QFxAnchorLine top READ top)
Q_PROPERTY(QFxAnchorLine bottom READ bottom)
Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter)
+ Q_PROPERTY(QFxAnchorLine baseline READ baseline)
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
@@ -258,6 +259,7 @@ private:
QFxAnchorLine top() const;
QFxAnchorLine bottom() const;
QFxAnchorLine verticalCenter() const;
+ QFxAnchorLine baseline() const;
void init(QFxItem *parent);
friend class QmlStatePrivate;
diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h
index 85ce171..b5f9554 100644
--- a/src/declarative/fx/qfxitem_p.h
+++ b/src/declarative/fx/qfxitem_p.h
@@ -157,6 +157,7 @@ public:
QFxAnchorLine top;
QFxAnchorLine bottom;
QFxAnchorLine vCenter;
+ QFxAnchorLine baseline;
};
mutable AnchorLines *_anchorLines;
AnchorLines *anchorLines() const {
diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp
index e315547..3f2e77a 100644
--- a/src/declarative/fx/qfxpathview.cpp
+++ b/src/declarative/fx/qfxpathview.cpp
@@ -744,6 +744,7 @@ void QFxPathView::createdItem(int index, QFxItem *item)
void QFxPathView::destroyingItem(QFxItem *item)
{
+ Q_UNUSED(item);
}
void QFxPathView::ticked()
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp
index e84255d..315b451 100644
--- a/src/declarative/fx/qfxtext.cpp
+++ b/src/declarative/fx/qfxtext.cpp
@@ -571,7 +571,6 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout)
QFont f; if (_font) f = _font->font();
QFontMetrics fm = QFontMetrics(f);
- int leading = fm.leading();
int height = 0;
qreal widthUsed = 0;
qreal lineWidth = 0;
@@ -592,9 +591,6 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout)
}
layout->endLayout();
- if (layout->lineCount() == 1)
- height -= leading;
-
for (int i = 0; i < layout->lineCount(); ++i) {
QTextLine line = layout->lineAt(i);
widthUsed = qMax(widthUsed, line.naturalTextWidth());
@@ -607,7 +603,6 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout)
QImage QFxTextPrivate::wrappedTextImage(bool drawStyle)
{
//do layout
- Q_Q(const QFxText);
QFont f; if (_font) f = _font->font();
QSize size = cachedLayoutSize;
diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp
index b9ddcb9..039998a 100644
--- a/src/declarative/fx/qfxvisualitemmodel.cpp
+++ b/src/declarative/fx/qfxvisualitemmodel.cpp
@@ -621,7 +621,7 @@ QVariant QFxVisualItemModel::evaluate(int index, const QString &expression, QObj
int QFxVisualItemModel::indexOf(QFxItem *item, QObject *objectContext) const
{
- QmlExpression e(qmlContext(item), "index", objectContext);
+ QmlExpression e(qmlContext(item), QLatin1String("index"), objectContext);
e.setTrackChange(false);
QVariant value = e.value();
if (value.isValid())
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 8990732..5f92721 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -862,6 +862,10 @@ bool QmlCompiler::compileProperty(Property *prop, Object *obj, int ctxt)
prop->type = t;
}
}
+ } else if(isAttachedProperty(prop->name) && prop->value) {
+ QmlType *type = QmlMetaType::qmlType(prop->name);
+ if (type && type->attachedPropertiesType())
+ prop->value->metatype = type->attachedPropertiesType();
}
if (prop->name == "id") {
diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp
index e1124a6..0da1a92 100644
--- a/src/declarative/qml/qmlcompositetypemanager.cpp
+++ b/src/declarative/qml/qmlcompositetypemanager.cpp
@@ -315,7 +315,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
continue;
}
- QUrl url = engine->componentUrl(QUrl(type + ".qml"), QUrl(unit->url));
+ QUrl url = engine->componentUrl(QUrl(QLatin1String(type + ".qml")), QUrl(unit->url));
QmlCompositeTypeData *urlUnit = components.value(url.toString());
if (!urlUnit) {
@@ -335,7 +335,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
{
QmlError error;
error.setUrl(unit->url);
- error.setDescription("Type " + type + " unavailable");
+ error.setDescription(tr("Type %1 unavailable").arg(QLatin1String(type)));
unit->errors << error;
}
if (urlUnit->errorType != QmlCompositeTypeData::AccessError)
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp
index ea72ebf..e5016f2 100644
--- a/src/declarative/qml/qmlcontext.cpp
+++ b/src/declarative/qml/qmlcontext.cpp
@@ -73,8 +73,6 @@ void QmlContextPrivate::dump(int depth)
void QmlContextPrivate::destroyed(QObject *obj)
{
- Q_Q(QmlContext);
-
defaultObjects.removeAll(obj);
QVariant variantObject = QVariant::fromValue(obj);
diff --git a/src/declarative/qml/qmlcustomparser.cpp b/src/declarative/qml/qmlcustomparser.cpp
index a60f783..2e8c8f6 100644
--- a/src/declarative/qml/qmlcustomparser.cpp
+++ b/src/declarative/qml/qmlcustomparser.cpp
@@ -224,6 +224,7 @@ QList<QVariant> QmlCustomParserProperty::assignedValues() const
QByteArray QmlCustomParser::compile(const QList<QmlCustomParserProperty> &, bool *ok)
{
+ Q_UNUSED(ok);
return QByteArray();
}
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index e3e9ff5..3aa4f1d 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -730,19 +730,19 @@ void QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value)
switch(t) {
case QVariant::Double:
{
- qreal r;
+ double d;
bool found = true;
if (vt == QVariant::Int) {
- r = value.toInt();
+ d = value.toInt();
} else if (vt == QVariant::UInt) {
- r = value.toUInt();
+ d = value.toUInt();
} else {
found = false;
}
if (found) {
void *a[1];
- a[0] = &r;
+ a[0] = &d;
QMetaObject::metacall(object,
QMetaObject::WriteProperty,
coreIdx, a);
@@ -906,19 +906,19 @@ void QmlMetaProperty::write(const QVariant &value) const
switch(t) {
case QVariant::Double:
{
- qreal r;
+ double dd;
bool found = true;
if (vt == QVariant::Int) {
- r = value.toInt();
+ dd = value.toInt();
} else if (vt == QVariant::UInt) {
- r = value.toUInt();
+ dd = value.toUInt();
} else {
found = false;
}
if (found) {
void *a[1];
- a[0] = &r;
+ a[0] = &dd;
QMetaObject::metacall(object(),
QMetaObject::WriteProperty,
d->coreIdx, a);
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index 2e490a4..6d44f7a 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -112,6 +112,7 @@ public:
QmlPrivate::Func m_opFunc;
const QMetaObject *m_baseMetaObject;
QmlAttachedPropertiesFunc m_attachedPropertiesFunc;
+ const QMetaObject *m_attachedPropertiesType;
int m_parserStatusCast;
QmlPrivate::CreateFunc m_extFunc;
const QMetaObject *m_extMetaObject;
@@ -124,7 +125,7 @@ public:
QmlTypePrivate::QmlTypePrivate()
: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0),
- m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0),
+ m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
m_parserStatusCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1),
m_customParser(0), m_isSetup(false)
{
@@ -149,6 +150,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
QmlPrivate::Func opFunc, const char *qmlName,
const QMetaObject *metaObject,
QmlAttachedPropertiesFunc attachedPropertiesFunc,
+ const QMetaObject *attachedType,
int parserStatusCast, QmlPrivate::CreateFunc extFunc,
const QMetaObject *extMetaObject, int index,
QmlCustomParser *customParser)
@@ -161,6 +163,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
d->m_opFunc = opFunc;
d->m_baseMetaObject = metaObject;
d->m_attachedPropertiesFunc = attachedPropertiesFunc;
+ d->m_attachedPropertiesType = attachedType;
d->m_parserStatusCast = parserStatusCast;
d->m_extFunc = extFunc;
d->m_index = index;
@@ -348,6 +351,11 @@ QmlAttachedPropertiesFunc QmlType::attachedPropertiesFunction() const
return d->m_attachedPropertiesFunc;
}
+const QMetaObject *QmlType::attachedPropertiesType() const
+{
+ return d->m_attachedPropertiesType;
+}
+
int QmlType::parserStatusCast() const
{
return d->m_parserStatusCast;
@@ -404,7 +412,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id,
return index;
}
-int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
+int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, const QMetaObject *attachMo, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
{
Q_UNUSED(object);
QWriteLocker lock(metaTypeDataLock());
@@ -421,7 +429,7 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun
int index = data->types.count();
QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId,
- func, cname, mo, attach, pStatus, extFunc,
+ func, cname, mo, attach, attachMo, pStatus, extFunc,
extmo, index, parser);
data->types.append(type);
diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h
index cc3887c..d10a0f0 100644
--- a/src/declarative/qml/qmlmetatype.h
+++ b/src/declarative/qml/qmlmetatype.h
@@ -59,7 +59,7 @@ class QmlCustomParser;
class Q_DECLARATIVE_EXPORT QmlMetaType
{
public:
- static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
+ static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *);
static bool copy(int type, void *data, const void *copy = 0);
@@ -136,6 +136,7 @@ public:
const QMetaObject *baseMetaObject() const;
QmlAttachedPropertiesFunc attachedPropertiesFunction() const;
+ const QMetaObject *attachedPropertiesType() const;
int parserStatusCast() const;
QVariant fromObject(QObject *) const;
@@ -146,7 +147,7 @@ private:
friend class QmlMetaType;
friend class QmlTypePrivate;
QmlType(int, int, int, QmlPrivate::Func, const char *, int);
- QmlType(int, int, int, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
+ QmlType(int, int, int, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
~QmlType();
QmlTypePrivate *d;
@@ -165,6 +166,7 @@ int qmlRegisterType(const char *typeName)
return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, 0);
@@ -183,6 +185,7 @@ int qmlRegisterType(const char *qmlName, const char *typeName)
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, 0);
@@ -200,11 +203,15 @@ int qmlRegisterExtendedType(const char *typeName)
QmlAttachedPropertiesFunc attached =
QmlPrivate::attachedPropertiesFunc<E>();
- if (!attached)
+ const QMetaObject * attachedMo =
+ QmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
attached = QmlPrivate::attachedPropertiesFunc<T>();
+ attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
+ }
return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0,
- &T::staticMetaObject, attached,
+ &T::staticMetaObject, attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
&QmlPrivate::CreateParent<E>::create, &E::staticMetaObject, 0);
@@ -222,13 +229,17 @@ int qmlRegisterExtendedType(const char *qmlName, const char *typeName)
QmlAttachedPropertiesFunc attached =
QmlPrivate::attachedPropertiesFunc<E>();
- if (!attached)
+ const QMetaObject * attachedMo =
+ QmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
attached = QmlPrivate::attachedPropertiesFunc<T>();
+ attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
+ }
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
qmlName,
&T::staticMetaObject,
- attached,
+ attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
&QmlPrivate::CreateParent<E>::create,
@@ -263,6 +274,7 @@ int qmlRegisterCustomType(const char *qmlName, const char *typeName, QmlCustomPa
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, parser);
diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h
index 590e0c0..2a9c503 100644
--- a/src/declarative/qml/qmlprivate.h
+++ b/src/declarative/qml/qmlprivate.h
@@ -123,57 +123,81 @@ namespace QmlPrivate
}
};
- template<typename T, int N>
- struct AttachedPropertySelector
- {
- static inline QmlAttachedPropertiesFunc func()
- {
- return 0;
- }
- };
- template<typename T>
- struct AttachedPropertySelector<T, 1>
- {
- static inline QmlAttachedPropertiesFunc func()
- {
- return &T::qmlAttachedProperties;
- }
- };
-
- template < typename T >
- class has_attachedProperties {
+ template <typename T>
+ class has_attachedPropertiesMember
+ {
typedef int yes_type;
typedef char no_type;
+ template <int>
+ struct Selector {};
- template<typename S, QObject *(S::*)(QObject *)>
- struct dummy {};
-
- template<typename S, QObject *(S::*)(QObject *) const>
- struct dummy_const {};
-
- template<typename S, QObject *(*) (QObject *)>
- struct dummy_static {};
+ template <typename S>
+ static yes_type test(Selector<sizeof(&S::qmlAttachedProperties)>*);
- template<typename S>
- static no_type check(dummy<S, &S::qmlAttachedProperties> *);
+ template <typename S>
+ static no_type test(...);
- template<typename S>
- static no_type check(dummy_const<S, &S::qmlAttachedProperties> *);
+ public:
+ static bool const value = sizeof(test<T>(0)) == sizeof(yes_type);
+ };
- template<typename S>
- static yes_type check(dummy_static<S, &S::qmlAttachedProperties> *);
+ template <typename T, bool hasMember>
+ class has_attachedPropertiesMethod
+ {
+ typedef int yes_type;
+ typedef char no_type;
- template<typename S>
+ template<typename ReturnType>
+ static yes_type check(ReturnType *(*)(QObject *));
static no_type check(...);
public:
- static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
+ static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
};
+ template <typename T>
+ class has_attachedPropertiesMethod<T, false>
+ {
+ public:
+ static bool const value = false;
+ };
+
+ template<typename T, int N>
+ class AttachedPropertySelector
+ {
+ public:
+ static inline QmlAttachedPropertiesFunc func() { return 0; }
+ static inline const QMetaObject *metaObject() { return 0; }
+ };
+ template<typename T>
+ class AttachedPropertySelector<T, 1>
+ {
+ static inline QObject *attachedProperties(QObject *obj) {
+ return T::qmlAttachedProperties(obj);
+ }
+ template<typename ReturnType>
+ static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
+ return &ReturnType::staticMetaObject;
+ }
+ public:
+ static inline QmlAttachedPropertiesFunc func() {
+ return &attachedProperties;
+ }
+ static inline const QMetaObject *metaObject() {
+ return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
+ }
+ };
+
template<typename T>
inline QmlAttachedPropertiesFunc attachedPropertiesFunc()
{
- return AttachedPropertySelector<T, has_attachedProperties<T>::value>::func();
+ return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
+ }
+
+ template<typename T>
+ inline const QMetaObject *attachedPropertiesMetaObject()
+ {
+ return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
}
struct MetaTypeIds {
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 01600b9..5b3564f 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -10,6 +10,7 @@
#include "parser/javascriptast_p.h"
#include <QStack>
+#include <QCoreApplication>
#include <QtDebug>
#include <qfxperf.h>
@@ -207,8 +208,8 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName,
{
int lastTypeDot = objectType.lastIndexOf(QLatin1Char('.'));
bool isType = !objectType.isEmpty() &&
- (objectType.at(0).isUpper() |
- lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper());
+ (objectType.at(0).isUpper() ||
+ (lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper()));
int propertyCount = 0;
for (; propertyName; propertyName = propertyName->next){
@@ -221,7 +222,7 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName,
if(propertyCount || !currentObject()) {
QmlError error;
- error.setDescription("Expected type name");
+ error.setDescription(QCoreApplication::translate("QmlParser","Expected type name"));
error.setLine(typeLocation.startLine);
error.setColumn(typeLocation.startColumn);
_parser->_errors << error;
@@ -427,7 +428,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
if(!typeFound) {
QmlError error;
- error.setDescription("Expected property type");
+ error.setDescription(QCoreApplication::translate("QmlParser","Expected property type"));
error.setLine(node->typeToken.startLine);
error.setColumn(node->typeToken.startColumn);
_parser->_errors << error;
@@ -573,7 +574,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
if(funDecl->formals) {
QmlError error;
- error.setDescription("Slot declarations must be parameterless");
+ error.setDescription(QCoreApplication::translate("QmlParser","Slot declarations must be parameterless"));
error.setLine(funDecl->lparenToken.startLine);
error.setColumn(funDecl->lparenToken.startColumn);
_parser->_errors << error;
@@ -587,7 +588,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
obj->dynamicSlots << slot;
} else {
QmlError error;
- error.setDescription("JavaScript declaration outside Script element");
+ error.setDescription(QCoreApplication::translate("QmlParser","JavaScript declaration outside Script element"));
error.setLine(node->firstSourceLocation().startLine);
error.setColumn(node->firstSourceLocation().startColumn);
_parser->_errors << error;
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 1552cb5..a5cc649 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -1017,7 +1017,8 @@ void QmlVME::runStoreInstruction(QStack<QObject *> &stack,
QFxCompilerTimer<QFxCompiler::InstrStoreReal> cc;
#endif
QObject *target = stack.top();
- qreal r = instr.storeReal.value;
+ //### moc treats qreal properties as having type double
+ double r = static_cast<double>(instr.storeReal.value);
void *a[1];
a[0] = &r;
QMetaObject::metacall(target, QMetaObject::WriteProperty,
diff --git a/src/declarative/qml/script/qmlbasicscript.cpp b/src/declarative/qml/script/qmlbasicscript.cpp
index e0a668a..37a6678 100644
--- a/src/declarative/qml/script/qmlbasicscript.cpp
+++ b/src/declarative/qml/script/qmlbasicscript.cpp
@@ -139,9 +139,16 @@ static QVariant fetch_value(QObject *o, int idx, int type)
}
break;
case 135:
+ {
+ float val;
+ void *args[] = { &val, 0 };
+ QMetaObject::metacall(o, QMetaObject::ReadProperty, idx, args);
+ return QVariant(val);
+ }
+ break;
case QVariant::Double:
{
- qreal val;
+ double val;
void *args[] = { &val, 0 };
QMetaObject::metacall(o, QMetaObject::ReadProperty, idx, args);
return QVariant(val);
diff --git a/src/declarative/util/qmlpackage.cpp b/src/declarative/util/qmlpackage.cpp
index bfad44c..107bcdb 100644
--- a/src/declarative/util/qmlpackage.cpp
+++ b/src/declarative/util/qmlpackage.cpp
@@ -142,7 +142,7 @@ QObject *QmlPackage::part(const QString &name)
return 0;
}
-QObject *QmlPackage::qmlAttachedProperties(QObject *o)
+QmlPackageAttached *QmlPackage::qmlAttachedProperties(QObject *o)
{
return new QmlPackageAttached(o);
}
diff --git a/src/declarative/util/qmlpackage.h b/src/declarative/util/qmlpackage.h
index 3861890..f4167fd 100644
--- a/src/declarative/util/qmlpackage.h
+++ b/src/declarative/util/qmlpackage.h
@@ -57,6 +57,7 @@ QT_MODULE(Declarative)
*****************************************************************************/
class QmlPackagePrivate;
+class QmlPackageAttached;
class QmlPackage : public QObject
{
Q_OBJECT
@@ -74,7 +75,7 @@ public:
QObject *part(const QString & = QString());
bool hasPart(const QString &);
- static QObject *qmlAttachedProperties(QObject *);
+ static QmlPackageAttached *qmlAttachedProperties(QObject *);
};
QML_DECLARE_TYPE(QmlPackage);