Revert be2338ff0 (intended just to reduce warnings)

- keep the calamaresstyle formatting changes,
 - drop shadowing and nullptr changes.

FIXES #805
This commit is contained in:
Adriaan de Groot 2017-09-18 15:10:13 +02:00
parent a14e98ce95
commit ddb6455365
6 changed files with 67 additions and 57 deletions

View File

@ -32,7 +32,7 @@ public:
bool runInChroot = false, bool runInChroot = false,
int secondsTimeout = 30, int secondsTimeout = 30,
QObject* parent = nullptr ); QObject* parent = nullptr );
virtual ~ProcessJob() override; virtual ~ProcessJob();
QString prettyName() const override; QString prettyName() const override;
QString prettyStatusMessage() const override; QString prettyStatusMessage() const override;

View File

@ -26,7 +26,7 @@
#include <QObjectCleanupHandler> #include <QObjectCleanupHandler>
#include <QDebug> #include <QDebug>
Q_GLOBAL_STATIC(QObjectCleanupHandler, factorycleanup) Q_GLOBAL_STATIC( QObjectCleanupHandler, factorycleanup )
extern int kLibraryDebugArea(); extern int kLibraryDebugArea();
@ -34,89 +34,96 @@ namespace Calamares
{ {
PluginFactory::PluginFactory() PluginFactory::PluginFactory()
: d_ptr_p(new PluginFactoryPrivate) : d_ptr( new PluginFactoryPrivate )
{ {
Q_D(PluginFactory); Q_D( PluginFactory );
d->q_ptr = this; d->q_ptr = this;
factorycleanup()->add(this); factorycleanup()->add( this );
} }
PluginFactory::PluginFactory(PluginFactoryPrivate &d) PluginFactory::PluginFactory( PluginFactoryPrivate& d )
: d_ptr_p(&d) : d_ptr( &d )
{ {
factorycleanup()->add(this); factorycleanup()->add( this );
} }
PluginFactory::~PluginFactory() PluginFactory::~PluginFactory()
{ {
delete d_ptr_p; delete d_ptr;
} }
void PluginFactory::doRegisterPlugin(const QString &keyword, const QMetaObject *metaObject, CreateInstanceFunction instanceFunction) void PluginFactory::doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction )
{ {
Q_D(PluginFactory); Q_D( PluginFactory );
Q_ASSERT(metaObject); Q_ASSERT( metaObject );
// we allow different interfaces to be registered without keyword // we allow different interfaces to be registered without keyword
if (!keyword.isEmpty()) { if ( !keyword.isEmpty() )
if (d->createInstanceHash.contains(keyword)) { {
if ( d->createInstanceHash.contains( keyword ) )
qWarning() << "A plugin with the keyword" << keyword << "was already registered. A keyword must be unique!"; qWarning() << "A plugin with the keyword" << keyword << "was already registered. A keyword must be unique!";
} d->createInstanceHash.insert( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
d->createInstanceHash.insert(keyword, PluginFactoryPrivate::Plugin(metaObject, instanceFunction)); }
} else { else
const QList<PluginFactoryPrivate::Plugin> clashes(d->createInstanceHash.values(keyword)); {
const QMetaObject *superClass = metaObject->superClass(); const QList<PluginFactoryPrivate::Plugin> clashes( d->createInstanceHash.values( keyword ) );
if (superClass) { const QMetaObject* superClass = metaObject->superClass();
for (const PluginFactoryPrivate::Plugin &plugin : clashes) { if ( superClass )
for (const QMetaObject *otherSuper = plugin.first->superClass(); otherSuper; {
otherSuper = otherSuper->superClass()) { for ( const PluginFactoryPrivate::Plugin& plugin : clashes )
if (superClass == otherSuper) { {
for ( const QMetaObject* otherSuper = plugin.first->superClass(); otherSuper;
otherSuper = otherSuper->superClass() )
{
if ( superClass == otherSuper )
qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins."; qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins.";
}
} }
} }
} }
for (const PluginFactoryPrivate::Plugin &plugin : clashes) { for ( const PluginFactoryPrivate::Plugin& plugin : clashes )
{
superClass = plugin.first->superClass(); superClass = plugin.first->superClass();
if (superClass) { if ( superClass )
for (const QMetaObject *otherSuper = metaObject->superClass(); otherSuper; {
otherSuper = otherSuper->superClass()) { for ( const QMetaObject* otherSuper = metaObject->superClass(); otherSuper;
if (superClass == otherSuper) { otherSuper = otherSuper->superClass() )
{
if ( superClass == otherSuper )
qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins."; qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins.";
}
} }
} }
} }
d->createInstanceHash.insertMulti(keyword, PluginFactoryPrivate::Plugin(metaObject, instanceFunction)); d->createInstanceHash.insertMulti( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
} }
} }
QObject *PluginFactory::create(const char *iface, QWidget *parentWidget, QObject *parent, const QString &keyword) QObject* PluginFactory::create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword )
{ {
Q_D(PluginFactory); Q_D( PluginFactory );
QObject *obj( nullptr ); QObject* obj = 0;
const QList<PluginFactoryPrivate::Plugin> candidates(d->createInstanceHash.values(keyword)); const QList<PluginFactoryPrivate::Plugin> candidates( d->createInstanceHash.values( keyword ) );
// for !keyword.isEmpty() candidates.count() is 0 or 1 // for !keyword.isEmpty() candidates.count() is 0 or 1
for (const PluginFactoryPrivate::Plugin &plugin : candidates) { for ( const PluginFactoryPrivate::Plugin& plugin : candidates )
for (const QMetaObject *current = plugin.first; current; current = current->superClass()) { {
if (0 == qstrcmp(iface, current->className())) { for ( const QMetaObject* current = plugin.first; current; current = current->superClass() )
if (obj) { {
if ( 0 == qstrcmp( iface, current->className() ) )
{
if ( obj )
qWarning() << "ambiguous interface requested from a DSO containing more than one plugin"; qWarning() << "ambiguous interface requested from a DSO containing more than one plugin";
} obj = plugin.second( parentWidget, parent );
obj = plugin.second(parentWidget, parent);
break; break;
} }
} }
} }
if (obj) { if ( obj )
emit objectCreated(obj); emit objectCreated( obj );
}
return obj; return obj;
} }

View File

@ -222,7 +222,7 @@ public:
* \returns A pointer to the created object is returned, or 0 if an error occurred. * \returns A pointer to the created object is returned, or 0 if an error occurred.
*/ */
template<typename T> template<typename T>
T* create( QObject* parent = nullptr ); T* create( QObject* parent = 0 );
/** /**
* Use this method to create an object. It will try to create an object which inherits * 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. * \returns A pointer to the created object is returned, or 0 if an error occurred.
*/ */
template<typename T> template<typename T>
T* create( const QString& keyword, QObject* parent = nullptr ); T* create( const QString& keyword, QObject* parent = 0 );
Q_SIGNALS: Q_SIGNALS:
void objectCreated( QObject* object ); void objectCreated( QObject* object );
@ -300,7 +300,7 @@ protected:
doRegisterPlugin( keyword, &T::staticMetaObject, instanceFunction ); doRegisterPlugin( keyword, &T::staticMetaObject, instanceFunction );
} }
PluginFactoryPrivate* const d_ptr_p; PluginFactoryPrivate* const d_ptr;
/** /**
* This function is called when the factory asked to create an Object. * This function is called when the factory asked to create an Object.
@ -321,7 +321,7 @@ protected:
static QObject* createInstance( QWidget* parentWidget, QObject* parent ) static QObject* createInstance( QWidget* parentWidget, QObject* parent )
{ {
Q_UNUSED( parentWidget ); Q_UNUSED( parentWidget );
ParentType* p( nullptr ); ParentType* p = 0;
if ( parent ) if ( parent )
{ {
p = qobject_cast<ParentType*>( parent ); p = qobject_cast<ParentType*>( parent );
@ -338,7 +338,7 @@ template<typename T>
inline T* PluginFactory::create( QObject* parent ) inline T* PluginFactory::create( QObject* parent )
{ {
QObject* o = create( T::staticMetaObject.className(), QObject* o = create( T::staticMetaObject.className(),
parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : nullptr, parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : 0,
parent, parent,
QString() ); QString() );
@ -352,7 +352,7 @@ template<typename T>
inline T* PluginFactory::create( const QString& keyword, QObject* parent ) inline T* PluginFactory::create( const QString& keyword, QObject* parent )
{ {
QObject* o = create( T::staticMetaObject.className(), QObject* o = create( T::staticMetaObject.className(),
parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : nullptr, parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : 0,
parent, parent,
keyword ); keyword );

View File

@ -25,7 +25,8 @@
class QPluginLoader; class QPluginLoader;
namespace Calamares { namespace Calamares
{
class UIDLLEXPORT CppJobModule : public Module class UIDLLEXPORT CppJobModule : public Module
{ {
@ -42,7 +43,7 @@ protected:
private: private:
friend class Module; //so only the superclass can instantiate friend class Module; //so only the superclass can instantiate
explicit CppJobModule(); explicit CppJobModule();
virtual ~CppJobModule() override; virtual ~CppJobModule();
QPluginLoader* m_loader; QPluginLoader* m_loader;
job_ptr m_job; job_ptr m_job;

View File

@ -23,7 +23,8 @@
#include "UiDllMacro.h" #include "UiDllMacro.h"
namespace Calamares { namespace Calamares
{
class UIDLLEXPORT ProcessJobModule : public Module class UIDLLEXPORT ProcessJobModule : public Module
{ {
@ -40,7 +41,7 @@ protected:
private: private:
friend class Module; friend class Module;
explicit ProcessJobModule(); explicit ProcessJobModule();
virtual ~ProcessJobModule() override; virtual ~ProcessJobModule();
QString m_command; QString m_command;
QString m_workingPath; QString m_workingPath;

View File

@ -24,7 +24,8 @@
class QPluginLoader; class QPluginLoader;
namespace Calamares { namespace Calamares
{
class ViewStep; class ViewStep;
@ -43,7 +44,7 @@ protected:
private: private:
friend class Module; //so only the superclass can instantiate friend class Module; //so only the superclass can instantiate
explicit ViewModule(); explicit ViewModule();
virtual ~ViewModule() override; virtual ~ViewModule();
QPluginLoader* m_loader; QPluginLoader* m_loader;
ViewStep* m_viewStep = nullptr; ViewStep* m_viewStep = nullptr;