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