Version: 1.5.3 (using KDE KDE 3.5.1) Installed from: SuSE RPMs Compiler: gcc 4.1.0 OS: Linux Precondition Two diagrams, - the first shows a package P1 and a class C1 inside this package - the second diagram contains a class C2 as a subclass of C1 Bug In case of making python code generation viewing the first diagram the result of class C2 is "class C2 (C1):", missing the include statement for class C1. The same generation gives a different output when viewing diagram two. Here is the result correct, i.e. "from P1.C1 import * class C2 (C1):" The following patch solves this problem and allows also the usage of the new-style objects (introduced with Python 2.2), simply using "object" as base class. cd umbrello-1.5.3/umbrello/umbrello/codegenerators diff pythonwriter.cpp pythonwriter.cpp_new 91a92,109 > // generate import statement for superclasses and take packages into account > int i = superclasses.count(); > if (cleanName(c->getPackage()) == "") > str = cleanName(c->getName()); > else > str = cleanName(c->getPackage())+"." +cleanName(c->getName()); > QStringList includesList = QStringList(str); //save imported classes > for(UMLClassifier *classifier = superclasses.first(); > classifier && i; classifier = superclasses.next(), i--) { > if (cleanName(classifier->getPackage()) == "") > str = cleanName(classifier->getName()); > else > str = cleanName(classifier->getPackage())+ "." +cleanName(classifier->getName()); > includesList.append(str); > h<<"from "+str +" import *" <<m_endl; > } > > 99,106c117,123 < first = headerName.at(0); < first = first.upper(); < headerName = headerName.replace(0, 1, first); < if (headerName.find('/') > 0) < h<<"from "<<headerName.replace(QChar('/'),QChar('.'))<<" import *"<<m_endl; < else < h<<"from "<<headerName<<" import *"<<m_endl; < } --- > first = headerName.at(0); > first = first.upper(); > headerName = headerName.replace(0, 1, first); > str = headerName.replace(QChar('/'),QChar('.')); > if (includesList.findIndex(str) <0) //not yet imported > h<<"from "<< str <<" import *"<<m_endl; > } 110,111c127,129 < h<<"class "<<classname<<(superclasses.count() > 0 ? " (":""); < int i = superclasses.count(); --- > > h<<"class "<<classname<<(superclasses.count() > 0 ? " (":"(object)"); > i = superclasses.count();
SVN commit 569409 by okellogg: writeClass(): Patch from Egbert Voigt adds missing imports for superclasses. BUG:131790 M +7 -0 ChangeLog M +22 -7 umbrello/codegenerators/pythonwriter.cpp --- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #569408:569409 @@ -1,3 +1,10 @@ +Version 1.5.5 + +* Bugs/wishes from http://bugs.kde.org: +* Java import - importing interfaces - absent visibility treated as package + instead of public (131327) +* Python code generation not independent of diagram view (131790) + Version 1.5.4 * Bugs/wishes from http://bugs.kde.org: --- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/pythonwriter.cpp #569408:569409 @@ -87,7 +87,23 @@ h<<str<<m_endl; } - + // generate import statement for superclasses and take packages into account + str = cleanName(c->getName()); + QString pkg = cleanName(c->getPackage()); + if (!pkg.isEmpty()) + str.prepend(pkg + "."); + QStringList includesList = QStringList(str); //save imported classes + int i = superclasses.count(); + for (UMLClassifier *classifier = superclasses.first(); + classifier && i; classifier = superclasses.next(), i--) { + str = cleanName(classifier->getName()); + pkg = cleanName(classifier->getPackage()); + if (!pkg.isEmpty()) + str.prepend(pkg + "."); + includesList.append(str); + h << "from " + str + " import *" << m_endl; + } + //write includes and take namespaces into account UMLClassifierList includes; findObjectsRelated(c,includes); @@ -99,16 +115,15 @@ first = headerName.at(0); first = first.upper(); headerName = headerName.replace(0, 1, first); - if (headerName.find('/') > 0) - h<<"from "<<headerName.replace(QChar('/'),QChar('.'))<<" import *"<<m_endl; - else - h<<"from "<<headerName<<" import *"<<m_endl; + str = headerName.replace(QChar('/'),QChar('.')); + if (includesList.findIndex(str) < 0) // not yet imported + h << "from " << str << " import *" << m_endl; } } h<<m_endl; - h<<"class "<<classname<<(superclasses.count() > 0 ? " (":""); - int i = superclasses.count(); + h << "class " << classname << (superclasses.count() > 0 ? " (" : "(object)"); + i = superclasses.count(); for (UMLClassifier *obj = superclasses.first(); obj && i; obj = superclasses.next(), i--) {