- Assistant
- Designer
+ * [QTBUG-8926] [QTBUG-20440] Properties of type QStringList now have
+ translation attributes which apply to all items.
+ They are by default translatable.
- Linguist
layoutmargins[marginType], suppressMarginDefault, str);
}
-static bool needsTranslation(DomString *str)
+template <class DomElement> // (DomString, DomStringList)
+static bool needsTranslation(const DomElement *element)
{
- if (!str)
+ if (!element)
return false;
- return !str->hasAttributeNotr() || !toBool(str->attributeNotr());
+ return !element->hasAttributeNotr() || !toBool(element->attributeNotr());
}
// --- WriteInitialization
m_actionOut << m_indent << varName << "->addAction(" << actionName << ");\n";
}
+QString WriteInitialization::writeStringListProperty(const DomStringList *list) const
+{
+ QString propertyValue;
+ QTextStream str(&propertyValue);
+ str << "QStringList()";
+ const QStringList values = list->elementString();
+ if (values.isEmpty())
+ return propertyValue;
+ if (needsTranslation(list)) {
+ const QString comment = list->attributeComment();
+ for (int i = 0; i < values.size(); ++i)
+ str << '\n' << m_indent << " << " << trCall(values.at(i), comment);
+ } else {
+ for (int i = 0; i < values.size(); ++i)
+ str << " << QString::fromUtf8(" << fixString(values.at(i), m_dindent) << ')';
+ }
+ return propertyValue;
+}
+
void WriteInitialization::writeProperties(const QString &varName,
const QString &className,
const DomPropertyList &lst,
break;
}
case DomProperty::StringList:
- propertyValue = QLatin1String("QStringList()");
- if (p->elementStringList()->elementString().size()) {
- const QStringList lst = p->elementStringList()->elementString();
- for (int i=0; i<lst.size(); ++i) {
- propertyValue += QLatin1String(" << QString::fromUtf8(");
- propertyValue += fixString(lst.at(i), m_dindent);
- propertyValue += QLatin1Char(')');
- }
- }
+ propertyValue = writeStringListProperty(p->elementStringList());
break;
case DomProperty::Url: {
else if (propertyName == QLatin1String("accessibleName") || propertyName == QLatin1String("accessibleDescription"))
defineC = accessibilityDefineC;
- QTextStream &o = autoTrOutput(p->elementString());
+ QTextStream &o = autoTrOutput(p);
if (defineC)
openIfndef(o, QLatin1String(defineC));
return noTrCall(str, defaultString);
}
-QTextStream &WriteInitialization::autoTrOutput(DomString *str, const QString &defaultString)
+QTextStream &WriteInitialization::autoTrOutput(const DomProperty *property)
+{
+ if (const DomString *str = property->elementString())
+ return autoTrOutput(str);
+ if (const DomStringList *list = property->elementStringList())
+ if (needsTranslation(list))
+ return m_refreshOut;
+ return m_output;
+}
+
+QTextStream &WriteInitialization::autoTrOutput(const DomString *str, const QString &defaultString)
{
if ((!str && !defaultString.isEmpty()) || needsTranslation(str))
return m_refreshOut;
class DomFont;
class DomResourceIcon;
class DomSizePolicy;
+class DomStringList;
struct Option;
namespace CPP {
QString trCall(DomString *str, const QString &defaultString = QString()) const;
QString noTrCall(DomString *str, const QString &defaultString = QString()) const;
QString autoTrCall(DomString *str, const QString &defaultString = QString()) const;
- QTextStream &autoTrOutput(DomString *str, const QString &defaultString = QString());
+ inline QTextStream &autoTrOutput(const DomProperty *str);
+ QTextStream &autoTrOutput(const DomString *str, const QString &defaultString = QString());
// Apply a comma-separated list of values using a function "setSomething(int idx, value)"
void writePropertyList(const QString &varName, const QString &setFunction, const QString &value, const QString &defaultValue);
enum { WritePropertyIgnoreMargin = 1, WritePropertyIgnoreSpacing = 2, WritePropertyIgnoreObjectName = 4 };
+ QString writeStringListProperty(const DomStringList *list) const;
void writeProperties(const QString &varName, const QString &className, const DomPropertyList &lst, unsigned flags = 0);
void writeColorGroup(DomColorGroup *colorGroup, const QString &group, const QString &paletteName);
void writeBrush(const DomBrush *brush, const QString &brushName);
continue;
}
if (name == QStringLiteral("native")) {
- setAttributeNative((attribute.value().toString() == QLatin1String("true") ? true : false));
+ setAttributeNative((attribute.value().toString() == QStringLiteral("true") ? true : false));
continue;
}
reader.raiseError(QStringLiteral("Unexpected attribute ") + name.toString());
continue;
}
if (tag == QStringLiteral("italic")) {
- setElementItalic((reader.readElementText() == QLatin1String("true") ? true : false));
+ setElementItalic((reader.readElementText() == QStringLiteral("true") ? true : false));
continue;
}
if (tag == QStringLiteral("bold")) {
- setElementBold((reader.readElementText() == QLatin1String("true") ? true : false));
+ setElementBold((reader.readElementText() == QStringLiteral("true") ? true : false));
continue;
}
if (tag == QStringLiteral("underline")) {
- setElementUnderline((reader.readElementText() == QLatin1String("true") ? true : false));
+ setElementUnderline((reader.readElementText() == QStringLiteral("true") ? true : false));
continue;
}
if (tag == QStringLiteral("strikeout")) {
- setElementStrikeOut((reader.readElementText() == QLatin1String("true") ? true : false));
+ setElementStrikeOut((reader.readElementText() == QStringLiteral("true") ? true : false));
continue;
}
if (tag == QStringLiteral("antialiasing")) {
- setElementAntialiasing((reader.readElementText() == QLatin1String("true") ? true : false));
+ setElementAntialiasing((reader.readElementText() == QStringLiteral("true") ? true : false));
continue;
}
if (tag == QStringLiteral("stylestrategy")) {
continue;
}
if (tag == QStringLiteral("kerning")) {
- setElementKerning((reader.readElementText() == QLatin1String("true") ? true : false));
+ setElementKerning((reader.readElementText() == QStringLiteral("true") ? true : false));
continue;
}
reader.raiseError(QStringLiteral("Unexpected element ") + tag);
if (clear_all) {
m_text.clear();
+ m_has_attr_notr = false;
+ m_has_attr_comment = false;
+ m_has_attr_extraComment = false;
}
m_children = 0;
DomStringList::DomStringList()
{
m_children = 0;
+ m_has_attr_notr = false;
+ m_has_attr_comment = false;
+ m_has_attr_extraComment = false;
}
DomStringList::~DomStringList()
void DomStringList::read(QXmlStreamReader &reader)
{
+ foreach (const QXmlStreamAttribute &attribute, reader.attributes()) {
+ QStringRef name = attribute.name();
+ if (name == QStringLiteral("notr")) {
+ setAttributeNotr(attribute.value().toString());
+ continue;
+ }
+ if (name == QStringLiteral("comment")) {
+ setAttributeComment(attribute.value().toString());
+ continue;
+ }
+ if (name == QStringLiteral("extracomment")) {
+ setAttributeExtraComment(attribute.value().toString());
+ continue;
+ }
+ reader.raiseError(QStringLiteral("Unexpected attribute ") + name.toString());
+ }
+
for (bool finished = false; !finished && !reader.hasError();) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement : {
{
writer.writeStartElement(tagName.isEmpty() ? QString::fromUtf8("stringlist") : tagName.toLower());
+ if (hasAttributeNotr())
+ writer.writeAttribute(QStringLiteral("notr"), attributeNotr());
+
+ if (hasAttributeComment())
+ writer.writeAttribute(QStringLiteral("comment"), attributeComment());
+
+ if (hasAttributeExtraComment())
+ writer.writeAttribute(QStringLiteral("extracomment"), attributeExtraComment());
+
for (int i = 0; i < m_string.size(); ++i) {
QString v = m_string[i];
writer.writeTextElement(QStringLiteral("string"), v);
inline void setText(const QString &s) { m_text = s; }
// attribute accessors
+ inline bool hasAttributeNotr() const { return m_has_attr_notr; }
+ inline QString attributeNotr() const { return m_attr_notr; }
+ inline void setAttributeNotr(const QString& a) { m_attr_notr = a; m_has_attr_notr = true; }
+ inline void clearAttributeNotr() { m_has_attr_notr = false; }
+
+ inline bool hasAttributeComment() const { return m_has_attr_comment; }
+ inline QString attributeComment() const { return m_attr_comment; }
+ inline void setAttributeComment(const QString& a) { m_attr_comment = a; m_has_attr_comment = true; }
+ inline void clearAttributeComment() { m_has_attr_comment = false; }
+
+ inline bool hasAttributeExtraComment() const { return m_has_attr_extraComment; }
+ inline QString attributeExtraComment() const { return m_attr_extraComment; }
+ inline void setAttributeExtraComment(const QString& a) { m_attr_extraComment = a; m_has_attr_extraComment = true; }
+ inline void clearAttributeExtraComment() { m_has_attr_extraComment = false; }
+
// child element accessors
inline QStringList elementString() const { return m_string; }
void setElementString(const QStringList& a);
void clear(bool clear_all = true);
// attribute data
+ QString m_attr_notr;
+ bool m_has_attr_notr;
+
+ QString m_attr_comment;
+ bool m_has_attr_comment;
+
+ QString m_attr_extraComment;
+ bool m_has_attr_extraComment;
+
// child element data
uint m_children;
QStringList m_string;