| 35 | }; |
| 36 | |
| 37 | ConfigOption SourceFileTemplatePrivate::readEntry(const QDomElement& element, |
| 38 | TemplateRenderer* renderer) const |
| 39 | { |
| 40 | ConfigOption entry; |
| 41 | |
| 42 | entry.name = element.attribute(QStringLiteral("name")); |
| 43 | entry.type = element.attribute(QStringLiteral("type"), QStringLiteral("String")); |
| 44 | |
| 45 | bool isDefaultValueSet = false; |
| 46 | for (QDomElement e = element.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { |
| 47 | QString tag = e.tagName(); |
| 48 | |
| 49 | if (tag == QLatin1String("label")) { |
| 50 | entry.label = e.text(); |
| 51 | } else if (tag == QLatin1String("tooltip")) { |
| 52 | if (entry.label.isEmpty()) { |
| 53 | entry.label = e.text(); |
| 54 | } |
| 55 | entry.context = e.text(); |
| 56 | } else if (tag == QLatin1String("whatsthis")) { |
| 57 | if (entry.label.isEmpty()) { |
| 58 | entry.label = e.text(); |
| 59 | } |
| 60 | if (entry.context.isEmpty()) { |
| 61 | entry.context = e.text(); |
| 62 | } |
| 63 | } else if (tag == QLatin1String("min")) { |
| 64 | entry.minValue = e.text(); |
| 65 | } else if (tag == QLatin1String("max")) { |
| 66 | entry.maxValue = e.text(); |
| 67 | } else if (tag == QLatin1String("default")) { |
| 68 | entry.value = renderer->render(e.text(), entry.name); |
| 69 | isDefaultValueSet = true; |
| 70 | } else if (tag == QLatin1String("choices")) { |
| 71 | QStringList values; |
| 72 | QDomNodeList choices = element.elementsByTagName(QStringLiteral("choice")); |
| 73 | values.reserve(choices.size()); |
| 74 | for (int j = 0; j < choices.size(); ++j) { |
| 75 | QDomElement choiceElement = choices.at(j).toElement(); |
| 76 | values << choiceElement.attribute(QStringLiteral("name")); |
| 77 | } |
| 78 | |
| 79 | Q_ASSERT(!values.isEmpty()); |
| 80 | if (values.isEmpty()) { |
| 81 | qCWarning(LANGUAGE) << "Entry " << entry.name << "has an enum without any choices"; |
| 82 | } |
| 83 | entry.values = values; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | qCDebug(LANGUAGE) << "Read entry" << entry.name << "with default value" << entry.value; |
| 88 | |
| 89 | // preset value for enum if needed |
| 90 | if (!entry.values.isEmpty()) { |
| 91 | if (isDefaultValueSet) { |
| 92 | const bool isSaneDefaultValue = entry.values.contains(entry.value.toString()); |
| 93 | Q_ASSERT(isSaneDefaultValue); |
| 94 | if (!isSaneDefaultValue) { |