|
|
|
@ -222,7 +222,7 @@ public:
|
|
|
|
|
* \returns A pointer to the created object is returned, or 0 if an error occurred.
|
|
|
|
|
*/
|
|
|
|
|
template<typename T>
|
|
|
|
|
T *create(QObject *parent = 0);
|
|
|
|
|
T* create( QObject* parent = nullptr );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use this method to create an object. It will try to create an object which inherits
|
|
|
|
@ -235,7 +235,7 @@ public:
|
|
|
|
|
* \returns A pointer to the created object is returned, or 0 if an error occurred.
|
|
|
|
|
*/
|
|
|
|
|
template<typename T>
|
|
|
|
|
T *create(const QString &keyword, QObject *parent = 0);
|
|
|
|
|
T* create( const QString& keyword, QObject* parent = nullptr );
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
void objectCreated( QObject* object );
|
|
|
|
@ -251,7 +251,8 @@ protected:
|
|
|
|
|
* You can inherit it, if you want to add new classes and still keep support for the old ones.
|
|
|
|
|
*/
|
|
|
|
|
template<class impl>
|
|
|
|
|
struct InheritanceChecker {
|
|
|
|
|
struct InheritanceChecker
|
|
|
|
|
{
|
|
|
|
|
CreateInstanceFunction createInstanceFunction( QWidget* )
|
|
|
|
|
{
|
|
|
|
|
return &createInstance<impl, QWidget>;
|
|
|
|
@ -299,7 +300,7 @@ protected:
|
|
|
|
|
doRegisterPlugin( keyword, &T::staticMetaObject, instanceFunction );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PluginFactoryPrivate *const d_ptr;
|
|
|
|
|
PluginFactoryPrivate* const d_ptr_p;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function is called when the factory asked to create an Object.
|
|
|
|
@ -320,8 +321,9 @@ protected:
|
|
|
|
|
static QObject* createInstance( QWidget* parentWidget, QObject* parent )
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED( parentWidget );
|
|
|
|
|
ParentType *p = 0;
|
|
|
|
|
if (parent) {
|
|
|
|
|
ParentType* p( nullptr );
|
|
|
|
|
if ( parent )
|
|
|
|
|
{
|
|
|
|
|
p = qobject_cast<ParentType*>( parent );
|
|
|
|
|
Q_ASSERT( p );
|
|
|
|
|
}
|
|
|
|
@ -336,14 +338,13 @@ template<typename T>
|
|
|
|
|
inline T* PluginFactory::create( QObject* parent )
|
|
|
|
|
{
|
|
|
|
|
QObject* o = create( T::staticMetaObject.className(),
|
|
|
|
|
parent && parent->isWidgetType() ? reinterpret_cast<QWidget *>(parent) : 0,
|
|
|
|
|
parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : nullptr,
|
|
|
|
|
parent,
|
|
|
|
|
QString() );
|
|
|
|
|
|
|
|
|
|
T* t = qobject_cast<T*>( o );
|
|
|
|
|
if (!t) {
|
|
|
|
|
if ( !t )
|
|
|
|
|
delete o;
|
|
|
|
|
}
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -351,14 +352,13 @@ template<typename T>
|
|
|
|
|
inline T* PluginFactory::create( const QString& keyword, QObject* parent )
|
|
|
|
|
{
|
|
|
|
|
QObject* o = create( T::staticMetaObject.className(),
|
|
|
|
|
parent && parent->isWidgetType() ? reinterpret_cast<QWidget *>(parent) : 0,
|
|
|
|
|
parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : nullptr,
|
|
|
|
|
parent,
|
|
|
|
|
keyword );
|
|
|
|
|
|
|
|
|
|
T* t = qobject_cast<T*>( o );
|
|
|
|
|
if (!t) {
|
|
|
|
|
if ( !t )
|
|
|
|
|
delete o;
|
|
|
|
|
}
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|