Merge branch 'qt5_migration' of dev.vatsim-germany.org:vatpilotclient/client into qt5_migration

This commit is contained in:
Roland Winklmeier
2013-07-06 10:18:24 +02:00
5 changed files with 60 additions and 66 deletions

View File

@@ -1,6 +1,9 @@
FILE(GLOB SRC *.cpp) FILE(GLOB SRC *.cpp)
SET(HEADERS server.h)
ADD_LIBRARY(sample_plugin MODULE ${SRC}) QT4_WRAP_CPP(HEADERS_MOC ${HEADERS})
ADD_LIBRARY(sample_plugin MODULE ${SRC} ${HEADERS_MOC})
TARGET_LINK_LIBRARIES(sample_plugin blackmisc ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(sample_plugin blackmisc ${QT_LIBRARIES})
SET_TARGET_PROPERTIES(sample_plugin PROPERTIES PROJECT_LABEL "Samples - Plugin") SET_TARGET_PROPERTIES(sample_plugin PROPERTIES PROJECT_LABEL "Samples - Plugin")

View File

@@ -3,28 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "blackmisc/plugins.h" #include "plugin.h"
#include <iostream> #include <iostream>
class CPlugin : public BlackMisc::IPlugin
{
public:
CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context);
virtual ~CPlugin();
virtual bool isValid() const { return m_ctorOK; }
virtual BlackMisc::IPluginFactory &getFactory() { return m_factory; }
private:
bool m_ctorOK;
BlackMisc::IPluginFactory &m_factory;
BlackMisc::IContext &m_context;
};
MAKE_BLACK_PLUGIN(sample_plugin, CPlugin, "An example minimal plugin")
CPlugin::CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context) CPlugin::CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context)
: m_ctorOK(false), : m_ctorOK(false),
m_factory(factory), m_factory(factory),

36
samples/plugin/plugin.h Normal file
View File

@@ -0,0 +1,36 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SAMPLE_PLUGIN_H
#define SAMPLE_PLUGIN_H
#include "blackmisc/plugins.h"
class CPlugin : public BlackMisc::IPlugin
{
public:
CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context);
virtual ~CPlugin();
virtual bool isValid() const { return m_ctorOK; }
virtual BlackMisc::IPluginFactory &getFactory() { return m_factory; }
private:
bool m_ctorOK;
BlackMisc::IPluginFactory &m_factory;
BlackMisc::IContext &m_context;
};
class CPluginFactory : public QObject, public BlackMisc::IPluginFactory
{
Q_OBJECT
Q_INTERFACES(BlackMisc::IPluginFactory)
Q_PLUGIN_METADATA(IID BLACKMISC_IPLUGINFACTORY_IID)
BLACKMISC_IMPLEMENT_IPLUGINFACTORY(CPlugin, "sample_plugin", "An example minimal plugin")
};
#endif //SAMPLE_PLUGIN_H

View File

@@ -9,6 +9,7 @@ DEPENDPATH += . ../../src
INCLUDEPATH += . ../../src INCLUDEPATH += . ../../src
SOURCES += *.cpp SOURCES += *.cpp
HEADERS += *.h
LIBS += -L../../lib -lblackmisc LIBS += -L../../lib -lblackmisc

View File

@@ -87,51 +87,6 @@ namespace BlackMisc
virtual const char *getDescription() const = 0; virtual const char *getDescription() const = 0;
}; };
} //namespace BlackMisc
// must be placed outside namespace and before CPluginFactoryBase
Q_DECLARE_INTERFACE(BlackMisc::IPluginFactory, "net.vatsim.client.BlackMisc.IPluginFactory")
namespace BlackMisc
{
/*!
Base class for CPluginFactory template used by MAKE_BLACK_PLUGIN.
*/
class CPluginFactoryBase : public QObject, public IPluginFactory
{
Q_OBJECT
Q_INTERFACES(BlackMisc::IPluginFactory)
};
/*!
Template used by MAKE_BLACK_PLUGIN.
*/
template <class P>
class CPluginFactory : public CPluginFactoryBase
{
public:
IPlugin *create(IContext &context) { return new P(*this, context); }
void destroy(IPlugin *plugin) { if (plugin) delete plugin; }
};
/*!
Simplifies the process of building a plugin.
Put this macro somewhere in one of your plugin's .cpp files (but not in a namespace)
to export the necessary factory class for your plugin.
FQCLASS must have a constructor with the signature (IPluginFactory&, IContext&).
\param NAME A short name for your plugin with no spaces (a bareword, not a string).
\param FQCLASS The fully qualified name of the IPlugin subclass that the factory will construct.
*/
#define MAKE_BLACK_PLUGIN(NAME, FQCLASS, DESCR) \
class CPluginFactory_##NAME : public BlackMisc::CPluginFactory<FQCLASS> \
{ \
const char *getName() const { return #NAME ; } \
const char *getDescription() const { return DESCR; } \
}; \
Q_EXPORT_PLUGIN2(NAME, CPluginFactory_##NAME )
/*! /*!
Custom deleter for QScopedPointer. Custom deleter for QScopedPointer.
*/ */
@@ -147,4 +102,22 @@ namespace BlackMisc
} //namespace BlackMisc } //namespace BlackMisc
//! Qt interface ID for IPluginFactory.
#define BLACKMISC_IPLUGINFACTORY_IID "net.vatsim.client.BlackMisc.IPluginFactory"
Q_DECLARE_INTERFACE(BlackMisc::IPluginFactory, BLACKMISC_IPLUGINFACTORY_IID)
/*!
Macro to put inside an IPluginFactory subclass to help with implementation.
\param CLASS The plugin class which this factory constructs.
\param NAME A string literal, the plugin's short name.
\param DESCRIPTION A string literal, a brief description of the plugin.
*/
#define BLACKMISC_IMPLEMENT_IPLUGINFACTORY(CLASS, NAME, DESCRIPTION) \
public: \
BlackMisc::IPlugin *create(BlackMisc::IContext &context) { return new CLASS(*this, context); } \
void destroy(BlackMisc::IPlugin *plugin) { if (plugin) delete plugin; } \
const char *getName() const { return NAME; } \
const char *getDescription() const { return DESCRIPTION; }
#endif //BLACKMISC_PLUGINS_H #endif //BLACKMISC_PLUGINS_H