forked from qt-creator/qt-creator
Library-Wizard: Write plugins compatible with Qt 4 / 5.
Add json-file and #ifdef plugin export for use with Qt 4 and 5. Change-Id: Ib04f2e56be08634f00c8aa2cde45837b9a138cbe Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "libraryparameters.h"
|
||||
#include "librarywizarddialog.h"
|
||||
|
||||
#include <utils/codegeneration.h>
|
||||
|
||||
@@ -61,6 +62,7 @@ void LibraryParameters::generateCode(QtProjectParameters:: Type t,
|
||||
const QString &headerName,
|
||||
const QString &sharedHeader,
|
||||
const QString &exportMacro,
|
||||
const QString &pluginJsonFileName,
|
||||
int indentation,
|
||||
QString *header,
|
||||
QString *source) const
|
||||
@@ -107,7 +109,19 @@ void LibraryParameters::generateCode(QtProjectParameters:: Type t,
|
||||
const bool inheritsQObject = t == QtProjectParameters::Qt4Plugin;
|
||||
if (inheritsQObject)
|
||||
headerStr << namespaceIndent << indent << "Q_OBJECT\n";
|
||||
headerStr << namespaceIndent << "public:\n";
|
||||
if (t == QtProjectParameters::Qt4Plugin) { // Write Qt 5 plugin meta data.
|
||||
const QString qt5InterfaceName = LibraryWizardDialog::pluginInterface(baseClassName);
|
||||
if (!qt5InterfaceName.isEmpty()) {
|
||||
headerStr << "#if QT_VERSION >= 0x050000\n"
|
||||
<< namespaceIndent << indent << "Q_PLUGIN_METADATA(IID \""
|
||||
<< qt5InterfaceName << '"';
|
||||
if (!pluginJsonFileName.isEmpty())
|
||||
headerStr << " FILE \"" << pluginJsonFileName << '"';
|
||||
headerStr << ")\n#endif // QT_VERSION >= 0x050000\n";
|
||||
}
|
||||
}
|
||||
|
||||
headerStr << namespaceIndent << "\npublic:\n";
|
||||
if (inheritsQObject)
|
||||
headerStr << namespaceIndent << indent << unqualifiedClassName << "(QObject *parent = 0);\n";
|
||||
else
|
||||
@@ -134,8 +148,11 @@ void LibraryParameters::generateCode(QtProjectParameters:: Type t,
|
||||
|
||||
Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
|
||||
|
||||
if (t == QtProjectParameters::Qt4Plugin)
|
||||
sourceStr << '\n' << "Q_EXPORT_PLUGIN2(" << projectTarget << ", " << className << ")\n";
|
||||
if (t == QtProjectParameters::Qt4Plugin) { // Qt 4 plugin export
|
||||
sourceStr << "\n#if QT_VERSION < 0x050000\n"
|
||||
<< "Q_EXPORT_PLUGIN2(" << projectTarget << ", " << className << ")\n"
|
||||
<< "#endif // QT_VERSION < 0x050000\n";
|
||||
}
|
||||
}
|
||||
|
||||
QString LibraryParameters::generateSharedHeader(const QString &globalHeaderFileName,
|
||||
|
||||
@@ -47,6 +47,7 @@ struct LibraryParameters {
|
||||
const QString &headerName,
|
||||
const QString &sharedHeader,
|
||||
const QString &exportMacro,
|
||||
const QString &pluginJsonFileName,
|
||||
int indentation,
|
||||
QString *header,
|
||||
QString *source) const;
|
||||
|
||||
@@ -95,6 +95,13 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
|
||||
|
||||
const QString headerFileFullName = buildFileName(projectPath, params.headerFileName, headerSuffix());
|
||||
const QString headerFileName = QFileInfo(headerFileFullName).fileName();
|
||||
QString pluginJsonFileFullName;
|
||||
QString pluginJsonFileName;
|
||||
if (projectParams.type == QtProjectParameters::Qt4Plugin) {
|
||||
pluginJsonFileFullName = buildFileName(projectPath, projectParams.fileName, QLatin1String("json"));
|
||||
pluginJsonFileName = QFileInfo(pluginJsonFileFullName).fileName();
|
||||
}
|
||||
|
||||
Core::GeneratedFile header(headerFileFullName);
|
||||
|
||||
// Create files: global header for shared libs
|
||||
@@ -111,7 +118,7 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
|
||||
// Generate code
|
||||
QString headerContents, sourceContents;
|
||||
params.generateCode(projectParams.type, projectParams.fileName, headerFileName,
|
||||
globalHeaderFileName, sharedLibExportMacro,
|
||||
globalHeaderFileName, sharedLibExportMacro, pluginJsonFileName,
|
||||
/* indentation*/ 4, &headerContents, &sourceContents);
|
||||
|
||||
source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName, params.className)
|
||||
@@ -133,11 +140,19 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
|
||||
<< "\n\nHEADERS += " << headerFileName;
|
||||
if (!globalHeaderFileName.isEmpty())
|
||||
proStr << "\\\n " << globalHeaderFileName << '\n';
|
||||
if (!pluginJsonFileName.isEmpty())
|
||||
proStr << "\nOTHER_FILES += " << pluginJsonFileName << '\n';
|
||||
if (mobileParams.type)
|
||||
mobileParams.writeProFile(proStr);
|
||||
}
|
||||
profile.setContents(profileContents);
|
||||
rc.push_back(profile);
|
||||
|
||||
if (!pluginJsonFileName.isEmpty()) {
|
||||
Core::GeneratedFile jsonFile(pluginJsonFileFullName);
|
||||
jsonFile.setContents(QLatin1String("{\n \"Keys\" : [ ]\n}\n"));
|
||||
rc.push_back(jsonFile);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,18 +58,20 @@ struct PluginBaseClasses {
|
||||
// blank separated list or 0
|
||||
const char *dependentModules;
|
||||
const char *targetDirectory;
|
||||
const char *pluginInterface;
|
||||
};
|
||||
|
||||
static const PluginBaseClasses pluginBaseClasses[] =
|
||||
{
|
||||
{ "QAccessiblePlugin", "QtGui", "QtCore", "accessible" },
|
||||
{ "QDecorationPlugin", "QtGui", "QtCore", 0},
|
||||
{ "QIconEnginePluginV2", "QtGui", "QtCore", "imageformats" },
|
||||
{ "QImageIOPlugin", "QtGui", "QtCore", "imageformats" },
|
||||
{ "QScriptExtensionPlugin", "QtScript", "QtCore", 0 },
|
||||
{ "QSqlDriverPlugin", "QtSql", "QtCore", "sqldrivers" },
|
||||
{ "QStylePlugin", "QtGui", "QtCore", "styles" },
|
||||
{ "QTextCodecPlugin", "QtCore", 0, "codecs" }
|
||||
{ "QAccessiblePlugin", "QtGui", "QtCore", "accessible", "QAccessibleFactoryInterface" },
|
||||
{ "QDecorationPlugin", "QtGui", "QtCore", 0, 0 }, // Qt 4 only.
|
||||
{ "QIconEnginePluginV2", "QtGui", "QtCore", "imageformats", 0 }, // Qt 4 only.
|
||||
{ "QIconEnginePlugin", "QtGui", "QtCore", "imageformats", "QIconEngineFactoryInterface" },
|
||||
{ "QImageIOPlugin", "QtGui", "QtCore", "imageformats", "QImageIOHandlerFactoryInterface" },
|
||||
{ "QScriptExtensionPlugin", "QtScript", "QtCore", 0, "QScriptExtensionInterface" },
|
||||
{ "QSqlDriverPlugin", "QtSql", "QtCore", "sqldrivers", "QSqlDriverFactoryInterface" },
|
||||
{ "QStylePlugin", "QtGui", "QtCore", "styles", "QStyleFactoryInterface" },
|
||||
{ "QTextCodecPlugin", "QtCore", 0, "codecs", 0 } // Qt 4 only.
|
||||
};
|
||||
|
||||
enum { defaultPluginBaseClass = 6 };
|
||||
@@ -357,6 +359,14 @@ LibraryParameters LibraryWizardDialog::libraryParameters() const
|
||||
return rc;
|
||||
}
|
||||
|
||||
QString LibraryWizardDialog::pluginInterface(const QString &baseClass)
|
||||
{
|
||||
if (const PluginBaseClasses *plb = findPluginBaseClass(baseClass))
|
||||
if (plb->pluginInterface)
|
||||
return QLatin1String("org.qt-project.Qt.") + QLatin1String(plb->pluginInterface);
|
||||
return QString();
|
||||
}
|
||||
|
||||
MobileLibraryParameters LibraryWizardDialog::mobileLibraryParameters() const
|
||||
{
|
||||
MobileLibraryParameters mlp;
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
LibraryParameters libraryParameters() const;
|
||||
MobileLibraryParameters mobileLibraryParameters() const;
|
||||
|
||||
static QString pluginInterface(const QString &baseClass);
|
||||
|
||||
virtual int nextId() const;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user