uic: Add translation-attributes to string list properties.
Task-number: QTBUG-8926 Task-number: QTBUG-20440 Change-Id: I57d92110bf532c717451336bd1943c9571020478 Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>bb10
parent
0f8ad242fb
commit
688d463f4a
|
|
@ -302,6 +302,9 @@ Qt for Windows CE
|
|||
- 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
|
||||
|
||||
|
|
|
|||
|
|
@ -466,11 +466,12 @@ void WriteInitialization::LayoutDefaultHandler::writeProperties(const QString &i
|
|||
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
|
||||
|
|
@ -1128,6 +1129,25 @@ void WriteInitialization::acceptActionRef(DomActionRef *node)
|
|||
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,
|
||||
|
|
@ -1434,15 +1454,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||
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: {
|
||||
|
|
@ -1469,7 +1481,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||
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));
|
||||
|
|
@ -2357,7 +2369,17 @@ QString WriteInitialization::autoTrCall(DomString *str, const QString &defaultSt
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ class DomBrush;
|
|||
class DomFont;
|
||||
class DomResourceIcon;
|
||||
class DomSizePolicy;
|
||||
class DomStringList;
|
||||
struct Option;
|
||||
|
||||
namespace CPP {
|
||||
|
|
@ -176,11 +177,13 @@ private:
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -3479,7 +3479,7 @@ void DomWidget::read(QXmlStreamReader &reader)
|
|||
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());
|
||||
|
|
@ -4853,23 +4853,23 @@ void DomFont::read(QXmlStreamReader &reader)
|
|||
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")) {
|
||||
|
|
@ -4877,7 +4877,7 @@ void DomFont::read(QXmlStreamReader &reader)
|
|||
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);
|
||||
|
|
@ -6028,6 +6028,9 @@ void DomStringList::clear(bool clear_all)
|
|||
|
||||
if (clear_all) {
|
||||
m_text.clear();
|
||||
m_has_attr_notr = false;
|
||||
m_has_attr_comment = false;
|
||||
m_has_attr_extraComment = false;
|
||||
}
|
||||
|
||||
m_children = 0;
|
||||
|
|
@ -6036,6 +6039,9 @@ void DomStringList::clear(bool clear_all)
|
|||
DomStringList::DomStringList()
|
||||
{
|
||||
m_children = 0;
|
||||
m_has_attr_notr = false;
|
||||
m_has_attr_comment = false;
|
||||
m_has_attr_extraComment = false;
|
||||
}
|
||||
|
||||
DomStringList::~DomStringList()
|
||||
|
|
@ -6046,6 +6052,23 @@ 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 : {
|
||||
|
|
@ -6074,6 +6097,15 @@ void DomStringList::write(QXmlStreamWriter &writer, const QString &tagName) cons
|
|||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -2593,6 +2593,21 @@ public:
|
|||
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);
|
||||
|
|
@ -2602,6 +2617,15 @@ private:
|
|||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue