Commit ea0d68f7 authored by Friedemann Kleint's avatar Friedemann Kleint

Qt Designer custom widget wizard: Write plugins compatible with Qt 4 / 5.

Generate plugin metadata for Qt 5 or plugin export for Qt 4.

Change-Id: I9888ebb22204c96755f82efc0dd2bceb51a19b0c
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 77dc72d3
......@@ -8,6 +8,7 @@ class @COLLECTION_PLUGIN_CLASS@ : public QObject, public QDesignerCustomWidgetCo
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
@COLLECTION_PLUGIN_METADATA@
public:
explicit @COLLECTION_PLUGIN_CLASS@(QObject *parent = 0);
......
CONFIG += designer plugin debug_and_release
CONFIG += plugin debug_and_release
TARGET = $$qtLibraryTarget(@PLUGIN_NAME@)
TEMPLATE = lib
......@@ -7,6 +7,12 @@ SOURCES =@PLUGIN_SOURCES@
RESOURCES = @PLUGIN_RESOURCES@
LIBS += -L. @WIDGET_LIBS@
greaterThan(QT_MAJOR_VERSION, 4) {
QT += designer
} else {
CONFIG += designer
}
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
......
......@@ -7,6 +7,7 @@ class @PLUGIN_CLASS@ : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
@SINGLE_PLUGIN_METADATA@
public:
@PLUGIN_CLASS@(QObject *parent = 0);
......
......@@ -68,6 +68,19 @@ static inline Core::GeneratedFile generateIconFile(const QString &source, const
return rc;
}
static QString qt4PluginExport(const QString &pluginName, const QString &pluginClassName)
{
return QLatin1String("#if QT_VERSION < 0x050000\nQ_EXPORT_PLUGIN2(")
+ pluginName + QLatin1String(", ") + pluginClassName
+ QLatin1String(")\n#endif // QT_VERSION < 0x050000");
}
static QString qt5PluginMetaData(const QString &interfaceName)
{
return QLatin1String("#if QT_VERSION >= 0x050000\n Q_PLUGIN_METADATA(IID \"org.qt-project.Qt.")
+ interfaceName + QLatin1String("\")\n#endif // QT_VERSION >= 0x050000");
}
QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationParameters& p, const PluginOptions &options,
QString *errorMessage)
{
......@@ -100,6 +113,9 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
sm.clear();
sm.insert(QLatin1String("SINGLE_INCLUDE_GUARD"), headerGuard(wo.pluginHeaderFile));
sm.insert(QLatin1String("PLUGIN_CLASS"), wo.pluginClassName);
sm.insert(QLatin1String("SINGLE_PLUGIN_METADATA"),
options.widgetOptions.count() == 1 ?
qt5PluginMetaData(QLatin1String("QDesignerCustomWidgetInterface")) : QString());
const QString pluginHeaderContents = processTemplate(p.templatePath + QLatin1String("/tpl_single.h"), sm, errorMessage);
if (pluginHeaderContents.isEmpty())
return QList<Core::GeneratedFile>();
......@@ -126,12 +142,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
sm.insert(QLatin1String("WIDGET_DOMXML"), cStringQuote(wo.domXml));
sm.insert(QLatin1String("SINGLE_PLUGIN_EXPORT"),
options.widgetOptions.count() == 1 ?
QLatin1String("\nQ_EXPORT_PLUGIN2(") +
options.pluginName +
QLatin1String(", ") +
wo.pluginClassName +
QLatin1Char(')') :
QString());
qt4PluginExport(options.pluginName, wo.pluginClassName) : QString());
const QString pluginSourceContents = processTemplate(p.templatePath + QLatin1String("/tpl_single.cpp"), sm, errorMessage);
if (pluginSourceContents.isEmpty())
return QList<Core::GeneratedFile>();
......@@ -222,6 +234,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
sm.clear();
sm.insert(QLatin1String("COLLECTION_INCLUDE_GUARD"), headerGuard(options.collectionHeaderFile));
sm.insert(QLatin1String("COLLECTION_PLUGIN_CLASS"), options.collectionClassName);
sm.insert(QLatin1String("COLLECTION_PLUGIN_METADATA"), qt5PluginMetaData(QLatin1String("QDesignerCustomWidgetCollectionInterface")));
const QString collectionHeaderContents = processTemplate(p.templatePath + QLatin1String("/tpl_collection.h"), sm, errorMessage);
if (collectionHeaderContents.isEmpty())
return QList<Core::GeneratedFile>();
......@@ -237,12 +250,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
options.collectionHeaderFile +
QLatin1String("\""));
sm.insert(QLatin1String("PLUGIN_ADDITIONS"), pluginAdditions);
sm.insert(QLatin1String("COLLECTION_PLUGIN_EXPORT"),
QLatin1String("Q_EXPORT_PLUGIN2(") +
options.pluginName +
QLatin1String(", ") +
options.collectionClassName +
QLatin1Char(')'));
sm.insert(QLatin1String("COLLECTION_PLUGIN_EXPORT"), qt4PluginExport(options.pluginName, options.collectionClassName));
const QString collectionSourceFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_collection.cpp"), sm, errorMessage);
if (collectionSourceFileContents.isEmpty())
return QList<Core::GeneratedFile>();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment