Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions generator/abstractmetalang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void AbstractMetaClass::setFunctions(const AbstractMetaFunctionList& functions)
bool AbstractMetaClass::hasFieldAccessors() const
{
for (const AbstractMetaField* field : fields()) {
if (field->getter() || field->setter())
if (field->isPublic() && (field->getter() || field->setter()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not used, why not just remove it?

return true;
}

Expand Down Expand Up @@ -1154,8 +1154,10 @@ bool AbstractMetaClass::hasProtectedFunctions() const
bool AbstractMetaClass::generateShellClass() const
{
return typeEntry()->shouldCreateShell()
// require that classes that get a shell have a virtual destructor
// (required for proper working of derived class)
&& (m_force_shell_class
|| (!isFinal() && (hasVirtualFunctions() || hasProtectedFunctions() || hasFieldAccessors())));
|| (!isFinal() && hasVirtualDestructor() && (hasVirtualFunctions() || hasProtectedConstructors())));
}

QPropertySpec* AbstractMetaClass::propertySpecForRead(const QString& name) const
Expand Down Expand Up @@ -1315,6 +1317,11 @@ bool AbstractMetaClass::hasConstructors() const
return queryFunctions(Constructors).size() != 0;
}

bool AbstractMetaClass::hasProtectedConstructors() const
{
return queryFunctions(Constructors | WasProtected).size() != 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size() != 0 is a bit strange. I would expect size() > 0, or better !isEmpty().
A matter of taste, I guess...

}

void AbstractMetaClass::addDefaultConstructor()
{
AbstractMetaFunction* f = new AbstractMetaFunction;
Expand Down
1 change: 1 addition & 0 deletions generator/abstractmetalang.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ class AbstractMetaClass : public AbstractMetaAttributes
bool hasSignal(const AbstractMetaFunction* f) const;

bool hasConstructors() const;
bool hasProtectedConstructors() const;

void addDefaultConstructor();

Expand Down
10 changes: 5 additions & 5 deletions generator/shellheadergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
}

// Shell-------------------------------------------------------------------
if (meta_class->generateShellClass() && !ctors.isEmpty()) {
bool generateShell = meta_class->generateShellClass() && !ctors.isEmpty();
if (generateShell) {

AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class);

Expand Down Expand Up @@ -348,12 +349,12 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
}
}
s << "public Q_SLOTS:" << Qt::endl;
if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
if (generateShell || !meta_class->isAbstract()) {

bool copyConstructorSeen = false;
bool defaultConstructorSeen = false;
for (const AbstractMetaFunction* fun : ctors) {
if (fun->isAbstract() || (!meta_class->generateShellClass() && !fun->isPublic())) {
if (fun->isAbstract() || (!generateShell && !fun->isPublic())) {
continue;
}

Expand All @@ -373,8 +374,7 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
if (meta_class->typeEntry()->isValue() && !copyConstructorSeen && defaultConstructorSeen
&& !meta_class->typeEntry()->hasNoCopy())
{
QString className =
meta_class->generateShellClass() ? shellClassName(meta_class) : meta_class->qualifiedCppName();
QString className = generateShell ? shellClassName(meta_class) : meta_class->qualifiedCppName();
s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const "
<< meta_class->qualifiedCppName() << "& other) {" << Qt::endl;
s << className << "* a = new " << className << "();" << Qt::endl;
Expand Down
8 changes: 3 additions & 5 deletions generator/shellimplgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ void ShellImplGenerator::write(QTextStream& s, const AbstractMetaClass* meta_cla
}
}

if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
if (generateShell || !meta_class->isAbstract()) {

// write constructors
for (const AbstractMetaFunction* ctor : ctors) {
if (ctor->isAbstract() || (!meta_class->generateShellClass() && !ctor->isPublic())) {
if (ctor->isAbstract() || (!generateShell && !ctor->isPublic())) {
continue;
}

Expand All @@ -241,8 +241,7 @@ void ShellImplGenerator::write(QTextStream& s, const AbstractMetaClass* meta_cla
writeFunctionSignature(s, ctor, 0, "new_", Option(AddOwnershipTemplates | ShowStatic));
s << Qt::endl;
s << "{ " << Qt::endl;
s << "return new "
<< (meta_class->generateShellClass() ? shellClassName(meta_class) : meta_class->qualifiedCppName()) << "(";
s << "return new " << (generateShell ? shellClassName(meta_class) : meta_class->qualifiedCppName()) << "(";
AbstractMetaArgumentList args = ctor->arguments();
for (int i = 0; i < args.size(); ++i) {
if (i > 0)
Expand Down Expand Up @@ -333,7 +332,6 @@ void ShellImplGenerator::write(QTextStream& s, const AbstractMetaClass* meta_cla
}
} else {
if (fun->wasProtected()) {
//|| (fun->isVirtual() && meta_class->typeEntry()->shouldCreatePromoter())) {
s << " ((" << promoterClassName(meta_class) << "*)theWrappedObject)->promoted_";
} else {
s << " theWrappedObject->";
Expand Down
Loading