From d2f456c8e94b6c7752818a9e3c819784e18237f0 Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Tue, 2 Mar 2010 11:12:34 +1000 Subject: Fixed compiler warnings when compiling multimedia module. Reviewed-by:Andrew den Exter --- src/multimedia/base/qmediaserviceprovider.cpp | 14 +++++++++----- src/multimedia/qml/qsoundeffect_qsound_p.cpp | 2 +- src/multimedia/qml/wavedecoder_p.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/multimedia/base/qmediaserviceprovider.cpp b/src/multimedia/base/qmediaserviceprovider.cpp index eb6505c..d51d682 100644 --- a/src/multimedia/base/qmediaserviceprovider.cpp +++ b/src/multimedia/base/qmediaserviceprovider.cpp @@ -268,7 +268,7 @@ class QPluginServiceProvider : public QMediaServiceProvider public: QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint) { - QString key(type); + QString key(QString::fromLatin1(type.constData(),type.length())); QListplugins; foreach (QObject *obj, loader()->instances(key)) { @@ -383,7 +383,8 @@ public: const QStringList& codecs, int flags) const { - QList instances = loader()->instances(serviceType); + QList instances = loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length())); if (instances.isEmpty()) return QtMultimedia::NotSupported; @@ -424,7 +425,8 @@ public: QStringList supportedMimeTypes(const QByteArray &serviceType, int flags) const { - QList instances = loader()->instances(serviceType); + QList instances = loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length())); QStringList supportedTypes; @@ -457,7 +459,8 @@ public: { QList res; - foreach(QObject *obj, loader()->instances(serviceType)) { + foreach(QObject *obj, loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length()))) { QMediaServiceSupportedDevicesInterface *iface = qobject_cast(obj); @@ -471,7 +474,8 @@ public: QString deviceDescription(const QByteArray &serviceType, const QByteArray &device) { - foreach(QObject *obj, loader()->instances(serviceType)) { + foreach(QObject *obj, loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length()))) { QMediaServiceSupportedDevicesInterface *iface = qobject_cast(obj); diff --git a/src/multimedia/qml/qsoundeffect_qsound_p.cpp b/src/multimedia/qml/qsoundeffect_qsound_p.cpp index 0292d26..df160a9 100644 --- a/src/multimedia/qml/qsoundeffect_qsound_p.cpp +++ b/src/multimedia/qml/qsoundeffect_qsound_p.cpp @@ -157,7 +157,7 @@ void QSoundEffectPrivate::setMedia(const QMediaContent &media) { m_queued = false; - if (media.isNull() || media.canonicalUrl().scheme() != "file") { + if (media.isNull() || media.canonicalUrl().scheme() != QLatin1String("file")) { m_media = QMediaContent(); return; } diff --git a/src/multimedia/qml/wavedecoder_p.cpp b/src/multimedia/qml/wavedecoder_p.cpp index b7d6101..f2277ae 100644 --- a/src/multimedia/qml/wavedecoder_p.cpp +++ b/src/multimedia/qml/wavedecoder_p.cpp @@ -122,7 +122,7 @@ void WaveDecoder::handleData() else { int bps = qFromLittleEndian(header.wave.bitsPerSample); - format.setCodec("audio/pcm"); + format.setCodec(QLatin1String("audio/pcm")); format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt); format.setByteOrder(QAudioFormat::LittleEndian); format.setFrequency(qFromLittleEndian(header.wave.sampleRate)); -- cgit v0.12 From c92b1da931a56f97bf1812db922d43c8f692de8f Mon Sep 17 00:00:00 2001 From: Dmytro Poplavskiy Date: Wed, 3 Mar 2010 13:13:45 +1000 Subject: Gstreamer playback backend: Start loading media on setMedia(), without waiting for play() or pause(). To keep behaviour consisten with the rest of backends. Reviewed-by: Andrew den Exter --- .../mediaplayer/qgstreamerplayercontrol.cpp | 133 ++++++++++++++++++--- .../mediaplayer/qgstreamerplayercontrol.h | 7 ++ .../mediaplayer/qgstreamerplayersession.cpp | 94 +++++++++------ .../mediaplayer/qgstreamerplayersession.h | 11 +- 4 files changed, 186 insertions(+), 59 deletions(-) diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp index 2d7aaa8..e646693 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp @@ -59,6 +59,9 @@ QT_BEGIN_NAMESPACE QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent) : QMediaPlayerControl(parent) , m_session(session) + , m_state(QMediaPlayer::StoppedState) + , m_mediaStatus(QMediaPlayer::NoMedia) + , m_bufferProgress(-1) , m_stream(0) , m_fifoNotifier(0) , m_fifoCanWrite(false) @@ -77,11 +80,11 @@ QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *sessio connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int))); connect(m_session, SIGNAL(stateChanged(QMediaPlayer::State)), - this, SIGNAL(stateChanged(QMediaPlayer::State))); - connect(m_session, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), - this, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + this, SLOT(updateState(QMediaPlayer::State))); connect(m_session,SIGNAL(bufferingProgressChanged(int)), - this, SIGNAL(bufferStatusChanged(int))); + this, SLOT(setBufferProgress(int))); + connect(m_session, SIGNAL(playbackFinished()), + this, SLOT(processEOS())); connect(m_session, SIGNAL(audioAvailableChanged(bool)), this, SIGNAL(audioAvailableChanged(bool))); connect(m_session, SIGNAL(videoAvailableChanged(bool)), @@ -114,17 +117,20 @@ qint64 QGstreamerPlayerControl::duration() const QMediaPlayer::State QGstreamerPlayerControl::state() const { - return m_session->state(); + return m_state; } QMediaPlayer::MediaStatus QGstreamerPlayerControl::mediaStatus() const { - return m_session->mediaStatus(); + return m_mediaStatus; } int QGstreamerPlayerControl::bufferStatus() const { - return 100; + if (m_bufferProgress == -1) { + return m_session->state() == QMediaPlayer::StoppedState ? 0 : 100; + } else + return m_bufferProgress; } int QGstreamerPlayerControl::volume() const @@ -169,23 +175,33 @@ void QGstreamerPlayerControl::setPosition(qint64 pos) void QGstreamerPlayerControl::play() { - m_session->play(); - - if (m_fifoFd[1] >= 0) { - m_fifoCanWrite = true; - - writeFifo(); + if (m_session->play()) { + if (m_state != QMediaPlayer::PlayingState) + emit stateChanged(m_state = QMediaPlayer::PlayingState); } } void QGstreamerPlayerControl::pause() { - m_session->pause(); + if (m_session->pause()) { + if (m_state != QMediaPlayer::PausedState) + emit stateChanged(m_state = QMediaPlayer::PausedState); + } } void QGstreamerPlayerControl::stop() { - m_session->stop(); + if (m_state != QMediaPlayer::StoppedState) { + m_session->pause(); + if (!m_session->seek(0)) { + m_bufferProgress = -1; + m_session->stop(); + m_session->pause(); + } + emit positionChanged(0); + if (m_state != QMediaPlayer::StoppedState) + emit stateChanged(m_state = QMediaPlayer::StoppedState); + } } void QGstreamerPlayerControl::setVolume(int volume) @@ -210,8 +226,15 @@ const QIODevice *QGstreamerPlayerControl::mediaStream() const void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) { + QMediaPlayer::State oldState = m_state; + m_state = QMediaPlayer::StoppedState; m_session->stop(); + if (m_bufferProgress != -1) { + m_bufferProgress = -1; + emit bufferStatusChanged(0); + } + if (m_stream) { closeFifo(); @@ -234,7 +257,25 @@ void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice * m_session->load(url); + if (m_fifoFd[1] >= 0) { + m_fifoCanWrite = true; + + writeFifo(); + } + + if (!url.isEmpty()) { + if (m_mediaStatus != QMediaPlayer::LoadingMedia) + emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::LoadingMedia); + m_session->pause(); + } else { + if (m_mediaStatus != QMediaPlayer::NoMedia) + emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::NoMedia); + setBufferProgress(0); + } + emit mediaChanged(m_currentResource); + if (m_state != oldState) + emit stateChanged(m_state); } void QGstreamerPlayerControl::setVideoOutput(QObject *output) @@ -252,6 +293,68 @@ bool QGstreamerPlayerControl::isVideoAvailable() const return m_session->isVideoAvailable(); } +void QGstreamerPlayerControl::updateState(QMediaPlayer::State state) +{ + QMediaPlayer::MediaStatus oldStatus = m_mediaStatus; + + switch (state) { + case QMediaPlayer::StoppedState: + if (m_state != QMediaPlayer::StoppedState) + emit stateChanged(m_state = QMediaPlayer::StoppedState); + break; + + case QMediaPlayer::PlayingState: + case QMediaPlayer::PausedState: + if (m_state == QMediaPlayer::StoppedState) + m_mediaStatus = QMediaPlayer::LoadedMedia; + else { + if (m_bufferProgress == -1) + m_mediaStatus = QMediaPlayer::BufferedMedia; + } + break; + } + + if (m_mediaStatus != oldStatus) + emit mediaStatusChanged(m_mediaStatus); +} + +void QGstreamerPlayerControl::processEOS() +{ + m_mediaStatus = QMediaPlayer::EndOfMedia; + m_state = QMediaPlayer::StoppedState; + + emit stateChanged(m_state); + emit mediaStatusChanged(m_mediaStatus); +} + +void QGstreamerPlayerControl::setBufferProgress(int progress) +{ + if (m_bufferProgress == progress || m_mediaStatus == QMediaPlayer::NoMedia) + return; + + QMediaPlayer::MediaStatus oldStatus = m_mediaStatus; + + m_bufferProgress = progress; + + if (m_state == QMediaPlayer::StoppedState) { + m_mediaStatus = QMediaPlayer::LoadedMedia; + } else { + if (m_bufferProgress < 100) { + m_mediaStatus = QMediaPlayer::StalledMedia; + m_session->pause(); + } else { + m_mediaStatus = QMediaPlayer::BufferedMedia; + if (m_state == QMediaPlayer::PlayingState) + m_session->play(); + } + } + + if (m_mediaStatus != oldStatus) + emit mediaStatusChanged(m_mediaStatus); + + emit bufferStatusChanged(m_bufferProgress); +} + void QGstreamerPlayerControl::writeFifo() { if (m_fifoCanWrite) { diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h index ae0f8b6..0c53945 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h @@ -107,11 +107,18 @@ private Q_SLOTS: void writeFifo(); void fifoReadyWrite(int socket); + void updateState(QMediaPlayer::State); + void processEOS(); + void setBufferProgress(int progress); + private: bool openFifo(); void closeFifo(); QGstreamerPlayerSession *m_session; + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_mediaStatus; + int m_bufferProgress; QMediaContent m_currentResource; QIODevice *m_stream; QSocketNotifier *m_fifoNotifier; diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp index 600621e..e80e820 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp @@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent) :QObject(parent), m_state(QMediaPlayer::StoppedState), - m_mediaStatus(QMediaPlayer::UnknownMediaStatus), m_busHelper(0), m_playbin(0), m_nullVideoOutput(0), @@ -115,6 +114,7 @@ QGstreamerPlayerSession::~QGstreamerPlayerSession() void QGstreamerPlayerSession::load(const QUrl &url) { m_url = url; + if (m_playbin) { m_tags.clear(); emit tagsChanged(); @@ -259,26 +259,36 @@ bool QGstreamerPlayerSession::isSeekable() const return m_seekable; } -void QGstreamerPlayerSession::play() +bool QGstreamerPlayerSession::play() { if (m_playbin) { if (gst_element_set_state(m_playbin, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { qWarning() << "GStreamer; Unable to play -" << m_url.toString(); - m_state = QMediaPlayer::StoppedState; - m_mediaStatus = QMediaPlayer::InvalidMedia; + m_state = QMediaPlayer::StoppedState; emit stateChanged(m_state); - emit mediaStatusChanged(m_mediaStatus); - emit error(int(QMediaPlayer::ResourceError), tr("Unable to play %1").arg(m_url.path())); - } + } else + return true; } + + return false; } -void QGstreamerPlayerSession::pause() +bool QGstreamerPlayerSession::pause() { - if (m_playbin) - gst_element_set_state(m_playbin, GST_STATE_PAUSED); + if (m_playbin) { + if (gst_element_set_state(m_playbin, GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) { + qWarning() << "GStreamer; Unable to play -" << m_url.toString(); + m_state = QMediaPlayer::StoppedState; + + emit stateChanged(m_state); + emit error(int(QMediaPlayer::ResourceError), tr("Unable to play %1").arg(m_url.path())); + } else + return true; + } + + return false; } void QGstreamerPlayerSession::stop() @@ -292,12 +302,14 @@ void QGstreamerPlayerSession::stop() } } -void QGstreamerPlayerSession::seek(qint64 ms) +bool QGstreamerPlayerSession::seek(qint64 ms) { if (m_playbin && m_state != QMediaPlayer::StoppedState) { gint64 position = (gint64)ms * 1000000; - gst_element_seek_simple(m_playbin, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, position); + return gst_element_seek_simple(m_playbin, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, position); } + + return false; } void QGstreamerPlayerSession::setVolume(int volume) @@ -388,14 +400,6 @@ void QGstreamerPlayerSession::setSeekable(bool seekable) } } -void QGstreamerPlayerSession::setMediaStatus(QMediaPlayer::MediaStatus status) -{ - if (m_mediaStatus != status) { - m_mediaStatus = status; - emit mediaStatusChanged(status); - } -} - bool QGstreamerPlayerSession::processSyncMessage(const QGstreamerMessage &message) { GstMessage* gm = message.rawMessage(); @@ -440,9 +444,6 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_playbin)) { switch (GST_MESSAGE_TYPE(gm)) { - case GST_MESSAGE_DURATION: - break; - case GST_MESSAGE_STATE_CHANGED: { GstState oldState; @@ -462,24 +463,19 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) switch (newState) { case GST_STATE_VOID_PENDING: case GST_STATE_NULL: - setMediaStatus(QMediaPlayer::UnknownMediaStatus); setSeekable(false); if (m_state != QMediaPlayer::StoppedState) emit stateChanged(m_state = QMediaPlayer::StoppedState); break; case GST_STATE_READY: - setMediaStatus(QMediaPlayer::LoadedMedia); setSeekable(false); if (m_state != QMediaPlayer::StoppedState) emit stateChanged(m_state = QMediaPlayer::StoppedState); break; case GST_STATE_PAUSED: - //don't emit state changes for intermediate states - if (m_state != QMediaPlayer::PausedState && pending == GST_STATE_VOID_PENDING) + if (m_state != QMediaPlayer::PausedState) emit stateChanged(m_state = QMediaPlayer::PausedState); - setMediaStatus(QMediaPlayer::LoadedMedia); - //check for seekable if (oldState == GST_STATE_READY) { /* @@ -513,17 +509,13 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) if (m_state != QMediaPlayer::PlayingState) emit stateChanged(m_state = QMediaPlayer::PlayingState); + break; } } break; case GST_MESSAGE_EOS: - if (m_state != QMediaPlayer::StoppedState) - emit stateChanged(m_state = QMediaPlayer::StoppedState); - - setMediaStatus(QMediaPlayer::EndOfMedia); - emit playbackFinished(); break; @@ -546,7 +538,11 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) case GST_MESSAGE_INFO: break; case GST_MESSAGE_BUFFERING: - setMediaStatus(QMediaPlayer::BufferingMedia); + { + int progress = 0; + gst_message_parse_buffering(gm, &progress); + emit bufferingProgressChanged(progress); + } break; case GST_MESSAGE_STATE_DIRTY: case GST_MESSAGE_STEP_DONE: @@ -556,8 +552,32 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) case GST_MESSAGE_STRUCTURE_CHANGE: case GST_MESSAGE_APPLICATION: case GST_MESSAGE_ELEMENT: + break; case GST_MESSAGE_SEGMENT_START: + { + const GstStructure *structure = gst_message_get_structure(gm); + qint64 position = g_value_get_int64(gst_structure_get_value(structure, "position")); + position /= 1000000; + m_lastPosition = position; + emit positionChanged(position); + } + break; case GST_MESSAGE_SEGMENT_DONE: + break; + case GST_MESSAGE_DURATION: + { + GstFormat format = GST_FORMAT_TIME; + gint64 duration = 0; + + if (gst_element_query_duration(m_playbin, &format, &duration)) { + int newDuration = duration / 1000000; + if (m_duration != newDuration) { + m_duration = newDuration; + emit durationChanged(m_duration); + } + } + } + break; case GST_MESSAGE_LATENCY: #if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 13) case GST_MESSAGE_ASYNC_START: @@ -604,7 +624,7 @@ void QGstreamerPlayerSession::getStreamsInfo() haveAudio = audioStreamsCount > 0; haveVideo = videoStreamsCount > 0; - m_playbin2StreamOffset[QMediaStreamsControl::AudioStream] = 0; + /*m_playbin2StreamOffset[QMediaStreamsControl::AudioStream] = 0; m_playbin2StreamOffset[QMediaStreamsControl::VideoStream] = audioStreamsCount; m_playbin2StreamOffset[QMediaStreamsControl::SubPictureStream] = audioStreamsCount+videoStreamsCount; @@ -648,7 +668,9 @@ void QGstreamerPlayerSession::getStreamsInfo() } m_streamProperties.append(streamProperties); + } + */ #else enum { diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h index d650ec7..edfec5b 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h @@ -71,7 +71,6 @@ public: QUrl url() const; QMediaPlayer::State state() const { return m_state; } - QMediaPlayer::MediaStatus mediaStatus() const { return m_mediaStatus; } qint64 duration() const; qint64 position() const; @@ -105,11 +104,11 @@ public: public slots: void load(const QUrl &url); - void play(); - void pause(); + bool play(); + bool pause(); void stop(); - void seek(qint64 pos); + bool seek(qint64 pos); void setVolume(int volume); void setMuted(bool muted); @@ -118,7 +117,6 @@ signals: void durationChanged(qint64 duration); void positionChanged(qint64 position); void stateChanged(QMediaPlayer::State state); - void mediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus); void volumeChanged(int volume); void mutedStateChanged(bool muted); void audioAvailableChanged(bool audioAvailable); @@ -137,11 +135,8 @@ private slots: void setSeekable(bool); private: - void setMediaStatus(QMediaPlayer::MediaStatus); - QUrl m_url; QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_mediaStatus; QGstreamerBusHelper* m_busHelper; GstElement* m_playbin; GstElement* m_nullVideoOutput; -- cgit v0.12 From 0994b819f6cbf550c067146324f24489d0b4fa1d Mon Sep 17 00:00:00 2001 From: Dmytro Poplavskiy Date: Wed, 3 Mar 2010 14:22:54 +1000 Subject: Use mute property instead of setting volume to 0 if playbin2 is used. Task-number: QTMOBILITY-67 Reviewed-by: Andrew den Exter --- .../mediaplayer/qgstreamerplayersession.cpp | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp index e80e820..be2273b 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp @@ -314,21 +314,33 @@ bool QGstreamerPlayerSession::seek(qint64 ms) void QGstreamerPlayerSession::setVolume(int volume) { - m_volume = volume; - emit volumeChanged(m_volume); + if (m_volume != volume) { + m_volume = volume; - if (!m_muted && m_playbin) - g_object_set(G_OBJECT(m_playbin), "volume", m_volume/100.0, NULL); + if (m_playbin) { +#ifndef USE_PLAYBIN2 + if(!m_muted) +#endif + g_object_set(G_OBJECT(m_playbin), "volume", m_volume/100.0, NULL); + } + + emit volumeChanged(m_volume); + } } void QGstreamerPlayerSession::setMuted(bool muted) { - m_muted = muted; + if (m_muted != muted) { + m_muted = muted; - g_object_set(G_OBJECT(m_playbin), "volume", (m_muted ? 0 : m_volume/100.0), NULL); - - emit mutedStateChanged(m_muted); +#ifdef USE_PLAYBIN2 + g_object_set(G_OBJECT(m_playbin), "mute", m_muted, NULL); +#else + g_object_set(G_OBJECT(m_playbin), "volume", (m_muted ? 0 : m_volume/100.0), NULL); +#endif + emit mutedStateChanged(m_muted); + } } static void addTagToMap(const GstTagList *list, -- cgit v0.12 From 61e29b6b4b1f96fecad1ad105cd190beed6621e6 Mon Sep 17 00:00:00 2001 From: Dmytro Poplavskiy Date: Wed, 3 Mar 2010 14:24:22 +1000 Subject: Gstreamer media backend: ensure the null video output is not deleted during player session lifetime Reviewed-by: Andrew den Exter --- .../mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp index be2273b..392a7a8 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp @@ -91,6 +91,7 @@ QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent) m_busHelper->installSyncEventFilter(this); m_nullVideoOutput = gst_element_factory_make("fakesink", NULL); + gst_object_ref(GST_OBJECT(m_nullVideoOutput)); g_object_set(G_OBJECT(m_playbin), "video-sink", m_nullVideoOutput, NULL); // Initial volume @@ -108,6 +109,7 @@ QGstreamerPlayerSession::~QGstreamerPlayerSession() delete m_busHelper; gst_object_unref(GST_OBJECT(m_bus)); gst_object_unref(GST_OBJECT(m_playbin)); + gst_object_unref(GST_OBJECT(m_nullVideoOutput)); } } -- cgit v0.12 From 4e5cf3f0936ed921973e451e23414059e1a9fc6b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 14:36:48 +1000 Subject: add colorbrowser qml example This example shows how to use qml packages to animate between pathview, gridview and listview. --- examples/declarative/colorbrowser/colorbrowser.qml | 101 ++++++++++++++++++ .../colorbrowser/dummydata/ColorsModel.qml | 96 +++++++++++++++++ .../declarative/colorbrowser/qml/ColorDelegate.qml | 114 +++++++++++++++++++++ .../declarative/colorbrowser/qml/box-shadow.png | Bin 0 -> 871 bytes examples/declarative/colorbrowser/qml/box.png | Bin 0 -> 765 bytes 5 files changed, 311 insertions(+) create mode 100644 examples/declarative/colorbrowser/colorbrowser.qml create mode 100644 examples/declarative/colorbrowser/dummydata/ColorsModel.qml create mode 100644 examples/declarative/colorbrowser/qml/ColorDelegate.qml create mode 100644 examples/declarative/colorbrowser/qml/box-shadow.png create mode 100644 examples/declarative/colorbrowser/qml/box.png diff --git a/examples/declarative/colorbrowser/colorbrowser.qml b/examples/declarative/colorbrowser/colorbrowser.qml new file mode 100644 index 0000000..ebd49c6 --- /dev/null +++ b/examples/declarative/colorbrowser/colorbrowser.qml @@ -0,0 +1,101 @@ +import Qt 4.6 +import 'qml' + +Rectangle { + id: mainWindow + width: 800; height: 480; color: '#454545' + + VisualDataModel { id: colorsVisualModel; delegate: colorsDelegate; model: ColorsModel } + + Component { + id: colorsDelegate + Package { + + Item { + Package.name: 'grid' + GridView { + id: gridView; model: visualModel.parts.grid; width: mainWindow.width; height: mainWindow.height + cellWidth: 160; cellHeight: 160; interactive: false + onCurrentIndexChanged: listView.positionViewAtIndex(currentIndex) + } + } + + Item { + Package.name: 'fullscreen' + ListView { + id: listView; model: visualModel.parts.list; orientation: Qt.Horizontal + width: mainWindow.width; height: mainWindow.height; interactive: false + onCurrentIndexChanged: gridView.positionViewAtIndex(currentIndex) + highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem + } + } + + Item { + Package.name: 'stack' + id: wrapper + width: 260; height: 240 + + VisualDataModel { id: visualModel; model: colors; delegate: ColorDelegate {} } + + PathView { + id: pathView; model: visualModel.parts.stack; anchors.centerIn: parent + pathItemCount: 3 + path: Path { + PathAttribute { name: 'z'; value: 9999.0 } + PathLine { x: 1; y: 1 } + PathAttribute { name: 'z'; value: 0.0 } + } + } + + Item { + anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom; anchors.bottomMargin: 20 + width: albumTitle.width + 20 ; height: albumTitle.height + 4 + Text { id: albumTitle; text: name; color: 'white'; font.bold: true; anchors.centerIn: parent } + } + + MouseRegion { anchors.fill: parent; onClicked: wrapper.state = 'inGrid' } + + states: [ + State { + name: 'inGrid' + PropertyChanges { target: gridView; interactive: true } + PropertyChanges { target: shade; opacity: 1 } + }, + State { + name: 'fullscreen'; extend: 'inGrid' + PropertyChanges { target: gridView; interactive: false } + PropertyChanges { target: listView; interactive: true } + PropertyChanges { target: infobox; opacity: 1 } + } + ] + + transitions: [ + Transition { + from: ''; to: 'inGrid'; reversible: true + NumberAnimation { target: shade; properties: 'opacity'; duration: 300 } + }, + Transition { + from: 'inGrid'; to: 'fullscreen'; reversible: true + SequentialAnimation { + PauseAnimation { duration: 300 } + NumberAnimation { target: infobox; properties: 'opacity'; duration: 300 } + } + } + ] + } + } + } + + GridView { width: parent.width; height: parent.height; cellWidth: 260; cellHeight: 240; model: colorsVisualModel.parts.stack } + Rectangle { id: shade; color: '#454545'; width: parent.width; height: parent.height; opacity: 0 } + ListView { anchors.fill: parent; model: colorsVisualModel.parts.grid; interactive: false } + ListView { anchors.fill: parent; model: colorsVisualModel.parts.fullscreen; interactive: false } + Item { id: foreground; anchors.fill: parent } + + Column { + id: infobox; opacity: 0 + anchors { left: parent.left; leftMargin: 20; bottom: parent.bottom; bottomMargin: 20 } + Text { id: infoColorName; color: '#eeeeee'; style: Text.Outline; styleColor: '#222222'; font.pointSize: 18 } + Text { id: infoColorHex; color: '#eeeeee'; style: Text.Outline; styleColor: '#222222'; font.pointSize: 14 } + } +} diff --git a/examples/declarative/colorbrowser/dummydata/ColorsModel.qml b/examples/declarative/colorbrowser/dummydata/ColorsModel.qml new file mode 100644 index 0000000..eefbcfe --- /dev/null +++ b/examples/declarative/colorbrowser/dummydata/ColorsModel.qml @@ -0,0 +1,96 @@ +import Qt 4.6 + +ListModel { + id: colorsModel + + ListElement { + name: "Reds" + colors: [ + ListElement { name: "Fire Brick"; hex: "#B22222" }, + ListElement { name: "Fire Brick 1"; hex: "#FF3030" }, + ListElement { name: "Fire Brick 2"; hex: "#EE2C2C" }, + ListElement { name: "Fire Brick 3"; hex: "#CD2626" }, + ListElement { name: "Fire Brick 4"; hex: "#8B1A1A" }, + ListElement { name: "Red"; hex: "#FF0000" }, + ListElement { name: "Red 2"; hex: "#EE0000" }, + ListElement { name: "Red 3"; hex: "#CD0000" }, + ListElement { name: "Red 4"; hex: "#8B0000" }, + ListElement { name: "Tomato"; hex: "#FF6347" }, + ListElement { name: "Tomato 2"; hex: "#EE5C42" }, + ListElement { name: "Tomato 3"; hex: "#CD4F39" }, + ListElement { name: "Tomato 4"; hex: "#8B3626" }, + ListElement { name: "Orange Red"; hex: "#FF4500" }, + ListElement { name: "Orange Red 2"; hex: "#EE4000" }, + ListElement { name: "Orange Red 3"; hex: "#CD3700" }, + ListElement { name: "Orange Red 4"; hex: "#8B2500" }, + ListElement { name: "Indian Red 2"; hex: "#EE6363" }, + ListElement { name: "Indian Red 3"; hex: "#CD5555" }, + ListElement { name: "Indian Red 4"; hex: "#8B3A3A" }, + ListElement { name: "Brown"; hex: "#A52A2A" }, + ListElement { name: "Brown 1"; hex: "#FF4040" }, + ListElement { name: "Brown 2"; hex: "#EE3B3B" }, + ListElement { name: "Brown 3"; hex: "#CD3333" }, + ListElement { name: "Brown 4"; hex: "#8B2323" } + ] + } + ListElement { + name: "Greens" + colors: [ + ListElement { name: "Green"; hex: "#008000" }, + ListElement { name: "Green 2"; hex: "#00EE00" }, + ListElement { name: "Green 3"; hex: "#00CD00" }, + ListElement { name: "Green 4"; hex: "#008B00" }, + ListElement { name: "Dark Green"; hex: "#006400" }, + ListElement { name: "Sap Green"; hex: "#308014" }, + ListElement { name: "Medium Spring Green"; hex: "#00FA9A" }, + ListElement { name: "Spring Green"; hex: "#00FF7F" }, + ListElement { name: "Spring Green 1"; hex: "#00EE76" }, + ListElement { name: "Spring Green 2"; hex: "#00CD66" }, + ListElement { name: "Spring Green 3"; hex: "#008B45" }, + ListElement { name: "Medium Sea Green"; hex: "#3CB371" }, + ListElement { name: "Sea Green 1"; hex: "#54FF9F" }, + ListElement { name: "Sea Green 2"; hex: "#4EEE94" }, + ListElement { name: "Sea Green 3"; hex: "#43CD80" }, + ListElement { name: "Sea Green 4"; hex: "#2E8B57" }, + ListElement { name: "Emerald Green"; hex: "#00C957" }, + ListElement { name: "Mint"; hex: "#BDFCC9" }, + ListElement { name: "Cobalt Green"; hex: "#3D9140" }, + ListElement { name: "Dark Sea Green"; hex: "#8FBC8F" }, + ListElement { name: "Dark Sea Green 1"; hex: "#C1FFC1" }, + ListElement { name: "Dark Sea Green 2"; hex: "#B4EEB4" }, + ListElement { name: "Dark Sea Green 3"; hex: "#9BCD9B" }, + ListElement { name: "Dark Sea Green 4"; hex: "#698B69" }, + ListElement { name: "Lime Green"; hex: "#00FF00" } + ] + } + ListElement { + name: "Blues" + colors: [ + ListElement { name: "Dark Slate Blue"; hex: "#483D8B" }, + ListElement { name: "Light Slate Blue"; hex: "#8470FF" }, + ListElement { name: "Medium Slate Blue"; hex: "#7B68EE" }, + ListElement { name: "Slate Blue"; hex: "#6A5ACD" }, + ListElement { name: "Blue"; hex: "#0000FF" }, + ListElement { name: "Midnight Blue"; hex: "#191970" }, + ListElement { name: "Cobalt"; hex: "#3D59AB" }, + ListElement { name: "Royal Blue"; hex: "#4169E1" }, + ListElement { name: "Corn Flower Blue"; hex: "#6495ED" }, + ListElement { name: "Light Steel Blue"; hex: "#B0C4DE" }, + ListElement { name: "Light Steel Blue 1"; hex: "#CAE1FF" }, + ListElement { name: "Light Steel Blue 2"; hex: "#BCD2EE" }, + ListElement { name: "Light Steel Blue 3"; hex: "#A2B5CD" }, + ListElement { name: "Dodger Blue"; hex: "#1E90FF" }, + ListElement { name: "Dodger Blue 2"; hex: "#1C86EE" }, + ListElement { name: "Dodger Blue 3"; hex: "#1874CD" }, + ListElement { name: "Dodger Blue 4"; hex: "#104E8B" }, + ListElement { name: "Steel Blue"; hex: "#4682B4" }, + ListElement { name: "Light Sky Blue"; hex: "#87CEFA" }, + ListElement { name: "Sky Blue"; hex: "#87CEEB" }, + ListElement { name: "Peacock"; hex: "#33A1C9" }, + ListElement { name: "Light Blue"; hex: "#ADD8E6" }, + ListElement { name: "Powder Blue"; hex: "#B0E0E6" }, + ListElement { name: "Cadet Blue"; hex: "#5F9EA0" }, + ListElement { name: "Cyan"; hex: "#00FFFF" } + ] + } +} diff --git a/examples/declarative/colorbrowser/qml/ColorDelegate.qml b/examples/declarative/colorbrowser/qml/ColorDelegate.qml new file mode 100644 index 0000000..605e45b --- /dev/null +++ b/examples/declarative/colorbrowser/qml/ColorDelegate.qml @@ -0,0 +1,114 @@ +import Qt 4.6 + +Package { + Item { id: stack; Package.name: 'stack'; width: 110; height: 110; z: stack.PathView.z } + Item { id: list; Package.name: 'list'; width: mainWindow.width + 4; height: 110 } + Item { id: grid; Package.name: 'grid'; width: 110; height: 110 } + + Item { + id: delegate + + property double randomAngle: Math.random() * (2 * 8 + 1) - 8 + property bool open: false + + width: 110; height: 110; z: stack.PathView.z + + Image { x: -6; y: -5; source: 'box-shadow.png'; smooth: true; } + Rectangle { color: hex; anchors.fill: parent; smooth: true } + Image { id: box; source: 'box.png'; smooth: true; anchors.fill: parent } + + Binding { + target: infoColorName; property: 'text' + value: name; when: delegate.open && list.ListView.isCurrentItem + } + + Binding { + target: infoColorHex; property: 'text' + value: hex; when: delegate.open && list.ListView.isCurrentItem + } + + MouseRegion { + anchors.fill: parent + acceptedButtons: Qt.RightButton | Qt.LeftButton + onClicked: { + if (wrapper.state == 'inGrid' && mouse.button == Qt.RightButton) { + wrapper.state = '' + } else if (wrapper.state == 'inGrid') { + grid.GridView.view.currentIndex = index; + wrapper.state = 'fullscreen' + } else { + grid.GridView.view.currentIndex = index; + wrapper.state = 'inGrid' + } + } + } + + states: [ + State { + name: 'stacked'; when: wrapper.state == '' + ParentChange { target: delegate; parent: stack; x: 0; y: 0; rotation: delegate.randomAngle } + PropertyChanges { target: delegate; visible: stack.PathView.onPath ? 1.0 : 0.0 } + }, + State { + name: 'inGrid'; when: wrapper.state == 'inGrid' + ParentChange { target: delegate; parent: grid; x: 24; y: 24 } + PropertyChanges { target: delegate; open: true } + }, + State { + name: 'fullscreen'; when: wrapper.state == 'fullscreen' + ParentChange { target: delegate; parent: list; x: 0; y: 0; width: mainWindow.width; height: mainWindow.height } + PropertyChanges { target: box; opacity: 0 } + PropertyChanges { target: delegate; open: true } + } + ] + + transitions: [ + Transition { + from: 'stacked'; to: 'inGrid' + SequentialAnimation { + PauseAnimation { duration: 20 * index } + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { targets: delegate; properties: 'x,y,width,height,rotation'; duration: 600; easing.type: 'OutBack' } + } + } + }, + Transition { + from: 'inGrid'; to: 'stacked' + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { properties: 'x,y,width,height,rotation'; duration: 300; easing.type: 'InOutQuad' } + } + }, + Transition { + from: 'inGrid'; to: 'fullscreen' + SequentialAnimation { + PauseAnimation { duration: grid.GridView.isCurrentItem ? 0 : 300 } + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { + properties: 'x,y,width,height,opacity' + duration: grid.GridView.isCurrentItem ? 300 : 1; easing.type: 'InOutQuad' + } + } + } + }, + Transition { + from: 'fullscreen'; to: 'inGrid' + SequentialAnimation { + PauseAnimation { duration: grid.GridView.isCurrentItem ? 3 : 0 } + ParallelAnimation { + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { + properties: 'x,y,width,height' + duration: grid.GridView.isCurrentItem ? 300 : 1; easing.type: 'InOutQuad' + } + } + NumberAnimation { properties: 'opacity'; duration: grid.GridView.isCurrentItem ? 300 : 1; easing.type: 'InOutQuad' } + } + } + } + ] + } +} diff --git a/examples/declarative/colorbrowser/qml/box-shadow.png b/examples/declarative/colorbrowser/qml/box-shadow.png new file mode 100644 index 0000000..3281a37 Binary files /dev/null and b/examples/declarative/colorbrowser/qml/box-shadow.png differ diff --git a/examples/declarative/colorbrowser/qml/box.png b/examples/declarative/colorbrowser/qml/box.png new file mode 100644 index 0000000..86538aa Binary files /dev/null and b/examples/declarative/colorbrowser/qml/box.png differ -- cgit v0.12 From a40a5fde406855473ba5f4cfa78208ee5efd9cb1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:58:55 +1000 Subject: fix crash, re-enable settings test --- .../declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp index f2ea076..b63e14b 100644 --- a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp +++ b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp @@ -181,9 +181,8 @@ void tst_qdeclarativewebview::settings() QVERIFY(wv != 0); QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); - qWarning("Need to test settings"); - /* - QObject *s = qvariant_cast(wv->property("settings")); + QObject *s = QDeclarativeProperty(wv,"settings").object(); + QVERIFY(s != 0); // merely tests that setting gets stored (in QWebSettings) // behavioural tests are in WebKit. @@ -238,7 +237,6 @@ void tst_qdeclarativewebview::settings() QVERIFY(s->property("privateBrowsingEnabled") == on); QVERIFY(s->property("zoomTextOnly") == on); } - */ } void tst_qdeclarativewebview::historyNav() -- cgit v0.12 From 004f77f8ab4d07499116d151d6f2b015b57effac Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:59:18 +1000 Subject: OS-friendlier, less noisy. --- tests/auto/declarative/runall.sh | 81 ++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/tests/auto/declarative/runall.sh b/tests/auto/declarative/runall.sh index 39485d3..62e03e3 100755 --- a/tests/auto/declarative/runall.sh +++ b/tests/auto/declarative/runall.sh @@ -41,37 +41,60 @@ ## ############################################################################/ -Xnest :7 2>/dev/null & -sleep 1 -trap "kill $!" EXIT -export DISPLAY=:7 +if [ "$(uname)" = Linux ] +then + Xnest :7 2>/dev/null & + sleep 1 + trap "kill $!" EXIT + export DISPLAY=:7 + export LANG=en_US + kwin 2>/dev/null & + sleep 1 +fi -( make -k -j1 install 2>&1; - for exe in $(make install | sed -n 's/^install .* "\([^"]*qt4\/tst_[^"]*\)".*/\1/p') - do - $exe - done -) | +function filter +{ + exe=$1 + skip=0 while read line do - case "$line" in - make*Error) echo "$line";; - make*Stop) echo "$line";; - make*) ;; - install*) ;; - */qmake*) ;; - */bin/moc*) ;; - *targ.debug*) ;; - g++*) ;; - cd*) ;; - PASS*) ;; - QDEBUG*) ;; - Makefile*) ;; - Config*) ;; - Totals*) ;; - \**) ;; - ./*) ;; - *) echo "$line" - esac + if [ $skip != 0 ] + then + let skip=skip-1 + else + case "$line" in + make*Error) echo "$line";; + make*Stop) echo "$line";; + /*/bin/make*) ;; + make*) ;; + install*) ;; + QDeclarativeDebugServer:*Waiting*) ;; + QDeclarativeDebugServer:*Connection*) ;; + */qmake*) ;; + */bin/moc*) ;; + *targ.debug*) ;; + g++*) ;; + cd*) ;; + XFAIL*) skip=1;; + SKIP*) skip=1;; + PASS*) ;; + QDEBUG*) ;; + Makefile*) ;; + Config*) ;; + Totals*) ;; + \**) ;; + ./*) ;; + *tst_*) echo "$line" ;; + *) echo "$exe: $line" + esac + fi done +} + +make -k -j1 install 2>&1 | filter build +for exe in $(make install | sed -n 's/^install .* "\([^"]*qt4\/tst_[^"]*\)".*/\1/p') +do + echo $exe + $exe 2>&1 | filter $exe +done -- cgit v0.12 From 2ef17050f740b4e0debc43f66f26f419b317b7ab Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 15:15:47 +1000 Subject: QDeclarativeGuard should handle objects being deleted --- src/declarative/qml/qdeclarativedeclarativedata_p.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h index a7a73bc..ae40130 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h @@ -120,6 +120,11 @@ public: template void QDeclarativeGuard::addGuard() { + if (QObjectPrivate::get(o)->wasDeleted) { + if (prev) remGuard(); + return; + } + QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(o, true); next = data->guards; if (next) reinterpret_cast *>(next)->prev = &next; -- cgit v0.12 From 55cec1c8e73f90f968ce181c3310e5e16f2d5bd8 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Wed, 3 Mar 2010 15:22:25 +1000 Subject: Fixed compile of some tests with `-qtnamespace' --- tests/auto/declarative/qdeclarativelanguage/testtypes.h | 3 +++ tests/auto/qmediaservice/tst_qmediaservice.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index 8ac7aa6..09cddcb 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -62,7 +62,10 @@ public: MyInterface() : id(913) {} int id; }; + +QT_BEGIN_NAMESPACE Q_DECLARE_INTERFACE(MyInterface, "com.trolltech.Qt.Test.MyInterface"); +QT_END_NAMESPACE QML_DECLARE_INTERFACE(MyInterface); struct MyCustomVariantType diff --git a/tests/auto/qmediaservice/tst_qmediaservice.cpp b/tests/auto/qmediaservice/tst_qmediaservice.cpp index 35f661d..a0cb69d 100644 --- a/tests/auto/qmediaservice/tst_qmediaservice.cpp +++ b/tests/auto/qmediaservice/tst_qmediaservice.cpp @@ -69,7 +69,9 @@ class QtTestMediaControlA : public QMediaControl #define QtTestMediaControlA_iid "com.nokia.QtTestMediaControlA" +QT_BEGIN_NAMESPACE Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlA, QtTestMediaControlA_iid) +QT_END_NAMESPACE class QtTestMediaControlB : public QMediaControl @@ -78,7 +80,9 @@ class QtTestMediaControlB : public QMediaControl }; #define QtTestMediaControlB_iid "com.nokia.QtTestMediaControlB" +QT_BEGIN_NAMESPACE Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlB, QtTestMediaControlB_iid) +QT_END_NAMESPACE class QtTestMediaControlC : public QMediaControl @@ -87,7 +91,9 @@ class QtTestMediaControlC : public QMediaControl }; #define QtTestMediaControlC_iid "com.nokia.QtTestMediaControlC" +QT_BEGIN_NAMESPACE Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlC, QtTestMediaControlA_iid) // Yes A. +QT_END_NAMESPACE class QtTestMediaControlD : public QMediaControl { @@ -95,7 +101,9 @@ class QtTestMediaControlD : public QMediaControl }; #define QtTestMediaControlD_iid "com.nokia.QtTestMediaControlD" +QT_BEGIN_NAMESPACE Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlD, QtTestMediaControlD_iid) +QT_END_NAMESPACE class QtTestMediaControlE : public QMediaControl { -- cgit v0.12 From 7d2471e3beba5745fb5ea4dade3188e643f6b562 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Mar 2010 16:25:21 +1000 Subject: Auto test for QTBUG-8677 --- .../declarative/qdeclarativelanguage/data/attachedProperties.qml | 2 ++ tests/auto/declarative/qdeclarativelanguage/testtypes.h | 7 +++++-- .../declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml b/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml index b46ec34..aecb3c3 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml @@ -3,6 +3,8 @@ import Test 1.0 as Namespace import Qt 4.6 QtObject { + property int value2: 8 MyQmlObject.value: 10 Namespace.MyQmlObject.value2: 13 + MyQmlObject.onValueChanged: value2 = MyQmlObject.value } diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index ec2c5f7..08d6d96 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -75,17 +75,20 @@ Q_DECLARE_METATYPE(MyCustomVariantType); class MyAttachedObject : public QObject { Q_OBJECT - Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) Q_PROPERTY(int value2 READ value2 WRITE setValue2) public: MyAttachedObject(QObject *parent) : QObject(parent), m_value(0), m_value2(0) {} int value() const { return m_value; } - void setValue(int v) { m_value = v; } + void setValue(int v) { if (m_value != v) { m_value = v; emit valueChanged(); } } int value2() const { return m_value2; } void setValue2(int v) { m_value2 = v; } +signals: + void valueChanged(); + private: int m_value; int m_value2; diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 39f5223..870f3fe 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -713,6 +713,11 @@ void tst_qdeclarativelanguage::attachedProperties() QVERIFY(attached != 0); QCOMPARE(attached->property("value"), QVariant(10)); QCOMPARE(attached->property("value2"), QVariant(13)); + + QEXPECT_FAIL("", "QTBUG-8677", Abort); + attached->setProperty("value", QVariant(12)); + int val = object->property("value2").toInt(); + QCOMPARE(val, 12); } // Tests non-static object properties -- cgit v0.12 From dba7eb104f7788fda36e8a2ecffc8f4c08ec1fae Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 16:59:04 +1000 Subject: Add documentation for the 'when' property of Binding. --- src/declarative/util/qdeclarativebind.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index e95a03e..26baa38 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -72,7 +72,7 @@ public: /*! \qmlclass Binding QDeclarativeBind - \since 4.7 + \since 4.7 \brief The Binding element allows arbitrary property bindings to be created. Sometimes it is necessary to bind to a property of an object that wasn't @@ -114,6 +114,19 @@ QDeclarativeBind::~QDeclarativeBind() { } +/*! + \qmlproperty bool Binding::when + + This property holds when the binding is active. + This should be set to an expression that evaluates to true when you want the binding to be active. + + \code + Binding { + target: contactName; property: 'text' + value: name; when: list.ListView.isCurrentItem + } + \endcode +*/ bool QDeclarativeBind::when() const { Q_D(const QDeclarativeBind); -- cgit v0.12 From 4690084e9f3fbf3635aa3fb6a8025ae046672aea Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 17:14:07 +1000 Subject: Move JS global scope to top of the QML scope chain QT-2787 --- src/declarative/qml/qdeclarativecompiler.cpp | 62 +++++++++++----------- src/declarative/qml/qdeclarativecompiler_p.h | 2 +- src/declarative/qml/qdeclarativecontext.cpp | 3 ++ src/declarative/qml/qdeclarativeexpression.cpp | 5 ++ .../qml/qdeclarativeglobalscriptclass.cpp | 15 ++++-- .../qml/qdeclarativeglobalscriptclass_p.h | 7 ++- .../qdeclarativeecmascript/data/scope.3.qml | 13 +++++ .../tst_qdeclarativeecmascript.cpp | 10 ++++ .../data/invalidID.2.errors.txt | 2 +- .../data/invalidID.6.errors.txt | 2 +- .../data/invalidID.7.errors.txt | 1 + .../qdeclarativelanguage/data/invalidID.7.qml | 5 ++ .../data/invalidID.8.errors.txt | 1 + .../qdeclarativelanguage/data/invalidID.8.qml | 5 ++ .../data/invalidID.9.errors.txt | 1 + .../qdeclarativelanguage/data/invalidID.9.qml | 5 ++ .../qdeclarativelanguage/data/invalidID.errors.txt | 2 +- .../tst_qdeclarativelanguage.cpp | 6 +-- 18 files changed, 103 insertions(+), 44 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index a9809c0..1eea012 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -65,6 +65,7 @@ #include "qdeclarativescriptparser_p.h" #include "qdeclarativebinding_p.h" #include "qdeclarativecompiledbindings_p.h" +#include "qdeclarativeglobalscriptclass_p.h" #include @@ -113,32 +114,6 @@ QList QDeclarativeCompiler::errors() const } /*! - Returns true if \a val is a legal object id, false otherwise. - - Legal ids must start with a lower-case letter or underscore, and contain only - letters, numbers and underscores. -*/ -bool QDeclarativeCompiler::isValidId(const QString &val) -{ - if (val.isEmpty()) - return false; - - if (val.at(0).isLetter() && !val.at(0).isLower()) { - qWarning().nospace() << "id " << val << " is invalid: ids cannot start with uppercase letters"; - return false; - } - - QChar u(QLatin1Char('_')); - for (int ii = 0; ii < val.count(); ++ii) - if (val.at(ii) != u && - ((ii == 0 && !val.at(ii).isLetter()) || - (ii != 0 && !val.at(ii).isLetterOrNumber())) ) - return false; - - return true; -} - -/*! Returns true if \a name refers to an attached property, false otherwise. Attached property names are those that start with a capital letter. @@ -1140,10 +1115,11 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, if (obj->properties.count()) idProp = *obj->properties.begin(); - if (idProp && (idProp->value || idProp->values.count() > 1 || !isValidId(idProp->values.first()->primitive()))) - COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QDeclarativeCompiler","Invalid component id specification")); - if (idProp) { + if (idProp->value || idProp->values.count() > 1 || idProp->values.at(0)->object) + COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QDeclarativeCompiler","Invalid component id specification")); + COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive())); + QString idVal = idProp->values.first()->primitive(); if (compileState.ids.contains(idVal)) @@ -1726,8 +1702,7 @@ bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Value *idValue = prop->values.at(0); QString val = idValue->primitive(); - if (!isValidId(val)) - COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","\"%1\" is not a valid object id").arg(val)); + COMPILE_CHECK(checkValidId(idValue, val)); // We disallow id's that conflict with import prefixes and types QDeclarativeEnginePrivate::ImportedNamespace *ns = 0; @@ -2476,6 +2451,31 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn return true; } +bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QString &val) +{ + if (val.isEmpty()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "Invalid empty ID")); + + if (val.at(0).isLetter() && !val.at(0).isLower()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs cannot start with an uppercase letter")); + + QChar u(QLatin1Char('_')); + for (int ii = 0; ii < val.count(); ++ii) { + + if (ii == 0 && !val.at(ii).isLetter() && val.at(ii) != u) { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs must start with a letter or underscore")); + } else if (ii != 0 && !val.at(ii).isLetterOrNumber() && val.at(ii) != u) { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs must contain only letters, numbers, and underscores")); + } + + } + + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(val)) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "ID illegally masks global JavaScript property")); + + return true; +} + #include static QStringList astNodeToStringList(QDeclarativeJS::AST::Node *node) diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 93a3f83..f8ada95 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -155,7 +155,6 @@ public: bool isError() const; QList errors() const; - static bool isValidId(const QString &); static bool isAttachedPropertyName(const QByteArray &); static bool isSignalPropertyName(const QByteArray &); @@ -247,6 +246,7 @@ private: QDeclarativeParser::Object *obj, const QDeclarativeParser::Object::DynamicProperty &); bool completeComponentBuild(); + bool checkValidId(QDeclarativeParser::Value *, const QString &); void genObject(QDeclarativeParser::Object *obj); diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 57ef90c..35e7a77 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -47,6 +47,7 @@ #include "qdeclarativeengine.h" #include "qdeclarativecompiledbindings_p.h" #include "qdeclarativeinfo.h" +#include "qdeclarativeglobalscriptclass_p.h" #include #include @@ -74,7 +75,9 @@ void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::Scr QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); + scriptContext->pushScope(enginePriv->contextClass->newContext(q, scopeObject)); + scriptContext->pushScope(enginePriv->globalClass->globalObject()); QScriptValue scope = scriptEngine->newObject(); scriptContext->setActivationObject(scope); diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index ae1e790..0030615 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -46,6 +46,7 @@ #include "qdeclarativecontext_p.h" #include "qdeclarativerewrite_p.h" #include "qdeclarativecompiler_p.h" +#include "qdeclarativeglobalscriptclass_p.h" #include #include @@ -135,6 +136,7 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContext *ctxt, void *expr, if (!dd->cachedClosures.at(progIdx)) { QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newSharedContext()); + scriptContext->pushScope(ep->globalClass->globalObject()); dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(data->expression, data->url, data->line)); scriptEngine->popContext(); } @@ -169,6 +171,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(context, object)); + scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); return rv; @@ -180,6 +183,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(context, object)); + scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); return rv; @@ -335,6 +339,7 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(data->context(), data->me)); + scriptContext->pushScope(ep->globalClass->globalObject()); if (data->expressionRewritten) { data->expressionFunction = scriptEngine->evaluate(data->expression, diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index 5b06b42..9ee2fe5 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -53,15 +53,17 @@ QT_BEGIN_NAMESPACE QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engine) : QScriptClass(engine) { - QScriptValue v = engine->newObject(); - globalObject = engine->globalObject(); + QScriptValue globalObject = engine->globalObject(); + m_globalObject = engine->newObject(); QScriptValueIterator iter(globalObject); while (iter.hasNext()) { iter.next(); - v.setProperty(iter.scriptName(), iter.value()); + m_globalObject.setProperty(iter.scriptName(), iter.value()); + m_illegalNames.insert(iter.name()); } + QScriptValue v = engine->newObject(); v.setScriptClass(this); engine->setGlobalObject(v); } @@ -101,12 +103,14 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, engine()->currentContext()->throwError(error); } +/* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value) { + QScriptValue globalObject = engine()->globalObject(); + QScriptValue v = engine()->newObject(); - globalObject = engine()->globalObject(); - QScriptValueIterator iter(globalObject); + QScriptValueIterator iter(v); while (iter.hasNext()) { iter.next(); v.setProperty(iter.scriptName(), iter.value()); @@ -114,6 +118,7 @@ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, con v.setProperty(name, value); v.setScriptClass(this); + engine()->setGlobalObject(v); } diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h index a33cf5e..1b34aee 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h @@ -54,6 +54,7 @@ // #include +#include QT_BEGIN_NAMESPACE @@ -74,8 +75,12 @@ public: void explicitSetProperty(const QString &, const QScriptValue &); + const QScriptValue &globalObject() const { return m_globalObject; } + const QSet &illegalNames() const { return m_illegalNames; } + private: - QScriptValue globalObject; + QSet m_illegalNames; + QScriptValue m_globalObject; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml new file mode 100644 index 0000000..4ad7f34 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml @@ -0,0 +1,13 @@ +import Qt 4.6 + +Item { + id: root + + property int foo: 12 + property int console: 11 + + property bool test1: foo == 12 + property bool test2: console != 11 + property bool test3: root.console == 11 +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 85a3ef3..e45f0fa 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -729,6 +729,16 @@ void tst_qdeclarativeecmascript::scope() QCOMPARE(object->property("test5").toInt(), 24); QCOMPARE(object->property("test6").toInt(), 24); } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scope.3.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test1").toBool(), true); + QCOMPARE(object->property("test2").toBool(), true); + QCOMPARE(object->property("test3").toBool(), true); + } } /* diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt index 56e3eeb..2c6b8bf 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt @@ -1,2 +1,2 @@ -3:5:"" is not a valid object id +3:9:Invalid empty ID diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt index 160e8b5..7251de1 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt @@ -1 +1 @@ -3:5:"StartsWithUpperCase" is not a valid object id +3:9:IDs cannot start with an uppercase letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt new file mode 100644 index 0000000..e4fd1db --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt @@ -0,0 +1 @@ +3:9:ID illegally masks global JavaScript property diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml new file mode 100644 index 0000000..d4bc539 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: gc +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt new file mode 100644 index 0000000..b03ec6c --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt @@ -0,0 +1 @@ +3:9:IDs must contain only letters, numbers, and underscores diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml new file mode 100644 index 0000000..1ea615c --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: hello.world +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt new file mode 100644 index 0000000..c010e79 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt @@ -0,0 +1 @@ +3:9:IDs must start with a letter or underscore diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml new file mode 100644 index 0000000..57474b7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: "3hello" +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt index 1ca678c..c010e79 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt @@ -1 +1 @@ -3:5:"1" is not a valid object id +3:9:IDs must start with a letter or underscore diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 870f3fe..5d480fa 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -232,6 +232,9 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidID.4") << "invalidID.4.qml" << "invalidID.4.errors.txt" << false; QTest::newRow("invalidID.5") << "invalidID.5.qml" << "invalidID.5.errors.txt" << false; QTest::newRow("invalidID.6") << "invalidID.6.qml" << "invalidID.6.errors.txt" << false; + QTest::newRow("invalidID.7") << "invalidID.7.qml" << "invalidID.7.errors.txt" << false; + QTest::newRow("invalidID.8") << "invalidID.8.qml" << "invalidID.8.errors.txt" << false; + QTest::newRow("invalidID.9") << "invalidID.9.qml" << "invalidID.9.errors.txt" << false; QTest::newRow("unsupportedProperty") << "unsupportedProperty.qml" << "unsupportedProperty.errors.txt" << false; QTest::newRow("nullDotProperty") << "nullDotProperty.qml" << "nullDotProperty.errors.txt" << true; @@ -327,9 +330,6 @@ void tst_qdeclarativelanguage::errors() QFETCH(QString, errorFile); QFETCH(bool, create); - if (file == "invalidID.6.qml") - QTest::ignoreMessage(QtWarningMsg, "id \"StartsWithUpperCase\" is invalid: ids cannot start with uppercase letters"); - QDeclarativeComponent component(&engine, TEST_FILE(file)); if(create) { -- cgit v0.12 From ef785f047adf6f559c282d67e627b78b75a7b9ef Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 17:53:05 +1000 Subject: QDeclarativeProperty::read() returns a QObjectStar when accessing a QObject property QT-2793 --- src/declarative/qml/qdeclarativeproperty.cpp | 11 +++++-- .../qdeclarativeproperty/data/TestType.qml | 6 ++++ .../data/readSynthesizedObject.qml | 9 ++++++ .../qdeclarativeproperty/qdeclarativeproperty.pro | 2 ++ .../tst_qdeclarativeproperty.cpp | 37 ++++++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeproperty/data/TestType.qml create mode 100644 tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index e1ec2cd..521c241 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -793,7 +793,7 @@ QVariant QDeclarativeProperty::read(QObject *object, const QString &name, QDecla QVariant QDeclarativePropertyPrivate::readValueProperty() { - if(isValueType()) { + if (isValueType()) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); QDeclarativeValueType *valueType = 0; @@ -809,13 +809,20 @@ QVariant QDeclarativePropertyPrivate::readValueProperty() if (!ep) delete valueType; return rv; - } else if(core.flags & QDeclarativePropertyCache::Data::IsQList) { + } else if (core.flags & QDeclarativePropertyCache::Data::IsQList) { QDeclarativeListProperty prop; void *args[] = { &prop, 0 }; QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); return QVariant::fromValue(QDeclarativeListReferencePrivate::init(prop, core.propType, engine)); + } else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) { + + QObject *rv = 0; + void *args[] = { &rv, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); + return QVariant::fromValue(rv); + } else { return object->metaObject()->property(core.coreIndex).read(object.data()); diff --git a/tests/auto/declarative/qdeclarativeproperty/data/TestType.qml b/tests/auto/declarative/qdeclarativeproperty/data/TestType.qml new file mode 100644 index 0000000..1dfb3e1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/data/TestType.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +QtObject { + property int a: 10 +} + diff --git a/tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml b/tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml new file mode 100644 index 0000000..8085db2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property TestType test + + test: TestType { + property int b: 19 + } +} diff --git a/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro b/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro index 22e50cc..af1e1b6 100644 --- a/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro +++ b/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro @@ -3,3 +3,5 @@ contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativeproperty.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp index 0333d98..9b8a643 100644 --- a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp +++ b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp @@ -46,6 +46,14 @@ #include #include #include +#include +#include + +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(QLatin1String("data/") + filename)); +} class MyQmlObject : public QObject { @@ -181,6 +189,7 @@ class PropertyObject : public QObject Q_PROPERTY(QUrl url READ url WRITE setUrl); Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) + Q_PROPERTY(MyQmlObject *qmlObject READ qmlObject); Q_CLASSINFO("DefaultProperty", "defaultProperty"); public: @@ -202,6 +211,7 @@ public: int propertyWithNotify() const { return m_propertyWithNotify; } void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); } + MyQmlObject *qmlObject() { return &m_qmlObject; } signals: void clicked(); void oddlyNamedNotifySignal(); @@ -211,6 +221,7 @@ private: QRect m_rect; QUrl m_url; int m_propertyWithNotify; + MyQmlObject m_qmlObject; }; QML_DECLARE_TYPE(PropertyObject); @@ -953,6 +964,32 @@ void tst_qdeclarativeproperty::read() QCOMPARE(p.read(), QVariant()); } + // Object property + { + PropertyObject o; + QDeclarativeProperty p(&o, "qmlObject"); + QCOMPARE(p.propertyTypeCategory(), QDeclarativeProperty::Object); + QCOMPARE(p.propertyType(), qMetaTypeId()); + QVariant v = p.read(); + QVERIFY(v.userType() == QMetaType::QObjectStar); + QVERIFY(qvariant_cast(v) == o.qmlObject()); + } + { + QDeclarativeComponent component(&engine, TEST_FILE("readSynthesizedObject.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "test", &engine); + + QCOMPARE(p.propertyTypeCategory(), QDeclarativeProperty::Object); + QVERIFY(p.propertyType() != QMetaType::QObjectStar); + + QVariant v = p.read(); + QVERIFY(v.userType() == QMetaType::QObjectStar); + QCOMPARE(qvariant_cast(v)->property("a").toInt(), 10); + QCOMPARE(qvariant_cast(v)->property("b").toInt(), 19); + } + // Attached property { QDeclarativeComponent component(&engine); -- cgit v0.12 From 07bd4f61caaa61866fcfa7847eeeb905d4fa2b38 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 17:54:43 +1000 Subject: 'on' syntax fixes --- .../graphicsitems/qdeclarativegridview.cpp | 6 ++-- .../graphicsitems/qdeclarativelistview.cpp | 2 +- src/declarative/qml/qdeclarativedom.cpp | 8 ++--- src/declarative/util/qdeclarativeanimation.cpp | 18 ++++++------ src/declarative/util/qdeclarativebehavior.cpp | 6 ++-- src/declarative/util/qdeclarativeeasefollow.cpp | 34 +++++++++++----------- src/declarative/util/qdeclarativespringfollow.cpp | 6 ++-- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 090c46d..5b313be 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -744,7 +744,7 @@ QDeclarativeGridView::~QDeclarativeGridView() id: myDelegate Item { id: wrapper - GridView.onRemove: SequentialAnimation { + SequentialAnimation on GridView.onRemove { PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true } NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false } @@ -989,8 +989,8 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) id: myHighlight Rectangle { id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 - y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } - x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } + SpringFollow on y { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } + SpringFollow on x { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } } } \endcode diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index a05e638..eb5315d 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1431,7 +1431,7 @@ QDeclarativeListView::~QDeclarativeListView() id: myDelegate Item { id: wrapper - ListView.onRemove: SequentialAnimation { + SequentialAnimation on ListView.onRemove { PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true } NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false } diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp index 5b43109..cb56ead 100644 --- a/src/declarative/qml/qdeclarativedom.cpp +++ b/src/declarative/qml/qdeclarativedom.cpp @@ -374,7 +374,7 @@ QDeclarativeDomValue QDeclarativeDomProperty::value() const QDeclarativeDomValue rv; if (d->property) { rv.d->property = d->property; - if (d->property->values.count()) + if (d->property->values.count()) rv.d->value = d->property->values.at(0); else rv.d->value = d->property->onValues.at(0); @@ -508,7 +508,7 @@ int QDeclarativeDomDynamicProperty::propertyType() const QByteArray QDeclarativeDomDynamicProperty::propertyTypeName() const { - if (isValid()) + if (isValid()) return d->property.customType; return QByteArray(); @@ -1184,7 +1184,7 @@ QDeclarativeDomObject QDeclarativeDomValueValueSource::object() const \qml Rectangle { - x: Behavior { NumberAnimation { duration: 500 } } + Behavior on x { NumberAnimation { duration: 500 } } } \endqml */ @@ -1228,7 +1228,7 @@ QDeclarativeDomValueValueInterceptor &QDeclarativeDomValueValueInterceptor::oper returned. \qml Rectangle { - x: Behavior { NumberAnimation { duration: 500 } } + Behavior on x { NumberAnimation { duration: 500 } } } \endqml */ diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 7f4f1c0..b14de19 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -110,7 +110,7 @@ QDeclarativeAbstractAnimation::QDeclarativeAbstractAnimation(QDeclarativeAbstrac \code Rectangle { width: 100; height: 100 - x: NumberAnimation { + NumberAnimation on x { running: myMouse.pressed from: 0; to: 100 } @@ -310,7 +310,7 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) \code Rectangle { - rotation: NumberAnimation { running: true; repeat: true; from: 0 to: 360 } + NumberAnimation on rotation { running: true; repeat: true; from: 0 to: 360 } } \endcode */ @@ -412,7 +412,7 @@ void QDeclarativeAbstractAnimation::resume() no further influence on property values. In this example animation \code Rectangle { - x: NumberAnimation { from: 0; to: 100; duration: 500 } + NumberAnimation on x { from: 0; to: 100; duration: 500 } } \endcode was stopped at time 250ms, the \c x property will have a value of 50. @@ -450,7 +450,7 @@ void QDeclarativeAbstractAnimation::restart() its end. In the following example, \code Rectangle { - x: NumberAnimation { from: 0; to: 100; duration: 500 } + NumberAnimation on x { from: 0; to: 100; duration: 500 } } \endcode calling \c stop() at time 250ms will result in the \c x property having @@ -1292,7 +1292,7 @@ QDeclarativeVector3dAnimation::QDeclarativeVector3dAnimation(QObject *parent) Q_D(QDeclarativePropertyAnimation); d->interpolatorType = QMetaType::QVector3D; d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); - d->defaultToInterpolatorType = true; + d->defaultToInterpolatorType = true; } QDeclarativeVector3dAnimation::~QDeclarativeVector3dAnimation() @@ -1741,7 +1741,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Animate all changes to a rectangle's x property. \qml Rectangle { - x: Behavior { PropertyAnimation {} } + Behavior on x { PropertyAnimation {} } } \endqml \o As a property value source @@ -1749,7 +1749,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Repeatedly animate the rectangle's x property. \qml Rectangle { - x: SequentialAnimation { + SequentialAnimation on x { repeat: true PropertyAnimation { to: 50 } PropertyAnimation { to: 0 } @@ -2140,8 +2140,8 @@ void QDeclarativePropertyAnimation::setProperties(const QString &prop) id: theRect width: 100; height: 100 color: Qt.rgba(0,0,1) - x: NumberAnimation { to: 500; repeat: true } //animate theRect's x property - y: Behavior { NumberAnimation {} } //animate theRect's y property + NumberAnimation on x { to: 500; repeat: true } //animate theRect's x property + Behavior on y { NumberAnimation {} } //animate theRect's y property } \endqml \row diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 5352341..dea2c02 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -75,13 +75,13 @@ public: Behaviors provide one way to specify \l{qdeclarativeanimation.html}{animations} in QML. - In the example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: + In the example below, the rectangle will use a bounce easing curve over 200 millisecond for any changes to its y property: \code Rectangle { width: 20; height: 20 color: "#00ff00" - y: 200 //initial value - y: Behavior { + y: 200 // initial value + Behavior on y { NumberAnimation { easing: "easeOutBounce(amplitude:100)" duration: 200 diff --git a/src/declarative/util/qdeclarativeeasefollow.cpp b/src/declarative/util/qdeclarativeeasefollow.cpp index 3fa9866..ee181dd 100644 --- a/src/declarative/util/qdeclarativeeasefollow.cpp +++ b/src/declarative/util/qdeclarativeeasefollow.cpp @@ -59,10 +59,10 @@ class QDeclarativeEaseFollowPrivate : public QObjectPrivate public: QDeclarativeEaseFollowPrivate() : source(0), velocity(200), duration(-1), maximumEasingTime(-1), - reversingMode(QDeclarativeEaseFollow::Eased), initialVelocity(0), + reversingMode(QDeclarativeEaseFollow::Eased), initialVelocity(0), initialValue(0), invert(false), enabled(true), trackVelocity(0), clockOffset(0), lastTick(0), clock(this) - {} + {} qreal source; qreal velocity; @@ -173,7 +173,7 @@ bool QDeclarativeEaseFollowPrivate::recalc() } /* - qWarning() << "a:" << a << "tf:" << tf << "tp:" << tp << "vp:" + qWarning() << "a:" << a << "tf:" << tf << "tp:" << tp << "vp:" << vp << "sp:" << sp << "vi:" << vi << "invert:" << invert; */ return true; @@ -254,19 +254,19 @@ void QDeclarativeEaseFollowPrivate::tick(int t) \since 4.7 \brief The EaseFollow element allows a property to smoothly track a value. - The EaseFollow smoothly animates a property's value to a set target value + The EaseFollow smoothly animates a property's value to a set target value using an ease in/out quad easing curve. If the target value changes while - the animation is in progress, the easing curves used to animate to the old + the animation is in progress, the easing curves used to animate to the old and the new target values are spliced together to avoid any obvious visual glitches. The property animation is configured by setting the velocity at which the - animation should occur, or the duration that the animation should take. + animation should occur, or the duration that the animation should take. If both a velocity and a duration are specified, the one that results in the quickest animation is chosen for each change in the target value. For example, animating from 0 to 800 will take 4 seconds if a velocity - of 200 is set, will take 8 seconds with a duration of 8000 set, and will + of 200 is set, will take 8 seconds with a duration of 8000 set, and will take 4 seconds with both a velocity of 200 and a duration of 8000 set. Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set, will take 8 seconds with a duration of 8000 set, and will take 8 seconds @@ -283,8 +283,8 @@ Rectangle { color: "green" width: 60; height: 60; x: -5; y: -5; - x: EaseFollow { source: rect1.x - 5; velocity: 200 } - y: EaseFollow { source: rect1.y - 5; velocity: 200 } + EaseFollow on x { source: rect1.x - 5; velocity: 200 } + EaseFollow on y { source: rect1.y - 5; velocity: 200 } } Rectangle { @@ -338,8 +338,8 @@ qreal QDeclarativeEaseFollow::sourceValue() const Sets how the EaseFollow behaves if an animation direction is reversed. If reversing mode is \c Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c Immediate, the - animation will immediately begin accelerating in the reverse direction, + then reverse direction. If the reversing mode is \c Immediate, the + animation will immediately begin accelerating in the reverse direction, begining with a velocity of 0. If the reversing mode is \c Sync, the property is immediately set to the target value. */ @@ -373,7 +373,7 @@ void QDeclarativeEaseFollowPrivate::restart() return; } - bool hasReversed = trackVelocity != 0. && + bool hasReversed = trackVelocity != 0. && ((trackVelocity > 0) == ((initialValue - source) > 0)); if (hasReversed) { @@ -440,7 +440,7 @@ void QDeclarativeEaseFollow::setDuration(qreal v) d->duration = v; d->trackVelocity = 0; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit durationChanged(); @@ -470,7 +470,7 @@ void QDeclarativeEaseFollow::setVelocity(qreal v) d->velocity = v; d->trackVelocity = 0; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit velocityChanged(); @@ -511,8 +511,8 @@ void QDeclarativeEaseFollow::setTarget(const QDeclarativeProperty &t) \qmlproperty qreal EaseFollow::maximumEasingTime This property specifies the maximum time an "eases" during the follow should take. -Setting this property causes the velocity to "level out" after at a time. Setting -a negative value reverts to the normal mode of easing over the entire animation +Setting this property causes the velocity to "level out" after at a time. Setting +a negative value reverts to the normal mode of easing over the entire animation duration. The default value is -1. @@ -528,7 +528,7 @@ void QDeclarativeEaseFollow::setMaximumEasingTime(qreal v) Q_D(QDeclarativeEaseFollow); d->maximumEasingTime = v; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit maximumEasingTimeChanged(); diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index 6205ab9..1d69dd3 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -222,8 +222,8 @@ void QDeclarativeSpringFollowPrivate::stop() id: rect1 width: 20; height: 20 color: "#00ff00" - y: 200 //initial value - y: SequentialAnimation { + y: 200 // initial value + SequentialAnimation on y { running: true repeat: true NumberAnimation { @@ -239,7 +239,7 @@ void QDeclarativeSpringFollowPrivate::stop() x: rect1.width width: 20; height: 20 color: "#ff0000" - y: SpringFollow { source: rect1.y; velocity: 200 } + SpringFollow on y { source: rect1.y; velocity: 200 } } \endcode -- cgit v0.12 From 64a4b25fac94fc5c9b75ab31690c658e95189797 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 18:33:44 +1000 Subject: Save secondary scope inside the expression's scope object This prevents the secondary scope from contaminating scopes outside itself when used as a signal expression. QTBUG-8641 --- .../qml/qdeclarativecontextscriptclass.cpp | 30 ++++++++++++++-- .../qml/qdeclarativecontextscriptclass_p.h | 1 + src/declarative/qml/qdeclarativeexpression.cpp | 41 +++++++++++++--------- src/declarative/qml/qdeclarativeexpression_p.h | 5 +-- .../tst_qdeclarativeecmascript.cpp | 3 +- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp index 7deed0b..d6305d8 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp +++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp @@ -50,10 +50,11 @@ QT_BEGIN_NAMESPACE struct ContextData : public QScriptDeclarativeClass::Object { - ContextData() : isSharedContext(true) {} - ContextData(QDeclarativeContext *c, QObject *o) : context(c), scopeObject(o), isSharedContext(false) {} + ContextData() : overrideObject(0), isSharedContext(true) {} + ContextData(QDeclarativeContext *c, QObject *o) : context(c), scopeObject(o), overrideObject(0), isSharedContext(false) {} QDeclarativeGuard context; QDeclarativeGuard scopeObject; + QObject *overrideObject; bool isSharedContext; QDeclarativeContext *getContext(QDeclarativeEngine *engine) { @@ -110,6 +111,17 @@ QDeclarativeContext *QDeclarativeContextScriptClass::contextFromValue(const QScr return data->getContext(engine); } +QObject *QDeclarativeContextScriptClass::setOverrideObject(QScriptValue &v, QObject *override) +{ + if (scriptClass(v) != this) + return 0; + + ContextData *data = (ContextData *)object(v); + QObject *rv = data->overrideObject; + data->overrideObject = override; + return rv; +} + QScriptClass::QueryFlags QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier &name, QScriptClass::QueryFlags flags) @@ -127,6 +139,20 @@ QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier & if (!bindContext) return 0; + QObject *overrideObject = ((ContextData *)object)->overrideObject; + if (overrideObject) { + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); + QScriptClass::QueryFlags rv = + ep->objectClass->queryProperty(overrideObject, name, flags, bindContext, + QDeclarativeObjectScriptClass::ImplicitObject | + QDeclarativeObjectScriptClass::SkipAttachedProperties); + if (rv) { + lastScopeObject = overrideObject; + lastContext = bindContext; + return rv; + } + } + bool includeTypes = true; while (bindContext) { QScriptClass::QueryFlags rv = diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/qdeclarativecontextscriptclass_p.h index 26086ec..4b0dca0 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h +++ b/src/declarative/qml/qdeclarativecontextscriptclass_p.h @@ -70,6 +70,7 @@ public: QScriptValue newSharedContext(); QDeclarativeContext *contextFromValue(const QScriptValue &); + QObject *setOverrideObject(QScriptValue &, QObject *); protected: virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 0030615..e528e9e 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -153,9 +153,11 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContext *ctxt, void *expr, new QScriptProgram(data->expression, data->url, data->line); } - data->expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx)); + data->expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx), + &data->expressionContext); #else - data->expressionFunction = evalInObjectScope(ctxt, me, data->expression); + data->expressionFunction = evalInObjectScope(ctxt, me, data->expression, + &data->expressionContext); #endif data->expressionFunctionValid = true; @@ -166,11 +168,16 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContext *ctxt, void *expr, } QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContext *context, QObject *object, - const QString &program) + const QString &program, QScriptValue *contextObject) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(context, object)); + if (contextObject) { + *contextObject = ep->contextClass->newContext(context, object); + scriptContext->pushScope(*contextObject); + } else { + scriptContext->pushScope(ep->contextClass->newContext(context, object)); + } scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); @@ -178,11 +185,16 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex } QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContext *context, QObject *object, - const QScriptProgram &program) + const QScriptProgram &program, QScriptValue *contextObject) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(context, object)); + if (contextObject) { + *contextObject = ep->contextClass->newContext(context, object); + scriptContext->pushScope(*contextObject); + } else { + scriptContext->pushScope(ep->contextClass->newContext(context, object)); + } scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); @@ -330,15 +342,13 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo QDeclarativeEngine *engine = data->context()->engine(); QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - if (secondaryScope) - ctxtPriv->defaultObjects.append(secondaryScope); - QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); if (!data->expressionFunctionValid) { QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(data->context(), data->me)); + data->expressionContext = ep->contextClass->newContext(data->context(), data->me); + scriptContext->pushScope(data->expressionContext); scriptContext->pushScope(ep->globalClass->globalObject()); if (data->expressionRewritten) { @@ -362,11 +372,14 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo QDeclarativeContext *oldSharedContext = 0; QObject *oldSharedScope = 0; + QObject *oldOverride = 0; if (data->isShared) { oldSharedContext = ep->sharedContext; oldSharedScope = ep->sharedScope; ep->sharedContext = data->context(); ep->sharedScope = data->me; + } else { + oldOverride = ep->contextClass->setOverrideObject(data->expressionContext, secondaryScope); } QScriptValue svalue = data->expressionFunction.call(); @@ -374,6 +387,8 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo if (data->isShared) { ep->sharedContext = oldSharedContext; ep->sharedScope = oldSharedScope; + } else { + ep->contextClass->setOverrideObject(data->expressionContext, oldOverride); } if (isUndefined) @@ -388,12 +403,6 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo data->error = QDeclarativeError(); } - if (secondaryScope) { - QObject *last = ctxtPriv->defaultObjects.takeLast(); - Q_ASSERT(last == secondaryScope); - Q_UNUSED(last); - } - QVariant rv; if (svalue.isArray()) { diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h index 91ac4c0..cd1729d 100644 --- a/src/declarative/qml/qdeclarativeexpression_p.h +++ b/src/declarative/qml/qdeclarativeexpression_p.h @@ -119,6 +119,7 @@ public: bool expressionFunctionValid:1; bool expressionRewritten:1; QScriptValue expressionFunction; + QScriptValue expressionContext; QObject *me; bool trackChange; @@ -180,8 +181,8 @@ public: virtual void emitValueChanged(); static void exceptionToError(QScriptEngine *, QDeclarativeError &); - static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QString &); - static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QScriptProgram &); + static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QString &, QScriptValue * = 0); + static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QScriptProgram &, QScriptValue * = 0); }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index e45f0fa..75ee7ce 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1676,8 +1676,7 @@ void tst_qdeclarativeecmascript::scriptScope() MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); emit object->argumentSignal(19, "Hello world!", 10.3); - QEXPECT_FAIL("", "QTBUG-8641", Continue); - QCOMPARE(object->property("result").toString(), QLatin1String("undefined")); + QCOMPARE(object->property("result").toString(), QString()); delete object; } -- cgit v0.12 From 5c1496d8839010653a9273586c10d99e0eeb66b2 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 18:36:44 +1000 Subject: More renaming: MouseRegion -> MouseArea --- doc/src/declarative/tutorial.qdoc | 6 +++--- examples/declarative/colorbrowser/colorbrowser.qml | 2 +- examples/declarative/colorbrowser/qml/ColorDelegate.qml | 2 +- examples/declarative/package/Delegate.qml | 2 +- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/src/declarative/tutorial.qdoc b/doc/src/declarative/tutorial.qdoc index 98efe12..310b776 100644 --- a/doc/src/declarative/tutorial.qdoc +++ b/doc/src/declarative/tutorial.qdoc @@ -173,10 +173,10 @@ In this case the rectangle will have the same size as its parent (see \l{anchor- \snippet examples/declarative/tutorials/helloworld/Cell.qml 3 -In order to change the color of the text when clicking on a cell, we create a \l MouseRegion element with +In order to change the color of the text when clicking on a cell, we create a \l MouseArea element with the same size as its parent. -A \l MouseRegion defines a signal called \e clicked. +A \l MouseArea defines a signal called \e clicked. When this signal is triggered we want to emit our own \e clicked signal with the color as parameter. \section2 The main QML file @@ -214,7 +214,7 @@ Here is the QML code: \snippet examples/declarative/tutorials/helloworld/tutorial3.qml 2 First, we create a new \e down state for our text element. -This state will be activated when the \l MouseRegion is pressed, and deactivated when it is released. +This state will be activated when the \l MouseArea is pressed, and deactivated when it is released. The \e down state includes a set of property changes from our implicit \e {default state} (the items as they were initially defined in the QML). diff --git a/examples/declarative/colorbrowser/colorbrowser.qml b/examples/declarative/colorbrowser/colorbrowser.qml index ebd49c6..421ae07 100644 --- a/examples/declarative/colorbrowser/colorbrowser.qml +++ b/examples/declarative/colorbrowser/colorbrowser.qml @@ -53,7 +53,7 @@ Rectangle { Text { id: albumTitle; text: name; color: 'white'; font.bold: true; anchors.centerIn: parent } } - MouseRegion { anchors.fill: parent; onClicked: wrapper.state = 'inGrid' } + MouseArea { anchors.fill: parent; onClicked: wrapper.state = 'inGrid' } states: [ State { diff --git a/examples/declarative/colorbrowser/qml/ColorDelegate.qml b/examples/declarative/colorbrowser/qml/ColorDelegate.qml index 605e45b..c123d12 100644 --- a/examples/declarative/colorbrowser/qml/ColorDelegate.qml +++ b/examples/declarative/colorbrowser/qml/ColorDelegate.qml @@ -27,7 +27,7 @@ Package { value: hex; when: delegate.open && list.ListView.isCurrentItem } - MouseRegion { + MouseArea { anchors.fill: parent acceptedButtons: Qt.RightButton | Qt.LeftButton onClicked: { diff --git a/examples/declarative/package/Delegate.qml b/examples/declarative/package/Delegate.qml index 62198d0..f35314f 100644 --- a/examples/declarative/package/Delegate.qml +++ b/examples/declarative/package/Delegate.qml @@ -11,7 +11,7 @@ Package { color: 'lightsteelblue' Text { text: display; anchors.centerIn: parent } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { if (wrapper.state == 'inList') diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index a0aed46..55f1c89 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -144,7 +144,7 @@ QDeclarativeVisualItemModel::QDeclarativeVisualItemModel() QDeclarativeListProperty QDeclarativeVisualItemModel::children() { Q_D(QDeclarativeVisualItemModel); - return QDeclarativeListProperty(this, d, d->children_append, + return QDeclarativeListProperty(this, d, d->children_append, d->children_count, d->children_at); } @@ -483,7 +483,7 @@ QVariant QDeclarativeVisualDataModelDataMetaObject::initialValue(int propId) QDeclarativeVisualDataModelData::QDeclarativeVisualDataModelData(int index, QDeclarativeVisualDataModel *model) -: m_index(index), m_model(model), +: m_index(index), m_model(model), m_meta(new QDeclarativeVisualDataModelDataMetaObject(this, QDeclarativeVisualDataModelPrivate::get(model)->m_delegateDataType)) { QDeclarativeVisualDataModelPrivate *modelPriv = QDeclarativeVisualDataModelPrivate::get(model); @@ -550,7 +550,7 @@ QVariant QDeclarativeVisualDataModelPartsMetaObject::initialValue(int id) } QDeclarativeVisualDataModelParts::QDeclarativeVisualDataModelParts(QDeclarativeVisualDataModel *parent) -: QObject(parent), model(parent) +: QObject(parent), model(parent) { new QDeclarativeVisualDataModelPartsMetaObject(this); } @@ -840,7 +840,7 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate) Rectangle { height: 25; width: 100 Text { text: path } - MouseRegion { + MouseArea { anchors.fill: parent; onClicked: myModel.setRoot(path) } @@ -969,7 +969,7 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q QObject *QDeclarativeVisualDataModel::parts() { Q_D(QDeclarativeVisualDataModel); - if (!d->m_parts) + if (!d->m_parts) d->m_parts = new QDeclarativeVisualDataModelParts(this); return d->m_parts; } -- cgit v0.12 From a2af08f9793b3884bdb770f89edd4754c0411654 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 4 Mar 2010 00:54:06 +1000 Subject: Clairify a comment in one of the auto tests. --- .../declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index dea88c4..b1935df 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -671,9 +671,9 @@ void tst_qdeclarativetextedit::delegateLoading() QTRY_VERIFY(view->status()==QDeclarativeView::Error); view->setFocus(); QTRY_VERIFY(!view->rootObject()); // there is fail item inside this test - //ErrorB should get a component which is ready but component.create() returns null + //A test should be added here with a component which is ready but component.create() returns null //Not sure how to accomplish this with QDeclarativeTextEdits cursor delegate - //###This could be a case of overzealous defensive programming + //###This was only needed for code coverage, and could be a case of overzealous defensive programming //delegate = view->rootObject()->findChild("delegateErrorB"); //QVERIFY(!delegate); } -- cgit v0.12 From 1a7df5ef1fc81fbf2d548c40e3feeb8ef3bb5a8c Mon Sep 17 00:00:00 2001 From: mae Date: Wed, 3 Mar 2010 19:39:45 +0100 Subject: make example work again The code is now a bit on the imperative side, but that was the only working solution to remove the binding loops. --- examples/declarative/dynamic/qml/Sun.qml | 8 ++++---- examples/declarative/imageprovider/imageprovider.qml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/declarative/dynamic/qml/Sun.qml b/examples/declarative/dynamic/qml/Sun.qml index 796a370..81b6e9b 100644 --- a/examples/declarative/dynamic/qml/Sun.qml +++ b/examples/declarative/dynamic/qml/Sun.qml @@ -11,14 +11,14 @@ Image { //x and y get set when instantiated //head offscreen - y: NumberAnimation { - to: parent.height; - duration: 10000; + NumberAnimation on y { + to: window.height / 2; running: created + onRunningChanged: if (running) duration = (window.height - sun.y) * 10; else state = "OffScreen"; } states: State { - name: "OffScreen"; when: created && y > window.height / 2;//Below the ground + name: "OffScreen"; StateChangeScript { script: { sun.created = false; sun.destroy() } } } } diff --git a/examples/declarative/imageprovider/imageprovider.qml b/examples/declarative/imageprovider/imageprovider.qml index a1f2794..f899b1e 100644 --- a/examples/declarative/imageprovider/imageprovider.qml +++ b/examples/declarative/imageprovider/imageprovider.qml @@ -1,5 +1,5 @@ import Qt 4.6 -import ImageProviderCore 1.0 +import "ImageProviderCore" //![0] ListView { width: 100 -- cgit v0.12