diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-01-19 13:49:52 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-01-21 11:10:14 +0100 |
commit | b6191b16d41459ed73cea738dfaf8e25e81ae22b (patch) | |
tree | 6ad0952af507bf1ab8df9612023d6e224db8d7e2 /src/corelib/kernel | |
parent | b2883a6acc7a8d8372a815cc91dd1a8449f25723 (diff) | |
parent | 9087df6bd2dd5198ccf101a237aadee331e51ec3 (diff) |
Merge remote-tracking branch 'origin/5.4' into dev
Conflicts:
src/corelib/global/global.pri
src/corelib/global/qcompilerdetection.h
src/corelib/global/qglobal.h
src/corelib/tools/qdatetime.cpp
src/plugins/platforms/xcb/qxcbscreen.h
src/plugins/platforms/xcb/qxcbwindow.h
src/widgets/dialogs/qcolordialog.cpp
src/widgets/dialogs/qcolordialog_p.h
tools/configure/configureapp.cpp
Change-Id: Ie9d6e9df13e570da0a90a67745a0d05f46c532af
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 10 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 49 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 6 |
3 files changed, 44 insertions, 21 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 223de0c8e0..84aa2e3184 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2741,9 +2741,9 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign You can check if the QMetaObject::Connection is valid by casting it to a bool. This function works in the same way as - connect(const QObject *sender, const char *signal, + \c {connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, - Qt::ConnectionType type) + Qt::ConnectionType type)} but it uses QMetaMethod to specify signal and method. \sa connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) @@ -2996,7 +2996,7 @@ bool QObject::disconnect(const QObject *sender, const char *signal, otherwise returns \c false. This function provides the same possibilities like - disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method) + \c {disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method) } but uses QMetaMethod to represent the signal and the method to be disconnected. Additionally this function returnsfalse and no signals and slots disconnected @@ -4112,7 +4112,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) This macro associates extra information to the class, which is available using QObject::metaObject(). Qt makes only limited use of this feature, in - the \l{Active Qt}, \l{Qt D-Bus} and \l{Qt QML} modules. + the \l{Active Qt}, \l{Qt D-Bus} and \l{Qt QML module}{Qt QML}. The extra information takes the form of a \a Name string and a \a Value literal string. @@ -4124,7 +4124,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) \sa QMetaObject::classInfo() \sa QAxFactory \sa {Using Qt D-Bus Adaptors} - \sa {Extending QML - Default Property Example} + \sa {Extending QML} */ /*! diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 3f958138b3..f7b8fe5ca5 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -4001,6 +4001,13 @@ void QAssociativeIterable::const_iterator::end() m_impl.end(); } +void find(QAssociativeIterable::const_iterator &it, const QVariant &key) +{ + Q_ASSERT(key.userType() == it.m_impl._metaType_id_key); + const QtMetaTypePrivate::VariantData dkey(key.userType(), key.constData(), 0 /*key.flags()*/); + it.m_impl.find(dkey); +} + /*! Returns a QAssociativeIterable::const_iterator for the beginning of the container. This can be used in stl-style iteration. @@ -4028,27 +4035,37 @@ QAssociativeIterable::const_iterator QAssociativeIterable::end() const } /*! + \internal + + Returns a QAssociativeIterable::const_iterator for the given key \a key + in the container, if the types are convertible. + + If the key is not found, returns end(). + + This can be used in stl-style iteration. + + \sa begin(), end(), value() +*/ +QAssociativeIterable::const_iterator find(const QAssociativeIterable &iterable, const QVariant &key) +{ + QAssociativeIterable::const_iterator it(iterable, new QAtomicInt(0)); + QVariant key_ = key; + if (key_.canConvert(iterable.m_impl._metaType_id_key) && key_.convert(iterable.m_impl._metaType_id_key)) + find(it, key_); + else + it.end(); + return it; +} + +/*! Returns the value for the given \a key in the container, if the types are convertible. */ QVariant QAssociativeIterable::value(const QVariant &key) const { - QVariant key_ = key; - if (!key_.canConvert(m_impl._metaType_id_key)) - return QVariant(); - if (!key_.convert(m_impl._metaType_id_key)) + const const_iterator it = find(*this, key); + if (it == end()) return QVariant(); - const QtMetaTypePrivate::VariantData dkey(key_.userType(), key_.constData(), 0 /*key.flags()*/); - QtMetaTypePrivate::QAssociativeIterableImpl impl = m_impl; - impl.find(dkey); - QtMetaTypePrivate::QAssociativeIterableImpl endIt = m_impl; - endIt.end(); - if (impl.equal(endIt)) - return QVariant(); - const QtMetaTypePrivate::VariantData d = impl.getCurrentValue(); - QVariant v(d.metaTypeId, d.data, d.flags); - if (d.metaTypeId == qMetaTypeId<QVariant>()) - return *reinterpret_cast<const QVariant*>(d.data); - return v; + return *it; } /*! diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 7bee756fa5..c33ac834c0 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -633,6 +633,9 @@ public: void begin(); void end(); + // ### Qt 5.5: make find() (1st one) a member function + friend void find(const_iterator &it, const QVariant &key); + friend const_iterator find(const QAssociativeIterable &iterable, const QVariant &key); public: ~const_iterator(); const_iterator(const const_iterator &other); @@ -662,6 +665,9 @@ public: const_iterator begin() const; const_iterator end() const; +private: // ### Qt 5.5: make it a public find() member function: + friend const_iterator find(const QAssociativeIterable &iterable, const QVariant &key); +public: QVariant value(const QVariant &key) const; |