summaryrefslogtreecommitdiffstats
path: root/src/wrappedobjects
diff options
context:
space:
mode:
Diffstat (limited to 'src/wrappedobjects')
-rw-r--r--src/wrappedobjects/qtwrappedobjectsglobal.h86
-rw-r--r--src/wrappedobjects/qwrappedobject.cpp102
-rw-r--r--src/wrappedobjects/qwrappedobject.h120
-rw-r--r--src/wrappedobjects/qwrappedobject_p.h92
-rw-r--r--src/wrappedobjects/qwrappedobjectpointer.h73
-rw-r--r--src/wrappedobjects/wrappedobjects.pro19
6 files changed, 492 insertions, 0 deletions
diff --git a/src/wrappedobjects/qtwrappedobjectsglobal.h b/src/wrappedobjects/qtwrappedobjectsglobal.h
new file mode 100644
index 00000000..b33e6a0c
--- /dev/null
+++ b/src/wrappedobjects/qtwrappedobjectsglobal.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Sandro S. Andrade <sandroandrade@kde.org>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtWrappedObjects module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QTWRAPPEDOBJECTSGLOBAL_H
+#define QTWRAPPEDOBJECTSGLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_HEADER
+
+#ifndef QT_STATIC
+# if defined(QT_BUILD_WRAPPEDOBJECTS_LIB)
+# define Q_WRAPPEDOBJECTS_EXPORT Q_DECL_EXPORT
+# else
+# define Q_WRAPPEDOBJECTS_EXPORT Q_DECL_IMPORT
+# endif
+#else
+# define Q_WRAPPEDOBJECTS_EXPORT
+#endif
+
+// QtWrappedObjects macros
+
+#if defined(Q_MOC_RUN)
+
+#define QT_NAMESPACE_QTWRAPPEDOBJECTS
+#define QT_BEGIN_NAMESPACE_QTWRAPPEDOBJECTS
+#define QT_END_NAMESPACE_QTWRAPPEDOBJECTS
+#define QT_USE_NAMESPACE_QTWRAPPEDOBJECTS
+#define QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(name) ::name
+
+#else
+
+#if defined(QT_NAMESPACE)
+# define QT_NAMESPACE_QTWRAPPEDOBJECTS QT_NAMESPACE::QtWrappedObjects
+#else
+# define QT_NAMESPACE_QTWRAPPEDOBJECTS QtWrappedObjects
+#endif
+
+#define QT_BEGIN_NAMESPACE_QTWRAPPEDOBJECTS QT_BEGIN_NAMESPACE namespace QtWrappedObjects {
+#define QT_END_NAMESPACE_QTWRAPPEDOBJECTS QT_END_NAMESPACE }
+#define QT_USE_NAMESPACE_QTWRAPPEDOBJECTS using namespace ::QT_NAMESPACE_QTWRAPPEDOBJECTS;
+#define QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(name) ::QT_NAMESPACE_QTWRAPPEDOBJECTS::name
+
+#endif /* defined(Q_MOC_RUN) */
+
+QT_END_HEADER
+
+#endif // QTWRAPPEDOBJECTSGLOBAL_H
+
diff --git a/src/wrappedobjects/qwrappedobject.cpp b/src/wrappedobjects/qwrappedobject.cpp
new file mode 100644
index 00000000..d0563809
--- /dev/null
+++ b/src/wrappedobjects/qwrappedobject.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Sandro S. Andrade <sandroandrade@kde.org>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtWrappedObjects module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwrappedobject.h"
+#include "qwrappedobject_p.h"
+
+QT_BEGIN_NAMESPACE_QTWRAPPEDOBJECTS
+
+QWrappedObjectPrivate::QWrappedObjectPrivate(int version)
+ : QObjectPrivate(version), wrapper(0)
+{
+}
+
+QWrappedObjectPrivate::~QWrappedObjectPrivate()
+{
+}
+
+QWrappedObject::QWrappedObject(QWrappedObject *parent, QWrappedObject *wrapper) :
+ QObject(*new QWrappedObjectPrivate, parent)
+{
+ setWrapper(wrapper);
+}
+
+QWrappedObject::QWrappedObject(QWrappedObjectPrivate &dd, QWrappedObject *parent, QWrappedObject *wrapper) :
+ QObject(dd, parent)
+{
+ setWrapper(wrapper);
+}
+
+QWrappedObject::~QWrappedObject()
+{
+}
+
+const QList<QWrappedObject *> &QWrappedObject::wrappedObjects() const
+{
+ Q_D(const QWrappedObject);
+ return d->wrappedObjects;
+}
+
+void QWrappedObject::setWrapper(QWrappedObject *wrapper)
+{
+ Q_D(QWrappedObject);
+ if (wrapper == d->wrapper)
+ return;
+
+ if (d->wrapper)
+ d->wrapper->d_func()->wrappedObjects.removeAll(this);
+
+ d->wrapper = wrapper;
+
+ if (wrapper)
+ wrapper->d_func()->wrappedObjects.append(this);
+}
+
+QWrappedObject *QWrappedObject::wrapper() const
+{
+ Q_D(const QWrappedObject);
+ return d->wrapper;
+}
+
+#include "moc_qwrappedobject.cpp"
+
+QT_END_NAMESPACE_QTWRAPPEDOBJECTS
+
diff --git a/src/wrappedobjects/qwrappedobject.h b/src/wrappedobjects/qwrappedobject.h
new file mode 100644
index 00000000..c0a27949
--- /dev/null
+++ b/src/wrappedobjects/qwrappedobject.h
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Sandro S. Andrade <sandroandrade@kde.org>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtWrappedObjects module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QTWRAPPEDOBJECTS_QWRAPPEDOBJECTSOBJECT_H
+#define QTWRAPPEDOBJECTS_QWRAPPEDOBJECTSOBJECT_H
+
+#include <QtWrappedObjects/QtWrappedObjectsGlobal>
+
+// Base class includes
+#include <QtCore/QObject>
+
+// Qt includes
+#include <QtCore/QSet>
+#include <QtCore/QList>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE_QTWRAPPEDOBJECTS
+
+QT_MODULE(QtWrappedObjects)
+
+class QWrappedObjectPrivate;
+
+class Q_WRAPPEDOBJECTS_EXPORT QWrappedObject : public QObject
+{
+ Q_OBJECT
+
+ Q_DISABLE_COPY(QWrappedObject)
+ Q_DECLARE_PRIVATE(QWrappedObject)
+
+public:
+ Q_INVOKABLE explicit QWrappedObject(QWrappedObject *parent = 0, QWrappedObject *wrapper = 0);
+ virtual ~QWrappedObject();
+
+ const QList<QWrappedObject *> &wrappedObjects() const;
+
+ void setWrapper(QWrappedObject *wrapper);
+ QWrappedObject *wrapper() const;
+
+protected:
+ explicit QWrappedObject(QWrappedObjectPrivate &dd, QWrappedObject *parent = 0, QWrappedObject *wrapper = 0);
+};
+
+QT_END_NAMESPACE_QTWRAPPEDOBJECTS
+
+Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *)
+Q_DECLARE_METATYPE(const QSet<QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *> *)
+Q_DECLARE_METATYPE(const QList<QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *> *)
+
+template <class T>
+inline T qwrappedobject_cast(QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *base, bool restoreToWrapper = true)
+{
+ if (!base)
+ return T();
+ while (restoreToWrapper && base->wrapper())
+ base = base->wrapper();
+ if (dynamic_cast<T>(base))
+ return dynamic_cast<T>(base);
+ foreach (QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *wrappedObject, base->wrappedObjects()) {
+ T returnValue = qwrappedobject_cast<T>(wrappedObject, false);
+ if (returnValue != T())
+ return returnValue;
+ }
+ return T(); // not found
+}
+
+template <class T>
+inline T qwrappedobject_cast(const QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *base, bool restoreToWrapper = true)
+{
+ return qwrappedobject_cast<T>(const_cast<QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *>(base), restoreToWrapper);
+}
+
+inline QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *qTopLevelWrapper(QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *wrapped)
+{
+ while (wrapped->wrapper())
+ wrapped = wrapped->wrapper();
+ return wrapped;
+}
+
+QT_END_HEADER
+
+#endif // QTWRAPPEDOBJECTS_QWRAPPEDOBJECTSOBJECT_H
+
diff --git a/src/wrappedobjects/qwrappedobject_p.h b/src/wrappedobjects/qwrappedobject_p.h
new file mode 100644
index 00000000..dc9e428f
--- /dev/null
+++ b/src/wrappedobjects/qwrappedobject_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Sandro S. Andrade <sandroandrade@kde.org>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtWrappedObjects module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QTWRAPPEDOBJECTS_QWRAPPEDOBJECT_P_H
+#define QTWRAPPEDOBJECTS_QWRAPPEDOBJECT_P_H
+
+// Base class includes
+#include "private/qobject_p.h"
+
+#include "QtWrappedObjects/QWrappedObject"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE_QTWRAPPEDOBJECTS
+
+QT_MODULE(QtWrappedObjects)
+
+class Q_WRAPPEDOBJECTS_EXPORT QWrappedObjectPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QWrappedObject)
+
+public:
+ explicit QWrappedObjectPrivate(int version = QObjectPrivateVersion);
+ virtual ~QWrappedObjectPrivate();
+
+ static QWrappedObjectPrivate *get(QWrappedObject *o)
+ {
+ return dynamic_cast<QWrappedObjectPrivate *>(o->d_func());
+ }
+
+ QList<QWrappedObject *> wrappedObjects;
+ QWrappedObject *wrapper;
+};
+
+QT_END_NAMESPACE_QTWRAPPEDOBJECTS
+
+template <class T>
+inline T qwrappedobject_cast(QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObjectPrivate) *base, bool restoreToWrapper = true)
+{
+ while (restoreToWrapper && base->wrapper)
+ base = base->get(base->wrapper);
+ if (dynamic_cast<T>(base))
+ return dynamic_cast<T>(base);
+ foreach (QT_PREPEND_NAMESPACE_QTWRAPPEDOBJECTS(QWrappedObject) *wrappedObject, base->wrappedObjects) {
+ T returnValue = qwrappedobject_cast<T>(base->get(wrappedObject), false);
+ if (returnValue != T())
+ return returnValue;
+ }
+ return T(); // not found
+}
+
+QT_END_HEADER
+
+#endif // QTWRAPPEDOBJECTS_QWRAPPEDOBJECT_P_H
+
diff --git a/src/wrappedobjects/qwrappedobjectpointer.h b/src/wrappedobjects/qwrappedobjectpointer.h
new file mode 100644
index 00000000..3a187ca5
--- /dev/null
+++ b/src/wrappedobjects/qwrappedobjectpointer.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Sandro S. Andrade <sandroandrade@kde.org>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtWrappedObjects module of the Qt Toolkit.
+**
+** :LGPL
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+**
+**
+****************************************************************************/
+#ifndef QTWRAPPEDOBJECTS_QWRAPPEDOBJECTPOINTER_H
+#define QTWRAPPEDOBJECTS_QWRAPPEDOBJECTPOINTER_H
+
+#include <QtWrappedObjects/QtWrappedObjectsGlobal>
+
+// Base class includes
+#include <QtCore/QPointer>
+
+#include <QtWrappedObjects/QWrappedObject>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE_QTWRAPPEDOBJECTS
+
+template <class T>
+class Q_WRAPPEDOBJECTS_EXPORT QWrappedObjectPointer : public QPointer<T>
+{
+public:
+ QWrappedObjectPointer(T *p = 0) : QPointer<T>(p) { }
+ virtual ~QWrappedObjectPointer() { }
+
+ template <class U> inline operator U *()
+ {
+ return qwrappedobject_cast<U *>(QPointer<T>::data());
+ }
+};
+
+QT_END_NAMESPACE_QTWRAPPEDOBJECTS
+
+QT_END_HEADER
+
+#endif // QTWRAPPEDOBJECTS_QWRAPPEDOBJECTPOINTER_H
+
diff --git a/src/wrappedobjects/wrappedobjects.pro b/src/wrappedobjects/wrappedobjects.pro
new file mode 100644
index 00000000..dc7aa25c
--- /dev/null
+++ b/src/wrappedobjects/wrappedobjects.pro
@@ -0,0 +1,19 @@
+load(qt_build_config)
+
+TARGET = QtWrappedObjects
+QT = core-private
+
+load(qt_module)
+
+PUBLIC_HEADERS += \
+ qtwrappedobjectsglobal.h \
+ qwrappedobject.h \
+ qwrappedobjectpointer.h
+
+PRIVATE_HEADERS += \
+ qwrappedobject_p.h
+
+SOURCES += \
+ qwrappedobject.cpp
+
+HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS