Skip to content

Commit cc3f68e

Browse files
committed
The algorithm that derived the package name for the init code...
did not really work well for package names that didn't start with com.trolltech., thus we modified this part a little bit to suit our needs
1 parent 8adca73 commit cc3f68e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

generator/setupgenerator.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ static void addListRegistration(AbstractMetaType::shared_pointer type, QSet<QStr
218218
}
219219
}
220220

221+
namespace {
222+
QStringList capitalize(QStringList parts)
223+
{
224+
for (QString& p : parts) {
225+
if (p.length() > 0) {
226+
p[0] = p[0].toUpper();
227+
}
228+
}
229+
return parts;
230+
}
231+
}
232+
221233
void SetupGenerator::generate()
222234
{
223235
AbstractMetaClassList classes_with_polymorphic_id;
@@ -245,9 +257,19 @@ void SetupGenerator::generate()
245257

246258
QString packKey = ShellGenerator::toFileNameBase(pack.key());
247259
QString packName = packKey;
248-
QString qtPackageName = "Qt" + pack.key().split('.').back().split('_').front();
249-
bool isBuiltin = packKey.endsWith("_builtin");
250-
QString initName = qtPackageName + (isBuiltin ? "Builtin" : "");
260+
QString packageName = pack.key();
261+
QString trolltechPrefix = "com.trolltech.";
262+
if (packageName.startsWith(trolltechPrefix)) {
263+
// remove this prefix
264+
packageName = packageName.mid(trolltechPrefix.length());
265+
}
266+
packageName = capitalize(packageName.split('.')).join("");
267+
bool isBuiltin = packageName.endsWith("_builtin");
268+
if (isBuiltin) {
269+
// remove trailing _builtin from packageName:
270+
packageName = packageName.left(packageName.length() - 8);
271+
}
272+
QString initName = packageName + (isBuiltin ? "Builtin" : "");
251273

252274
{
253275
QString fileName(packName + "/" + packKey + "_init.cpp");
@@ -336,12 +358,12 @@ void SetupGenerator::generate()
336358
operatorCodes = "0";
337359
}
338360
if (cls->isQObject()) {
339-
s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << qtPackageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
361+
s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << packageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
340362
} else if (cls->isGlobalNamespace()) {
341-
s << "PythonQt::priv()->registerGlobalNamespace(\"" << cls->qualifiedCppName() << "\", \"" << qtPackageName << "\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">, PythonQtWrapper_" << cls->name() << "::staticMetaObject, module); " << endl;
363+
s << "PythonQt::priv()->registerGlobalNamespace(\"" << cls->qualifiedCppName() << "\", \"" << packageName << "\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">, PythonQtWrapper_" << cls->name() << "::staticMetaObject, module); " << endl;
342364
} else {
343365
QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():"";
344-
s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << qtPackageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
366+
s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << packageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
345367
}
346368
for (AbstractMetaClass* interface : cls->interfaces()) {
347369
// the interface might be our own class... (e.g. QPaintDevice)

0 commit comments

Comments
 (0)