summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-07-08 06:38:29 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-07-08 06:38:29 (GMT)
commit4c916bd688bc9e20d75359f12208eb8a33dc6670 (patch)
tree190fb084f69128f6a1a788524cda21079f29cc6a /src
parent239c3581bb84b6484547918fbb1672fed08970dd (diff)
parent46688b1e8b953f9e3a12d42b9aa73a8eba904f5b (diff)
downloadQt-4c916bd688bc9e20d75359f12208eb8a33dc6670.zip
Qt-4c916bd688bc9e20d75359f12208eb8a33dc6670.tar.gz
Qt-4c916bd688bc9e20d75359f12208eb8a33dc6670.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/corelib/animation/qvariantanimation.cpp2
-rw-r--r--src/corelib/kernel/qmetaobjectbuilder.cpp4
-rw-r--r--src/corelib/kernel/qobject.cpp77
-rw-r--r--src/corelib/kernel/qobject_p.h2
-rw-r--r--src/corelib/kernel/qobjectdefs.h3
-rw-r--r--src/declarative/debugger/qpacketprotocol.cpp5
-rw-r--r--src/declarative/fx/qfxtext.cpp75
-rw-r--r--src/declarative/fx/qfxtext.h8
-rw-r--r--src/declarative/fx/qfxtext_p.h4
-rw-r--r--src/declarative/fx/qfxtextedit.cpp23
-rw-r--r--src/declarative/fx/qfxtextedit.h4
-rw-r--r--src/declarative/fx/qfxvisualitemmodel.h2
-rw-r--r--src/declarative/qml/qml.h6
-rw-r--r--src/declarative/qml/qmlcomponent.cpp28
-rw-r--r--src/declarative/qml/qmlcomponent.h5
-rw-r--r--src/declarative/qml/qmlengine.cpp94
-rw-r--r--src/declarative/qml/qmlengine.h5
-rw-r--r--src/declarative/qml/qmlengine_p.h2
-rw-r--r--src/declarative/util/qmlanimation.cpp29
-rw-r--r--src/declarative/util/qmlanimation_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp8
22 files changed, 312 insertions, 78 deletions
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
index c5c805f..d166869 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -267,7 +267,7 @@ void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress)
localProgress);
qSwap(currentValue, ret);
q->updateCurrentValue(currentValue);
- if ((connectedSignals & changedSignalMask) && currentValue != ret) {
+ if ((connectedSignals[0] & changedSignalMask) && currentValue != ret) {
//the value has changed
emit q->valueChanged(currentValue);
}
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp
index d4891ff..8775c5c 100644
--- a/src/corelib/kernel/qmetaobjectbuilder.cpp
+++ b/src/corelib/kernel/qmetaobjectbuilder.cpp
@@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QMetaObjectBuilder
+ \internal
\brief The QMetaObjectBuilder class supports building QMetaObject objects at runtime.
*/
@@ -1725,6 +1726,7 @@ void QMetaObjectBuilder::deserialize
/*!
\class QMetaMethodBuilder
+ \internal
\brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder.
*/
@@ -1921,6 +1923,7 @@ void QMetaMethodBuilder::setAttributes(int value)
/*!
\class QMetaPropertyBuilder
+ \internal
\brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder.
*/
@@ -2340,6 +2343,7 @@ void QMetaPropertyBuilder::setDynamic(bool value)
/*!
\class QMetaEnumBuilder
+ \internal
\brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder.
*/
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index d53ca7d..724ebca 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -139,7 +139,8 @@ QObjectPrivate::QObjectPrivate(int version)
receiveChildEvents = true;
postedEvents = 0;
extraData = 0;
- connectedSignals = 0;
+ for (uint i = 0; i < (sizeof connectedSignals / sizeof connectedSignals[0]); ++i)
+ connectedSignals[i] = 0;
inEventHandler = false;
inThreadChangeEvent = false;
deleteWatch = 0;
@@ -2831,10 +2832,16 @@ bool QMetaObject::connect(const QObject *sender, int signal_index,
s->d_func()->addConnection(signal_index, c);
- if (signal_index < 0)
- sender->d_func()->connectedSignals = ~0u;
- else if (signal_index < 32)
- sender->d_func()->connectedSignals |= (1 << signal_index);
+ if (signal_index < 0) {
+ for (uint i = 0; i < (sizeof sender->d_func()->connectedSignals
+ / sizeof sender->d_func()->connectedSignals[0] ); ++i)
+ sender->d_func()->connectedSignals[i] = ~0u;
+ } else if (signal_index < (int)sizeof sender->d_func()->connectedSignals * 8) {
+ uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0]));
+ sender->d_func()->connectedSignals[n] |= (1 << (signal_index - n * 8
+ * sizeof sender->d_func()->connectedSignals[0]));
+ }
+
return true;
}
@@ -3174,11 +3181,12 @@ void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal
*/
void QMetaObject::activate(QObject *sender, int signal_index, void **argv)
{
- if (signal_index < 32
+ if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8
&& !qt_signal_spy_callback_set.signal_begin_callback
&& !qt_signal_spy_callback_set.signal_end_callback) {
- uint signal_mask = 1 << signal_index;
- if ((sender->d_func()->connectedSignals & signal_mask) == 0)
+ uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0]));
+ uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]);
+ if ((sender->d_func()->connectedSignals[n] & m) == 0)
// nothing connected to these signals, and no spy
return;
}
@@ -3191,11 +3199,12 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign
void **argv)
{
int signal_index = m->methodOffset() + local_signal_index;
- if (signal_index < 32
+ if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8
&& !qt_signal_spy_callback_set.signal_begin_callback
&& !qt_signal_spy_callback_set.signal_end_callback) {
- uint signal_mask = 1 << signal_index;
- if ((sender->d_func()->connectedSignals & signal_mask) == 0)
+ uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0]));
+ uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]);
+ if ((sender->d_func()->connectedSignals[n] & m) == 0)
// nothing connected to these signals, and no spy
return;
}
@@ -3207,21 +3216,59 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign
void QMetaObject::activate(QObject *sender, const QMetaObject *m,
int from_local_signal_index, int to_local_signal_index, void **argv)
{
+ Q_ASSERT(from_local_signal_index <= to_local_signal_index);
int offset = m->methodOffset();
int from_signal_index = offset + from_local_signal_index;
int to_signal_index = offset + to_local_signal_index;
- if (to_signal_index < 32
+
+ if (to_signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8
&& !qt_signal_spy_callback_set.signal_begin_callback
&& !qt_signal_spy_callback_set.signal_end_callback) {
- uint signal_mask = (1 << (to_signal_index + 1)) - 1;
- signal_mask ^= (1 << from_signal_index) - 1;
- if ((sender->d_func()->connectedSignals & signal_mask) == 0)
+
+ uint n = (from_signal_index / (8 * sizeof sender->d_func()->connectedSignals[0]));
+ uint m = 1 << (from_signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]);
+ uint nt = (to_signal_index / (8 * sizeof sender->d_func()->connectedSignals[0]));
+ uint mt = 1 << (to_signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]);
+ bool connected = false;
+ quint32 *connectedSignals = sender->d_func()->connectedSignals;
+ for (uint i = 0; !connected && i < (sizeof sender->d_func()->connectedSignals
+ / sizeof sender->d_func()->connectedSignals[0]); ++i) {
+ uint mask = 0;
+ if (i > n)
+ mask = ~0u;
+ else if (i == n)
+ mask = ~(m -1);
+ if (i > nt)
+ mask = 0;
+ else if (i == nt)
+ mask &= (mt << 1) - 1;
+ connected = connectedSignals[i] & mask;
+ }
+ if (!connected)
// nothing connected to these signals, and no spy
return;
}
activate(sender, from_signal_index, to_signal_index, argv);
}
+/*! \internal
+
+ Returns true if the signal with index \a signal_index from object \a sender is connected.
+ Signals with indices above a certain range are always considered connected (see connectedSignals
+ in QObjectPrivate). If a signal spy is installed, all signals are considered connected.
+*/
+bool QMetaObject::isConnected(QObject *sender, int signal_index) {
+ if (signal_index < (int)sizeof(sender->d_func()->connectedSignals) * 8
+ && !qt_signal_spy_callback_set.signal_begin_callback
+ && !qt_signal_spy_callback_set.signal_end_callback) {
+ uint n = (signal_index / (8 * sizeof sender->d_func()->connectedSignals[0]));
+ uint m = 1 << (signal_index - n * 8 * sizeof sender->d_func()->connectedSignals[0]);
+ if ((sender->d_func()->connectedSignals[n] & m) == 0)
+ // nothing connected to these signals, and no spy
+ return false;
+ }
+ return true;
+}
/*****************************************************************************
Properties
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index 1b8aee6..83239fe 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -150,7 +150,7 @@ public:
QList<QVariant> propertyValues;
};
ExtraData *extraData;
- mutable quint32 connectedSignals;
+ mutable quint32 connectedSignals[2];
QString objectName;
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 7eb7c44..abfb01a 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -336,6 +336,9 @@ struct Q_CORE_EXPORT QMetaObject
static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv);
static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv);
+
+ static bool isConnected(QObject *sender, int signal_index);
+
// internal guarded pointers
static void addGuard(QObject **ptr);
static void removeGuard(QObject **ptr);
diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp
index 7be23b7..d109836 100644
--- a/src/declarative/debugger/qpacketprotocol.cpp
+++ b/src/declarative/debugger/qpacketprotocol.cpp
@@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QPacketProtocol
+ \internal
\brief The QPacketProtocol class encapsulates communicating discrete packets
across fragmented IO channels, such as TCP sockets.
@@ -354,7 +355,7 @@ QIODevice * QPacketProtocol::device()
/*!
\class QPacket
- \inpublicgroup QtBaseModule
+ \internal
\brief The QPacket class encapsulates an unfragmentable packet of data to be
transmitted by QPacketProtocol.
@@ -476,7 +477,7 @@ void QPacket::clear()
/*!
\class QPacketAutoSend
- \inpublicgroup QtBaseModule
+ \internal
\internal
*/
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp
index f2519dc..57897ed 100644
--- a/src/declarative/fx/qfxtext.cpp
+++ b/src/declarative/fx/qfxtext.cpp
@@ -162,7 +162,7 @@ void QFxText::setText(const QString &n)
if (d->text == n)
return;
- d->richText = Qt::mightBeRichText(n); // ### what's the cost?
+ d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(n));
if (d->richText) {
if (!d->doc)
{
@@ -170,7 +170,7 @@ void QFxText::setText(const QString &n)
d->control->setTextInteractionFlags(Qt::TextBrowserInteraction);
d->doc = d->control->document();
d->doc->setDocumentMargin(0);
- }
+ }
d->doc->setHtml(n);
}
@@ -377,6 +377,77 @@ void QFxText::setWrap(bool w)
}
/*!
+ \qmlproperty enumeration Text::textFormat
+
+ The way the text property should be displayed.
+
+ Supported text formats are \c AutoText, \c PlainText and \c RichText.
+
+ The default is AutoText. If the text format is AutoText the text element
+ will automatically determine whether the text should be treated as
+ rich text. This determination is made using Qt::mightBeRichText().
+
+ \table
+ \row
+ \o
+ \qml
+VerticalLayout {
+ TextEdit {
+ font.size: 24
+ text: "<b>Hello</b> <i>World!</i>"
+ }
+ TextEdit {
+ font.size: 24
+ textFormat: "RichText"
+ text: "<b>Hello</b> <i>World!</i>"
+ }
+ TextEdit {
+ font.size: 24
+ textFormat: "PlainText"
+ text: "<b>Hello</b> <i>World!</i>"
+ }
+}
+ \endqml
+ \o \image declarative-textformat.png
+ \endtable
+*/
+
+QFxText::TextFormat QFxText::textFormat() const
+{
+ Q_D(const QFxText);
+ return d->format;
+}
+
+void QFxText::setTextFormat(TextFormat format)
+{
+ Q_D(QFxText);
+ if (format == d->format)
+ return;
+ bool wasRich = d->richText;
+ d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text));
+
+ if (wasRich && !d->richText) {
+ //### delete control? (and vice-versa below)
+ d->imgDirty = true;
+ d->updateSize();
+ update();
+ } else if (!wasRich && d->richText) {
+ if (!d->doc)
+ {
+ d->control = new QTextControl(this);
+ d->control->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ d->doc = d->control->document();
+ d->doc->setDocumentMargin(0);
+ }
+ d->doc->setHtml(d->text);
+ d->imgDirty = true;
+ d->updateSize();
+ update();
+ }
+ d->format = format;
+}
+
+/*!
\qmlproperty Qt::TextElideMode Text::elide
Set this property to elide parts of the text fit to the Text item's width.
diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h
index ee38a94..bd91f0e 100644
--- a/src/declarative/fx/qfxtext.h
+++ b/src/declarative/fx/qfxtext.h
@@ -58,6 +58,7 @@ class Q_DECLARATIVE_EXPORT QFxText : public QFxItem
Q_ENUMS(HAlignment)
Q_ENUMS(VAlignment)
Q_ENUMS(TextStyle)
+ Q_ENUMS(TextFormat)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QmlFont *font READ font CONSTANT)
@@ -67,6 +68,7 @@ class Q_DECLARATIVE_EXPORT QFxText : public QFxItem
Q_PROPERTY(HAlignment hAlign READ hAlign WRITE setHAlign)
Q_PROPERTY(VAlignment vAlign READ vAlign WRITE setVAlign)
Q_PROPERTY(bool wrap READ wrap WRITE setWrap)
+ Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat)
Q_PROPERTY(Qt::TextElideMode elide READ elideMode WRITE setElideMode)
Q_PROPERTY(QString activeLink READ activeLink)
Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform)
@@ -85,6 +87,9 @@ public:
Outline,
Raised,
Sunken };
+ enum TextFormat { AutoText,
+ PlainText,
+ RichText };
QString text() const;
void setText(const QString &);
@@ -109,6 +114,9 @@ public:
bool wrap() const;
void setWrap(bool w);
+ TextFormat textFormat() const;
+ void setTextFormat(TextFormat format);
+
Qt::TextElideMode elideMode() const;
void setElideMode(Qt::TextElideMode);
diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h
index c58705c..670b685 100644
--- a/src/declarative/fx/qfxtext_p.h
+++ b/src/declarative/fx/qfxtext_p.h
@@ -75,7 +75,8 @@ public:
QFxTextPrivate()
: _font(0), color((QRgb)0), style(QFxText::Normal), imgDirty(true),
hAlign(QFxText::AlignLeft), vAlign(QFxText::AlignTop), elideMode(Qt::ElideNone),
- dirty(false), wrap(false), smooth(false), richText(false), singleline(false), control(0), doc(0)
+ dirty(false), wrap(false), smooth(false), richText(false), singleline(false), control(0), doc(0),
+ format(QFxText::AutoText)
{
}
@@ -132,6 +133,7 @@ public:
QTextDocument *doc;
QTextLayout layout;
QSize cachedLayoutSize;
+ QFxText::TextFormat format;
};
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp
index 7f08fba..7162bdf 100644
--- a/src/declarative/fx/qfxtextedit.cpp
+++ b/src/declarative/fx/qfxtextedit.cpp
@@ -179,7 +179,7 @@ void QFxTextEdit::setText(const QString &text)
Supported text formats are \c AutoText, \c PlainText and \c RichText.
The default is AutoText. If the text format is AutoText the text edit
- edit will automatically determine whether the text should be treated as
+ will automatically determine whether the text should be treated as
rich text. This determination is made using Qt::mightBeRichText().
\table
@@ -410,7 +410,7 @@ void QFxTextEdit::setWrap(bool w)
}
/*!
- \property QFxTextEdit::cursorVisible
+ \qmlproperty TextEdit::cursorVisible
\brief If true the text edit shows a cursor.
This property is set and unset when the text edit gets focus, but it can also
@@ -435,6 +435,25 @@ void QFxTextEdit::setCursorVisible(bool on)
}
/*!
+ \qmlproperty TextEdit::cursorPosition
+ \brief The position of the cursor in the TextEdit.
+*/
+int QFxTextEdit::cursorPosition() const
+{
+ Q_D(const QFxTextEdit);
+ return d->control->textCursor().position();
+}
+
+void QFxTextEdit::setCursorPosition(int pos)
+{
+ Q_D(QFxTextEdit);
+ QTextCursor cursor = d->control->textCursor();
+ if (cursor.position() == pos)
+ return;
+ cursor.setPosition(pos);
+}
+
+/*!
\qmlproperty bool TextEdit::focusOnPress
Whether the TextEdit should gain focus on a mouse press. By default this is
diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h
index 24ba3fe..6988822 100644
--- a/src/declarative/fx/qfxtextedit.h
+++ b/src/declarative/fx/qfxtextedit.h
@@ -77,6 +77,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem
Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible)
+ Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress)
Q_PROPERTY(bool preserveSelection READ preserveSelection WRITE setPreserveSelection)
Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin)
@@ -129,6 +130,9 @@ public:
bool isCursorVisible() const;
void setCursorVisible(bool on);
+ int cursorPosition() const;
+ void setCursorPosition(int pos);
+
bool focusOnPress() const;
void setFocusOnPress(bool on);
diff --git a/src/declarative/fx/qfxvisualitemmodel.h b/src/declarative/fx/qfxvisualitemmodel.h
index 9cacde4..551c08d 100644
--- a/src/declarative/fx/qfxvisualitemmodel.h
+++ b/src/declarative/fx/qfxvisualitemmodel.h
@@ -70,7 +70,7 @@ class Q_DECLARATIVE_EXPORT QFxVisualItemModel : public QObject
Q_PROPERTY(QVariant model READ model WRITE setModel)
Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate)
Q_PROPERTY(QString part READ part WRITE setPart)
- Q_PROPERTY(QObject *parts READ parts)
+ Q_PROPERTY(QObject *parts READ parts CONSTANT)
Q_CLASSINFO("DefaultProperty", "delegate")
public:
QFxVisualItemModel();
diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h
index 1990b7f..cd01f6a 100644
--- a/src/declarative/qml/qml.h
+++ b/src/declarative/qml/qml.h
@@ -93,10 +93,10 @@ class QmlEngine;
Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *);
Q_DECLARATIVE_EXPORT QmlContext *qmlContext(const QObject *);
Q_DECLARATIVE_EXPORT QmlEngine *qmlEngine(const QObject *);
-Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObjectById(int, const QObject *);
+Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObjectById(int, const QObject *, bool create = true);
template<typename T>
-QObject *qmlAttachedPropertiesObject(const QObject *obj)
+QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true)
{
// ### is this threadsafe?
static int idx = -1;
@@ -107,7 +107,7 @@ QObject *qmlAttachedPropertiesObject(const QObject *obj)
if (idx == -1 || !obj)
return 0;
- return qmlAttachedPropertiesObjectById(idx, obj);
+ return qmlAttachedPropertiesObjectById(idx, obj, create);
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp
index d6b38c9..3474487 100644
--- a/src/declarative/qml/qmlcomponent.cpp
+++ b/src/declarative/qml/qmlcomponent.cpp
@@ -270,10 +270,25 @@ QmlComponent::QmlComponent(QmlEngine *engine, const QUrl &url, QObject *parent)
}
/*!
+ Create a QmlComponent from the given \a url and give it the specified
+ \a parent and \a engine.
+
+ \sa loadUrl()
+*/
+QmlComponent::QmlComponent(QmlEngine *engine, const QString &url,
+ QObject *parent)
+: QObject(*(new QmlComponentPrivate), parent)
+{
+ Q_D(QmlComponent);
+ d->engine = engine;
+ loadUrl(QUrl(url));
+}
+
+/*!
Create a QmlComponent from the given QML \a data and give it the
- specified \a parent and \a engine. If \a url is provided, it is used to set
- the component name, and to provide a base path for items resolved
- by this component.
+ specified \a parent and \a engine. \a url is used to provide a base path
+ for items resolved by this component, and may be an empty url if the
+ component contains no items to resolve.
\sa setData()
*/
@@ -339,10 +354,13 @@ void QmlComponent::loadUrl(const QUrl &url)
d->clear();
- d->url = url;
+ if (url.isRelative())
+ d->url = d->engine->baseUrl().resolved(url);
+ else
+ d->url = url;
QmlCompositeTypeData *data =
- d->engine->d_func()->typeManager.get(url);
+ d->engine->d_func()->typeManager.get(d->url);
if (data->status == QmlCompositeTypeData::Waiting) {
diff --git a/src/declarative/qml/qmlcomponent.h b/src/declarative/qml/qmlcomponent.h
index b29c123..5e6dce9 100644
--- a/src/declarative/qml/qmlcomponent.h
+++ b/src/declarative/qml/qmlcomponent.h
@@ -67,9 +67,10 @@ class Q_DECLARATIVE_EXPORT QmlComponent : public QObject
public:
QmlComponent(QObject *parent = 0);
QmlComponent(QmlEngine *, QObject *parent=0);
+ QmlComponent(QmlEngine *, const QString &url, QObject *parent = 0);
QmlComponent(QmlEngine *, const QUrl &url, QObject *parent = 0);
QmlComponent(QmlEngine *, const QByteArray &data,
- const QUrl &baseUrl=QUrl(), QObject *parent=0);
+ const QUrl &baseUrl, QObject *parent=0);
virtual ~QmlComponent();
Q_ENUMS(Status)
@@ -92,7 +93,7 @@ public:
virtual void completeCreate();
void loadUrl(const QUrl &url);
- void setData(const QByteArray &, const QUrl &baseUrl = QUrl());
+ void setData(const QByteArray &, const QUrl &baseUrl);
Q_SIGNALS:
void statusChanged(QmlComponent::Status);
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 9eb169e..d88d11f 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -194,8 +194,8 @@ void QmlEnginePrivate::init()
//###needed for the other funcs, but should it be exposed?
scriptEngine.globalObject().setProperty(QLatin1String("qmlEngine"),
scriptEngine.newQObject(q));
- scriptEngine.globalObject().setProperty(QLatin1String("evalQml"),
- scriptEngine.newFunction(QmlEngine::createQMLObject, 1));
+ scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"),
+ scriptEngine.newFunction(QmlEngine::createQmlObject, 1));
scriptEngine.globalObject().setProperty(QLatin1String("createComponent"),
scriptEngine.newFunction(QmlEngine::createComponent, 1));
}
@@ -638,6 +638,36 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const
}
/*!
+ Return the base URL for this engine. The base URL is only used to resolve
+ components when a relative URL is passed to the QmlComponent constructor.
+
+ If a base URL has not been explicitly set, this method returns the
+ application's current working directory.
+
+ \sa setBaseUrl()
+*/
+QUrl QmlEngine::baseUrl() const
+{
+ Q_D(const QmlEngine);
+ if (d->baseUrl.isEmpty()) {
+ return QUrl::fromLocalFile(QDir::currentPath() + QDir::separator());
+ } else {
+ return d->baseUrl;
+ }
+}
+
+/*!
+ Set the base URL for this engine to \a url.
+
+ \sa baseUrl()
+*/
+void QmlEngine::setBaseUrl(const QUrl &url)
+{
+ Q_D(QmlEngine);
+ d->baseUrl = url;
+}
+
+/*!
Returns the QmlContext for the \a object, or 0 if no context has been set.
When the QmlEngine instantiates a QObject, the context is set automatically.
@@ -707,13 +737,13 @@ QmlEngine *qmlEngine(const QObject *obj)
return context?context->engine():0;
}
-QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object)
+QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool create)
{
QmlExtendedDeclarativeData *edata =
QmlExtendedDeclarativeData::get(const_cast<QObject *>(object), true);
QObject *rv = edata->attachedProperties.value(id);
- if (rv)
+ if (rv || !create)
return rv;
QmlAttachedPropertiesFunc pf = QmlMetaType::attachedPropertiesFuncById(id);
@@ -844,8 +874,8 @@ QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine)
\endcode
If you want to just create an arbitrary string of QML, instead of
- loading a qml file, consider the evalQML() function.
- \sa QmlComponent::createObject(), QmlEngine::createQMLObject()
+ loading a qml file, consider the createQmlObject() function.
+ \sa QmlComponent::createObject(), QmlEngine::createQmlObject()
*/
QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *engine)
{
@@ -855,21 +885,31 @@ QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *eng
if(ctxt->argumentCount() != 1 || !activeEngine){
c = new QmlComponent(activeEngine);
}else{
- //### This url needs to be resolved in the context that the function
- //### is called - it can't be done here.
- QUrl url = QUrl(ctxt->argument(0).toString());
+ QUrl url = QUrl(activeEngine->d_func()->currentExpression->context()
+ ->resolvedUrl(ctxt->argument(0).toString()));
+ if(!url.isValid()){
+ qDebug() << "Error A:" << url << activeEngine->activeContext() << QmlEngine::activeEngine() << activeEngine;
+ url = QUrl(ctxt->argument(0).toString());
+ }
c = new QmlComponent(activeEngine, url, activeEngine);
}
return engine->newQObject(c);
}
/*!
- Creates a new object from the specified string of qml. If a second argument
- is provided, this is treated as the filepath that the qml came from.
+ Creates a new object from the specified string of QML. It requires a
+ second argument, which is the id of an existing QML object to use as
+ the new object's parent. If a third argument is provided, this is used
+ as the filepath that the qml came from.
+
+ Example (where targetItem is the id of an existing QML item):
+ \code
+ newObject = createQmlObject('Rect {color: "red"; width: 20; height: 20}',
+ targetItem, "dynamicSnippet1");
+ \endcode
This function is intended for use inside QML only. It is intended to behave
- similarly to eval, but for creating QML elements. Thus, it is called as
- evalQml() in QtScript.
+ similarly to eval, but for creating QML elements.
Returns the created object, or null if there is an error. In the case of an
error, details of the error are output using qWarning().
@@ -878,48 +918,54 @@ QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *eng
the QML loads new components. If you are trying to load a new component,
for example from a QML file, consider the createComponent() function
instead. 'New components' refers to external QML files that have not yet
- been loaded, and so it is safe to use evalQml to load built-in components.
+ been loaded, and so it is safe to use createQmlObject to load built-in
+ components.
\sa QmlEngine::createComponent()
*/
-QScriptValue QmlEngine::createQMLObject(QScriptContext *ctxt, QScriptEngine *engine)
+QScriptValue QmlEngine::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine)
{
QmlEngine* activeEngine = qobject_cast<QmlEngine*>(
engine->globalObject().property(QLatin1String("qmlEngine")).toQObject());
- if(ctxt->argumentCount() < 1 || !activeEngine){
- if(ctxt->argumentCount() < 1){
- qWarning() << "createQMLObject requires a string argument.";
+ if(ctxt->argumentCount() < 2 || !activeEngine){
+ if(ctxt->argumentCount() < 2){
+ qWarning() << "createQmlObject requires two arguments, A QML string followed by an existing QML item id.";
}else{
- qWarning() << "createQMLObject cannot find engine.";
+ qWarning() << "createQmlObject cannot find engine.";
}
return engine->nullValue();
}
QString qml = ctxt->argument(0).toString();
QUrl url;
- if(ctxt->argumentCount() > 1)
- url = QUrl(ctxt->argument(1).toString());
+ if(ctxt->argumentCount() > 2)
+ url = QUrl(ctxt->argument(2).toString());
+ QObject *parentArg = ctxt->argument(1).data().toQObject();
+ QmlContext *qmlCtxt = qmlContext(parentArg);
+ url = qmlCtxt->resolvedUrl(url);
QmlComponent component(activeEngine, qml.toUtf8(), url);
if(component.isError()) {
QList<QmlError> errors = component.errors();
foreach (const QmlError &error, errors) {
- qWarning() << error;
+ qWarning() <<"Error in createQmlObject(): "<< error;
}
return engine->nullValue();
}
- QObject *obj = component.create();
+ QObject *obj = component.create(qmlCtxt);
if(component.isError()) {
QList<QmlError> errors = component.errors();
foreach (const QmlError &error, errors) {
- qWarning() << error;
+ qWarning() <<"Error in createQmlObject(): "<< error;
}
return engine->nullValue();
}
if(obj){
+ obj->setParent(parentArg);
+ obj->setProperty("parent", QVariant::fromValue<QObject*>(parentArg));
return qmlScriptObject(obj, activeEngine);
}
return engine->nullValue();
diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h
index 42359e1..9e0ac87 100644
--- a/src/declarative/qml/qmlengine.h
+++ b/src/declarative/qml/qmlengine.h
@@ -85,13 +85,16 @@ public:
void setNetworkAccessManager(QNetworkAccessManager *);
QNetworkAccessManager *networkAccessManager() const;
+ QUrl baseUrl() const;
+ void setBaseUrl(const QUrl &);
+
static QmlContext *contextForObject(const QObject *);
static void setContextForObject(QObject *, QmlContext *);
static QScriptValue qmlScriptObject(QObject*, QmlEngine*);
static QScriptValue createComponent(QScriptContext*, QScriptEngine*);
- static QScriptValue createQMLObject(QScriptContext*, QScriptEngine*);
+ static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*);
private:
// LK: move to the private class
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 25f6edf..9171fbb 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -129,6 +129,8 @@ public:
QScriptEngine scriptEngine;
+ QUrl baseUrl;
+
template<class T>
struct SimpleList {
SimpleList()
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index c0d6481..ff070c1 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -1436,11 +1436,11 @@ void QmlParallelAnimation::transition(QmlStateActions &actions,
QML_DEFINE_TYPE(QmlParallelAnimation,ParallelAnimation)
//convert a variant from string type to another animatable type
-//### should use any registered string convertor
-void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, QVariant::Type type)
+void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
{
if (variant.type() != QVariant::String) {
- variant.convert(type);
+ if ((uint)type < QVariant::UserType)
+ variant.convert((QVariant::Type)type);
return;
}
@@ -1474,7 +1474,12 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, QVariant::Ty
break;
}
default:
- variant.convert(type);
+ if ((uint)type >= QVariant::UserType) {
+ QmlMetaType::StringConverter converter = QmlMetaType::customStringConverter(type);
+ if (converter)
+ variant = converter(variant.toString());
+ } else
+ variant.convert((QVariant::Type)type);
break;
}
}
@@ -1722,7 +1727,7 @@ void QmlPropertyAnimationPrivate::valueChanged(qreal r)
if (!fromSourced) {
if (!fromIsDefined) {
from = property.read();
- convertVariant(from, (QVariant::Type)(interpolatorType ? interpolatorType : property.propertyType()));
+ convertVariant(from, interpolatorType ? interpolatorType : property.propertyType());
//### check for invalid variant if using property type
}
fromSourced = true;
@@ -1751,9 +1756,9 @@ void QmlPropertyAnimation::prepare(QmlMetaProperty &p)
d->property = d->userProperty;
int propType = d->property.propertyType();
- d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : propType));
+ d->convertVariant(d->to, d->interpolatorType ? d->interpolatorType : propType);
if (d->fromIsDefined)
- d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : propType));
+ d->convertVariant(d->from, d->interpolatorType ? d->interpolatorType : propType);
if (!d->interpolatorType) {
//### check for invalid variants
@@ -1795,7 +1800,7 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
if (action.fromValue.isNull()) {
action.fromValue = action.property.read();
if (interpolatorType)
- QmlPropertyAnimationPrivate::convertVariant(action.fromValue, (QVariant::Type)interpolatorType);
+ QmlPropertyAnimationPrivate::convertVariant(action.fromValue, interpolatorType);
}
if (!interpolatorType) {
int propType = action.property.propertyType();
@@ -1856,8 +1861,8 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
if (d->toIsDefined)
myAction.toValue = d->to;
- d->convertVariant(myAction.fromValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()));
- d->convertVariant(myAction.toValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()));
+ d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
+ d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
modified << action.property;
@@ -1875,10 +1880,10 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions,
continue;
if (d->fromIsDefined) {
- d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()));
+ d->convertVariant(d->from, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
myAction.fromValue = d->from;
}
- d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()));
+ d->convertVariant(d->to, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
myAction.toValue = d->to;
data->actions << myAction;
}
diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h
index 00759e1..87d480f 100644
--- a/src/declarative/util/qmlanimation_p.h
+++ b/src/declarative/util/qmlanimation_p.h
@@ -346,7 +346,7 @@ public:
QmlTimeLineValueProxy<QmlPropertyAnimationPrivate> value;
static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress);
- static void convertVariant(QVariant &variant, QVariant::Type type);
+ static void convertVariant(QVariant &variant, int type);
};
QT_END_NAMESPACE
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 2223f5d..4c15a15 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -6490,7 +6490,7 @@ void QGraphicsItem::prepareGeometryChange()
// if someone is connected to the changed signal or the scene has no views.
// Note that this has to be done *after* markDirty to ensure that
// _q_processDirtyItems is called before _q_emitUpdated.
- if ((scenePrivate->connectedSignals & scenePrivate->changedSignalMask)
+ if ((scenePrivate->connectedSignals[0] & scenePrivate->changedSignalMask)
|| scenePrivate->views.isEmpty()) {
d_ptr->scene->update(sceneTransform().mapRect(boundingRect()));
}
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index e50ee94..7e7ea98 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -604,7 +604,7 @@ void QGraphicsScenePrivate::_q_emitUpdated()
// the optimization that items send updates directly to the views, but it
// needs to happen in order to keep compatibility with the behavior from
// Qt 4.4 and backward.
- if (connectedSignals & changedSignalMask) {
+ if (connectedSignals[0] & changedSignalMask) {
for (int i = 0; i < views.size(); ++i) {
QGraphicsView *view = views.at(i);
if (!view->d_func()->connectedToScene) {
@@ -3730,7 +3730,7 @@ void QGraphicsScene::update(const QRectF &rect)
// Check if anyone's connected; if not, we can send updates directly to
// the views. Otherwise or if there are no views, use old behavior.
- bool directUpdates = !(d->connectedSignals & d->changedSignalMask) && !d->views.isEmpty();
+ bool directUpdates = !(d->connectedSignals[0] & d->changedSignalMask) && !d->views.isEmpty();
if (rect.isNull()) {
d->updateAll = true;
d->updatedRects.clear();
@@ -5394,7 +5394,7 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b
if (removingItemFromScene) {
// Note that this function can be called from the item's destructor, so
// do NOT call any virtual functions on it within this block.
- if ((connectedSignals & changedSignalMask) || views.isEmpty()) {
+ if ((connectedSignals[0] & changedSignalMask) || views.isEmpty()) {
// This block of code is kept for compatibility. Since 4.5, by default
// QGraphicsView does not connect the signal and we use the below
// method of delivering updates.
@@ -5481,7 +5481,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
// Process item.
if (item && (item->d_ptr->dirty || item->d_ptr->paintedViewBoundingRectsNeedRepaint)) {
- const bool useCompatUpdate = views.isEmpty() || (connectedSignals & changedSignalMask);
+ const bool useCompatUpdate = views.isEmpty() || (connectedSignals[0] & changedSignalMask);
const bool untransformableItem = item->d_ptr->itemIsUntransformable();
const QRectF itemBoundingRect = adjustedItemBoundingRect(item);