summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.cpp10
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.h2
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp21
-rw-r--r--src/corelib/kernel/qcoreapplication.h4
-rw-r--r--src/corelib/kernel/qcoreevent.cpp1
-rw-r--r--src/corelib/kernel/qcoreevent.h16
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib.cpp13
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib_p.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp13
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp39
-rw-r--r--src/corelib/kernel/qeventdispatcher_win_p.h4
-rw-r--r--src/corelib/kernel/qeventloop.cpp13
-rw-r--r--src/corelib/kernel/qmetaobject.cpp757
-rw-r--r--src/corelib/kernel/qmetaobject.h15
-rw-r--r--src/corelib/kernel/qmetaobject_p.h81
-rw-r--r--src/corelib/kernel/qmetaobjectbuilder.cpp339
-rw-r--r--src/corelib/kernel/qmetaobjectbuilder_p.h19
-rw-r--r--src/corelib/kernel/qmetatype.cpp139
-rw-r--r--src/corelib/kernel/qmetatype.h117
-rw-r--r--src/corelib/kernel/qmetatype_p.h56
-rw-r--r--src/corelib/kernel/qmetatypeswitcher_p.h7
-rw-r--r--src/corelib/kernel/qobject.cpp271
-rw-r--r--src/corelib/kernel/qobject.h32
-rw-r--r--src/corelib/kernel/qobjectdefs.h10
-rw-r--r--src/corelib/kernel/qpointer.h58
-rw-r--r--src/corelib/kernel/qtimer.cpp19
-rw-r--r--src/corelib/kernel/qtimer.h3
-rw-r--r--src/corelib/kernel/qtimerinfo_unix.cpp31
-rw-r--r--src/corelib/kernel/qtimerinfo_unix_p.h2
-rw-r--r--src/corelib/kernel/qtranslator.cpp285
-rw-r--r--src/corelib/kernel/qvariant.cpp110
-rw-r--r--src/corelib/kernel/qvariant.h20
-rw-r--r--src/corelib/kernel/qvariant_p.h87
34 files changed, 1861 insertions, 737 deletions
diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp
index 9d76aa610f..cf9b0cea4f 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.cpp
+++ b/src/corelib/kernel/qabstracteventdispatcher.cpp
@@ -295,6 +295,16 @@ int QAbstractEventDispatcher::registerTimer(int interval, Qt::TimerType timerTyp
\sa Qt::TimerType
*/
+/*!
+ \fn int QAbstractEventDispatcher::remainingTime(int timerId)
+
+ Returns the remaining time in milliseconds with the given \a timerId.
+ If the timer is inactive, the returned value will be -1. If the timer is
+ overdue, the returned value will be 0.
+
+ \sa Qt::TimerType
+*/
+
/*! \fn void QAbstractEventDispatcher::wakeUp()
\threadsafe
diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h
index 76f264c3c0..96498d207d 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.h
+++ b/src/corelib/kernel/qabstracteventdispatcher.h
@@ -93,6 +93,8 @@ public:
virtual bool unregisterTimers(QObject *object) = 0;
virtual QList<TimerInfo> registeredTimers(QObject *object) const = 0;
+ virtual int remainingTime(int timerId) = 0;
+
virtual void wakeUp() = 0;
virtual void interrupt() = 0;
virtual void flush() = 0;
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 3d09d858a3..7b26a01cbf 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -1513,26 +1513,29 @@ void QCoreApplication::quit()
generated by \l{Qt Designer} provide a \c retranslateUi() function that can be
called.
+ The function returns true on success and false on failure.
+
\sa removeTranslator() translate() QTranslator::load() {Dynamic Translation}
*/
-void QCoreApplication::installTranslator(QTranslator *translationFile)
+bool QCoreApplication::installTranslator(QTranslator *translationFile)
{
if (!translationFile)
- return;
+ return false;
if (!QCoreApplicationPrivate::checkInstance("installTranslator"))
- return;
+ return false;
QCoreApplicationPrivate *d = self->d_func();
d->translators.prepend(translationFile);
#ifndef QT_NO_TRANSLATION_BUILDER
if (translationFile->isEmpty())
- return;
+ return false;
#endif
QEvent ev(QEvent::LanguageChange);
QCoreApplication::sendEvent(self, &ev);
+ return true;
}
/*!
@@ -1540,20 +1543,24 @@ void QCoreApplication::installTranslator(QTranslator *translationFile)
translation files used by this application. (It does not delete the
translation file from the file system.)
+ The function returns true on success and false on failure.
+
\sa installTranslator() translate(), QObject::tr()
*/
-void QCoreApplication::removeTranslator(QTranslator *translationFile)
+bool QCoreApplication::removeTranslator(QTranslator *translationFile)
{
if (!translationFile)
- return;
+ return false;
if (!QCoreApplicationPrivate::checkInstance("removeTranslator"))
- return;
+ return false;
QCoreApplicationPrivate *d = self->d_func();
if (d->translators.removeAll(translationFile) && !self->closingDown()) {
QEvent ev(QEvent::LanguageChange);
QCoreApplication::sendEvent(self, &ev);
+ return true;
}
+ return false;
}
static void replacePercentN(QString *result, int n)
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h
index cf76511f25..2c942f9037 100644
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -134,8 +134,8 @@ public:
#endif // QT_NO_LIBRARY
#ifndef QT_NO_TRANSLATION
- static void installTranslator(QTranslator * messageFile);
- static void removeTranslator(QTranslator * messageFile);
+ static bool installTranslator(QTranslator * messageFile);
+ static bool removeTranslator(QTranslator * messageFile);
#endif
enum Encoding { UnicodeUTF8, Latin1, DefaultCodec = Latin1
#if QT_DEPRECATED_SINCE(5, 0)
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index f8aa001410..45b2293112 100644
--- a/src/corelib/kernel/qcoreevent.cpp
+++ b/src/corelib/kernel/qcoreevent.cpp
@@ -170,7 +170,6 @@ QT_BEGIN_NAMESPACE
\value NonClientAreaMouseButtonRelease A mouse button release occurred outside the client area.
\value NonClientAreaMouseMove A mouse move occurred outside the client area.
\value MacSizeChange The user changed his widget sizes (Mac OS X only).
- \value MenubarUpdated The window's menu bar has been updated.
\value MetaCall An asynchronous method invocation via QMetaObject::invokeMethod().
\value ModifiedChange Widgets modification state has been changed.
\value MouseButtonDblClick Mouse press again (QMouseEvent).
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index bfd99208cc..a833394bba 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -192,9 +192,6 @@ public:
#endif
AcceptDropsChange = 152,
- MenubarUpdated = 153, // Support event for Q3MainWindow, which needs to
- // knwow when QMenubar is updated.
-
ZeroTimerEvent = 154, // Used for Windows Zero timer events
GraphicsSceneMouseMove = 155, // GraphicsView
@@ -269,17 +266,14 @@ public:
ScrollPrepare = 204,
Scroll = 205,
- Map = 206,
- Unmap = 207,
-
- Expose = 208,
+ Expose = 206,
- InputMethodQuery = 209,
- OrientationChange = 210, // Screen orientation has changed
+ InputMethodQuery = 207,
+ OrientationChange = 208, // Screen orientation has changed
- TouchCancel = 211,
+ TouchCancel = 209,
- ThemeChange = 212,
+ ThemeChange = 210,
// 512 reserved for Qt Jambi's MetaCall event
// 513 reserved for Qt Jambi's DeleteOnMainThread event
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp
index 3f272a2512..4429679e72 100644
--- a/src/corelib/kernel/qeventdispatcher_glib.cpp
+++ b/src/corelib/kernel/qeventdispatcher_glib.cpp
@@ -567,6 +567,19 @@ QList<QEventDispatcherGlib::TimerInfo> QEventDispatcherGlib::registeredTimers(QO
return d->timerSource->timerList.registeredTimers(object);
}
+int QEventDispatcherGlib::remainingTime(int timerId)
+{
+#ifndef QT_NO_DEBUG
+ if (timerId < 1) {
+ qWarning("QEventDispatcherGlib::remainingTimeTime: invalid argument");
+ return -1;
+ }
+#endif
+
+ Q_D(QEventDispatcherGlib);
+ return d->timerSource->timerList.timerRemainingTime(timerId);
+}
+
void QEventDispatcherGlib::interrupt()
{
wakeUp();
diff --git a/src/corelib/kernel/qeventdispatcher_glib_p.h b/src/corelib/kernel/qeventdispatcher_glib_p.h
index 7bd40564b9..e230972092 100644
--- a/src/corelib/kernel/qeventdispatcher_glib_p.h
+++ b/src/corelib/kernel/qeventdispatcher_glib_p.h
@@ -85,6 +85,8 @@ public:
bool unregisterTimers(QObject *object);
QList<TimerInfo> registeredTimers(QObject *object) const;
+ int remainingTime(int timerId);
+
void wakeUp();
void interrupt();
void flush();
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index d5805112e9..6eb96b832c 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -628,6 +628,19 @@ bool QEventDispatcherUNIX::hasPendingEvents()
return qGlobalPostedEventsCount();
}
+int QEventDispatcherUNIX::remainingTime(int timerId)
+{
+#ifndef QT_NO_DEBUG
+ if (timerId < 1) {
+ qWarning("QEventDispatcherUNIX::remainingTime: invalid argument");
+ return -1;
+ }
+#endif
+
+ Q_D(QEventDispatcherUNIX);
+ return d->timerList.timerRemainingTime(timerId);
+}
+
void QEventDispatcherUNIX::wakeUp()
{
Q_D(QEventDispatcherUNIX);
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index e618853e09..05ecf52dbf 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -116,6 +116,8 @@ public:
bool unregisterTimers(QObject *object);
QList<TimerInfo> registeredTimers(QObject *object) const;
+ int remainingTime(int timerId);
+
void wakeUp();
void interrupt();
void flush();
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index 768fde682b..26fd6316ae 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -50,6 +50,7 @@
#include "qvarlengtharray.h"
#include "qwineventnotifier.h"
+#include "qelapsedtimer.h"
#include "qcoreapplication_p.h"
#include <private/qthread_p.h>
#include <private/qmutexpool_p.h>
@@ -532,6 +533,8 @@ void QEventDispatcherWin32Private::registerTimer(WinTimerInfo *t)
ok = SetTimer(internalHwnd, t->timerId, interval, 0);
}
+ t->timeout = qt_msectime() + interval;
+
if (ok == 0)
qErrnoWarning("QEventDispatcherWin32::registerTimer: Failed to create a timer");
}
@@ -998,6 +1001,42 @@ void QEventDispatcherWin32::activateEventNotifiers()
}
}
+int QEventDispatcherWin32::remainingTime(int timerId)
+{
+#ifndef QT_NO_DEBUG
+ if (timerId < 1) {
+ qWarning("QEventDispatcherWin32::remainingTime: invalid argument");
+ return -1;
+ }
+#endif
+
+ Q_D(QEventDispatcherWin32);
+
+ if (d->timerVec.isEmpty())
+ return -1;
+
+ quint64 currentTime = qt_msectime();
+
+ register WinTimerInfo *t;
+ for (int i=0; i<d->timerVec.size(); i++) {
+ t = d->timerVec.at(i);
+ if (t && t->timerId == timerId) { // timer found
+ if (currentTime < t->timeout) {
+ // time to wait
+ return t->timeout - currentTime;
+ } else {
+ return 0;
+ }
+ }
+ }
+
+#ifndef QT_NO_DEBUG
+ qWarning("QEventDispatcherWin32::remainingTime: timer id %s not found", timerId);
+#endif
+
+ return -1;
+}
+
void QEventDispatcherWin32::wakeUp()
{
Q_D(QEventDispatcherWin32);
diff --git a/src/corelib/kernel/qeventdispatcher_win_p.h b/src/corelib/kernel/qeventdispatcher_win_p.h
index 565f1ef4b3..e78236fd40 100644
--- a/src/corelib/kernel/qeventdispatcher_win_p.h
+++ b/src/corelib/kernel/qeventdispatcher_win_p.h
@@ -66,6 +66,7 @@ class QEventDispatcherWin32Private;
// forward declaration
LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp);
+int qt_msectime();
class Q_CORE_EXPORT QEventDispatcherWin32 : public QAbstractEventDispatcher
{
@@ -94,6 +95,8 @@ public:
void unregisterEventNotifier(QWinEventNotifier *notifier);
void activateEventNotifiers();
+ int remainingTime(int timerId);
+
void wakeUp();
void interrupt();
void flush();
@@ -123,6 +126,7 @@ struct WinTimerInfo { // internal timer info
int timerId;
int interval;
Qt::TimerType timerType;
+ quint64 timeout; // - when to actually fire
QObject *obj; // - object to receive events
bool inTimerEvent;
int fastTimerId;
diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp
index 58e2c5cd2f..d3a64aae04 100644
--- a/src/corelib/kernel/qeventloop.cpp
+++ b/src/corelib/kernel/qeventloop.cpp
@@ -374,7 +374,7 @@ private:
\brief The QEventLoopLocker class provides a means to quit an event loop when it is no longer needed.
The QEventLoopLocker operates on particular objects - either a QCoreApplication
- instance or a QEventLoop instance.
+ instance, a QEventLoop instance or a QThread instance.
This makes it possible to, for example, run a batch of jobs with an event loop
and exit that event loop after the last job is finished. That is accomplished
@@ -388,7 +388,7 @@ private:
*/
/*!
- Creates an event locker operating on the \p app.
+ Creates an event locker operating on the QCoreApplication.
The application will quit when there are no more QEventLoopLockers operating on it.
@@ -401,7 +401,7 @@ QEventLoopLocker::QEventLoopLocker()
}
/*!
- Creates an event locker operating on the \p app.
+ Creates an event locker operating on the \p loop.
This particular QEventLoop will quit when there are no more QEventLoopLockers operating on it.
@@ -413,6 +413,13 @@ QEventLoopLocker::QEventLoopLocker(QEventLoop *loop)
}
+/*!
+ Creates an event locker operating on the \p thread.
+
+ This particular QThread will quit when there are no more QEventLoopLockers operating on it.
+
+ \sa QThread::quit()
+ */
QEventLoopLocker::QEventLoopLocker(QThread *thread)
: d_ptr(new QEventLoopLockerPrivate(static_cast<QThreadPrivate*>(QObjectPrivate::get(thread))))
{
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index 428c2629ff..e3b0b15e26 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -146,6 +146,79 @@ QT_BEGIN_NAMESPACE
static inline const QMetaObjectPrivate *priv(const uint* data)
{ return reinterpret_cast<const QMetaObjectPrivate*>(data); }
+static inline const QByteArrayData &stringData(const QMetaObject *mo, int index)
+{
+ Q_ASSERT(priv(mo->d.data)->revision >= 7);
+ const QByteArrayData &data = mo->d.stringdata[index];
+ Q_ASSERT(data.ref.isStatic());
+ Q_ASSERT(data.alloc == 0);
+ Q_ASSERT(data.capacityReserved == 0);
+ Q_ASSERT(data.size >= 0);
+ return data;
+}
+
+static inline QByteArray toByteArray(const QByteArrayData &d)
+{
+ QByteArrayDataPtr holder = { const_cast<QByteArrayData *>(&d) };
+ return QByteArray(holder);
+}
+
+static inline const char *rawStringData(const QMetaObject *mo, int index)
+{
+ return stringData(mo, index).data();
+}
+
+static inline int stringSize(const QMetaObject *mo, int index)
+{
+ return stringData(mo, index).size;
+}
+
+static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo)
+{
+ if (typeInfo & IsUnresolvedType) {
+ return toByteArray(stringData(mo, typeInfo & TypeNameIndexMask));
+ } else {
+ // ### Use the QMetaType::typeName() that returns QByteArray
+ const char *t = QMetaType::typeName(typeInfo);
+ return QByteArray::fromRawData(t, qstrlen(t));
+ }
+}
+
+static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo)
+{
+ return typeNameFromTypeInfo(mo, typeInfo).constData();
+}
+
+static inline int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo)
+{
+ if (!(typeInfo & IsUnresolvedType))
+ return typeInfo;
+ return QMetaType::type(toByteArray(stringData(mo, typeInfo & TypeNameIndexMask)));
+}
+
+class QMetaMethodPrivate : public QMetaMethod
+{
+public:
+ static const QMetaMethodPrivate *get(const QMetaMethod *q)
+ { return static_cast<const QMetaMethodPrivate *>(q); }
+
+ inline QByteArray signature() const;
+ inline QByteArray name() const;
+ inline int typesDataIndex() const;
+ inline const char *rawReturnTypeName() const;
+ inline int returnType() const;
+ inline int parameterCount() const;
+ inline int parametersDataIndex() const;
+ inline uint parameterTypeInfo(int index) const;
+ inline int parameterType(int index) const;
+ inline void getParameterTypes(int *types) const;
+ inline QList<QByteArray> parameterTypes() const;
+ inline QList<QByteArray> parameterNames() const;
+ inline QByteArray tag() const;
+
+private:
+ QMetaMethodPrivate();
+};
/*!
\since 4.5
@@ -222,19 +295,11 @@ QObject *QMetaObject::newInstance(QGenericArgument val0,
int QMetaObject::static_metacall(Call cl, int idx, void **argv) const
{
const QMetaObjectExtraData *extra = reinterpret_cast<const QMetaObjectExtraData *>(d.extradata);
- if (priv(d.data)->revision >= 6) {
- if (!extra || !extra->static_metacall)
- return 0;
- extra->static_metacall(0, cl, idx, argv);
- return -1;
- } else if (priv(d.data)->revision >= 2) {
- if (!extra || !extra->static_metacall)
- return 0;
- typedef int (*OldMetacall)(QMetaObject::Call, int, void **);
- OldMetacall o = reinterpret_cast<OldMetacall>(extra->static_metacall);
- return o(cl, idx, argv);
- }
- return 0;
+ Q_ASSERT(priv(d.data)->revision >= 6);
+ if (!extra || !extra->static_metacall)
+ return 0;
+ extra->static_metacall(0, cl, idx, argv);
+ return -1;
}
/*!
@@ -249,12 +314,14 @@ int QMetaObject::metacall(QObject *object, Call cl, int idx, void **argv)
}
/*!
- \fn const char *QMetaObject::className() const
-
Returns the class name.
\sa superClass()
*/
+const char *QMetaObject::className() const
+{
+ return rawStringData(this, 0);
+}
/*!
\fn QMetaObject *QMetaObject::superClass() const
@@ -307,7 +374,7 @@ const QObject *QMetaObject::cast(const QObject *obj) const
*/
QString QMetaObject::tr(const char *s, const char *c, int n) const
{
- return QCoreApplication::translate(d.stringdata, s, c, QCoreApplication::DefaultCodec, n);
+ return QCoreApplication::translate(rawStringData(this, 0), s, c, QCoreApplication::DefaultCodec, n);
}
/*!
@@ -315,7 +382,7 @@ QString QMetaObject::tr(const char *s, const char *c, int n) const
*/
QString QMetaObject::trUtf8(const char *s, const char *c, int n) const
{
- return QCoreApplication::translate(d.stringdata, s, c, QCoreApplication::UnicodeUTF8, n);
+ return QCoreApplication::translate(rawStringData(this, 0), s, c, QCoreApplication::UnicodeUTF8, n);
}
#endif // QT_NO_TRANSLATION
@@ -413,8 +480,7 @@ int QMetaObject::classInfoOffset() const
*/
int QMetaObject::constructorCount() const
{
- if (priv(d.data)->revision < 2)
- return 0;
+ Q_ASSERT(priv(d.data)->revision >= 2);
return priv(d.data)->constructorCount;
}
@@ -495,38 +561,57 @@ int QMetaObject::classInfoCount() const
return n;
}
+// Returns true if the method defined by the given meta-object&handle
+// matches the given name, argument count and argument types, otherwise
+// returns false.
+static bool methodMatch(const QMetaObject *m, int handle,
+ const QByteArray &name, int argc,
+ const QArgumentType *types)
+{
+ Q_ASSERT(priv(m->d.data)->revision >= 7);
+ if (int(m->d.data[handle + 1]) != argc)
+ return false;
+
+ if (toByteArray(stringData(m, m->d.data[handle])) != name)
+ return false;
+
+ int paramsIndex = m->d.data[handle + 2] + 1;
+ for (int i = 0; i < argc; ++i) {
+ uint typeInfo = m->d.data[paramsIndex + i];
+ if (types[i].type()) {
+ if (types[i].type() != typeFromTypeInfo(m, typeInfo))
+ return false;
+ } else {
+ if (types[i].name() != typeNameFromTypeInfo(m, typeInfo))
+ return false;
+ }
+ }
+
+ return true;
+}
+
/** \internal
* helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within
* the baseObject
* \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything.
-* \a normalizeStringData set to true if we should do a second pass for old moc generated files normalizing all the symbols.
*/
template<int MethodType>
static inline int indexOfMethodRelative(const QMetaObject **baseObject,
- const char *method,
- bool normalizeStringData)
+ const QByteArray &name, int argc,
+ const QArgumentType *types)
{
for (const QMetaObject *m = *baseObject; m; m = m->d.superdata) {
- int i = (MethodType == MethodSignal && priv(m->d.data)->revision >= 4)
- ? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1);
- const int end = (MethodType == MethodSlot && priv(m->d.data)->revision >= 4)
+ Q_ASSERT(priv(m->d.data)->revision >= 7);
+ int i = (MethodType == MethodSignal)
+ ? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1);
+ const int end = (MethodType == MethodSlot)
? (priv(m->d.data)->signalCount) : 0;
- if (!normalizeStringData) {
- for (; i >= end; --i) {
- const char *stringdata = m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5*i];
- if (method[0] == stringdata[0] && strcmp(method + 1, stringdata + 1) == 0) {
- *baseObject = m;
- return i;
- }
- }
- } else if (priv(m->d.data)->revision < 5) {
- for (; i >= end; --i) {
- const char *stringdata = (m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5 * i]);
- const QByteArray normalizedSignature = QMetaObject::normalizedSignature(stringdata);
- if (normalizedSignature == method) {
- *baseObject = m;
- return i;
- }
+
+ for (; i >= end; --i) {
+ int handle = priv(m->d.data)->methodData + 5*i;
+ if (methodMatch(m, handle, name, argc, types)) {
+ *baseObject = m;
+ return i;
}
}
}
@@ -546,15 +631,10 @@ static inline int indexOfMethodRelative(const QMetaObject **baseObject,
*/
int QMetaObject::indexOfConstructor(const char *constructor) const
{
- if (priv(d.data)->revision < 2)
- return -1;
- for (int i = priv(d.data)->constructorCount-1; i >= 0; --i) {
- const char *data = d.stringdata + d.data[priv(d.data)->constructorData + 5*i];
- if (data[0] == constructor[0] && strcmp(constructor + 1, data + 1) == 0) {
- return i;
- }
- }
- return -1;
+ Q_ASSERT(priv(d.data)->revision >= 7);
+ QArgumentTypeArray types;
+ QByteArray name = QMetaObjectPrivate::decodeMethodSignature(constructor, types);
+ return QMetaObjectPrivate::indexOfConstructor(this, name, types.size(), types.constData());
}
/*!
@@ -568,16 +648,54 @@ int QMetaObject::indexOfConstructor(const char *constructor) const
int QMetaObject::indexOfMethod(const char *method) const
{
const QMetaObject *m = this;
- int i = indexOfMethodRelative<0>(&m, method, false);
- if (i < 0) {
- m = this;
- i = indexOfMethodRelative<0>(&m, method, true);
- }
+ int i;
+ Q_ASSERT(priv(m->d.data)->revision >= 7);
+ QArgumentTypeArray types;
+ QByteArray name = QMetaObjectPrivate::decodeMethodSignature(method, types);
+ i = indexOfMethodRelative<0>(&m, name, types.size(), types.constData());
if (i >= 0)
i += m->methodOffset();
return i;
}
+// Parses a string of comma-separated types into QArgumentTypes.
+static void argumentTypesFromString(const char *str, const char *end,
+ QArgumentTypeArray &types)
+{
+ Q_ASSERT(str <= end);
+ while (str != end) {
+ if (!types.isEmpty())
+ ++str; // Skip comma
+ const char *begin = str;
+ int level = 0;
+ while (str != end && (level > 0 || *str != ',')) {
+ if (*str == '<')
+ ++level;
+ else if (*str == '>')
+ --level;
+ ++str;
+ }
+ types += QArgumentType(QByteArray(begin, str - begin));
+ }
+}
+
+// Given a method \a signature (e.g. "foo(int,double)"), this function
+// populates the argument \a types array and returns the method name.
+QByteArray QMetaObjectPrivate::decodeMethodSignature(
+ const char *signature, QArgumentTypeArray &types)
+{
+ Q_ASSERT(signature != 0);
+ const char *lparens = strchr(signature, '(');
+ if (!lparens)
+ return QByteArray();
+ const char *rparens = strchr(lparens + 1, ')');
+ if (!rparens || *(rparens+1))
+ return QByteArray();
+ int nameLength = lparens - signature;
+ argumentTypesFromString(lparens + 1, rparens, types);
+ return QByteArray::fromRawData(signature, nameLength);
+}
+
/*!
Finds \a signal and returns its index; otherwise returns -1.
@@ -592,11 +710,11 @@ int QMetaObject::indexOfMethod(const char *method) const
int QMetaObject::indexOfSignal(const char *signal) const
{
const QMetaObject *m = this;
- int i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal, false);
- if (i < 0) {
- m = this;
- i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal, true);
- }
+ int i;
+ Q_ASSERT(priv(m->d.data)->revision >= 7);
+ QArgumentTypeArray types;
+ QByteArray name = QMetaObjectPrivate::decodeMethodSignature(signal, types);
+ i = QMetaObjectPrivate::indexOfSignalRelative(&m, name, types.size(), types.constData());
if (i >= 0)
i += m->methodOffset();
return i;
@@ -608,20 +726,23 @@ int QMetaObject::indexOfSignal(const char *signal) const
\a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found
*/
int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject,
- const char *signal,
- bool normalizeStringData)
+ const QByteArray &name, int argc,
+ const QArgumentType *types)
{
- int i = indexOfMethodRelative<MethodSignal>(baseObject, signal, normalizeStringData);
+ int i = indexOfMethodRelative<MethodSignal>(baseObject, name, argc, types);
#ifndef QT_NO_DEBUG
const QMetaObject *m = *baseObject;
if (i >= 0 && m && m->d.superdata) {
- int conflict = m->d.superdata->indexOfMethod(signal);
- if (conflict >= 0)
+ int conflict = indexOfMethod(m->d.superdata, name, argc, types);
+ if (conflict >= 0) {
+ QMetaMethod conflictMethod = m->d.superdata->method(conflict);
qWarning("QMetaObject::indexOfSignal: signal %s from %s redefined in %s",
- signal, m->d.superdata->d.stringdata, m->d.stringdata);
- }
-#endif
- return i;
+ conflictMethod.methodSignature().constData(),
+ rawStringData(m->d.superdata, 0), rawStringData(m, 0));
+ }
+ }
+ #endif
+ return i;
}
/*!
@@ -635,9 +756,11 @@ int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject,
int QMetaObject::indexOfSlot(const char *slot) const
{
const QMetaObject *m = this;
- int i = QMetaObjectPrivate::indexOfSlotRelative(&m, slot, false);
- if (i < 0)
- i = QMetaObjectPrivate::indexOfSlotRelative(&m, slot, true);
+ int i;
+ Q_ASSERT(priv(m->d.data)->revision >= 7);
+ QArgumentTypeArray types;
+ QByteArray name = QMetaObjectPrivate::decodeMethodSignature(slot, types);
+ i = QMetaObjectPrivate::indexOfSlotRelative(&m, name, types.size(), types.constData());
if (i >= 0)
i += m->methodOffset();
return i;
@@ -645,26 +768,112 @@ int QMetaObject::indexOfSlot(const char *slot) const
// same as indexOfSignalRelative but for slots.
int QMetaObjectPrivate::indexOfSlotRelative(const QMetaObject **m,
- const char *slot,
- bool normalizeStringData)
+ const QByteArray &name, int argc,
+ const QArgumentType *types)
+{
+ return indexOfMethodRelative<MethodSlot>(m, name, argc, types);
+}
+
+int QMetaObjectPrivate::indexOfSignal(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types)
{
- return indexOfMethodRelative<MethodSlot>(m, slot, normalizeStringData);
+ int i = indexOfSignalRelative(&m, name, argc, types);
+ if (i >= 0)
+ i += m->methodOffset();
+ return i;
+}
+
+int QMetaObjectPrivate::indexOfSlot(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types)
+{
+ int i = indexOfSlotRelative(&m, name, argc, types);
+ if (i >= 0)
+ i += m->methodOffset();
+ return i;
+}
+
+int QMetaObjectPrivate::indexOfMethod(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types)
+{
+ int i = indexOfMethodRelative<0>(&m, name, argc, types);
+ if (i >= 0)
+ i += m->methodOffset();
+ return i;
+}
+
+int QMetaObjectPrivate::indexOfConstructor(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types)
+{
+ for (int i = priv(m->d.data)->constructorCount-1; i >= 0; --i) {
+ int handle = priv(m->d.data)->constructorData + 5*i;
+ if (methodMatch(m, handle, name, argc, types))
+ return i;
+ }
+ return -1;
+}
+
+/*!
+ \internal
+
+ Returns true if the \a signalTypes and \a methodTypes are
+ compatible; otherwise returns false.
+*/
+bool QMetaObjectPrivate::checkConnectArgs(int signalArgc, const QArgumentType *signalTypes,
+ int methodArgc, const QArgumentType *methodTypes)
+{
+ if (signalArgc < methodArgc)
+ return false;
+ for (int i = 0; i < methodArgc; ++i) {
+ if (signalTypes[i] != methodTypes[i])
+ return false;
+ }
+ return true;
+}
+
+/*!
+ \internal
+
+ Returns true if the \a signal and \a method arguments are
+ compatible; otherwise returns false.
+*/
+bool QMetaObjectPrivate::checkConnectArgs(const QMetaMethodPrivate *signal,
+ const QMetaMethodPrivate *method)
+{
+ if (signal->methodType() != QMetaMethod::Signal)
+ return false;
+ if (signal->parameterCount() < method->parameterCount())
+ return false;
+ const QMetaObject *smeta = signal->enclosingMetaObject();
+ const QMetaObject *rmeta = method->enclosingMetaObject();
+ for (int i = 0; i < method->parameterCount(); ++i) {
+ uint sourceTypeInfo = signal->parameterTypeInfo(i);
+ uint targetTypeInfo = method->parameterTypeInfo(i);
+ if ((sourceTypeInfo & IsUnresolvedType)
+ || (targetTypeInfo & IsUnresolvedType)) {
+ QByteArray sourceName = typeNameFromTypeInfo(smeta, sourceTypeInfo);
+ QByteArray targetName = typeNameFromTypeInfo(rmeta, targetTypeInfo);
+ if (sourceName != targetName)
+ return false;
+ } else {
+ int sourceType = typeFromTypeInfo(smeta, sourceTypeInfo);
+ int targetType = typeFromTypeInfo(rmeta, targetTypeInfo);
+ if (sourceType != targetType)
+ return false;
+ }
+ }
+ return true;
}
static const QMetaObject *QMetaObject_findMetaObject(const QMetaObject *self, const char *name)
{
while (self) {
- if (strcmp(self->d.stringdata, name) == 0)
+ if (strcmp(rawStringData(self, 0), name) == 0)
return self;
if (self->d.extradata) {
const QMetaObject **e;
- if (priv(self->d.data)->revision < 2) {
- e = (const QMetaObject**)(self->d.extradata);
- } else
- {
- const QMetaObjectExtraData *extra = (const QMetaObjectExtraData*)(self->d.extradata);
- e = extra->objects;
- }
+ Q_ASSERT(priv(self->d.data)->revision >= 2);
+ const QMetaObjectExtraData *extra = (const QMetaObjectExtraData*)(self->d.extradata);
+ e = extra->objects;
if (e) {
while (*e) {
if (const QMetaObject *m =QMetaObject_findMetaObject((*e), name))
@@ -690,7 +899,7 @@ int QMetaObject::indexOfEnumerator(const char *name) const
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
for (int i = d->enumeratorCount - 1; i >= 0; --i) {
- const char *prop = m->d.stringdata + m->d.data[d->enumeratorData + 4*i];
+ const char *prop = rawStringData(m, m->d.data[d->enumeratorData + 4*i]);
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->enumeratorOffset();
return i;
@@ -713,7 +922,7 @@ int QMetaObject::indexOfProperty(const char *name) const
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
for (int i = d->propertyCount-1; i >= 0; --i) {
- const char *prop = m->d.stringdata + m->d.data[d->propertyData + 3*i];
+ const char *prop = rawStringData(m, m->d.data[d->propertyData + 3*i]);
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->propertyOffset();
return i;
@@ -722,7 +931,8 @@ int QMetaObject::indexOfProperty(const char *name) const
m = m->d.superdata;
}
- if (priv(this->d.data)->revision >= 3 && (priv(this->d.data)->flags & DynamicMetaObject)) {
+ Q_ASSERT(priv(this->d.data)->revision >= 3);
+ if (priv(this->d.data)->flags & DynamicMetaObject) {
QAbstractDynamicMetaObject *me =
const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this));
@@ -744,8 +954,7 @@ int QMetaObject::indexOfClassInfo(const char *name) const
const QMetaObject *m = this;
while (m && i < 0) {
for (i = priv(m->d.data)->classInfoCount-1; i >= 0; --i)
- if (strcmp(name, m->d.stringdata
- + m->d.data[priv(m->d.data)->classInfoData + 2*i]) == 0) {
+ if (strcmp(name, rawStringData(m, m->d.data[priv(m->d.data)->classInfoData + 2*i])) == 0) {
i += m->classInfoOffset();
break;
}
@@ -765,7 +974,8 @@ QMetaMethod QMetaObject::constructor(int index) const
{
int i = index;
QMetaMethod result;
- if (priv(d.data)->revision >= 2 && i >= 0 && i < priv(d.data)->constructorCount) {
+ Q_ASSERT(priv(d.data)->revision >= 2);
+ if (i >= 0 && i < priv(d.data)->constructorCount) {
result.mobj = this;
result.handle = priv(d.data)->constructorData + 5*i;
}
@@ -829,16 +1039,16 @@ QMetaProperty QMetaObject::property(int index) const
if (i >= 0 && i < priv(d.data)->propertyCount) {
int handle = priv(d.data)->propertyData + 3*i;
int flags = d.data[handle + 2];
- const char *type = d.stringdata + d.data[handle + 1];
result.mobj = this;
result.handle = handle;
result.idx = i;
if (flags & EnumOrFlag) {
+ const char *type = rawTypeNameFromTypeInfo(this, d.data[handle + 1]);
result.menum = enumerator(indexOfEnumerator(type));
if (!result.menum.isValid()) {
const char *enum_name = type;
- const char *scope_name = d.stringdata;
+ const char *scope_name = rawStringData(this, 0);
char *scope_buffer = 0;
const char *colon = strrchr(enum_name, ':');
@@ -847,7 +1057,7 @@ QMetaProperty QMetaObject::property(int index) const
if (colon > enum_name) {
int len = colon-enum_name-1;
scope_buffer = (char *)malloc(len+1);
- qMemCopy(scope_buffer, enum_name, len);
+ memcpy(scope_buffer, enum_name, len);
scope_buffer[len] = '\0';
scope_name = scope_buffer;
enum_name = colon+1;
@@ -934,6 +1144,21 @@ bool QMetaObject::checkConnectArgs(const char *signal, const char *method)
return false;
}
+/*!
+ \since 5.0
+ \overload
+
+ Returns true if the \a signal and \a method arguments are
+ compatible; otherwise returns false.
+*/
+bool QMetaObject::checkConnectArgs(const QMetaMethod &signal,
+ const QMetaMethod &method)
+{
+ return QMetaObjectPrivate::checkConnectArgs(
+ QMetaMethodPrivate::get(&signal),
+ QMetaMethodPrivate::get(&method));
+}
+
static void qRemoveWhitespace(const char *s, char *d)
{
char last = 0;
@@ -963,7 +1188,9 @@ static char *qNormalizeType(char *d, int &templdepth, QByteArray &result)
--templdepth;
++d;
}
- if (strncmp("void", t, d - t) != 0)
+ // "void" should only be removed if this is part of a signature that has
+ // an explicit void argument; e.g., "void foo(void)" --> "void foo()"
+ if (strncmp("void)", t, d - t + 1) != 0)
result += normalizeTypeInternal(t, d);
return d;
@@ -1230,7 +1457,7 @@ bool QMetaObject::invokeMethod(QObject *obj,
\ingroup objectmodel
- A QMetaMethod has a methodType(), a signature(), a list of
+ A QMetaMethod has a methodType(), a methodSignature(), a list of
parameterTypes() and parameterNames(), a return typeName(), a
tag(), and an access() specifier. You can use invoke() to invoke
the method on an arbitrary QObject.
@@ -1275,72 +1502,244 @@ bool QMetaObject::invokeMethod(QObject *obj,
\internal
*/
+QByteArray QMetaMethodPrivate::signature() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ QByteArray result;
+ result.reserve(256);
+ result += name();
+ result += '(';
+ QList<QByteArray> argTypes = parameterTypes();
+ for (int i = 0; i < argTypes.size(); ++i) {
+ if (i)
+ result += ',';
+ result += argTypes.at(i);
+ }
+ result += ')';
+ return result;
+}
+
+QByteArray QMetaMethodPrivate::name() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return toByteArray(stringData(mobj, mobj->d.data[handle]));
+}
+
+int QMetaMethodPrivate::typesDataIndex() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return mobj->d.data[handle + 2];
+}
+
+const char *QMetaMethodPrivate::rawReturnTypeName() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ uint typeInfo = mobj->d.data[typesDataIndex()];
+ if (typeInfo & IsUnresolvedType)
+ return rawStringData(mobj, typeInfo & TypeNameIndexMask);
+ else
+ return QMetaType::typeName(typeInfo);
+}
+
+int QMetaMethodPrivate::returnType() const
+{
+ return parameterType(-1);
+}
+
+int QMetaMethodPrivate::parameterCount() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return mobj->d.data[handle + 1];
+}
+
+int QMetaMethodPrivate::parametersDataIndex() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return typesDataIndex() + 1;
+}
+
+uint QMetaMethodPrivate::parameterTypeInfo(int index) const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return mobj->d.data[parametersDataIndex() + index];
+}
+
+int QMetaMethodPrivate::parameterType(int index) const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return typeFromTypeInfo(mobj, parameterTypeInfo(index));
+}
+
+void QMetaMethodPrivate::getParameterTypes(int *types) const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ int dataIndex = parametersDataIndex();
+ int argc = parameterCount();
+ for (int i = 0; i < argc; ++i) {
+ int id = typeFromTypeInfo(mobj, mobj->d.data[dataIndex++]);
+ *(types++) = id;
+ }
+}
+
+QList<QByteArray> QMetaMethodPrivate::parameterTypes() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ QList<QByteArray> list;
+ int argc = parameterCount();
+ int paramsIndex = parametersDataIndex();
+ for (int i = 0; i < argc; ++i)
+ list += typeNameFromTypeInfo(mobj, mobj->d.data[paramsIndex + i]);
+ return list;
+}
+
+QList<QByteArray> QMetaMethodPrivate::parameterNames() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ QList<QByteArray> list;
+ int argc = parameterCount();
+ int namesIndex = parametersDataIndex() + argc;
+ for (int i = 0; i < argc; ++i)
+ list += toByteArray(stringData(mobj, mobj->d.data[namesIndex + i]));
+ return list;
+}
+
+QByteArray QMetaMethodPrivate::tag() const
+{
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ return toByteArray(stringData(mobj, mobj->d.data[handle + 3]));
+}
+
/*!
+ \since 5.0
+
Returns the signature of this method (e.g.,
\c{setValue(double)}).
\sa parameterTypes(), parameterNames()
*/
-const char *QMetaMethod::signature() const
+QByteArray QMetaMethod::methodSignature() const
+{
+ if (!mobj)
+ return QByteArray();
+ return QMetaMethodPrivate::get(this)->signature();
+}
+
+/*!
+ \since 5.0
+
+ Returns the name of this method.
+
+ \sa methodSignature(), parameterCount()
+*/
+QByteArray QMetaMethod::name() const
+{
+ if (!mobj)
+ return QByteArray();
+ return QMetaMethodPrivate::get(this)->name();
+}
+
+/*!
+ \since 5.0
+
+ Returns the return type of this method.
+
+ The return value is one of the types that are registered
+ with QMetaType, or QMetaType::UnknownType if the type is not registered.
+
+ \sa parameterType(), QMetaType, typeName()
+*/
+int QMetaMethod::returnType() const
+ {
+ if (!mobj)
+ return QMetaType::UnknownType;
+ return QMetaMethodPrivate::get(this)->returnType();
+}
+
+/*!
+ \since 5.0
+
+ Returns the number of parameters of this method.
+
+ \sa parameterType(), parameterNames()
+*/
+int QMetaMethod::parameterCount() const
{
if (!mobj)
return 0;
- return mobj->d.stringdata + mobj->d.data[handle];
+ return QMetaMethodPrivate::get(this)->parameterCount();
+}
+
+/*!
+ \since 5.0
+
+ Returns the type of the parameter at the given \a index.
+
+ The return value is one of the types that are registered
+ with QMetaType, or QMetaType::UnknownType if the type is not registered.
+
+ \sa parameterCount(), returnType(), QMetaType
+*/
+int QMetaMethod::parameterType(int index) const
+{
+ if (!mobj || index < 0)
+ return QMetaType::UnknownType;
+ if (index >= QMetaMethodPrivate::get(this)->parameterCount())
+ return QMetaType::UnknownType;
+ return QMetaMethodPrivate::get(this)->parameterType(index);
+}
+
+/*!
+ \since 5.0
+ \internal
+
+ Gets the parameter \a types of this method. The storage
+ for \a types must be able to hold parameterCount() items.
+
+ \sa parameterCount(), returnType(), parameterType()
+*/
+void QMetaMethod::getParameterTypes(int *types) const
+{
+ if (!mobj)
+ return;
+ QMetaMethodPrivate::get(this)->getParameterTypes(types);
}
/*!
Returns a list of parameter types.
- \sa parameterNames(), signature()
+ \sa parameterNames(), methodSignature()
*/
QList<QByteArray> QMetaMethod::parameterTypes() const
{
if (!mobj)
return QList<QByteArray>();
- return QMetaObjectPrivate::parameterTypeNamesFromSignature(
- mobj->d.stringdata + mobj->d.data[handle]);
+ return QMetaMethodPrivate::get(this)->parameterTypes();
}
/*!
Returns a list of parameter names.
- \sa parameterTypes(), signature()
+ \sa parameterTypes(), methodSignature()
*/
QList<QByteArray> QMetaMethod::parameterNames() const
{
QList<QByteArray> list;
if (!mobj)
return list;
- const char *names = mobj->d.stringdata + mobj->d.data[handle + 1];
- if (*names == 0) {
- // do we have one or zero arguments?
- const char *signature = mobj->d.stringdata + mobj->d.data[handle];
- while (*signature && *signature != '(')
- ++signature;
- if (*++signature != ')')
- list += QByteArray();
- } else {
- --names;
- do {
- const char *begin = ++names;
- while (*names && *names != ',')
- ++names;
- list += QByteArray(begin, names - begin);
- } while (*names);
- }
- return list;
+ return QMetaMethodPrivate::get(this)->parameterNames();
}
/*!
- Returns the return type of this method, or an empty string if the
- return type is \e void.
+ Returns the return type name of this method.
+
+ \sa returnType(), QMetaType::type()
*/
const char *QMetaMethod::typeName() const
{
if (!mobj)
return 0;
- return mobj->d.stringdata + mobj->d.data[handle + 2];
+ return QMetaMethodPrivate::get(this)->rawReturnTypeName();
}
/*!
@@ -1377,7 +1776,7 @@ const char *QMetaMethod::tag() const
{
if (!mobj)
return 0;
- return mobj->d.stringdata + mobj->d.data[handle + 3];
+ return QMetaMethodPrivate::get(this)->tag().constData();
}
@@ -1577,28 +1976,7 @@ bool QMetaMethod::invoke(QObject *object,
if (qstrlen(typeNames[paramCount]) <= 0)
break;
}
- int metaMethodArgumentCount = 0;
- {
- // based on QMetaObject::parameterNames()
- const char *names = mobj->d.stringdata + mobj->d.data[handle + 1];
- if (*names == 0) {
- // do we have one or zero arguments?
- const char *signature = mobj->d.stringdata + mobj->d.data[handle];
- while (*signature && *signature != '(')
- ++signature;
- if (*++signature != ')')
- ++metaMethodArgumentCount;
- } else {
- --names;
- do {
- ++names;
- while (*names && *names != ',')
- ++names;
- ++metaMethodArgumentCount;
- } while (*names);
- }
- }
- if (paramCount <= metaMethodArgumentCount)
+ if (paramCount <= QMetaMethodPrivate::get(this)->parameterCount())
return false;
// check connection type
@@ -1633,8 +2011,8 @@ bool QMetaMethod::invoke(QObject *object,
// recompute the methodIndex by reversing the arithmetic in QMetaObject::property()
int idx_relative = ((handle - priv(mobj->d.data)->methodData) / 5);
int idx_offset = mobj->methodOffset();
- QObjectPrivate::StaticMetaCallFunction callFunction =
- (QMetaObjectPrivate::get(mobj)->revision >= 6 && mobj->d.extradata)
+ Q_ASSERT(QMetaObjectPrivate::get(mobj)->revision >= 6);
+ QObjectPrivate::StaticMetaCallFunction callFunction = mobj->d.extradata
? reinterpret_cast<const QMetaObjectExtraData *>(mobj->d.extradata)->static_metacall : 0;
if (connectionType == Qt::DirectConnection) {
@@ -1661,7 +2039,7 @@ bool QMetaMethod::invoke(QObject *object,
for (int i = 1; i < paramCount; ++i) {
types[i] = QMetaType::type(typeNames[i]);
- if (types[i]) {
+ if (types[i] != QMetaType::UnknownType) {
args[i] = QMetaType::create(types[i], param[i]);
++nargs;
} else if (param[i]) {
@@ -1803,7 +2181,7 @@ const char *QMetaEnum::name() const
{
if (!mobj)
return 0;
- return mobj->d.stringdata + mobj->d.data[handle];
+ return rawStringData(mobj, mobj->d.data[handle]);
}
/*!
@@ -1831,7 +2209,7 @@ const char *QMetaEnum::key(int index) const
int count = mobj->d.data[handle + 2];
int data = mobj->d.data[handle + 3];
if (index >= 0 && index < count)
- return mobj->d.stringdata + mobj->d.data[data + 2*index];
+ return rawStringData(mobj, mobj->d.data[data + 2*index]);
return 0;
}
@@ -1878,7 +2256,7 @@ bool QMetaEnum::isFlag() const
*/
const char *QMetaEnum::scope() const
{
- return mobj?mobj->d.stringdata : 0;
+ return mobj?rawStringData(mobj, 0) : 0;
}
/*!
@@ -1910,8 +2288,8 @@ int QMetaEnum::keyToValue(const char *key, bool *ok) const
int count = mobj->d.data[handle + 2];
int data = mobj->d.data[handle + 3];
for (int i = 0; i < count; ++i) {
- if ((!scope || (qstrlen(mobj->d.stringdata) == scope && strncmp(qualified_key, mobj->d.stringdata, scope) == 0))
- && strcmp(key, mobj->d.stringdata + mobj->d.data[data + 2*i]) == 0) {
+ if ((!scope || (stringSize(mobj, 0) == int(scope) && strncmp(qualified_key, rawStringData(mobj, 0), scope) == 0))
+ && strcmp(key, rawStringData(mobj, mobj->d.data[data + 2*i])) == 0) {
if (ok != 0)
*ok = true;
return mobj->d.data[data + 2*i + 1];
@@ -1936,7 +2314,7 @@ const char* QMetaEnum::valueToKey(int value) const
int data = mobj->d.data[handle + 3];
for (int i = 0; i < count; ++i)
if (value == (int)mobj->d.data[data + 2*i + 1])
- return mobj->d.stringdata + mobj->d.data[data + 2*i];
+ return rawStringData(mobj, mobj->d.data[data + 2*i]);
return 0;
}
@@ -1979,8 +2357,8 @@ int QMetaEnum::keysToValue(const char *keys, bool *ok) const
}
int i;
for (i = count-1; i >= 0; --i)
- if ((!scope || (qstrlen(mobj->d.stringdata) == scope && strncmp(qualified_key.constData(), mobj->d.stringdata, scope) == 0))
- && strcmp(key, mobj->d.stringdata + mobj->d.data[data + 2*i]) == 0) {
+ if ((!scope || (stringSize(mobj, 0) == int(scope) && strncmp(qualified_key.constData(), rawStringData(mobj, 0), scope) == 0))
+ && strcmp(key, rawStringData(mobj, mobj->d.data[data + 2*i])) == 0) {
value |= mobj->d.data[data + 2*i + 1];
break;
}
@@ -2013,7 +2391,7 @@ QByteArray QMetaEnum::valueToKeys(int value) const
v = v & ~k;
if (!keys.isEmpty())
keys += '|';
- keys += mobj->d.stringdata + mobj->d.data[data + 2*i];
+ keys += toByteArray(stringData(mobj, mobj->d.data[data + 2*i]));
}
}
return keys;
@@ -2092,7 +2470,7 @@ const char *QMetaProperty::name() const
if (!mobj)
return 0;
int handle = priv(mobj->d.data)->propertyData + 3*idx;
- return mobj->d.stringdata + mobj->d.data[handle];
+ return rawStringData(mobj, mobj->d.data[handle]);
}
/*!
@@ -2105,7 +2483,7 @@ const char *QMetaProperty::typeName() const
if (!mobj)
return 0;
int handle = priv(mobj->d.data)->propertyData + 3*idx;
- return mobj->d.stringdata + mobj->d.data[handle + 1];
+ return rawTypeNameFromTypeInfo(mobj, mobj->d.data[handle + 1]);
}
/*!
@@ -2119,14 +2497,16 @@ QVariant::Type QMetaProperty::type() const
if (!mobj)
return QVariant::Invalid;
int handle = priv(mobj->d.data)->propertyData + 3*idx;
- uint flags = mobj->d.data[handle + 2];
- uint type = flags >> 24;
- if (type)
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ uint type = typeFromTypeInfo(mobj, mobj->d.data[handle + 1]);
+ if (type >= QMetaType::User)
+ return QVariant::UserType;
+ if (type != QMetaType::UnknownType)
return QVariant::Type(type);
if (isEnumType()) {
int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
- if (enumMetaTypeId == 0)
+ if (enumMetaTypeId == QMetaType::UnknownType)
return QVariant::Int;
}
#ifdef QT_COORD_TYPE
@@ -2142,18 +2522,24 @@ QVariant::Type QMetaProperty::type() const
\since 4.2
Returns this property's user type. The return value is one
- of the values that are registered with QMetaType, or 0 if
+ of the values that are registered with QMetaType, or QMetaType::UnknownType if
the type is not registered.
\sa type(), QMetaType, typeName()
*/
int QMetaProperty::userType() const
{
- QVariant::Type tp = type();
- if (tp != QVariant::UserType)
- return tp;
+ if (!mobj)
+ return QMetaType::UnknownType;
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ int handle = priv(mobj->d.data)->propertyData + 3*idx;
+ int type = typeFromTypeInfo(mobj, mobj->d.data[handle + 1]);
+ if (type != QMetaType::UnknownType)
+ return type;
if (isEnumType()) {
int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
+ if (enumMetaTypeId == QMetaType::UnknownType)
+ return QVariant::Int; // Match behavior of QMetaType::type()
return enumMetaTypeId;
}
return QMetaType::type(typeName());
@@ -2249,18 +2635,20 @@ QVariant QMetaProperty::read(const QObject *object) const
with QMetaType)
*/
int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
- if (enumMetaTypeId != 0)
+ if (enumMetaTypeId != QMetaType::UnknownType)
t = enumMetaTypeId;
} else {
int handle = priv(mobj->d.data)->propertyData + 3*idx;
- uint flags = mobj->d.data[handle + 2];
- const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1];
- t = (flags >> 24);
- if (t == QVariant::Invalid)
+ const char *typeName = 0;
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ uint typeInfo = mobj->d.data[handle + 1];
+ if (!(typeInfo & IsUnresolvedType))
+ t = typeInfo;
+ else {
+ typeName = rawStringData(mobj, typeInfo & TypeNameIndexMask);
t = QMetaType::type(typeName);
- if (t == QVariant::Invalid)
- t = QVariant::nameToType(typeName);
- if (t == QVariant::Invalid) {
+ }
+ if (t == QMetaType::UnknownType) {
qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name());
return QVariant();
}
@@ -2315,17 +2703,24 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const
return false;
} else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) {
int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
- if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData())
+ if ((enumMetaTypeId == QMetaType::UnknownType) || (v.userType() != enumMetaTypeId) || !v.constData())
return false;
v = QVariant(*reinterpret_cast<const int *>(v.constData()));
}
v.convert(QVariant::Int);
} else {
int handle = priv(mobj->d.data)->propertyData + 3*idx;
- uint flags = mobj->d.data[handle + 2];
- t = flags >> 24;
- if (t == QVariant::Invalid) {
- const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1];
+ const char *typeName = 0;
+ Q_ASSERT(priv(mobj->d.data)->revision >= 7);
+ uint typeInfo = mobj->d.data[handle + 1];
+ if (!(typeInfo & IsUnresolvedType))
+ t = typeInfo;
+ else {
+ typeName = rawStringData(mobj, typeInfo & TypeNameIndexMask);
+ t = QMetaType::type(typeName);
+ }
+ if (t == QMetaType::UnknownType) {
+ Q_ASSERT(typeName != 0);
const char *vtypeName = value.typeName();
if (vtypeName && strcmp(typeName, vtypeName) == 0)
t = value.userType();
@@ -2691,7 +3086,7 @@ const char *QMetaClassInfo::name() const
{
if (!mobj)
return 0;
- return mobj->d.stringdata + mobj->d.data[handle];
+ return rawStringData(mobj, mobj->d.data[handle]);
}
/*!
@@ -2703,7 +3098,7 @@ const char* QMetaClassInfo::value() const
{
if (!mobj)
return 0;
- return mobj->d.stringdata + mobj->d.data[handle + 1];
+ return rawStringData(mobj, mobj->d.data[handle + 1]);
}
/*!
diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h
index 9e51af7556..095b196dca 100644
--- a/src/corelib/kernel/qmetaobject.h
+++ b/src/corelib/kernel/qmetaobject.h
@@ -57,8 +57,13 @@ class Q_CORE_EXPORT QMetaMethod
public:
inline QMetaMethod() : mobj(0),handle(0) {}
- const char *signature() const;
+ QByteArray methodSignature() const;
+ QByteArray name() const;
const char *typeName() const;
+ int returnType() const;
+ int parameterCount() const;
+ int parameterType(int index) const;
+ void getParameterTypes(int *types) const;
QList<QByteArray> parameterTypes() const;
QList<QByteArray> parameterNames() const;
const char *tag() const;
@@ -137,8 +142,16 @@ public:
inline bool isValid() const { return mobj != 0; }
private:
+#if QT_DEPRECATED_SINCE(5,0)
+ // signature() has been renamed to methodSignature() in Qt 5.
+ // Warning, that function returns a QByteArray; check the life time if
+ // you convert to char*.
+ char *signature(struct renamedInQt5_warning_checkTheLifeTime * = 0) Q_DECL_EQ_DELETE;
+#endif
+
const QMetaObject *mobj;
uint handle;
+ friend class QMetaMethodPrivate;
friend struct QMetaObject;
friend struct QMetaObjectPrivate;
friend class QObject;
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index 59a5c5f280..3b732b4b93 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -105,11 +105,64 @@ enum MetaObjectFlags {
RequiresVariantMetaObject = 0x02
};
+enum MetaDataFlags {
+ IsUnresolvedType = 0x80000000,
+ TypeNameIndexMask = 0x7FFFFFFF
+};
+
+class QArgumentType
+{
+public:
+ QArgumentType(int type)
+ : _type(type)
+ {}
+ QArgumentType(const QByteArray &name)
+ : _type(QMetaType::type(name.constData())), _name(name)
+ {}
+ QArgumentType()
+ : _type(0)
+ {}
+ int type() const
+ { return _type; }
+ QByteArray name() const
+ {
+ if (_type && _name.isEmpty())
+ const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
+ return _name;
+ }
+ bool operator==(const QArgumentType &other) const
+ {
+ if (_type)
+ return _type == other._type;
+ else if (other._type)
+ return false;
+ else
+ return _name == other._name;
+ }
+ bool operator!=(const QArgumentType &other) const
+ {
+ if (_type)
+ return _type != other._type;
+ else if (other._type)
+ return true;
+ else
+ return _name != other._name;
+ }
+
+private:
+ int _type;
+ QByteArray _name;
+};
+
+template <class T, int> class QVarLengthArray;
+typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray;
+
+class QMetaMethodPrivate;
class QMutex;
struct QMetaObjectPrivate
{
- enum { OutputRevision = 6 }; // Used by moc and qmetaobjectbuilder
+ enum { OutputRevision = 7 }; // Used by moc, qmetaobjectbuilder and qdbus
int revision;
int className;
@@ -122,17 +175,33 @@ struct QMetaObjectPrivate
int signalCount; //since revision 4
// revision 5 introduces changes in normalized signatures, no new members
// revision 6 added qt_static_metacall as a member of each Q_OBJECT and inside QMetaObject itself
+ // revision 7 is Qt 5
static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject)
{ return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); }
+ static int originalClone(const QMetaObject *obj, int local_method_index);
+
+ static QByteArray decodeMethodSignature(const char *signature,
+ QArgumentTypeArray &types);
static int indexOfSignalRelative(const QMetaObject **baseObject,
- const char* name,
- bool normalizeStringData);
+ const QByteArray &name, int argc,
+ const QArgumentType *types);
static int indexOfSlotRelative(const QMetaObject **m,
- const char *slot,
- bool normalizeStringData);
- static int originalClone(const QMetaObject *obj, int local_method_index);
+ const QByteArray &name, int argc,
+ const QArgumentType *types);
+ static int indexOfSignal(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types);
+ static int indexOfSlot(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types);
+ static int indexOfMethod(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types);
+ static int indexOfConstructor(const QMetaObject *m, const QByteArray &name,
+ int argc, const QArgumentType *types);
+ static bool checkConnectArgs(int signalArgc, const QArgumentType *signalTypes,
+ int methodArgc, const QArgumentType *methodTypes);
+ static bool checkConnectArgs(const QMetaMethodPrivate *signal,
+ const QMetaMethodPrivate *method);
static QList<QByteArray> parameterTypeNamesFromSignature(const char *signature);
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp
index 8bece6636b..d262d6a61b 100644
--- a/src/corelib/kernel/qmetaobjectbuilder.cpp
+++ b/src/corelib/kernel/qmetaobjectbuilder.cpp
@@ -78,26 +78,17 @@ QT_BEGIN_NAMESPACE
*/
// copied from moc's generator.cpp
-uint qvariant_nameToType(const char* name)
+bool isBuiltinType(const QByteArray &type)
{
- if (!name)
- return 0;
-
- uint tp = QMetaType::type(name);
- return tp < QMetaType::User ? tp : 0;
-}
-
-/*
- Returns true if the type is a QVariant types.
-*/
-bool isVariantType(const char* type)
-{
- return qvariant_nameToType(type) != 0;
+ int id = QMetaType::type(type);
+ if (!id && !type.isEmpty() && type != "void")
+ return false;
+ return (id < QMetaType::User);
}
+// copied from qmetaobject.cpp
static inline const QMetaObjectPrivate *priv(const uint* data)
{ return reinterpret_cast<const QMetaObjectPrivate*>(data); }
-// end of copied lines from qmetaobject.cpp
class QMetaMethodBuilderPrivate
{
@@ -105,7 +96,7 @@ public:
QMetaMethodBuilderPrivate
(QMetaMethod::MethodType _methodType,
const QByteArray& _signature,
- const QByteArray& _returnType = QByteArray(),
+ const QByteArray& _returnType = QByteArray("void"),
QMetaMethod::Access _access = QMetaMethod::Public,
int _revision = 0)
: signature(QMetaObject::normalizedSignature(_signature.constData())),
@@ -113,6 +104,7 @@ public:
attributes(((int)_access) | (((int)_methodType) << 2)),
revision(_revision)
{
+ Q_ASSERT((_methodType == QMetaMethod::Constructor) == returnType.isNull());
}
QByteArray signature;
@@ -136,6 +128,21 @@ public:
{
attributes = ((attributes & ~AccessMask) | (int)value);
}
+
+ QList<QByteArray> parameterTypes() const
+ {
+ return QMetaObjectPrivate::parameterTypeNamesFromSignature(signature);
+ }
+
+ int parameterCount() const
+ {
+ return parameterTypes().size();
+ }
+
+ QByteArray name() const
+ {
+ return signature.left(qMax(signature.indexOf('('), 0));
+ }
};
class QMetaPropertyBuilderPrivate
@@ -429,8 +436,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature)
\a signature and \a returnType. Returns an object that can be
used to adjust the other attributes of the method. The \a signature
and \a returnType will be normalized before they are added to
- the class. If \a returnType is empty, then it indicates that
- the method has \c{void} as its return type.
+ the class.
\sa method(), methodCount(), removeMethod(), indexOfMethod()
*/
@@ -458,13 +464,13 @@ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype)
{
QMetaMethodBuilder method;
if (prototype.methodType() == QMetaMethod::Method)
- method = addMethod(prototype.signature());
+ method = addMethod(prototype.methodSignature());
else if (prototype.methodType() == QMetaMethod::Signal)
- method = addSignal(prototype.signature());
+ method = addSignal(prototype.methodSignature());
else if (prototype.methodType() == QMetaMethod::Slot)
- method = addSlot(prototype.signature());
+ method = addSlot(prototype.methodSignature());
else if (prototype.methodType() == QMetaMethod::Constructor)
- method = addConstructor(prototype.signature());
+ method = addConstructor(prototype.methodSignature());
method.setReturnType(prototype.typeName());
method.setParameterNames(prototype.parameterNames());
method.setTag(prototype.tag());
@@ -501,7 +507,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature)
{
int index = d->methods.size();
d->methods.append(QMetaMethodBuilderPrivate
- (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected));
+ (QMetaMethod::Signal, signature, QByteArray("void"), QMetaMethod::Protected));
return QMetaMethodBuilder(this, index);
}
@@ -517,7 +523,8 @@ QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature)
QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature)
{
int index = d->constructors.size();
- d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature));
+ d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature,
+ /*returnType=*/QByteArray()));
return QMetaMethodBuilder(this, -(index + 1));
}
@@ -535,7 +542,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signatur
QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype)
{
Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor);
- QMetaMethodBuilder ctor = addConstructor(prototype.signature());
+ QMetaMethodBuilder ctor = addConstructor(prototype.methodSignature());
ctor.setReturnType(prototype.typeName());
ctor.setParameterNames(prototype.parameterNames());
ctor.setTag(prototype.tag());
@@ -588,7 +595,7 @@ QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& protot
if (prototype.hasNotifySignal()) {
// Find an existing method for the notify signal, or add a new one.
QMetaMethod method = prototype.notifySignal();
- int index = indexOfMethod(method.signature());
+ int index = indexOfMethod(method.methodSignature());
if (index == -1)
index = addMethod(method).index();
d->properties[property._index].notifySignal = index;
@@ -731,16 +738,12 @@ void QMetaObjectBuilder::addMetaObject
if ((members & RelatedMetaObjects) != 0) {
const QMetaObject **objects;
- if (priv(prototype->d.data)->revision < 2) {
- objects = (const QMetaObject **)(prototype->d.extradata);
- } else
- {
- const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata);
- if (extra)
- objects = extra->objects;
- else
- objects = 0;
- }
+ Q_ASSERT(priv(prototype->d.data)->revision >= 2);
+ const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata);
+ if (extra)
+ objects = extra->objects;
+ else
+ objects = 0;
if (objects) {
while (*objects != 0) {
addRelatedMetaObject(*objects);
@@ -750,12 +753,11 @@ void QMetaObjectBuilder::addMetaObject
}
if ((members & StaticMetacall) != 0) {
- if (priv(prototype->d.data)->revision >= 6) {
- const QMetaObjectExtraData *extra =
- (const QMetaObjectExtraData *)(prototype->d.extradata);
- if (extra && extra->static_metacall)
- setStaticMetacallFunction(extra->static_metacall);
- }
+ Q_ASSERT(priv(prototype->d.data)->revision >= 6);
+ const QMetaObjectExtraData *extra =
+ (const QMetaObjectExtraData *)(prototype->d.extradata);
+ if (extra && extra->static_metacall)
+ setStaticMetacallFunction(extra->static_metacall);
}
}
@@ -1070,75 +1072,79 @@ int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name)
#define ALIGN(size,type) \
(size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)
-class MetaStringTable
+/*!
+ \class QMetaStringTable
+ \internal
+ \brief The QMetaStringTable class can generate a meta-object string table at runtime.
+*/
+
+QMetaStringTable::QMetaStringTable()
+ : m_index(0) {}
+
+// Enters the given value into the string table (if it hasn't already been
+// entered). Returns the index of the string.
+int QMetaStringTable::enter(const QByteArray &value)
{
-public:
- typedef QHash<QByteArray, int> Entries; // string --> offset mapping
- typedef Entries::const_iterator const_iterator;
- Entries::const_iterator constBegin() const
- { return m_entries.constBegin(); }
- Entries::const_iterator constEnd() const
- { return m_entries.constEnd(); }
+ Entries::iterator it = m_entries.find(value);
+ if (it != m_entries.end())
+ return it.value();
+ int pos = m_index;
+ m_entries.insert(value, pos);
+ ++m_index;
+ return pos;
+}
- MetaStringTable() : m_offset(0) {}
+int QMetaStringTable::preferredAlignment()
+{
+ return Q_ALIGNOF(QByteArrayData);
+}
- int enter(const QByteArray &value)
- {
- Entries::iterator it = m_entries.find(value);
- if (it != m_entries.end())
- return it.value();
- int pos = m_offset;
- m_entries.insert(value, pos);
- m_offset += value.size() + 1;
- return pos;
- }
+// Returns the size (in bytes) required for serializing this string table.
+int QMetaStringTable::blobSize() const
+{
+ int size = m_entries.size() * sizeof(QByteArrayData);
+ Entries::const_iterator it;
+ for (it = m_entries.constBegin(); it != m_entries.constEnd(); ++it)
+ size += it.key().size() + 1;
+ return size;
+}
- int arraySize() const { return m_offset; }
+// Writes strings to string data struct.
+// The struct consists of an array of QByteArrayData, followed by a char array
+// containing the actual strings. This format must match the one produced by
+// moc (see generator.cpp).
+void QMetaStringTable::writeBlob(char *out)
+{
+ Q_ASSERT(!(reinterpret_cast<quintptr>(out) & (preferredAlignment()-1)));
-private:
- Entries m_entries;
- int m_offset;
-};
+ int offsetOfStringdataMember = m_entries.size() * sizeof(QByteArrayData);
+ int stringdataOffset = 0;
+ for (int i = 0; i < m_entries.size(); ++i) {
+ const QByteArray &str = m_entries.key(i);
+ int size = str.size();
+ qptrdiff offset = offsetOfStringdataMember + stringdataOffset
+ - i * sizeof(QByteArrayData);
+ const QByteArrayData data =
+ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset);
-// Build the parameter array string for a method.
-static QByteArray buildParameterNames
- (const QByteArray& signature, const QList<QByteArray>& parameterNames)
-{
- // If the parameter name list is specified, then concatenate them.
- if (!parameterNames.isEmpty()) {
- QByteArray names;
- bool first = true;
- foreach (const QByteArray &name, parameterNames) {
- if (first)
- first = false;
- else
- names += (char)',';
- names += name;
- }
- return names;
- }
+ memcpy(out + i * sizeof(QByteArrayData), &data, sizeof(QByteArrayData));
- // Count commas in the signature, excluding those inside template arguments.
- int index = signature.indexOf('(');
- if (index < 0)
- return QByteArray();
- ++index;
- if (index >= signature.size())
- return QByteArray();
- if (signature[index] == ')')
- return QByteArray();
- int count = 1;
- int brackets = 0;
- while (index < signature.size() && signature[index] != ',') {
- char ch = signature[index++];
- if (ch == '<')
- ++brackets;
- else if (ch == '>')
- --brackets;
- else if (ch == ',' && brackets <= 0)
- ++count;
+ memcpy(out + offsetOfStringdataMember + stringdataOffset, str.constData(), size);
+ out[offsetOfStringdataMember + stringdataOffset + size] = '\0';
+
+ stringdataOffset += size + 1;
}
- return QByteArray(count - 1, ',');
+}
+
+// Returns the sum of all parameters (including return type) for the given
+// \a methods. This is needed for calculating the size of the methods'
+// parameter type/name meta-data.
+static int aggregateParameterCount(const QList<QMetaMethodBuilderPrivate> &methods)
+{
+ int sum = 0;
+ for (int i = 0; i < methods.size(); ++i)
+ sum += methods.at(i).parameterCount() + 1; // +1 for return type
+ return sum;
}
// Build a QMetaObject in "buf" based on the information in "d".
@@ -1151,6 +1157,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
Q_UNUSED(expectedSize); // Avoid warning in release mode
int size = 0;
int dataIndex;
+ int paramsIndex;
int enumIndex;
int index;
bool hasRevisionedMethods = d->hasRevisionedMethods();
@@ -1181,8 +1188,13 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
break;
}
}
+ int methodParametersDataSize =
+ ((aggregateParameterCount(d->methods)
+ + aggregateParameterCount(d->constructors)) * 2) // types and parameter names
+ - d->methods.size() // return "parameters" don't have names
+ - d->constructors.size(); // "this" parameters don't have names
if (buf) {
- Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 6, "QMetaObjectBuilder should generate the same version as moc");
+ Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 7, "QMetaObjectBuilder should generate the same version as moc");
pmeta->revision = QMetaObjectPrivate::OutputRevision;
pmeta->flags = d->flags;
pmeta->className = 0; // Class name is always the first string.
@@ -1197,6 +1209,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
dataIndex += 5 * d->methods.size();
if (hasRevisionedMethods)
dataIndex += d->methods.size();
+ paramsIndex = dataIndex;
+ dataIndex += methodParametersDataSize;
pmeta->propertyCount = d->properties.size();
pmeta->propertyData = dataIndex;
@@ -1218,6 +1232,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
dataIndex += 5 * d->methods.size();
if (hasRevisionedMethods)
dataIndex += d->methods.size();
+ paramsIndex = dataIndex;
+ dataIndex += methodParametersDataSize;
dataIndex += 3 * d->properties.size();
if (hasNotifySignals)
dataIndex += d->properties.size();
@@ -1240,13 +1256,14 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
// Find the start of the data and string tables.
int *data = reinterpret_cast<int *>(pmeta);
size += dataIndex * sizeof(int);
+ ALIGN(size, void *);
char *str = reinterpret_cast<char *>(buf + size);
if (buf) {
if (relocatable) {
- meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size);
+ meta->d.stringdata = reinterpret_cast<const QByteArrayData *>((quintptr)size);
meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize);
} else {
- meta->d.stringdata = str;
+ meta->d.stringdata = reinterpret_cast<const QByteArrayData *>(str);
meta->d.data = reinterpret_cast<uint *>(data);
}
}
@@ -1254,7 +1271,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
// Reset the current data position to just past the QMetaObjectPrivate.
dataIndex = MetaObjectPrivateFieldCount;
- MetaStringTable strings;
+ QMetaStringTable strings;
strings.enter(d->className);
// Output the class infos,
@@ -1273,24 +1290,21 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
Q_ASSERT(!buf || dataIndex == pmeta->methodData);
for (index = 0; index < d->methods.size(); ++index) {
QMetaMethodBuilderPrivate *method = &(d->methods[index]);
- int sig = strings.enter(method->signature);
- int params;
- QByteArray names = buildParameterNames
- (method->signature, method->parameterNames);
- params = strings.enter(names);
- int ret = strings.enter(method->returnType);
+ int name = strings.enter(method->name());
+ int argc = method->parameterCount();
int tag = strings.enter(method->tag);
int attrs = method->attributes;
if (buf) {
- data[dataIndex] = sig;
- data[dataIndex + 1] = params;
- data[dataIndex + 2] = ret;
+ data[dataIndex] = name;
+ data[dataIndex + 1] = argc;
+ data[dataIndex + 2] = paramsIndex;
data[dataIndex + 3] = tag;
data[dataIndex + 4] = attrs;
if (method->methodType() == QMetaMethod::Signal)
pmeta->signalCount++;
}
dataIndex += 5;
+ paramsIndex += 1 + argc * 2;
}
if (hasRevisionedMethods) {
for (index = 0; index < d->methods.size(); ++index) {
@@ -1301,23 +1315,59 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
}
}
+ // Output the method parameters in the class.
+ Q_ASSERT(!buf || dataIndex == pmeta->methodData + d->methods.size() * 5
+ + (hasRevisionedMethods ? d->methods.size() : 0));
+ for (int x = 0; x < 2; ++x) {
+ QList<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors;
+ for (index = 0; index < methods.size(); ++index) {
+ QMetaMethodBuilderPrivate *method = &(methods[index]);
+ QList<QByteArray> paramTypeNames = method->parameterTypes();
+ int paramCount = paramTypeNames.size();
+ for (int i = -1; i < paramCount; ++i) {
+ const QByteArray &typeName = (i < 0) ? method->returnType : paramTypeNames.at(i);
+ int typeInfo;
+ if (isBuiltinType(typeName))
+ typeInfo = QMetaType::type(typeName);
+ else
+ typeInfo = IsUnresolvedType | strings.enter(typeName);
+ if (buf)
+ data[dataIndex] = typeInfo;
+ ++dataIndex;
+ }
+
+ QList<QByteArray> paramNames = method->parameterNames;
+ while (paramNames.size() < paramCount)
+ paramNames.append(QByteArray());
+ for (int i = 0; i < paramCount; ++i) {
+ int stringIndex = strings.enter(paramNames.at(i));
+ if (buf)
+ data[dataIndex] = stringIndex;
+ ++dataIndex;
+ }
+ }
+ }
+
// Output the properties in the class.
Q_ASSERT(!buf || dataIndex == pmeta->propertyData);
for (index = 0; index < d->properties.size(); ++index) {
QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
int name = strings.enter(prop->name);
- int type = strings.enter(prop->type);
+
+ int typeInfo;
+ if (isBuiltinType(prop->type))
+ typeInfo = QMetaType::type(prop->type);
+ else
+ typeInfo = IsUnresolvedType | strings.enter(prop->type);
+
int flags = prop->flags;
- if (!isVariantType(prop->type)) {
+ if (!isBuiltinType(prop->type))
flags |= EnumOrFlag;
- } else {
- flags |= qvariant_nameToType(prop->type) << 24;
- }
if (buf) {
data[dataIndex] = name;
- data[dataIndex + 1] = type;
+ data[dataIndex + 1] = typeInfo;
data[dataIndex + 2] = flags;
}
dataIndex += 3;
@@ -1372,34 +1422,25 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
Q_ASSERT(!buf || dataIndex == pmeta->constructorData);
for (index = 0; index < d->constructors.size(); ++index) {
QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
- int sig = strings.enter(method->signature);
- int params;
- QByteArray names = buildParameterNames
- (method->signature, method->parameterNames);
- params = strings.enter(names);
- int ret = strings.enter(method->returnType);
+ int name = strings.enter(method->name());
+ int argc = method->parameterCount();
int tag = strings.enter(method->tag);
int attrs = method->attributes;
if (buf) {
- data[dataIndex] = sig;
- data[dataIndex + 1] = params;
- data[dataIndex + 2] = ret;
+ data[dataIndex] = name;
+ data[dataIndex + 1] = argc;
+ data[dataIndex + 2] = paramsIndex;
data[dataIndex + 3] = tag;
data[dataIndex + 4] = attrs;
}
dataIndex += 5;
+ paramsIndex += 1 + argc * 2;
}
- size += strings.arraySize();
+ size += strings.blobSize();
- if (buf) {
- // Write strings to string data array.
- MetaStringTable::const_iterator it;
- for (it = strings.constBegin(); it != strings.constEnd(); ++it) {
- memcpy(str + it.value(), it.key().constData(), it.key().size());
- str[it.value() + it.key().size()] = '\0';
- }
- }
+ if (buf)
+ strings.writeBlob(str);
// Output the zero terminator in the data array.
if (buf)
@@ -1508,7 +1549,7 @@ void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output,
quintptr dataOffset = (quintptr)dataMo->d.data;
output->d.superdata = superclass;
- output->d.stringdata = buf + stringdataOffset;
+ output->d.stringdata = reinterpret_cast<const QByteArrayData *>(buf + stringdataOffset);
output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
output->d.extradata = 0;
}
@@ -1896,7 +1937,7 @@ QByteArray QMetaMethodBuilder::returnType() const
is empty, then the method's return type is \c{void}. The \a value
will be normalized before it is added to the method.
- \sa returnType(), signature()
+ \sa returnType(), parameterTypes(), signature()
*/
void QMetaMethodBuilder::setReturnType(const QByteArray& value)
{
@@ -1906,6 +1947,20 @@ void QMetaMethodBuilder::setReturnType(const QByteArray& value)
}
/*!
+ Returns the list of parameter types for this method.
+
+ \sa returnType(), parameterNames()
+*/
+QList<QByteArray> QMetaMethodBuilder::parameterTypes() const
+{
+ QMetaMethodBuilderPrivate *d = d_func();
+ if (d)
+ return d->parameterTypes();
+ else
+ return QList<QByteArray>();
+}
+
+/*!
Returns the list of parameter names for this method.
\sa setParameterNames()
diff --git a/src/corelib/kernel/qmetaobjectbuilder_p.h b/src/corelib/kernel/qmetaobjectbuilder_p.h
index 86bc354164..4d766a9197 100644
--- a/src/corelib/kernel/qmetaobjectbuilder_p.h
+++ b/src/corelib/kernel/qmetaobjectbuilder_p.h
@@ -56,6 +56,7 @@
#include <QtCore/qobject.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qdatastream.h>
+#include <QtCore/qhash.h>
#include <QtCore/qmap.h>
@@ -203,6 +204,7 @@ public:
QByteArray returnType() const;
void setReturnType(const QByteArray& value);
+ QList<QByteArray> parameterTypes() const;
QList<QByteArray> parameterNames() const;
void setParameterNames(const QList<QByteArray>& value);
@@ -318,6 +320,23 @@ private:
QMetaEnumBuilderPrivate *d_func() const;
};
+class Q_CORE_EXPORT QMetaStringTable
+{
+public:
+ QMetaStringTable();
+
+ int enter(const QByteArray &value);
+
+ static int preferredAlignment();
+ int blobSize() const;
+ void writeBlob(char *out);
+
+private:
+ typedef QHash<QByteArray, int> Entries; // string --> index mapping
+ Entries m_entries;
+ int m_index;
+};
+
Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers)
Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::MetaObjectFlags)
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index fc9053520c..fba1aaf9b6 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -54,15 +54,16 @@
#include "qvariant.h"
#include "qmetatypeswitcher_p.h"
-#ifdef QT_BOOTSTRAPPED
-# ifndef QT_NO_GEOM_VARIANT
-# define QT_NO_GEOM_VARIANT
-# endif
-#else
+#ifndef QT_BOOTSTRAPPED
# include "qbitarray.h"
# include "qurl.h"
# include "qvariant.h"
# include "qabstractitemmodel.h"
+# include "qregularexpression.h"
+# include "qjsonvalue.h"
+# include "qjsonobject.h"
+# include "qjsonarray.h"
+# include "qjsondocument.h"
#endif
#ifndef QT_NO_GEOM_VARIANT
@@ -78,42 +79,12 @@ QT_BEGIN_NAMESPACE
namespace {
-template<typename T>
-struct TypeDefinition {
- static const bool IsAvailable = true;
-};
-
struct DefinedTypesFilter {
template<typename T>
struct Acceptor {
- static const bool IsAccepted = TypeDefinition<T>::IsAvailable && QTypeModuleInfo<T>::IsCore;
+ static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition<T>::IsAvailable && QTypeModuleInfo<T>::IsCore;
};
};
-
-// Ignore these types, as incomplete
-#ifdef QT_NO_GEOM_VARIANT
-template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
-#endif
-#ifdef QT_BOOTSTRAPPED
-template<> struct TypeDefinition<QVariantMap> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QVariantHash> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QVariantList> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QVariant> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
-#endif
-#ifdef QT_NO_REGEXP
-template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
-#endif
} // namespace
/*!
@@ -219,6 +190,7 @@ template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = fals
\value QPoint QPoint
\value QUrl QUrl
\value QRegExp QRegExp
+ \value QRegularExpression QRegularExpression
\value QDateTime QDateTime
\value QPointF QPointF
\value QPalette QPalette
@@ -240,8 +212,13 @@ template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = fals
\value QVector4D QVector4D
\value QQuaternion QQuaternion
\value QEasingCurve QEasingCurve
+ \value QJsonValue QJsonValue
+ \value QJsonObject QJsonObject
+ \value QJsonArray QJsonArray
+ \value QJsonDocument QJsonDocument
\value User Base value for user types
+ \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
\omitvalue FirstGuiType
\omitvalue FirstWidgetsType
@@ -311,7 +288,7 @@ static const struct { const char * typeName; int typeNameLength; int type; } typ
QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE)
QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER)
QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER)
- {0, 0, QMetaType::Void}
+ {0, 0, QMetaType::UnknownType}
};
Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0;
@@ -348,10 +325,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveOp,
LoadOperator loadOp)
{
- int idx = type(typeName);
- if (!idx)
- return;
- registerStreamOperators(idx, saveOp, loadOp);
+ registerStreamOperators(type(typeName), saveOp, loadOp);
}
/*! \internal
@@ -435,7 +409,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
{
const QVector<QCustomTypeInfo> * const ct = customTypes();
if (!ct)
- return 0;
+ return QMetaType::UnknownType;
for (int v = 0; v < ct->count(); ++v) {
const QCustomTypeInfo &customInfo = ct->at(v);
@@ -446,7 +420,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
return v + QMetaType::User;
}
}
- return 0;
+ return QMetaType::UnknownType;
}
/*! \internal
@@ -457,7 +431,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
int QMetaType::registerType(const char *typeName, Deleter deleter,
Creator creator)
{
- return registerType(typeName, deleter, creator, qMetaTypeDestructHelper<void>, qMetaTypeConstructHelper<void>, 0, TypeFlags());
+ return registerType(typeName, deleter, creator, qMetaTypeDestructHelper<void>, qMetaTypeConstructHelper<void>, 0, TypeFlags(), 0);
}
/*! \internal
@@ -472,8 +446,9 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
Creator creator,
Destructor destructor,
Constructor constructor,
- int size, TypeFlags flags)
+ int size, TypeFlags flags, const QMetaObject *metaObject)
{
+ Q_UNUSED(metaObject);
QVector<QCustomTypeInfo> *ct = customTypes();
if (!ct || !typeName || !deleter || !creator || !destructor || !constructor)
return -1;
@@ -489,11 +464,11 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
int previousSize = 0;
int previousFlags = 0;
- if (!idx) {
+ if (idx == UnknownType) {
QWriteLocker locker(customTypesLock());
idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!idx) {
+ if (idx == UnknownType) {
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
inf.creator = creator;
@@ -559,12 +534,12 @@ int QMetaType::registerTypedef(const char* typeName, int aliasId)
int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!idx) {
+ if (idx == UnknownType) {
QWriteLocker locker(customTypesLock());
idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!idx) {
+ if (idx == UnknownType) {
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
inf.alias = aliasId;
@@ -593,17 +568,20 @@ int QMetaType::registerTypedef(const char* typeName, int aliasId)
*/
bool QMetaType::isRegistered(int type)
{
- if (type >= 0 && type < User) {
- // predefined type
+ // predefined type
+ if ((type >= FirstCoreType && type <= LastCoreType)
+ || (type >= FirstGuiType && type <= LastGuiType)
+ || (type >= FirstWidgetsType && type <= LastWidgetsType)) {
return true;
}
+
QReadLocker locker(customTypesLock());
const QVector<QCustomTypeInfo> * const ct = customTypes();
return ((type >= User) && (ct && ct->count() > type - User) && !ct->at(type - User).typeName.isEmpty());
}
/*!
- Returns a handle to the type called \a typeName, or 0 if there is
+ Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is
no such type.
\sa isRegistered(), typeName(), Type
@@ -612,17 +590,17 @@ int QMetaType::type(const char *typeName)
{
int length = qstrlen(typeName);
if (!length)
- return 0;
+ return UnknownType;
int type = qMetaTypeStaticType(typeName, length);
- if (!type) {
+ if (type == UnknownType) {
QReadLocker locker(customTypesLock());
type = qMetaTypeCustomType_unlocked(typeName, length);
#ifndef QT_NO_QOBJECT
- if (!type) {
+ if (type == UnknownType) {
const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
type = qMetaTypeStaticType(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!type) {
+ if (type == UnknownType) {
type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
normalizedTypeName.size());
}
@@ -653,11 +631,16 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
return false;
switch(type) {
+ case QMetaType::UnknownType:
case QMetaType::Void:
case QMetaType::VoidStar:
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
case QMetaType::QModelIndex:
+ case QMetaType::QJsonValue:
+ case QMetaType::QJsonObject:
+ case QMetaType::QJsonArray:
+ case QMetaType::QJsonDocument:
return false;
case QMetaType::Long:
stream << qlonglong(*static_cast<const long *>(data));
@@ -779,10 +762,15 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
break;
#endif
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGEXP
+ case QMetaType::QRegularExpression:
+ stream << *static_cast<const NS(QRegularExpression)*>(data);
+ break;
+#endif // QT_NO_REGEXP
case QMetaType::QEasingCurve:
stream << *static_cast<const NS(QEasingCurve)*>(data);
break;
-#endif
+#endif // QT_BOOTSTRAPPED
case QMetaType::QFont:
case QMetaType::QPixmap:
case QMetaType::QBrush:
@@ -858,11 +846,16 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
return false;
switch(type) {
+ case QMetaType::UnknownType:
case QMetaType::Void:
case QMetaType::VoidStar:
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
case QMetaType::QModelIndex:
+ case QMetaType::QJsonValue:
+ case QMetaType::QJsonObject:
+ case QMetaType::QJsonArray:
+ case QMetaType::QJsonDocument:
return false;
case QMetaType::Long: {
qlonglong l;
@@ -990,10 +983,15 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
break;
#endif
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGEXP
+ case QMetaType::QRegularExpression:
+ stream >> *static_cast< NS(QRegularExpression)*>(data);
+ break;
+#endif // QT_NO_REGEXP
case QMetaType::QEasingCurve:
stream >> *static_cast< NS(QEasingCurve)*>(data);
break;
-#endif
+#endif // QT_BOOTSTRAPPED
case QMetaType::QFont:
case QMetaType::QPixmap:
case QMetaType::QBrush:
@@ -1084,6 +1082,7 @@ public:
template<typename T>
void *delegate(const T *copy) { return CreatorImpl<T>::Create(m_type, copy); }
void *delegate(const void*) { return 0; }
+ void *delegate(const QMetaTypeSwitcher::UnknownType *) { return 0; }
void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy)
{
QMetaType::Creator creator;
@@ -1146,6 +1145,7 @@ public:
template<typename T>
void delegate(const T *where) { DestroyerImpl<T>::Destroy(m_type, const_cast<T*>(where)); }
void delegate(const void *) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); }
private:
@@ -1209,6 +1209,7 @@ public:
template<typename T>
void *delegate(const T *copy) { return ConstructorImpl<T>::Construct(m_type, m_where, copy); }
void *delegate(const void *) { return m_where; }
+ void *delegate(const QMetaTypeSwitcher::UnknownType*) { return m_where; }
void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); }
private:
@@ -1298,6 +1299,7 @@ public:
template<typename T>
void delegate(const T *where) { DestructorImpl<T>::Destruct(m_type, const_cast<T*>(where)); }
void delegate(const void *) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); }
private:
@@ -1367,6 +1369,7 @@ public:
template<typename T>
int delegate(const T*) { return SizeOfImpl<T>::Size(m_type); }
+ int delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; }
int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); }
private:
static int customTypeSizeOf(const int type)
@@ -1433,6 +1436,7 @@ public:
template<typename T>
quint32 delegate(const T*) { return FlagsImpl<T>::Flags(m_type); }
quint32 delegate(const void*) { return 0; }
+ quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; }
quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); }
private:
const int m_type;
@@ -1620,6 +1624,7 @@ public:
template<typename T>
void delegate(const T*) { TypeInfoImpl<T>(m_type, info); }
void delegate(const void*) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); }
private:
void customTypeInfo(const uint type)
@@ -1640,7 +1645,7 @@ QMetaType QMetaType::typeInfo(const int type)
{
TypeInfo typeInfo(type);
QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0);
- return typeInfo.info.creator || !type ? QMetaType(QMetaType::NoExtensionFlags
+ return typeInfo.info.creator || type == Void ? QMetaType(QMetaType::NoExtensionFlags
, static_cast<const QMetaTypeInterface *>(0) // typeInfo::info is a temporary variable, we can't return address of it.
, typeInfo.info.creator
, typeInfo.info.deleter
@@ -1650,27 +1655,25 @@ QMetaType QMetaType::typeInfo(const int type)
, typeInfo.info.destructor
, typeInfo.info.size
, typeInfo.info.flags
- , type)
- : QMetaType(-1);
+ , type
+ , 0)
+ : QMetaType(UnknownType);
}
QMetaType::QMetaType(const int typeId)
: m_typeId(typeId)
{
- if (Q_UNLIKELY(typeId == -1)) {
+ if (Q_UNLIKELY(typeId == UnknownType)) {
// Constructs invalid QMetaType instance.
m_extensionFlags = 0xffffffff;
Q_ASSERT(!isValid());
} else {
// TODO it can be better.
*this = QMetaType::typeInfo(typeId);
- if (m_typeId > 0 && !m_creator) {
+ if (m_typeId == UnknownType)
m_extensionFlags = 0xffffffff;
- m_typeId = -1;
- }
- if (m_typeId == QMetaType::Void) {
+ else if (m_typeId == QMetaType::Void)
m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx;
- }
}
}
@@ -1686,6 +1689,7 @@ QMetaType::QMetaType(const QMetaType &other)
, m_typeFlags(other.m_typeFlags)
, m_extensionFlags(other.m_extensionFlags)
, m_typeId(other.m_typeId)
+ , m_metaObject(other.m_metaObject)
{}
QMetaType &QMetaType::operator =(const QMetaType &other)
@@ -1701,6 +1705,7 @@ QMetaType &QMetaType::operator =(const QMetaType &other)
m_extensionFlags = other.m_extensionFlags;
m_extension = other.m_extension; // space reserved for future use
m_typeId = other.m_typeId;
+ m_metaObject = other.m_metaObject;
return *this;
}
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index bf1b126200..21f4bc7afe 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
// F is a tuple: (QMetaType::TypeName, QMetaType::TypeNameID, RealType)
#define QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\
- F(Void, 0, void) \
+ F(Void, 43, void) \
F(Bool, 1, bool) \
F(Int, 2, int) \
F(UInt, 3, uint) \
@@ -102,6 +102,11 @@ QT_BEGIN_NAMESPACE
F(QUuid, 30, QUuid) \
F(QVariant, 41, QVariant) \
F(QModelIndex, 42, QModelIndex) \
+ F(QRegularExpression, 44, QRegularExpression) \
+ F(QJsonValue, 45, QJsonValue) \
+ F(QJsonObject, 46, QJsonObject) \
+ F(QJsonArray, 47, QJsonArray) \
+ F(QJsonDocument, 48, QJsonDocument) \
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\
F(QObjectStar, 39, QObject*) \
@@ -179,6 +184,7 @@ QT_BEGIN_NAMESPACE
class QDataStream;
class QMetaTypeInterface;
+struct QMetaObject;
class Q_CORE_EXPORT QMetaType {
enum ExtensionFlag { NoExtensionFlags,
@@ -193,8 +199,8 @@ public:
// these are merged with QVariant
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
- FirstCoreType = Void,
- LastCoreType = QModelIndex,
+ FirstCoreType = Bool,
+ LastCoreType = QJsonDocument,
FirstGuiType = QFont,
LastGuiType = QPolygonF,
FirstWidgetsType = QIcon,
@@ -203,7 +209,8 @@ public:
QReal = sizeof(qreal) == sizeof(double) ? Double : Float,
- User = 256
+ UnknownType = 0,
+ User = 1024
};
enum TypeFlag {
@@ -236,7 +243,8 @@ public:
Destructor destructor,
Constructor constructor,
int size,
- QMetaType::TypeFlags flags);
+ QMetaType::TypeFlags flags,
+ const QMetaObject *metaObject);
static int registerTypedef(const char *typeName, int aliasId);
static int type(const char *typeName);
static const char *typeName(int type);
@@ -280,7 +288,8 @@ private:
Destructor destructor,
uint sizeOf,
uint theTypeFlags,
- int typeId);
+ int typeId,
+ const QMetaObject *metaObject);
QMetaType(const QMetaType &other);
QMetaType &operator =(const QMetaType &);
inline bool isExtended(const ExtensionFlag flag) const { return m_extensionFlags & flag; }
@@ -306,6 +315,7 @@ private:
uint m_typeFlags;
uint m_extensionFlags;
int m_typeId;
+ const QMetaObject *m_metaObject; // Placeholder for Qt 5.1 feature.
};
#undef QT_DEFINE_METATYPE_ID
@@ -366,33 +376,11 @@ void qMetaTypeLoadHelper(QDataStream &stream, void *t)
template <> inline void qMetaTypeLoadHelper<void>(QDataStream &, void *) {}
#endif // QT_NO_DATASTREAM
-template <typename T>
-struct QMetaTypeId
-{
- enum { Defined = 0 };
-};
-
-template <typename T>
-struct QMetaTypeId2
-{
- enum { Defined = QMetaTypeId<T>::Defined };
- static inline int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
-};
-
class QObject;
class QWidget;
-namespace QtPrivate {
- template <typename T, bool Defined = QMetaTypeId2<T>::Defined>
- struct QMetaTypeIdHelper {
- static inline int qt_metatype_id()
- { return QMetaTypeId2<T>::qt_metatype_id(); }
- };
- template <typename T> struct QMetaTypeIdHelper<T, false> {
- static inline int qt_metatype_id()
- { return -1; }
- };
-
+namespace QtPrivate
+{
template<typename T>
struct IsPointerToTypeDerivedFromQObject
{
@@ -430,6 +418,49 @@ namespace QtPrivate {
enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(yes_type) };
};
+ template<typename T, bool = IsPointerToTypeDerivedFromQObject<T>::Value>
+ struct MetaObjectForType
+ {
+ static inline const QMetaObject *value() { return 0; }
+ };
+ template<typename T>
+ struct MetaObjectForType<T*, /* isPointerToTypeDerivedFromQObject = */ true>
+ {
+ static inline const QMetaObject *value() { return &T::staticMetaObject; }
+ };
+}
+
+template <typename T, bool = QtPrivate::IsPointerToTypeDerivedFromQObject<T>::Value>
+struct QMetaTypeIdQObject
+{
+ enum {
+ Defined = 0
+ };
+};
+
+template <typename T>
+struct QMetaTypeId : public QMetaTypeIdQObject<T>
+{
+};
+
+template <typename T>
+struct QMetaTypeId2
+{
+ enum { Defined = QMetaTypeId<T>::Defined };
+ static inline int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
+};
+
+namespace QtPrivate {
+ template <typename T, bool Defined = QMetaTypeId2<T>::Defined>
+ struct QMetaTypeIdHelper {
+ static inline int qt_metatype_id()
+ { return QMetaTypeId2<T>::qt_metatype_id(); }
+ };
+ template <typename T> struct QMetaTypeIdHelper<T, false> {
+ static inline int qt_metatype_id()
+ { return -1; }
+ };
+
// Function pointers don't derive from QObject
template <class Result> struct IsPointerToTypeDerivedFromQObject<Result(*)()> { enum { Value = false }; };
template <class Result, class Arg0> struct IsPointerToTypeDerivedFromQObject<Result(*)(Arg0)> { enum { Value = false }; };
@@ -465,7 +496,8 @@ int qRegisterMetaType(const char *typeName
qMetaTypeDestructHelper<T>,
qMetaTypeConstructHelper<T>,
sizeof(T),
- flags);
+ flags,
+ QtPrivate::MetaObjectForType<T>::value());
}
#ifndef QT_NO_DATASTREAM
@@ -506,6 +538,23 @@ inline int qRegisterMetaType(
#endif
}
+template <typename T>
+struct QMetaTypeIdQObject<T*, /* isPointerToTypeDerivedFromQObject */ true>
+{
+ enum {
+ Defined = 1
+ };
+
+ static int qt_metatype_id()
+ {
+ static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
+ if (!metatype_id.load())
+ metatype_id.storeRelease(qRegisterMetaType<T*>(QByteArray(T::staticMetaObject.className() + QByteArrayLiteral("*")).constData(),
+ reinterpret_cast<T**>(quintptr(-1))));
+ return metatype_id.loadAcquire();
+ }
+};
+
#ifndef QT_NO_DATASTREAM
template <typename T>
inline int qRegisterMetaTypeStreamOperators()
@@ -630,7 +679,8 @@ inline QMetaType::QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeI
Destructor destructor,
uint size,
uint theTypeFlags,
- int typeId)
+ int typeId,
+ const QMetaObject *metaObject)
: m_creator(creator)
, m_deleter(deleter)
, m_saveOp(saveOp)
@@ -641,6 +691,7 @@ inline QMetaType::QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeI
, m_typeFlags(theTypeFlags)
, m_extensionFlags(extensionFlags)
, m_typeId(typeId)
+ , m_metaObject(metaObject)
{
if (Q_UNLIKELY(isExtended(CtorEx) || typeId == QMetaType::Void))
ctor(info);
@@ -654,7 +705,7 @@ inline QMetaType::~QMetaType()
inline bool QMetaType::isValid() const
{
- return m_typeId >= 0;
+ return m_typeId != UnknownType;
}
inline bool QMetaType::isRegistered() const
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index c73f8d0a20..2ab4a3896f 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -182,6 +182,62 @@ public:
/*flags*/ 0 \
}
+namespace QtMetaTypePrivate {
+template<typename T>
+struct TypeDefinition {
+ static const bool IsAvailable = true;
+};
+
+// Ignore these types, as incomplete
+#ifdef QT_BOOTSTRAPPED
+template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_GEOM_VARIANT
+template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_REGEXP
+template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
+#endif
+#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGEXP)
+template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_SHORTCUT
+template<> struct TypeDefinition<QKeySequence> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_CURSOR
+template<> struct TypeDefinition<QCursor> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_MATRIX4X4
+template<> struct TypeDefinition<QMatrix4x4> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_VECTOR2D
+template<> struct TypeDefinition<QVector2D> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_VECTOR3D
+template<> struct TypeDefinition<QVector3D> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_VECTOR4D
+template<> struct TypeDefinition<QVector4D> { static const bool IsAvailable = false; };
+#endif
+#ifdef QT_NO_QUATERNION
+template<> struct TypeDefinition<QQuaternion> { static const bool IsAvailable = false; };
+#endif
+} //namespace QtMetaTypePrivate
+
QT_END_NAMESPACE
#endif // QMETATYPE_P_H
diff --git a/src/corelib/kernel/qmetatypeswitcher_p.h b/src/corelib/kernel/qmetatypeswitcher_p.h
index e9c15ea214..ffd188c972 100644
--- a/src/corelib/kernel/qmetatypeswitcher_p.h
+++ b/src/corelib/kernel/qmetatypeswitcher_p.h
@@ -59,7 +59,8 @@ QT_BEGIN_NAMESPACE
class QMetaTypeSwitcher {
public:
- class NotBuiltinType;
+ class NotBuiltinType; // type is not a built-in type, but it may be a custom type or an unknown type
+ class UnknownType; // type not known to QMetaType system
template<class ReturnType, class DelegateObject>
static ReturnType switcher(DelegateObject &logic, int type, const void *data);
};
@@ -74,7 +75,11 @@ ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const vo
switch (QMetaType::Type(type)) {
QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_SWICHER_CASE)
+ case QMetaType::UnknownType:
+ return logic.delegate(static_cast<UnknownType const *>(data));
default:
+ if (type < QMetaType::User)
+ return logic.delegate(static_cast<UnknownType const *>(data));
return logic.delegate(static_cast<NotBuiltinType const *>(data));
}
}
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 984624b58f..fb3e4e396b 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -50,6 +50,7 @@
#include "qvariant.h"
#include "qmetaobject.h"
#include <qregexp.h>
+#include <qregularexpression.h>
#include <qthread.h>
#include <private/qthread_p.h>
#include <qdebug.h>
@@ -105,6 +106,30 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
return types;
}
+static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc)
+{
+ QScopedArrayPointer<int> types(new int [argc + 1]);
+ for (int i = 0; i < argc; ++i) {
+ const QArgumentType &type = argumentTypes[i];
+ if (type.type())
+ types[i] = type.type();
+ else if (type.name().endsWith('*'))
+ types[i] = QMetaType::VoidStar;
+ else
+ types[i] = QMetaType::type(type.name());
+
+ if (!types[i]) {
+ qWarning("QObject::connect: Cannot queue arguments of type '%s'\n"
+ "(Make sure '%s' is registered using qRegisterMetaType().)",
+ type.name().constData(), type.name().constData());
+ return 0;
+ }
+ }
+ types[argc] = 0;
+
+ return types.take();
+}
+
static QBasicMutex _q_ObjectMutexPool[131];
/** \internal
@@ -220,9 +245,8 @@ static void computeOffsets(const QMetaObject *metaobject, int *signalOffset, int
while (m) {
const QMetaObjectPrivate *d = QMetaObjectPrivate::get(m);
*methodOffset += d->methodCount;
- *signalOffset += (d->revision >= 4) ? d->signalCount : d->methodCount;
- /*Before Qt 4.6 (revision 4), the signalCount information was not generated by moc.
- so for compatibility we consider all the method as slot for old moc output*/
+ Q_ASSERT(d->revision >= 4);
+ *signalOffset += d->signalCount;
m = m->d.superdata;
}
}
@@ -1534,7 +1558,21 @@ void QObject::killTimer(int id)
Returns the children of this object that can be cast to type T
and that have names matching the regular expression \a regExp,
or an empty list if there are no such objects.
- The search is performed recursively.
+ The search is performed recursively, unless \a options specifies the
+ option FindDirectChildrenOnly.
+*/
+
+/*!
+ \fn QList<T> QObject::findChildren(const QRegularExpression &re, Qt::FindChildOptions options) const
+ \overload findChildren()
+
+ \since 5.0
+
+ Returns the children of this object that can be cast to type T
+ and that have names matching the regular expression \a re,
+ or an empty list if there are no such objects.
+ The search is performed recursively, unless \a options specifies the
+ option FindDirectChildrenOnly.
*/
/*!
@@ -1587,7 +1625,7 @@ void QObject::killTimer(int id)
/*!
\internal
*/
-void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re,
+void qt_qFindChildren_helper(const QObject *parent, const QString &name,
const QMetaObject &mo, QList<void*> *list, Qt::FindChildOptions options)
{
if (!parent || !list)
@@ -1597,19 +1635,60 @@ void qt_qFindChildren_helper(const QObject *parent, const QString &name, const Q
for (int i = 0; i < children.size(); ++i) {
obj = children.at(i);
if (mo.cast(obj)) {
- if (re) {
- if (re->indexIn(obj->objectName()) != -1)
- list->append(obj);
- } else {
- if (name.isNull() || obj->objectName() == name)
- list->append(obj);
- }
+ if (name.isNull() || obj->objectName() == name)
+ list->append(obj);
}
if (options & Qt::FindChildrenRecursively)
- qt_qFindChildren_helper(obj, name, re, mo, list, options);
+ qt_qFindChildren_helper(obj, name, mo, list, options);
}
}
+#ifndef QT_NO_REGEXP
+/*!
+ \internal
+*/
+void qt_qFindChildren_helper(const QObject *parent, const QRegExp &re,
+ const QMetaObject &mo, QList<void*> *list, Qt::FindChildOptions options)
+{
+ if (!parent || !list)
+ return;
+ const QObjectList &children = parent->children();
+ QObject *obj;
+ for (int i = 0; i < children.size(); ++i) {
+ obj = children.at(i);
+ if (mo.cast(obj) && re.indexIn(obj->objectName()) != -1)
+ list->append(obj);
+
+ if (options & Qt::FindChildrenRecursively)
+ qt_qFindChildren_helper(obj, re, mo, list, options);
+ }
+}
+#endif // QT_NO_REGEXP
+
+#ifndef QT_NO_REGEXP
+/*!
+ \internal
+*/
+void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re,
+ const QMetaObject &mo, QList<void*> *list, Qt::FindChildOptions options)
+{
+ if (!parent || !list)
+ return;
+ const QObjectList &children = parent->children();
+ QObject *obj;
+ for (int i = 0; i < children.size(); ++i) {
+ obj = children.at(i);
+ if (mo.cast(obj)) {
+ QRegularExpressionMatch m = re.match(obj->objectName());
+ if (m.hasMatch())
+ list->append(obj);
+ }
+ if (options & Qt::FindChildrenRecursively)
+ qt_qFindChildren_helper(obj, re, mo, list, options);
+ }
+}
+#endif // QT_NO_REGEXP
+
/*! \internal
*/
QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options)
@@ -2179,12 +2258,12 @@ static inline void check_and_warn_compat(const QMetaObject *sender, const QMetaM
if (signal.attributes() & QMetaMethod::Compatibility) {
if (!(method.attributes() & QMetaMethod::Compatibility))
qWarning("QObject::connect: Connecting from COMPAT signal (%s::%s)",
- sender->className(), signal.signature());
+ sender->className(), signal.methodSignature().constData());
} else if ((method.attributes() & QMetaMethod::Compatibility) &&
method.methodType() == QMetaMethod::Signal) {
qWarning("QObject::connect: Connecting from %s::%s to COMPAT slot (%s::%s)",
- sender->className(), signal.signature(),
- receiver->className(), method.signature());
+ sender->className(), signal.methodSignature().constData(),
+ receiver->className(), method.methodSignature().constData());
}
}
@@ -2258,16 +2337,6 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
const QObject *receiver, const char *method,
Qt::ConnectionType type)
{
-#ifndef QT_NO_DEBUG
- bool warnCompat = true;
-#endif
- if (type == Qt::AutoCompatConnection) {
- type = Qt::AutoConnection;
-#ifndef QT_NO_DEBUG
- warnCompat = false;
-#endif
- }
-
if (sender == 0 || receiver == 0 || signal == 0 || method == 0) {
qWarning("QObject::connect: Cannot connect %s::%s to %s::%s",
sender ? sender->metaObject()->className() : "(null)",
@@ -2283,20 +2352,21 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
const QMetaObject *smeta = sender->metaObject();
const char *signal_arg = signal;
++signal; //skip code
- int signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false);
+ QArgumentTypeArray signalTypes;
+ Q_ASSERT(QMetaObjectPrivate::get(smeta)->revision >= 7);
+ QByteArray signalName = QMetaObjectPrivate::decodeMethodSignature(signal, signalTypes);
+ int signal_index = QMetaObjectPrivate::indexOfSignalRelative(
+ &smeta, signalName, signalTypes.size(), signalTypes.constData());
if (signal_index < 0) {
// check for normalized signatures
tmp_signal_name = QMetaObject::normalizedSignature(signal - 1);
signal = tmp_signal_name.constData() + 1;
+ signalTypes.clear();
+ signalName = QMetaObjectPrivate::decodeMethodSignature(signal, signalTypes);
smeta = sender->metaObject();
- signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false);
- }
- if (signal_index < 0) {
- // re-use tmp_signal_name and signal from above
-
- smeta = sender->metaObject();
- signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, true);
+ signal_index = QMetaObjectPrivate::indexOfSignalRelative(
+ &smeta, signalName, signalTypes.size(), signalTypes.constData());
}
if (signal_index < 0) {
err_method_notfound(sender, signal_arg, "connect");
@@ -2317,34 +2387,38 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
const char *method_arg = method;
++method; // skip code
+ QByteArray methodName;
+ QArgumentTypeArray methodTypes;
const QMetaObject *rmeta = receiver->metaObject();
int method_index_relative = -1;
+ Q_ASSERT(QMetaObjectPrivate::get(rmeta)->revision >= 7);
switch (membcode) {
case QSLOT_CODE:
- method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(&rmeta, method, false);
+ method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(
+ &rmeta, methodName, methodTypes.size(), methodTypes.constData());
break;
case QSIGNAL_CODE:
- method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, false);
+ method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(
+ &rmeta, methodName, methodTypes.size(), methodTypes.constData());
break;
}
-
if (method_index_relative < 0) {
// check for normalized methods
tmp_method_name = QMetaObject::normalizedSignature(method);
method = tmp_method_name.constData();
+ methodTypes.clear();
+ methodName = QMetaObjectPrivate::decodeMethodSignature(method, methodTypes);
// rmeta may have been modified above
rmeta = receiver->metaObject();
switch (membcode) {
case QSLOT_CODE:
- method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(&rmeta, method, false);
- if (method_index_relative < 0)
- method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(&rmeta, method, true);
+ method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(
+ &rmeta, methodName, methodTypes.size(), methodTypes.constData());
break;
case QSIGNAL_CODE:
- method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, false);
- if (method_index_relative < 0)
- method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, true);
+ method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(
+ &rmeta, methodName, methodTypes.size(), methodTypes.constData());
break;
}
}
@@ -2355,7 +2429,8 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
return QMetaObject::Connection(0);
}
- if (!QMetaObject::checkConnectArgs(signal, method)) {
+ if (!QMetaObjectPrivate::checkConnectArgs(signalTypes.size(), signalTypes.constData(),
+ methodTypes.size(), methodTypes.constData())) {
qWarning("QObject::connect: Incompatible sender/receiver arguments"
"\n %s::%s --> %s::%s",
sender->metaObject()->className(), signal,
@@ -2365,15 +2440,14 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
int *types = 0;
if ((type == Qt::QueuedConnection)
- && !(types = queuedConnectionTypes(smeta->method(signal_absolute_index).parameterTypes())))
+ && !(types = queuedConnectionTypes(signalTypes.constData(), signalTypes.size()))) {
return QMetaObject::Connection(0);
+ }
#ifndef QT_NO_DEBUG
- if (warnCompat) {
- QMetaMethod smethod = smeta->method(signal_absolute_index);
- QMetaMethod rmethod = rmeta->method(method_index_relative + rmeta->methodOffset());
- check_and_warn_compat(smeta, smethod, rmeta, rmethod);
- }
+ QMetaMethod smethod = smeta->method(signal_absolute_index);
+ QMetaMethod rmethod = rmeta->method(method_index_relative + rmeta->methodOffset());
+ check_and_warn_compat(smeta, smethod, rmeta, rmethod);
#endif
QMetaObject::Connection handle = QMetaObject::Connection(QMetaObjectPrivate::connect(
sender, signal_index, receiver, method_index_relative, rmeta ,type, types));
@@ -2408,33 +2482,23 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho
const QObject *receiver, const QMetaMethod &method,
Qt::ConnectionType type)
{
-#ifndef QT_NO_DEBUG
- bool warnCompat = true;
-#endif
- if (type == Qt::AutoCompatConnection) {
- type = Qt::AutoConnection;
-#ifndef QT_NO_DEBUG
- warnCompat = false;
-#endif
- }
-
if (sender == 0
|| receiver == 0
|| signal.methodType() != QMetaMethod::Signal
|| method.methodType() == QMetaMethod::Constructor) {
qWarning("QObject::connect: Cannot connect %s::%s to %s::%s",
sender ? sender->metaObject()->className() : "(null)",
- signal.signature(),
+ signal.methodSignature().constData(),
receiver ? receiver->metaObject()->className() : "(null)",
- method.signature() );
+ method.methodSignature().constData() );
return QMetaObject::Connection(0);
}
- // Reconstructing SIGNAL() macro result for signal.signature() string
+ // Reconstructing SIGNAL() macro result for signal.methodSignature() string
QByteArray signalSignature;
- signalSignature.reserve(qstrlen(signal.signature())+1);
+ signalSignature.reserve(signal.methodSignature().size()+1);
signalSignature.append((char)(QSIGNAL_CODE + '0'));
- signalSignature.append(signal.signature());
+ signalSignature.append(signal.methodSignature());
int signal_index;
int method_index;
@@ -2448,20 +2512,20 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho
const QMetaObject *rmeta = receiver->metaObject();
if (signal_index == -1) {
qWarning("QObject::connect: Can't find signal %s on instance of class %s",
- signal.signature(), smeta->className());
+ signal.methodSignature().constData(), smeta->className());
return QMetaObject::Connection(0);
}
if (method_index == -1) {
qWarning("QObject::connect: Can't find method %s on instance of class %s",
- method.signature(), rmeta->className());
+ method.methodSignature().constData(), rmeta->className());
return QMetaObject::Connection(0);
}
- if (!QMetaObject::checkConnectArgs(signal.signature(), method.signature())) {
+ if (!QMetaObject::checkConnectArgs(signal.methodSignature().constData(), method.methodSignature().constData())) {
qWarning("QObject::connect: Incompatible sender/receiver arguments"
"\n %s::%s --> %s::%s",
- smeta->className(), signal.signature(),
- rmeta->className(), method.signature());
+ smeta->className(), signal.methodSignature().constData(),
+ rmeta->className(), method.methodSignature().constData());
return QMetaObject::Connection(0);
}
@@ -2471,8 +2535,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho
return QMetaObject::Connection(0);
#ifndef QT_NO_DEBUG
- if (warnCompat)
- check_and_warn_compat(smeta, signal, rmeta, method);
+ check_and_warn_compat(smeta, signal, rmeta, method);
#endif
QMetaObject::Connection handle = QMetaObject::Connection(QMetaObjectPrivate::connect(
sender, signal_index, receiver, method_index, 0, type, types));
@@ -2609,12 +2672,21 @@ bool QObject::disconnect(const QObject *sender, const char *signal,
*/
bool res = false;
const QMetaObject *smeta = sender->metaObject();
+ QByteArray signalName;
+ QArgumentTypeArray signalTypes;
+ Q_ASSERT(QMetaObjectPrivate::get(smeta)->revision >= 7);
+ if (signal)
+ signalName = QMetaObjectPrivate::decodeMethodSignature(signal, signalTypes);
+ QByteArray methodName;
+ QArgumentTypeArray methodTypes;
+ Q_ASSERT(!receiver || QMetaObjectPrivate::get(receiver->metaObject())->revision >= 7);
+ if (method)
+ methodName = QMetaObjectPrivate::decodeMethodSignature(method, methodTypes);
do {
int signal_index = -1;
if (signal) {
- signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false);
- if (signal_index < 0)
- signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, true);
+ signal_index = QMetaObjectPrivate::indexOfSignalRelative(
+ &smeta, signalName, signalTypes.size(), signalTypes.constData());
if (signal_index < 0)
break;
signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index);
@@ -2629,7 +2701,8 @@ bool QObject::disconnect(const QObject *sender, const char *signal,
} else {
const QMetaObject *rmeta = receiver->metaObject();
do {
- int method_index = rmeta->indexOfMethod(method);
+ int method_index = QMetaObjectPrivate::indexOfMethod(
+ rmeta, methodName, methodTypes.size(), methodTypes.constData());
if (method_index >= 0)
while (method_index < rmeta->methodOffset())
rmeta = rmeta->superClass();
@@ -2693,24 +2766,24 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
if(signal.methodType() != QMetaMethod::Signal) {
qWarning("QObject::%s: Attempt to %s non-signal %s::%s",
"disconnect","unbind",
- sender->metaObject()->className(), signal.signature());
+ sender->metaObject()->className(), signal.methodSignature().constData());
return false;
}
}
if (method.mobj) {
if(method.methodType() == QMetaMethod::Constructor) {
qWarning("QObject::disconect: cannot use constructor as argument %s::%s",
- receiver->metaObject()->className(), method.signature());
+ receiver->metaObject()->className(), method.methodSignature().constData());
return false;
}
}
- // Reconstructing SIGNAL() macro result for signal.signature() string
+ // Reconstructing SIGNAL() macro result for signal.methodSignature() string
QByteArray signalSignature;
if (signal.mobj) {
- signalSignature.reserve(qstrlen(signal.signature())+1);
+ signalSignature.reserve(signal.methodSignature().size()+1);
signalSignature.append((char)(QSIGNAL_CODE + '0'));
- signalSignature.append(signal.signature());
+ signalSignature.append(signal.methodSignature());
}
int signal_index;
@@ -2724,13 +2797,13 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
// is -1 then this signal is not a member of sender.
if (signal.mobj && signal_index == -1) {
qWarning("QObject::disconect: signal %s not found on class %s",
- signal.signature(), sender->metaObject()->className());
+ signal.methodSignature().constData(), sender->metaObject()->className());
return false;
}
// If this condition is true then method is not a member of receeiver.
if (receiver && method.mobj && method_index == -1) {
qWarning("QObject::disconect: method %s not found on class %s",
- method.signature(), receiver->metaObject()->className());
+ method.methodSignature().constData(), receiver->metaObject()->className());
return false;
}
@@ -2744,7 +2817,7 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
/*!
\threadsafe
- \fn bool QObject::disconnect(const char *signal, const QObject *receiver, const char *method)
+ \fn bool QObject::disconnect(const char *signal, const QObject *receiver, const char *method) const
\overload disconnect()
Disconnects \a signal from \a method of \a receiver.
@@ -2754,7 +2827,7 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
*/
/*!
- \fn bool QObject::disconnect(const QObject *receiver, const char *method)
+ \fn bool QObject::disconnect(const QObject *receiver, const char *method) const
\overload disconnect()
Disconnects all signals in this object from \a receiver's \a
@@ -2865,8 +2938,9 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender, i
QObject *r = const_cast<QObject *>(receiver);
int method_offset = rmeta ? rmeta->methodOffset() : 0;
+ Q_ASSERT(!rmeta || QMetaObjectPrivate::get(rmeta)->revision >= 6);
QObjectPrivate::StaticMetaCallFunction callFunction =
- (rmeta && QMetaObjectPrivate::get(rmeta)->revision >= 6 && rmeta->d.extradata)
+ (rmeta && rmeta->d.extradata)
? reinterpret_cast<const QMetaObjectExtraData *>(rmeta->d.extradata)->static_metacall : 0;
QOrderedMutexLocker locker(signalSlotLock(sender),
@@ -3045,7 +3119,8 @@ void QMetaObject::connectSlotsByName(QObject *o)
Q_ASSERT(mo);
const QObjectList list = o->findChildren<QObject *>(QString());
for (int i = 0; i < mo->methodCount(); ++i) {
- const char *slot = mo->method(i).signature();
+ QByteArray slotSignature = mo->method(i).methodSignature();
+ const char *slot = slotSignature.constData();
Q_ASSERT(slot);
if (slot[0] != 'o' || slot[1] != 'n' || slot[2] != '_')
continue;
@@ -3065,7 +3140,7 @@ void QMetaObject::connectSlotsByName(QObject *o)
if (method.methodType() != QMetaMethod::Signal)
continue;
- if (!qstrncmp(method.signature(), slot + len + 4, slotlen)) {
+ if (!qstrncmp(method.methodSignature().constData(), slot + len + 4, slotlen)) {
int signalOffset, methodOffset;
computeOffsets(method.enclosingMetaObject(), &signalOffset, &methodOffset);
sigIndex = k + - methodOffset + signalOffset;
@@ -3311,9 +3386,11 @@ int QObjectPrivate::signalIndex(const char *signalName) const
{
Q_Q(const QObject);
const QMetaObject *base = q->metaObject();
- int relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName, false);
- if (relative_index < 0)
- relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName, true);
+ Q_ASSERT(QMetaObjectPrivate::get(base)->revision >= 7);
+ QArgumentTypeArray types;
+ QByteArray name = QMetaObjectPrivate::decodeMethodSignature(signalName, types);
+ int relative_index = QMetaObjectPrivate::indexOfSignalRelative(
+ &base, name, types.size(), types.constData());
if (relative_index < 0)
return relative_index;
relative_index = QMetaObjectPrivate::originalClone(base, relative_index);
@@ -3536,7 +3613,7 @@ void QObject::dumpObjectInfo()
offset = methodOffset - signalOffset;
}
const QMetaMethod signal = metaObject()->method(signal_index + offset);
- qDebug(" signal: %s", signal.signature());
+ qDebug(" signal: %s", signal.methodSignature().constData());
// receivers
const QObjectPrivate::Connection *c =
@@ -3552,7 +3629,7 @@ void QObject::dumpObjectInfo()
qDebug(" --> %s::%s %s",
receiverMetaObject->className(),
c->receiver->objectName().isEmpty() ? "unnamed" : qPrintable(c->receiver->objectName()),
- method.signature());
+ method.methodSignature().constData());
c = c->nextConnectionList;
}
}
@@ -3569,7 +3646,7 @@ void QObject::dumpObjectInfo()
qDebug(" <-- %s::%s %s",
s->sender->metaObject()->className(),
s->sender->objectName().isEmpty() ? "unnamed" : qPrintable(s->sender->objectName()),
- slot.signature());
+ slot.methodSignature().constData());
}
} else {
qDebug(" <None>");
@@ -4044,9 +4121,9 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
locker.unlock();
// reconstruct the signature to call connectNotify
- const char *sig = senderMetaObject->d.stringdata + senderMetaObject->d.data[
- reinterpret_cast<const QMetaObjectPrivate*>(senderMetaObject->d.data)->methodData
- + 5 * (signal_index - signalOffset)];
+ const char *sig;
+ QByteArray tmp_sig = senderMetaObject->method(signal_index - signalOffset + methodOffset).methodSignature();
+ sig = tmp_sig.constData();
QVarLengthArray<char> signalSignature(qstrlen(sig) + 2);
signalSignature.data()[0] = char(QSIGNAL_CODE + '0');
strcpy(signalSignature.data() + 1 , sig);
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index 59339da894..11b1a19e0b 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -73,13 +73,20 @@ class QWidget;
#ifndef QT_NO_REGEXP
class QRegExp;
#endif
+#ifndef QT_NO_REGEXP
+class QRegularExpression;
+#endif
#ifndef QT_NO_USERDATA
class QObjectUserData;
#endif
typedef QList<QObject*> QObjectList;
-Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re,
+Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QString &name,
+ const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options);
+Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QRegExp &re,
+ const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options);
+Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re,
const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options);
Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options);
@@ -163,7 +170,7 @@ public:
QList<void *> *voidList;
} u;
u.typedList = &list;
- qt_qFindChildren_helper(this, aName, 0, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
+ qt_qFindChildren_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
return list;
}
@@ -177,7 +184,22 @@ public:
QList<void *> *voidList;
} u;
u.typedList = &list;
- qt_qFindChildren_helper(this, QString(), &re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
+ qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
+ return list;
+ }
+#endif
+
+#ifndef QT_NO_REGEXP
+ template<typename T>
+ inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
+ {
+ QList<T> list;
+ union {
+ QList<T> *typedList;
+ QList<void *> *voidList;
+ } u;
+ u.typedList = &list;
+ qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
return list;
}
#endif
@@ -272,9 +294,9 @@ public:
static bool disconnect(const QObject *sender, const QMetaMethod &signal,
const QObject *receiver, const QMetaMethod &member);
inline bool disconnect(const char *signal = 0,
- const QObject *receiver = 0, const char *member = 0)
+ const QObject *receiver = 0, const char *member = 0) const
{ return disconnect(this, signal, receiver, member); }
- inline bool disconnect(const QObject *receiver, const char *member = 0)
+ inline bool disconnect(const QObject *receiver, const char *member = 0) const
{ return disconnect(this, 0, receiver, member); }
static bool disconnect(const QMetaObject::Connection &);
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index d391fb94ce..9bcb8b9211 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -50,11 +50,12 @@ QT_BEGIN_NAMESPACE
class QByteArray;
+struct QByteArrayData;
class QString;
#ifndef Q_MOC_OUTPUT_REVISION
-#define Q_MOC_OUTPUT_REVISION 64
+#define Q_MOC_OUTPUT_REVISION 65
#endif
// The following macros are our "extensions" to C++
@@ -333,6 +334,8 @@ struct Q_CORE_EXPORT QMetaObject
QMetaProperty userProperty() const;
static bool checkConnectArgs(const char *signal, const char *method);
+ static bool checkConnectArgs(const QMetaMethod &signal,
+ const QMetaMethod &method);
static QByteArray normalizedSignature(const char *method);
static QByteArray normalizedType(const char *type);
@@ -446,7 +449,7 @@ struct Q_CORE_EXPORT QMetaObject
struct { // private data
const QMetaObject *superdata;
- const char *stringdata;
+ const QByteArrayData *stringdata;
const uint *data;
const void *extradata;
} d;
@@ -487,9 +490,6 @@ struct QMetaObjectExtraData
StaticMetacallFunction static_metacall;
};
-inline const char *QMetaObject::className() const
-{ return d.stringdata; }
-
inline const QMetaObject *QMetaObject::superClass() const
{ return d.superdata; }
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h
index 836c13e3fc..a3035ebc94 100644
--- a/src/corelib/kernel/qpointer.h
+++ b/src/corelib/kernel/qpointer.h
@@ -44,40 +44,60 @@
#include <QtCore/qsharedpointer.h>
+#ifndef QT_NO_QOBJECT
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-template <class T>
-class QPointer
+class QPointerBase
{
- QWeakPointer<T> wp;
+ QWeakPointer<QObject> wp;
-public:
- inline QPointer() : wp() { }
- inline QPointer(T *p) : wp(p) { }
- inline QPointer(const QPointer<T> &p) : wp(p.wp) { }
- inline ~QPointer() { }
+protected:
+ inline QPointerBase() : wp() { }
+ inline QPointerBase(QObject *p) : wp(p) { }
+ // compiler-generated copy/move ctor/assignment operators are fine! (even though public)
+ inline ~QPointerBase() { }
- inline QPointer<T> &operator=(const QPointer<T> &p)
- { wp = p.wp; return *this; }
- inline QPointer<T> &operator=(T* p)
- { wp = p; return *this; }
+ inline QObject* data() const
+ { return wp.data(); }
+
+ inline void assign(QObject *p)
+ { wp = p; }
inline bool isNull() const
{ return wp.isNull(); }
+};
+
+template <class T>
+class QPointer : private QPointerBase
+{
+public:
+ inline QPointer() { }
+ inline QPointer(T *p) : QPointerBase(p) { }
+ // compiler-generated copy/move ctor/assignment operators are fine!
+ inline ~QPointer() { }
+
+ inline QPointer<T> &operator=(T* p)
+ { QPointerBase::assign(p); return *this; }
+ inline T* data() const
+ { return static_cast<T*>(QPointerBase::data()); }
inline T* operator->() const
- { return wp.data(); }
+ { return data(); }
inline T& operator*() const
- { return *wp.data(); }
+ { return *data(); }
inline operator T*() const
- { return wp.data(); }
- inline T* data() const
- { return wp.data(); }
+ { return data(); }
+#ifdef qdoc
+ inline bool isNull() const;
+#else
+ using QPointerBase::isNull;
+#endif
};
-
+template <class T> Q_DECLARE_TYPEINFO_BODY(QPointer<T>, Q_MOVABLE_TYPE);
#if (!defined(Q_CC_SUN) || (__SUNPRO_CC >= 0x580)) // ambiguity between const T * and T *
@@ -163,4 +183,6 @@ QT_END_NAMESPACE
QT_END_HEADER
+#endif // QT_NO_QOBJECT
+
#endif // QPOINTER_H
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index f434df177c..2131188439 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -387,6 +387,25 @@ void QTimer::setInterval(int msec)
}
/*!
+ \property QTimer::remainingTime
+ \brief the remaining time in milliseconds
+
+ Returns the timer's remaining value in milliseconds left until the timeout.
+ If the timer is inactive, the returned value will be -1. If the timer is
+ overdue, the returned value will be 0.
+
+ \sa interval
+*/
+int QTimer::remainingTime() const
+{
+ if (id != INV_TIMER) {
+ return QAbstractEventDispatcher::instance()->remainingTime(id);
+ }
+
+ return -1;
+}
+
+/*!
\property QTimer::timerType
\brief controls the accuracy of the timer
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index eff2a7bfe1..fa68676f27 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -57,6 +57,7 @@ class Q_CORE_EXPORT QTimer : public QObject
Q_OBJECT
Q_PROPERTY(bool singleShot READ isSingleShot WRITE setSingleShot)
Q_PROPERTY(int interval READ interval WRITE setInterval)
+ Q_PROPERTY(int remainingTime READ remainingTime)
Q_PROPERTY(Qt::TimerType timerType READ timerType WRITE setTimerType)
Q_PROPERTY(bool active READ isActive)
public:
@@ -69,6 +70,8 @@ public:
void setInterval(int msec);
int interval() const { return inter; }
+ int remainingTime() const;
+
void setTimerType(Qt::TimerType atype) { this->type = atype; }
Qt::TimerType timerType() const { return Qt::TimerType(type); }
diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp
index 32e24edcf3..709338afda 100644
--- a/src/corelib/kernel/qtimerinfo_unix.cpp
+++ b/src/corelib/kernel/qtimerinfo_unix.cpp
@@ -412,6 +412,37 @@ bool QTimerInfoList::timerWait(timeval &tm)
return true;
}
+/*
+ Returns the timer's remaining time in milliseconds with the given timerId, or
+ null if there is nothing left. If the timer id is not found in the list, the
+ returned value will be -1. If the timer is overdue, the returned value will be 0.
+*/
+int QTimerInfoList::timerRemainingTime(int timerId)
+{
+ timeval currentTime = updateCurrentTime();
+ repairTimersIfNeeded();
+ timeval tm = {0, 0};
+
+ for (int i = 0; i < count(); ++i) {
+ register QTimerInfo *t = at(i);
+ if (t->id == timerId) {
+ if (currentTime < t->timeout) {
+ // time to wait
+ tm = roundToMillisecond(t->timeout - currentTime);
+ return tm.tv_sec*1000 + tm.tv_usec/1000;
+ } else {
+ return 0;
+ }
+ }
+ }
+
+#ifndef QT_NO_DEBUG
+ qWarning("QTimerInfoList::timerRemainingTime: timer id %i not found", timerId);
+#endif
+
+ return -1;
+}
+
void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
{
QTimerInfo *t = new QTimerInfo;
diff --git a/src/corelib/kernel/qtimerinfo_unix_p.h b/src/corelib/kernel/qtimerinfo_unix_p.h
index 4bf6b91ea6..cd431f9a4f 100644
--- a/src/corelib/kernel/qtimerinfo_unix_p.h
+++ b/src/corelib/kernel/qtimerinfo_unix_p.h
@@ -104,6 +104,8 @@ public:
bool timerWait(timeval &);
void timerInsert(QTimerInfo *);
+ int timerRemainingTime(int timerId);
+
void registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object);
bool unregisterTimer(int timerId);
bool unregisterTimers(QObject *object);
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index dad3318870..892883bacd 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -57,6 +57,7 @@
#include "qhash.h"
#include "qtranslator_p.h"
#include "qlocale.h"
+#include "qendian.h"
#if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY)
#define QT_USE_MMAP
@@ -101,36 +102,112 @@ static bool match(const uchar* found, const char* target, uint len)
return (memcmp(found, target, len) == 0 && target[len] == '\0');
}
-static uint elfHash(const char *name)
+static void elfHash_continue(const char *name, uint &h)
{
const uchar *k;
- uint h = 0;
uint g;
- if (name) {
- k = (const uchar *) name;
- while (*k) {
- h = (h << 4) + *k++;
- if ((g = (h & 0xf0000000)) != 0)
- h ^= g >> 24;
- h &= ~g;
- }
+ k = (const uchar *) name;
+ while (*k) {
+ h = (h << 4) + *k++;
+ if ((g = (h & 0xf0000000)) != 0)
+ h ^= g >> 24;
+ h &= ~g;
}
+}
+
+static void elfHash_finish(uint &h)
+{
if (!h)
h = 1;
- return h;
}
-static int numerusHelper(int n, const uchar *rules, int rulesSize)
+static uint elfHash(const char *name)
{
-#define CHECK_RANGE \
- do { \
- if (i >= rulesSize) \
- return -1; \
- } while (0)
+ uint hash = 0;
+ elfHash_continue(name, hash);
+ elfHash_finish(hash);
+ return hash;
+}
+
+/*
+ \internal
+
+ Determines whether \a rules are valid "numerus rules". Test input with this
+ function before calling numerusHelper, below.
+ */
+static bool isValidNumerusRules(const uchar *rules, uint rulesSize)
+{
+ // Disabled computation of maximum numerus return value
+ // quint32 numerus = 0;
+
+ if (rulesSize == 0)
+ return true;
+
+ quint32 offset = 0;
+ do {
+ uchar opcode = rules[offset];
+ uchar op = opcode & Q_OP_MASK;
+
+ if (opcode & 0x80)
+ return false; // Bad op
+
+ if (++offset == rulesSize)
+ return false; // Missing operand
+
+ // right operand
+ ++offset;
+
+ switch (op)
+ {
+ case Q_EQ:
+ case Q_LT:
+ case Q_LEQ:
+ break;
- int result = 0;
- int i = 0;
+ case Q_BETWEEN:
+ if (offset != rulesSize) {
+ // third operand
+ ++offset;
+ break;
+ }
+ return false; // Missing operand
+
+ default:
+ return false; // Bad op (0)
+ }
+
+ // ++numerus;
+ if (offset == rulesSize)
+ return true;
+
+ } while (((rules[offset] == Q_AND)
+ || (rules[offset] == Q_OR)
+ || (rules[offset] == Q_NEWRULE))
+ && ++offset != rulesSize);
+
+ // Bad op
+ return false;
+}
+
+/*
+ \internal
+
+ This function does no validation of input and assumes it is well-behaved,
+ these assumptions can be checked with isValidNumerusRules, above.
+
+ Determines which translation to use based on the value of \a n. The return
+ value is an index identifying the translation to be used.
+
+ \a rules is a character array of size \a rulesSize containing bytecode that
+ operates on the value of \a n and ultimately determines the result.
+
+ This function has O(1) space and O(rulesSize) time complexity.
+ */
+static uint numerusHelper(int n, const uchar *rules, uint rulesSize)
+{
+ uint result = 0;
+ uint i = 0;
if (rulesSize == 0)
return 0;
@@ -143,8 +220,6 @@ static int numerusHelper(int n, const uchar *rules, int rulesSize)
for (;;) {
bool truthValue = true;
-
- CHECK_RANGE;
int opcode = rules[i++];
int leftOperand = n;
@@ -158,13 +233,9 @@ static int numerusHelper(int n, const uchar *rules, int rulesSize)
}
int op = opcode & Q_OP_MASK;
-
- CHECK_RANGE;
int rightOperand = rules[i++];
switch (op) {
- default:
- return -1;
case Q_EQ:
truthValue = (leftOperand == rightOperand);
break;
@@ -174,9 +245,8 @@ static int numerusHelper(int n, const uchar *rules, int rulesSize)
case Q_LEQ:
truthValue = (leftOperand <= rightOperand);
break;
- case Q_BETWEEN:
+ case Q_BETWEEN:
int bottom = rightOperand;
- CHECK_RANGE;
int top = rules[i++];
truthValue = (leftOperand >= bottom && leftOperand <= top);
}
@@ -206,10 +276,10 @@ static int numerusHelper(int n, const uchar *rules, int rulesSize)
if (i == rulesSize)
return result;
- if (rules[i++] != Q_NEWRULE)
- break;
+ i++; // Q_NEWRULE
}
- return -1;
+
+ Q_ASSERT(false);
}
class QTranslatorPrivate : public QObjectPrivate
@@ -218,17 +288,22 @@ class QTranslatorPrivate : public QObjectPrivate
public:
enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88 };
- QTranslatorPrivate()
- : used_mmap(0), unmapPointer(0), unmapLength(0),
+ QTranslatorPrivate() :
+#if defined(QT_USE_MMAP)
+ used_mmap(0),
+#endif
+ unmapPointer(0), unmapLength(0),
messageArray(0), offsetArray(0), contextArray(0), numerusRulesArray(0),
messageLength(0), offsetLength(0), contextLength(0), numerusRulesLength(0) {}
- // for mmap'ed files, this is what needs to be unmapped.
+#if defined(QT_USE_MMAP)
bool used_mmap : 1;
- char *unmapPointer;
- unsigned int unmapLength;
+#endif
+ char *unmapPointer; // owned memory (mmap or new)
+ quint32 unmapLength;
- // for squeezed but non-file data, this is what needs to be deleted
+ // Pointers and offsets into unmapPointer[unmapLength] array, or user
+ // provided data array
const uchar *messageArray;
const uchar *offsetArray;
const uchar *contextArray;
@@ -439,6 +514,23 @@ bool QTranslatorPrivate::do_load(const QString &realname)
QTranslatorPrivate *d = this;
bool ok = false;
+ QFile file(realname);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
+ return false;
+
+ qint64 fileSize = file.size();
+ if (fileSize <= MagicLength || quint32(-1) <= fileSize)
+ return false;
+
+ {
+ char magicBuffer[MagicLength];
+ if (MagicLength != file.read(magicBuffer, MagicLength)
+ || memcmp(magicBuffer, magic, MagicLength))
+ return false;
+ }
+
+ d->unmapLength = quint32(fileSize);
+
#ifdef QT_USE_MMAP
#ifndef MAP_FILE
@@ -448,54 +540,48 @@ bool QTranslatorPrivate::do_load(const QString &realname)
#define MAP_FAILED -1
#endif
- int fd = -1;
- if (!realname.startsWith(QLatin1Char(':')))
- fd = QT_OPEN(QFile::encodeName(realname), O_RDONLY,
-#if defined(Q_OS_WIN)
- _S_IREAD | _S_IWRITE
-#else
- 0666
-#endif
- );
+ int fd = file.handle();
if (fd >= 0) {
- QT_STATBUF st;
- if (!QT_FSTAT(fd, &st)) {
- char *ptr;
- ptr = reinterpret_cast<char *>(
- mmap(0, st.st_size, // any address, whole file
- PROT_READ, // read-only memory
- MAP_FILE | MAP_PRIVATE, // swap-backed map from file
- fd, 0)); // from offset 0 of fd
- if (ptr && ptr != reinterpret_cast<char *>(MAP_FAILED)) {
- d->used_mmap = true;
- d->unmapPointer = ptr;
- d->unmapLength = st.st_size;
- ok = true;
- }
+ char *ptr;
+ ptr = reinterpret_cast<char *>(
+ mmap(0, d->unmapLength, // any address, whole file
+ PROT_READ, // read-only memory
+ MAP_FILE | MAP_PRIVATE, // swap-backed map from file
+ fd, 0)); // from offset 0 of fd
+ if (ptr && ptr != reinterpret_cast<char *>(MAP_FAILED)) {
+ file.close();
+ d->used_mmap = true;
+ d->unmapPointer = ptr;
+ ok = true;
}
- ::close(fd);
}
#endif // QT_USE_MMAP
if (!ok) {
- QFile file(realname);
- d->unmapLength = file.size();
- if (!d->unmapLength)
- return false;
d->unmapPointer = new char[d->unmapLength];
-
- if (file.open(QIODevice::ReadOnly))
- ok = (d->unmapLength == (uint)file.read(d->unmapPointer, d->unmapLength));
-
- if (!ok) {
- delete [] d->unmapPointer;
- d->unmapPointer = 0;
- d->unmapLength = 0;
- return false;
+ if (d->unmapPointer) {
+ file.seek(0);
+ qint64 readResult = file.read(d->unmapPointer, d->unmapLength);
+ if (readResult == qint64(unmapLength))
+ ok = true;
}
}
- return d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength);
+ if (ok && d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength))
+ return true;
+
+#if defined(QT_USE_MMAP)
+ if (used_mmap) {
+ used_mmap = false;
+ munmap(unmapPointer, unmapLength);
+ } else
+#endif
+ delete [] unmapPointer;
+
+ d->unmapPointer = 0;
+ d->unmapLength = 0;
+
+ return false;
}
static QString find_translation(const QLocale & locale,
@@ -654,32 +740,30 @@ bool QTranslator::load(const uchar *data, int len)
{
Q_D(QTranslator);
d->clear();
+
+ if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
+ return false;
+
return d->do_load(data, len);
}
static quint8 read8(const uchar *data)
{
- return *data;
+ return qFromBigEndian<quint8>(data);
}
static quint16 read16(const uchar *data)
{
- return (data[0] << 8) | (data[1]);
+ return qFromBigEndian<quint16>(data);
}
static quint32 read32(const uchar *data)
{
- return (data[0] << 24)
- | (data[1] << 16)
- | (data[2] << 8)
- | (data[3]);
+ return qFromBigEndian<quint32>(data);
}
bool QTranslatorPrivate::do_load(const uchar *data, int len)
{
- if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
- return false;
-
bool ok = true;
const uchar *end = data + len;
@@ -691,7 +775,7 @@ bool QTranslatorPrivate::do_load(const uchar *data, int len)
data += 4;
if (!tag || !blockLen)
break;
- if (data + blockLen > end) {
+ if (end - data < blockLen) {
ok = false;
break;
}
@@ -713,15 +797,30 @@ bool QTranslatorPrivate::do_load(const uchar *data, int len)
data += blockLen;
}
+ if (!offsetArray || !messageArray)
+ ok = false;
+ if (!isValidNumerusRules(numerusRulesArray, numerusRulesLength))
+ ok = false;
+
+ if (!ok) {
+ messageArray = 0;
+ contextArray = 0;
+ offsetArray = 0;
+ numerusRulesArray = 0;
+ messageLength = 0;
+ contextLength = 0;
+ offsetLength = 0;
+ numerusRulesLength = 0;
+ }
+
return ok;
}
static QString getMessage(const uchar *m, const uchar *end, const char *context,
- const char *sourceText, const char *comment, int numerus)
+ const char *sourceText, const char *comment, uint numerus)
{
const uchar *tn = 0;
uint tn_length = 0;
- int currentNumerus = -1;
for (;;) {
uchar tag = 0;
@@ -735,7 +834,7 @@ static QString getMessage(const uchar *m, const uchar *end, const char *context,
if (len % 1)
return QString();
m += 4;
- if (++currentNumerus == numerus) {
+ if (!numerus--) {
tn_length = len;
tn = m;
}
@@ -825,12 +924,15 @@ QString QTranslatorPrivate::do_translate(const char *context, const char *source
if (!numItems)
return QString();
- int numerus = 0;
+ uint numerus = 0;
if (n >= 0)
numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength);
for (;;) {
- quint32 h = elfHash(QByteArray(QByteArray(sourceText) + comment).constData());
+ quint32 h = 0;
+ elfHash_continue(sourceText, h);
+ elfHash_continue(comment, h);
+ elfHash_finish(h);
const uchar *start = offsetArray;
const uchar *end = start + ((numItems-1) << 3);
@@ -883,9 +985,10 @@ void QTranslatorPrivate::clear()
Q_Q(QTranslator);
if (unmapPointer && unmapLength) {
#if defined(QT_USE_MMAP)
- if (used_mmap)
+ if (used_mmap) {
+ used_mmap = false;
munmap(unmapPointer, unmapLength);
- else
+ } else
#endif
delete [] unmapPointer;
}
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index d723355204..82e0435d0a 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -48,6 +48,7 @@
#include "qdatetime.h"
#include "qeasingcurve.h"
#include "qlist.h"
+#include "qregularexpression.h"
#include "qstring.h"
#include "qstringlist.h"
#include "qurl.h"
@@ -55,6 +56,10 @@
#include "quuid.h"
#ifndef QT_BOOTSTRAPPED
#include "qabstractitemmodel.h"
+#include "qjsonvalue.h"
+#include "qjsonobject.h"
+#include "qjsonarray.h"
+#include "qjsondocument.h"
#endif
#include "private/qvariant_p.h"
#include "qmetatype_p.h"
@@ -91,40 +96,17 @@ public:
{
Handlers[name] = handler;
}
-
- inline void unregisterHandler(const QModulesPrivate::Names name);
};
} // namespace
namespace {
-template<typename T>
-struct TypeDefinition {
- static const bool IsAvailable = true;
-};
-
-// Ignore these types, as incomplete
-#ifdef QT_BOOTSTRAPPED
-template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
-#endif
-#ifdef QT_NO_GEOM_VARIANT
-template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
-template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
-#endif
-
struct CoreTypesFilter {
template<typename T>
struct Acceptor {
- static const bool IsAccepted = QTypeModuleInfo<T>::IsCore && TypeDefinition<T>::IsAvailable;
+ static const bool IsAccepted = QTypeModuleInfo<T>::IsCore && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable;
};
};
-} // annonymous used to hide TypeDefinition
+} // annonymous
namespace { // annonymous used to hide QVariant handlers
@@ -289,6 +271,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
ok = &dummy;
switch (uint(t)) {
+#ifndef QT_BOOTSTRAPPED
case QVariant::Url:
switch (d->type) {
case QVariant::String:
@@ -298,6 +281,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
return false;
}
break;
+#endif
case QVariant::String: {
QString *str = static_cast<QString *>(result);
switch (d->type) {
@@ -347,9 +331,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
if (v_cast<QStringList>(d)->count() == 1)
*str = v_cast<QStringList>(d)->at(0);
break;
+#ifndef QT_BOOTSTRAPPED
case QVariant::Url:
*str = v_cast<QUrl>(d)->toString();
break;
+#endif
case QVariant::Uuid:
*str = v_cast<QUuid>(d)->toString();
break;
@@ -848,7 +834,13 @@ static bool customConvert(const QVariant::Private *, int, void *, bool *ok)
}
#if !defined(QT_NO_DEBUG_STREAM)
-static void customStreamDebug(QDebug, const QVariant &) {}
+static void customStreamDebug(QDebug dbg, const QVariant &variant) {
+#ifndef QT_BOOTSTRAPPED
+ QMetaType::TypeFlags flags = QMetaType::typeFlags(variant.userType());
+ if (flags & QMetaType::PointerToQObject)
+ dbg.nospace() << variant.value<QObject*>();
+#endif
+}
#endif
const QVariant::Handler qt_custom_variant_handler = {
@@ -882,21 +874,11 @@ Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler()
return &qt_kernel_variant_handler;
}
-inline void HandlersManager::unregisterHandler(const QModulesPrivate::Names name)
-{
- Handlers[name] = &qt_dummy_variant_handler;
-}
-
Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names */name, const QVariant::Handler *handler)
{
handlerManager.registerHandler(static_cast<QModulesPrivate::Names>(name), handler);
}
-Q_CORE_EXPORT void QVariantPrivate::unregisterHandler(const int /* Modules::Names */ name)
-{
- handlerManager.unregisterHandler(static_cast<QModulesPrivate::Names>(name));
-}
-
/*!
\class QVariant
\brief The QVariant class acts like a union for the most common Qt data types.
@@ -1028,6 +1010,7 @@ Q_CORE_EXPORT void QVariantPrivate::unregisterHandler(const int /* Modules::Name
\value Rect a QRect
\value RectF a QRectF
\value RegExp a QRegExp
+ \value RegularExpression a QRegularExpression
\value Region a QRegion
\value Size a QSize
\value SizeF a QSizeF
@@ -1358,6 +1341,14 @@ QVariant::QVariant(const char *val)
Constructs a new variant with the regexp value \a regExp.
*/
+/*!
+ \fn QVariant::QVariant(const QRegularExpression &re)
+
+ \since 5.0
+
+ Constructs a new variant with the regular expression value \a re.
+*/
+
/*! \since 4.2
\fn QVariant::QVariant(Qt::GlobalColor color)
@@ -1442,11 +1433,16 @@ QVariant::QVariant(const QRect &r) { d.is_null = false; d.type = Rect; v_constru
QVariant::QVariant(const QSize &s) { d.is_null = false; d.type = Size; v_construct<QSize>(&d, s); }
QVariant::QVariant(const QSizeF &s) { d.is_null = false; d.type = SizeF; v_construct<QSizeF>(&d, s); }
#endif
+#ifndef QT_BOOTSTRAPPED
QVariant::QVariant(const QUrl &u) { d.is_null = false; d.type = Url; v_construct<QUrl>(&d, u); }
+#endif
QVariant::QVariant(const QLocale &l) { d.is_null = false; d.type = Locale; v_construct<QLocale>(&d, l); }
#ifndef QT_NO_REGEXP
QVariant::QVariant(const QRegExp &regExp) { d.is_null = false; d.type = RegExp; v_construct<QRegExp>(&d, regExp); }
-#endif
+#ifndef QT_BOOTSTRAPPED
+QVariant::QVariant(const QRegularExpression &re) { d.is_null = false; d.type = QMetaType::QRegularExpression; v_construct<QRegularExpression>(&d, re); }
+#endif // QT_BOOTSTRAPPED
+#endif // QT_NO_REGEXP
QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); }
/*!
@@ -1696,7 +1692,7 @@ void QVariant::load(QDataStream &s)
QByteArray name;
s >> name;
typeId = QMetaType::type(name.constData());
- if (!typeId) {
+ if (typeId == QMetaType::UnknownType) {
s.setStatus(QDataStream::ReadCorruptData);
return;
}
@@ -2083,6 +2079,7 @@ QPointF QVariant::toPointF() const
#endif // QT_NO_GEOM_VARIANT
+#ifndef QT_BOOTSTRAPPED
/*!
\fn QUrl QVariant::toUrl() const
@@ -2095,6 +2092,7 @@ QUrl QVariant::toUrl() const
{
return qVariantToHelper<QUrl>(d, handlerManager);
}
+#endif
/*!
\fn QLocale QVariant::toLocale() const
@@ -2126,6 +2124,24 @@ QRegExp QVariant::toRegExp() const
#endif
/*!
+ \fn QRegularExpression QVariant::toRegularExpression() const
+ \since 5.0
+
+ Returns the variant as a QRegularExpression if the variant has type() \l
+ QRegularExpression; otherwise returns an empty QRegularExpression.
+
+ \sa canConvert(), convert()
+*/
+#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGEXP
+QRegularExpression QVariant::toRegularExpression() const
+{
+ return qVariantToHelper<QRegularExpression>(d, handlerManager);
+}
+#endif
+#endif
+
+/*!
\fn QChar QVariant::toChar() const
Returns the variant as a QChar if the variant has type() \l Char,
@@ -2493,8 +2509,7 @@ bool QVariant::canConvert(int targetTypeId) const
if (targetTypeId == String && currentType == StringList)
return v_cast<QStringList>(&d)->count() == 1;
- else
- return qCanConvertMatrix[targetTypeId] & (1 << currentType);
+ return qCanConvertMatrix[targetTypeId] & (1 << currentType);
}
/*!
@@ -2645,15 +2660,24 @@ bool QVariant::isNull() const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QVariant &v)
{
- dbg.nospace() << "QVariant(" << QMetaType::typeName(v.userType()) << ", ";
- handlerManager[v.d.type]->debugStream(dbg, v);
+ const uint typeId = v.d.type;
+ dbg.nospace() << "QVariant(";
+ if (typeId != QMetaType::UnknownType) {
+ dbg.nospace() << QMetaType::typeName(typeId) << ", ";
+ handlerManager[typeId]->debugStream(dbg, v);
+ } else {
+ dbg.nospace() << "Invalid";
+ }
dbg.nospace() << ')';
return dbg.space();
}
QDebug operator<<(QDebug dbg, const QVariant::Type p)
{
- dbg.nospace() << "QVariant::" << QMetaType::typeName(p);
+ dbg.nospace() << "QVariant::"
+ << (int(p) != int(QMetaType::UnknownType)
+ ? QMetaType::typeName(p)
+ : "Invalid");
return dbg.space();
}
#endif
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 5da482d5cd..fb0e059f45 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -76,7 +76,8 @@ class QRect;
class QRectF;
#ifndef QT_NO_REGEXP
class QRegExp;
-#endif
+class QRegularExpression;
+#endif // QT_NO_REGEXP
class QTextFormat;
class QTextLength;
class QUrl;
@@ -126,7 +127,7 @@ class Q_CORE_EXPORT QVariant
{
public:
enum Type {
- Invalid = QMetaType::Void,
+ Invalid = QMetaType::UnknownType,
Bool = QMetaType::Bool,
Int = QMetaType::Int,
UInt = QMetaType::UInt,
@@ -154,6 +155,7 @@ class Q_CORE_EXPORT QVariant
Point = QMetaType::QPoint,
PointF = QMetaType::QPointF,
RegExp = QMetaType::QRegExp,
+ RegularExpression = QMetaType::QRegularExpression,
Hash = QMetaType::QVariantHash,
EasingCurve = QMetaType::QEasingCurve,
Uuid = QMetaType::QUuid,
@@ -235,12 +237,15 @@ class Q_CORE_EXPORT QVariant
QVariant(const QRect &rect);
QVariant(const QRectF &rect);
#endif
- QVariant(const QUrl &url);
QVariant(const QLocale &locale);
#ifndef QT_NO_REGEXP
QVariant(const QRegExp &regExp);
-#endif
+#ifndef QT_BOOTSRAPPED
+ QVariant(const QRegularExpression &re);
+#endif // QT_BOOTSTRAPPED
+#endif // QT_NO_REGEXP
#ifndef QT_BOOTSTRAPPED
+ QVariant(const QUrl &url);
QVariant(const QEasingCurve &easing);
#endif
QVariant(Qt::GlobalColor color);
@@ -298,12 +303,15 @@ class Q_CORE_EXPORT QVariant
QLineF toLineF() const;
QRectF toRectF() const;
#endif
- QUrl toUrl() const;
QLocale toLocale() const;
#ifndef QT_NO_REGEXP
QRegExp toRegExp() const;
-#endif
#ifndef QT_BOOTSTRAPPED
+ QRegularExpression toRegularExpression() const;
+#endif // QT_BOOTSTRAPPED
+#endif // QT_NO_REGEXP
+#ifndef QT_BOOTSTRAPPED
+ QUrl toUrl() const;
QEasingCurve toEasingCurve() const;
#endif
diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h
index 36eb31110b..6b778f3fb2 100644
--- a/src/corelib/kernel/qvariant_p.h
+++ b/src/corelib/kernel/qvariant_p.h
@@ -172,7 +172,12 @@ class QVariantComparator {
};
template<typename T>
struct FilteredComparator<T, /* IsAcceptedType = */ false> {
- static bool compare(const QVariant::Private *, const QVariant::Private *) { return false; }
+ static bool compare(const QVariant::Private *, const QVariant::Private *)
+ {
+ // It is not possible to construct a QVariant containing not fully defined type
+ Q_ASSERT(false);
+ return false;
+ }
};
public:
QVariantComparator(const QVariant::Private *a, const QVariant::Private *b)
@@ -187,7 +192,11 @@ public:
return FilteredComparator<T>::compare(m_a, m_b);
}
- bool delegate(const void*) { return true; }
+ bool delegate(const void*) { Q_ASSERT(false); return true; }
+ bool delegate(const QMetaTypeSwitcher::UnknownType*)
+ {
+ return true; // for historical reason invalid variant == invalid variant
+ }
bool delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return false; }
protected:
const QVariant::Private *m_a;
@@ -203,6 +212,19 @@ class QVariantIsNull
/// \internal
/// This class checks if a type T has method called isNull. Result is kept in the Value property
/// TODO Can we somehow generalize it? A macro version?
+#if defined(Q_COMPILER_DECLTYPE) // C++11 version
+ template<typename T>
+ class HasIsNullMethod {
+ struct Yes { char unused[1]; };
+ struct No { char unused[2]; };
+ Q_STATIC_ASSERT(sizeof(Yes) != sizeof(No));
+
+ template<class C> static decltype(static_cast<const C*>(0)->isNull(), Yes()) test(int);
+ template<class C> static No test(...);
+ public:
+ static const bool Value = (sizeof(test<T>(0)) == sizeof(Yes));
+ };
+#else // C++98 version (doesn't work for final classes)
template<typename T, bool IsClass = QTypeInfo<T>::isComplex>
class HasIsNullMethod
{
@@ -211,7 +233,7 @@ class QVariantIsNull
Q_STATIC_ASSERT(sizeof(Yes) != sizeof(No));
struct FallbackMixin { bool isNull() const; };
- struct Derived : public T, public FallbackMixin {};
+ struct Derived : public T, public FallbackMixin {}; // <- doesn't work for final classes
template<class C, C> struct TypeCheck {};
template<class C> static Yes test(...);
@@ -227,6 +249,7 @@ class QVariantIsNull
public:
static const bool Value = false;
};
+#endif
// TODO This part should go to autotests during HasIsNullMethod generalization.
Q_STATIC_ASSERT(!HasIsNullMethod<bool>::Value);
@@ -236,6 +259,12 @@ class QVariantIsNull
Q_STATIC_ASSERT(!HasIsNullMethod<SelfTest2>::Value);
struct SelfTest3 : public SelfTest1 {};
Q_STATIC_ASSERT(HasIsNullMethod<SelfTest3>::Value);
+ struct SelfTestFinal1 Q_DECL_FINAL_CLASS { bool isNull() const; };
+ Q_STATIC_ASSERT(HasIsNullMethod<SelfTestFinal1>::Value);
+ struct SelfTestFinal2 Q_DECL_FINAL_CLASS {};
+ Q_STATIC_ASSERT(!HasIsNullMethod<SelfTestFinal2>::Value);
+ struct SelfTestFinal3 Q_DECL_FINAL_CLASS : public SelfTest1 {};
+ Q_STATIC_ASSERT(HasIsNullMethod<SelfTestFinal3>::Value);
template<typename T, bool HasIsNull = HasIsNullMethod<T>::Value>
struct CallFilteredIsNull
@@ -281,8 +310,14 @@ public:
return CallIsNull<T>::isNull(m_d);
}
// we need that as sizof(void) is undefined and it is needed in HasIsNullMethod
- bool delegate(const void *) { return m_d->is_null; }
- bool delegate(const QMetaTypeSwitcher::NotBuiltinType *) { return m_d->is_null; }
+ bool delegate(const void *) { Q_ASSERT(false); return m_d->is_null; }
+ bool delegate(const QMetaTypeSwitcher::UnknownType *) { return m_d->is_null; }
+ bool delegate(const QMetaTypeSwitcher::NotBuiltinType *)
+ {
+ // QVariantIsNull is used only for built-in types
+ Q_ASSERT(false);
+ return m_d->is_null;
+ }
protected:
const QVariant::Private *m_d;
};
@@ -348,14 +383,24 @@ public:
void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
- qWarning("Trying to construct an instance of an invalid type, type id: %i", m_x->type);
- m_x->type = QVariant::Invalid;
+ // QVariantConstructor is used only for built-in types.
+ Q_ASSERT(false);
}
void delegate(const void*)
{
- // QMetaType::Void == QVariant::Invalid, creating an invalid value creates invalid QVariant
- // TODO it might go away, check is needed
+ qWarning("Trying to create a QVariant instance of QMetaType::Void type, an invalid QVariant will be constructed instead");
+ m_x->type = QMetaType::UnknownType;
+ m_x->is_shared = false;
+ m_x->is_null = !m_copy;
+ }
+
+ void delegate(const QMetaTypeSwitcher::UnknownType*)
+ {
+ if (m_x->type != QMetaType::UnknownType) {
+ qWarning("Trying to construct an instance of an invalid type, type id: %i", m_x->type);
+ m_x->type = QMetaType::UnknownType;
+ }
m_x->is_shared = false;
m_x->is_null = !m_copy;
}
@@ -376,7 +421,11 @@ class QVariantDestructor
};
template<typename T>
struct FilteredDestructor<T, /* IsAcceptedType = */ false> {
- FilteredDestructor(QVariant::Private *) {} // ignore non accessible types
+ FilteredDestructor(QVariant::Private *)
+ {
+ // It is not possible to create not accepted type
+ Q_ASSERT(false);
+ }
};
public:
@@ -398,17 +447,18 @@ public:
void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
- qWarning("Trying to destruct an instance of an invalid type, type id: %i", m_d->type);
+ // QVariantDestructor class is used only for a built-in type
+ Q_ASSERT(false);
}
// Ignore nonconstructible type
- void delegate(const void*) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
+ void delegate(const void*) { Q_ASSERT(false); }
private:
QVariant::Private *m_d;
};
namespace QVariantPrivate {
Q_CORE_EXPORT void registerHandler(const int /* Modules::Names */ name, const QVariant::Handler *handler);
-Q_CORE_EXPORT void unregisterHandler(const int /* Modules::Names */ name);
}
#if !defined(QT_NO_DEBUG_STREAM)
@@ -424,9 +474,10 @@ class QVariantDebugStream
};
template<typename T>
struct Filtered<T, /* IsAcceptedType = */ false> {
- Filtered(QDebug dbg, QVariant::Private *d)
+ Filtered(QDebug /* dbg */, QVariant::Private *)
{
- dbg.nospace() << "QVariant::Type(" << d->type << ")";
+ // It is not possible to construct not acccepted type, QVariantConstructor creates an invalid variant for them
+ Q_ASSERT(false);
}
};
@@ -445,12 +496,14 @@ public:
void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
- qWarning("Trying to stream an instance of an invalid type, type id: %i", m_d->type);
+ // QVariantDebugStream class is used only for a built-in type
+ Q_ASSERT(false);
}
- void delegate(const void*)
+ void delegate(const QMetaTypeSwitcher::UnknownType*)
{
m_debugStream.nospace() << "QVariant::Invalid";
}
+ void delegate(const void*) { Q_ASSERT(false); }
private:
QDebug m_debugStream;
QVariant::Private *m_d;