2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "libraryparameters.h"
|
2013-02-12 14:02:07 +01:00
|
|
|
#include "librarywizarddialog.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
#include <utils/codegeneration.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QStringList>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Contents of the header defining the shared library export.
|
|
|
|
|
#define GUARD_VARIABLE "<GUARD>"
|
|
|
|
|
#define EXPORT_MACRO_VARIABLE "<EXPORT_MACRO>"
|
|
|
|
|
#define LIBRARY_MACRO_VARIABLE "<LIBRARY_MACRO>"
|
|
|
|
|
|
|
|
|
|
static const char *globalHeaderContentsC =
|
2011-11-22 15:50:49 +01:00
|
|
|
"#ifndef " GUARD_VARIABLE "\n"
|
|
|
|
|
"#define " GUARD_VARIABLE "\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
"\n"
|
|
|
|
|
"#include <QtCore/qglobal.h>\n"
|
|
|
|
|
"\n"
|
2011-11-22 15:50:49 +01:00
|
|
|
"#if defined(" LIBRARY_MACRO_VARIABLE ")\n"
|
|
|
|
|
"# define " EXPORT_MACRO_VARIABLE " Q_DECL_EXPORT\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
"#else\n"
|
2011-11-22 15:50:49 +01:00
|
|
|
"# define " EXPORT_MACRO_VARIABLE " Q_DECL_IMPORT\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
"#endif\n"
|
|
|
|
|
"\n"
|
2011-11-22 15:50:49 +01:00
|
|
|
"#endif // " GUARD_VARIABLE "\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
void LibraryParameters::generateCode(QtProjectParameters:: Type t,
|
|
|
|
|
const QString &projectTarget,
|
|
|
|
|
const QString &headerName,
|
|
|
|
|
const QString &sharedHeader,
|
|
|
|
|
const QString &exportMacro,
|
2013-02-12 14:02:07 +01:00
|
|
|
const QString &pluginJsonFileName,
|
2008-12-02 12:01:29 +01:00
|
|
|
int indentation,
|
|
|
|
|
QString *header,
|
|
|
|
|
QString *source) const
|
|
|
|
|
{
|
|
|
|
|
QString rc;
|
|
|
|
|
QTextStream headerStr(header);
|
|
|
|
|
|
|
|
|
|
const QString indent = QString(indentation, QLatin1Char(' '));
|
|
|
|
|
|
2011-01-18 12:18:08 +01:00
|
|
|
// Do we have namespaces?
|
|
|
|
|
QStringList namespaceList = className.split(QLatin1String("::"));
|
|
|
|
|
if (namespaceList.empty()) // Paranoia!
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QString unqualifiedClassName = namespaceList.takeLast();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// 1) Header
|
2011-01-18 12:18:08 +01:00
|
|
|
const QString guard = Utils::headerGuard(headerFileName, namespaceList);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << "#ifndef " << guard
|
|
|
|
|
<< "\n#define " << guard << '\n' << '\n';
|
|
|
|
|
|
|
|
|
|
if (!sharedHeader.isEmpty())
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeIncludeFileDirective(sharedHeader, false, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// include base class header
|
|
|
|
|
if (!baseClassName.isEmpty()) {
|
2013-02-11 12:41:34 +01:00
|
|
|
Utils::writeIncludeFileDirective(baseClassName, true, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << '\n';
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, indent, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Class declaraction
|
|
|
|
|
headerStr << '\n' << namespaceIndent << "class ";
|
|
|
|
|
if (t == QtProjectParameters::SharedLibrary && !exportMacro.isEmpty())
|
|
|
|
|
headerStr << exportMacro << ' ';
|
|
|
|
|
|
|
|
|
|
headerStr << unqualifiedClassName;
|
|
|
|
|
if (!baseClassName.isEmpty())
|
|
|
|
|
headerStr << " : public " << baseClassName;
|
2012-01-09 16:41:32 +01:00
|
|
|
headerStr << "\n{\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Is this a QObject (plugin)
|
|
|
|
|
const bool inheritsQObject = t == QtProjectParameters::Qt4Plugin;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (inheritsQObject)
|
2009-06-09 13:50:37 +02:00
|
|
|
headerStr << namespaceIndent << indent << "Q_OBJECT\n";
|
2013-02-12 14:02:07 +01:00
|
|
|
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";
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (inheritsQObject)
|
2009-06-09 15:52:58 +02:00
|
|
|
headerStr << namespaceIndent << indent << unqualifiedClassName << "(QObject *parent = 0);\n";
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << namespaceIndent << indent << unqualifiedClassName << "();\n";
|
|
|
|
|
headerStr << namespaceIndent << "};\n\n";
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeClosingNameSpaces(namespaceList, indent, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << "#endif // "<< guard << '\n';
|
|
|
|
|
/// 2) Source
|
|
|
|
|
QTextStream sourceStr(source);
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeIncludeFileDirective(headerName, false, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << '\n';
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeOpeningNameSpaces(namespaceList, indent, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
// Constructor
|
|
|
|
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName;
|
|
|
|
|
if (inheritsQObject) {
|
|
|
|
|
sourceStr << "(QObject *parent) :\n"
|
|
|
|
|
<< namespaceIndent << indent << baseClassName << "(parent)\n";
|
|
|
|
|
} else {
|
|
|
|
|
sourceStr << "()\n";
|
|
|
|
|
}
|
|
|
|
|
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-02-12 14:02:07 +01:00
|
|
|
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";
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString LibraryParameters::generateSharedHeader(const QString &globalHeaderFileName,
|
|
|
|
|
const QString &projectTarget,
|
|
|
|
|
const QString &exportMacro)
|
|
|
|
|
{
|
|
|
|
|
QString contents = QLatin1String(globalHeaderContentsC);
|
2009-10-05 11:06:05 +02:00
|
|
|
contents.replace(QLatin1String(GUARD_VARIABLE), Utils::headerGuard(globalHeaderFileName));
|
2008-12-02 12:01:29 +01:00
|
|
|
contents.replace(QLatin1String(EXPORT_MACRO_VARIABLE), exportMacro);
|
|
|
|
|
contents.replace(QLatin1String(LIBRARY_MACRO_VARIABLE), QtProjectParameters::libraryMacro(projectTarget));
|
|
|
|
|
return contents;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|