Skip to content
Merged
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
17 changes: 15 additions & 2 deletions code_generation/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Enum::Private
QString mName;
QStringList mEnums;
bool mCombinable = false;
bool mTypedef = false;
bool mIsQENUM = false;
};

Expand Down Expand Up @@ -71,7 +72,10 @@ QString Enum::name() const

void Enum::printDeclaration(Code &code) const
{
code.addLine(QStringLiteral("enum %1 {").arg(d->mName));
if (d->mTypedef)
code.addLine(QStringLiteral("typedef enum {"));
else
code.addLine(QStringLiteral("enum %1 {").arg(d->mName));
code.indent();
auto last = (d->mEnums.count() - 1);
for (int value = 0; value <= last; value++) {
Expand All @@ -88,7 +92,11 @@ void Enum::printDeclaration(Code &code) const
}
}
code.unindent();
code.addLine("};");
if (d->mTypedef)
code.addLine(QString("} %1;").arg(d->mName));
else
code.addLine("};");

if (d->mIsQENUM)
code.addLine(QStringLiteral("Q_ENUM(%1)").arg(d->mName));
code.newLine();
Expand All @@ -98,3 +106,8 @@ void Enum::setIsQENUM(bool qenum)
{
d->mIsQENUM = qenum;
}

void Enum::setTypedef(bool typeDef)
{
d->mTypedef = typeDef;
}
8 changes: 8 additions & 0 deletions code_generation/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class KODE_EXPORT Enum
*/
void setIsQENUM(bool qenum = true);

/**
* @brief setTypedef
* This method can be used to generate typedef for the given enum.
* Using typedefs is mostly useful for C code and not recommended in C++ code.
* @param typeDef
*/
void setTypedef(bool typeDef = true);

private:
class Private;
Private *d;
Expand Down