Commit bd8ad9e0 authored by hjk's avatar hjk

customwizard: implement modifiers to create safer include guards and class names

parent 30fcdf52
......@@ -3,9 +3,9 @@
#include <QtDeclarative/qdeclarative.h>
void %ProjectName%Plugin::registerTypes(const char *uri)
void %ProjectName:s%Plugin::registerTypes(const char *uri)
{
qmlRegisterType<%ObjectName%>(uri, 1, 0, "%ObjectName%");
}
Q_EXPORT_PLUGIN2(%ProjectName%, %ProjectName%Plugin)
Q_EXPORT_PLUGIN2(%ProjectName:s%, %ProjectName:s%Plugin)
#ifndef %ProjectName:u%_PLUGIN_H
#define %ProjectName:u%_PLUGIN_H
#ifndef %ProjectName:h%_PLUGIN_H
#define %ProjectName:h%_PLUGIN_H
#include <QtDeclarative/QDeclarativeExtensionPlugin>
class %ProjectName%Plugin : public QDeclarativeExtensionPlugin
class %ProjectName:s%Plugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
......@@ -11,4 +11,4 @@ public:
void registerTypes(const char *uri);
};
#endif // %ProjectName:u%_PLUGIN_H
#endif // %ProjectName:h%_PLUGIN_H
......@@ -747,6 +747,38 @@ QString CustomWizardParameters::toString() const
static inline QString passThrough(const QString &in) { return in; }
static inline QString headerGuard(const QString &in)
{
QString result;
foreach (const QChar c, in) {
if (c.isLetterOrNumber())
result.append(c.toUpper());
else
result.append(QLatin1Char('_'));
}
return result;
}
static inline QString structName(const QString &in)
{
bool capNeeded = true;
QString result;
foreach (const QChar c, in) {
if (c.isLetterOrNumber()) {
if (capNeeded) {
result.append(c.toUpper());
capNeeded = false;
} else {
result.append(c);
}
} else {
result.append(QLatin1Char('_'));
capNeeded = true;
}
}
return result;
}
// Do field replacements applying modifiers and string transformation
// for the value
template <class ValueStringTransformation>
......@@ -797,7 +829,13 @@ bool replaceFieldHelper(ValueStringTransformation transform,
case 'u':
replacement = it.value().toUpper();
break;
case 'c': // Capitalize first letter
case 'h': // Create a header guard.
replacement = headerGuard(it.value());
break;
case 's': // Create a struct or class name.
replacement = structName(it.value());
break;
case 'c': // Capitalize first letter.
replacement = it.value();
if (!replacement.isEmpty())
replacement[0] = replacement.at(0).toUpper();
......
......@@ -152,9 +152,13 @@ struct CustomWizardContext {
// Replace field values delimited by '%' with special modifiers:
// %Field% -> simple replacement
// %Field:l% -> lower case replacement, 'u' upper case,
// 'c' capitalize first letter. Return value indicates whether non-empty
// replacements where encountered
// %Field:l% -> replace with everything changed to lower case
// %Field:u% -> replace with everything changed to upper case
// %Field:c% -> replace with first character capitalized
// %Field:h% -> replace with something usable as header guard
// %Field:s% -> replace with something usable as structure or class name
// The return value indicates whether non-empty
// replacements were encountered.
static bool replaceFields(const FieldReplacementMap &fm, QString *s);
// Special replaceFields() overload used for the arguments of a generator
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment