diff --git a/generator/classgenerator.cpp b/generator/classgenerator.cpp index 5288551..b0032b0 100644 --- a/generator/classgenerator.cpp +++ b/generator/classgenerator.cpp @@ -1388,33 +1388,6 @@ static void writeHelperFunctions(QTextStream &stream, const AbstractMetaClass *m << "}" << endl << endl; } -void writeQtScriptQtBindingsLicense(QTextStream &stream) -{ - stream - << "/****************************************************************************" << endl - << "**" << endl - << "** Copyright (C) 2008 Trolltech ASA. All rights reserved." << endl - << "**" << endl - << "** This file is part of the Qt Script Qt Bindings project on Trolltech Labs." << endl - << "**" << endl - << "** This file may be used under the terms of the GNU General Public" << endl - << "** License version 2.0 as published by the Free Software Foundation" << endl - << "** and appearing in the file LICENSE.GPL included in the packaging of" << endl - << "** this file. Please review the following information to ensure GNU" << endl - << "** General Public Licensing requirements will be met:" << endl - << "** http://www.trolltech.com/products/qt/opensource.html" << endl - << "**" << endl - << "** If you are unsure which license is appropriate for your use, please" << endl - << "** review the following information:" << endl - << "** http://www.trolltech.com/products/qt/licensing.html or contact the" << endl - << "** sales department at sales@trolltech.com." << endl - << "**" << endl - << "** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE" << endl - << "** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE." << endl - << "**" << endl - << "****************************************************************************/" << endl - << endl; -} /*! Finds the functions in \a meta_class that we actually want to @@ -1465,9 +1438,6 @@ static void writeFunctionSignaturesString(QTextStream &s, const AbstractMetaFunc */ void ClassGenerator::write(QTextStream &stream, const AbstractMetaClass *meta_class) { - if (FileOut::license) - writeQtScriptQtBindingsLicense(stream); - // write common includes stream << "#include " << endl; stream << "#include " << endl; diff --git a/generator/prigenerator.cpp b/generator/prigenerator.cpp index d0d4a01..a726227 100644 --- a/generator/prigenerator.cpp +++ b/generator/prigenerator.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "prigenerator.h" +#include "shellgenerator.h" #include "reporthandler.h" #include "fileout.h" @@ -53,6 +54,63 @@ void PriGenerator::addSource(const QString &folder, const QString &source) priHash[folder].sources << source; } +static void collectAndRemoveFile(QTextStream& stream, const QString& file) { + QFile f(file); + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString s = QString::fromLatin1(f.readAll()); + if (file.endsWith(".cpp")) { + // remove first line include + s = s.mid(s.indexOf('\n')+1); + } + stream << s; + f.close(); + QFile::remove(file); + } +} + +static QString combineIncludes(const QString& text) { + QStringList lines = text.split('\n'); + QSet includes; + QString result; + foreach(QString line, lines) { + if (line.startsWith("#include")) { + includes.insert(line); + } else if (line.startsWith("#")) { + // skip preprocessor stuff + } else { + result += line + "\n"; + } + } + QStringList includeList = includes.toList(); + qSort(includeList); + result = includeList.join("\n") + result; + return result; +} + +static QStringList compactFiles(const QStringList& list, const QString& ext, const QString& dir, const QString& prefix) { + QStringList outList; + int count = list.count(); + int fileNum = 0; + while (count>0) { + QString outFileName = prefix + QString::number(fileNum) + ext; + FileOut file(dir + "/" + outFileName); + if (ext == ".cpp") { + file.stream << "#include \"" + prefix + QString::number(fileNum) + ".h\"\n"; + } + outList << outFileName; + QString allText; + QTextStream ts(&allText); + for (int i = 0; i0; i++) { + collectAndRemoveFile(ts, dir + "/" + list.at(list.length()-count)); + count--; + } + allText = combineIncludes(allText); + file.stream << allText; + fileNum++; + } + return outList; +} + void PriGenerator::generate() { QHashIterator pri(priHash); @@ -63,17 +121,30 @@ void PriGenerator::generate() continue; QString folder = pri.key(); - FileOut file(m_out_dir + "/generated_cpp/" + folder + "/" + folder + ".pri"); - file.stream << "HEADERS += \\\n"; + folder.replace('\\','/'); + folder = folder.left(folder.indexOf('/')); + qSort(list.begin(), list.end()); + FileOut file(m_out_dir + "/generated_cpp/" + pri.key()); + + // strange idea to do the file compacting so late, but it is the most effective way without patching the generator a lot + bool compact = true; + if (compact) { + list = compactFiles(list, ".h", m_out_dir + "/generated_cpp/" + folder, folder); + } + + file.stream << "HEADERS += \\\n"; foreach (const QString &entry, list) { - file.stream << " $$PWD/" << entry << " \\\n"; + file.stream << " $$PWD/" << entry << " \\\n"; } file.stream << "\n"; file.stream << "SOURCES += \\\n"; list = pri.value().sources; qSort(list.begin(), list.end()); + if (compact) { + list = compactFiles(list, ".cpp", m_out_dir + "/generated_cpp/" + folder, folder); + } foreach (const QString &entry, list) { file.stream << " $$PWD/" << entry << " \\\n"; } diff --git a/generator/setupgenerator.cpp b/generator/setupgenerator.cpp index 8fb0365..49a14f4 100644 --- a/generator/setupgenerator.cpp +++ b/generator/setupgenerator.cpp @@ -51,8 +51,6 @@ void SetupGenerator::addClass(const AbstractMetaClass *cls) packHash[cls->package()].append(cls); } -void writeQtScriptQtBindingsLicense(QTextStream &stream); - void maybeDeclareMetaType(QTextStream &stream, const QString &typeName, QSet ®isteredTypeNames); bool hasDefaultConstructor(const AbstractMetaClass *meta_class); @@ -113,13 +111,10 @@ void SetupGenerator::generate() FileOut initFile(m_out_dir + "/generated_cpp/" + packName + "/" + packKey + "_init.cpp"); QTextStream &s = initFile.stream; - if (FileOut::license) - writeQtScriptQtBindingsLicense(s); - s << "#include " << endl; - foreach (const AbstractMetaClass *cls, list) { - s << "#include \"" << ShellGenerator::wrapperClassName(cls) << ".h\"" << endl; + for (int i=0; i<(list.count()+MAX_CLASSES_PER_FILE-1) / MAX_CLASSES_PER_FILE; i++) { + s << "#include \"" << packKey << QString::number(i) << ".h\"" << endl; } s << endl; diff --git a/generator/setupgenerator.h b/generator/setupgenerator.h index 9ccb5f0..7d57e0e 100644 --- a/generator/setupgenerator.h +++ b/generator/setupgenerator.h @@ -54,6 +54,10 @@ class SetupGenerator : public Generator void addClass(const AbstractMetaClass *cls); + static void writeInclude(QTextStream &stream, const Include &inc); + + static bool isSpecialStreamingOperator(const AbstractMetaFunction *fun); + private: QStringList writePolymorphicHandler(QTextStream &s, const QString &package, const AbstractMetaClassList &classes); diff --git a/generator/shellgenerator.cpp b/generator/shellgenerator.cpp index 7311f53..e288f9e 100644 --- a/generator/shellgenerator.cpp +++ b/generator/shellgenerator.cpp @@ -342,7 +342,9 @@ bool ShellGenerator::isBuiltIn(const QString& name) { builtIn.insert("QFont"); builtIn.insert("QPixmap"); builtIn.insert("QBrush"); + builtIn.insert("QBitArray"); builtIn.insert("QPalette"); + builtIn.insert("QPen"); builtIn.insert("QIcon"); builtIn.insert("QImage"); builtIn.insert("QPolygon"); @@ -372,3 +374,4 @@ bool ShellGenerator::isBuiltIn(const QString& name) { } return builtIn.contains(name); } + diff --git a/generator/shellgenerator.h b/generator/shellgenerator.h index 3d26a7c..2fa67ca 100644 --- a/generator/shellgenerator.h +++ b/generator/shellgenerator.h @@ -46,6 +46,8 @@ #include "metaqtscript.h" #include "prigenerator.h" +#define MAX_CLASSES_PER_FILE 20 + class ShellGenerator : public Generator { Q_OBJECT @@ -88,7 +90,7 @@ public: static bool isBuiltIn(const QString& name); static bool isSpecialStreamingOperator(const AbstractMetaFunction *fun); - + static void writeInclude(QTextStream &stream, const Include &inc); protected: diff --git a/generator/shellheadergenerator.cpp b/generator/shellheadergenerator.cpp index 29cefda..3db4f4f 100644 --- a/generator/shellheadergenerator.cpp +++ b/generator/shellheadergenerator.cpp @@ -51,15 +51,11 @@ QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_cla return QString("PythonQtWrapper_%1.h").arg(meta_class->name()); } -void writeQtScriptQtBindingsLicense(QTextStream &stream); - void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class) { - - setupGenerator->addClass(meta_class); - - if (FileOut::license) - writeQtScriptQtBindingsLicense(s); + if (!ShellGenerator::isBuiltIn(meta_class->name())) { + setupGenerator->addClass(meta_class); + } QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H"; diff --git a/generator/shellimplgenerator.cpp b/generator/shellimplgenerator.cpp index b602eba..88f71dc 100644 --- a/generator/shellimplgenerator.cpp +++ b/generator/shellimplgenerator.cpp @@ -61,12 +61,8 @@ static void writeHelperCode(QTextStream &s, const AbstractMetaClass *) { } -void writeQtScriptQtBindingsLicense(QTextStream &stream); - void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class) { - if (FileOut::license) - writeQtScriptQtBindingsLicense(s); QString pro_file_name = meta_class->package().replace(".", "_") + "/" + meta_class->package().replace(".", "_") + ".pri";