tools/designer/src/lib/extension/extension.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the Qt Designer of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef EXTENSION_H
00025 #define EXTENSION_H
00026 
00027 #include <QtCore/QString>
00028 #include <QtCore/QObject>
00029 
00030 QT_BEGIN_HEADER
00031 
00032 #define Q_TYPEID(IFace) QLatin1String(IFace##_iid)
00033 
00034 class QAbstractExtensionFactory
00035 {
00036 public:
00037     virtual ~QAbstractExtensionFactory() {}
00038 
00039     virtual QObject *extension(QObject *object, const QString &iid) const = 0;
00040 };
00041 Q_DECLARE_INTERFACE(QAbstractExtensionFactory, "com.trolltech.Qt.QAbstractExtensionFactory")
00042 
00043 class QAbstractExtensionManager
00044 {
00045 public:
00046     virtual ~QAbstractExtensionManager() {}
00047 
00048     virtual void registerExtensions(QAbstractExtensionFactory *factory, const QString &iid) = 0;
00049     virtual void unregisterExtensions(QAbstractExtensionFactory *factory, const QString &iid) = 0;
00050 
00051     virtual QObject *extension(QObject *object, const QString &iid) const = 0;
00052 };
00053 Q_DECLARE_INTERFACE(QAbstractExtensionManager, "com.trolltech.Qt.QAbstractExtensionManager")
00054 
00055 #if defined(Q_CC_MSVC) && (_MSC_VER < 1300)
00056 
00057 template <class T>
00058 inline T qt_extension_helper(QAbstractExtensionManager *, QObject *, T)
00059 { return 0; }
00060 
00061 template <class T>
00062 inline T qt_extension(QAbstractExtensionManager* manager, QObject *object)
00063 { return qt_extension_helper(manager, object, T(0)); }
00064 
00065 #define Q_DECLARE_EXTENSION_INTERFACE(IFace, IId) \
00066 const char * const IFace##_iid = IId; \
00067 Q_DECLARE_INTERFACE(IFace, IId) \
00068 template <> inline IFace *qt_extension_helper<IFace *>(QAbstractExtensionManager *manager, QObject *object, IFace *) \
00069 { QObject *extension = manager->extension(object, Q_TYPEID(IFace)); return (IFace *)(extension ? extension->qt_metacast(IFace##_iid) : 0); }
00070 
00071 #else
00072 
00073 template <class T>
00074 inline T qt_extension(QAbstractExtensionManager* manager, QObject *object)
00075 { return 0; }
00076 
00077 #define Q_DECLARE_EXTENSION_INTERFACE(IFace, IId) \
00078 const char * const IFace##_iid = IId; \
00079 Q_DECLARE_INTERFACE(IFace, IId) \
00080 template <> inline IFace *qt_extension<IFace *>(QAbstractExtensionManager *manager, QObject *object) \
00081 { QObject *extension = manager->extension(object, Q_TYPEID(IFace)); return extension ? static_cast<IFace *>(extension->qt_metacast(IFace##_iid)) : static_cast<IFace *>(0); }
00082 
00083 #endif
00084 
00085 QT_END_HEADER
00086 
00087 #endif // EXTENSION_H

Generated on Thu Mar 15 12:01:21 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1