diff options
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 2f9ef9ca4a..be6441933f 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2742,9 +2742,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) @@ -2997,7 +2997,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 @@ -4113,7 +4113,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. @@ -4125,7 +4125,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; |