summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-12-18 14:13:17 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-01-18 11:31:09 +0000
commitd4079b0797dae46f80d9ada09d43b571749e68dc (patch)
tree821a11f4e9c39284b714a91f3a9da51227e3a1bd
parent1c8f7082f70af934ddc46b9687a88e02233e1082 (diff)
uic: Support id-based translations
Use Ids from newly introduced id attribute depending on the global form setting. Change-Id: I0a5094d5543c0714c88511fa159b60afc9be3c81 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp13
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.h2
-rw-r--r--src/tools/uic/driver.cpp1
-rw-r--r--src/tools/uic/driver.h4
-rw-r--r--src/tools/uic/ui4.cpp21
-rw-r--r--src/tools/uic/ui4.h24
-rw-r--r--src/tools/uic/uic.cpp2
-rw-r--r--tests/auto/tools/uic/baseline/idbased.ui37
-rw-r--r--tests/auto/tools/uic/baseline/idbased.ui.h67
9 files changed, 164 insertions, 7 deletions
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index 86908147d8..9ab5fd4eb0 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -2261,7 +2261,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w)
enableSorting(w, varName, tempName);
}
-QString WriteInitialization::trCall(const QString &str, const QString &commentHint) const
+QString WriteInitialization::trCall(const QString &str, const QString &commentHint, const QString &id) const
{
if (str.isEmpty())
return QLatin1String("QString()");
@@ -2269,8 +2269,9 @@ QString WriteInitialization::trCall(const QString &str, const QString &commentHi
QString result;
const QString comment = commentHint.isEmpty() ? QString(QLatin1String("nullptr")) : fixString(commentHint, m_dindent);
+ const bool idBasedTranslations = m_driver->useIdBasedTranslations();
if (m_option.translateFunction.isEmpty()) {
- if (m_option.idBased) {
+ if (idBasedTranslations || m_option.idBased) {
result += QLatin1String("qtTrId(");
} else {
result += QLatin1String("QApplication::translate(\"")
@@ -2281,9 +2282,9 @@ QString WriteInitialization::trCall(const QString &str, const QString &commentHi
result += m_option.translateFunction + QLatin1Char('(');
}
- result += fixString(str, m_dindent);
+ result += fixString(idBasedTranslations ? id : str, m_dindent);
- if (!m_option.idBased) {
+ if (!idBasedTranslations && !m_option.idBased) {
result += QLatin1String(", ") + comment;
}
@@ -2306,11 +2307,13 @@ QString WriteInitialization::trCall(DomString *str, const QString &defaultString
{
QString value = defaultString;
QString comment;
+ QString id;
if (str) {
value = toString(str);
comment = str->attributeComment();
+ id = str->attributeId();
}
- return trCall(value, comment);
+ return trCall(value, comment, id);
}
QString WriteInitialization::noTrCall(DomString *str, const QString &defaultString) const
diff --git a/src/tools/uic/cpp/cppwriteinitialization.h b/src/tools/uic/cpp/cppwriteinitialization.h
index 64cbde13f7..21116057d4 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.h
+++ b/src/tools/uic/cpp/cppwriteinitialization.h
@@ -144,7 +144,7 @@ private:
QString iconCall(const DomProperty *prop);
QString pixCall(const DomProperty *prop) const;
QString pixCall(const QString &type, const QString &text) const;
- QString trCall(const QString &str, const QString &comment = QString()) const;
+ QString trCall(const QString &str, const QString &comment = QString(), const QString &id = QString()) const;
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;
diff --git a/src/tools/uic/driver.cpp b/src/tools/uic/driver.cpp
index 5f56007f6c..72be667468 100644
--- a/src/tools/uic/driver.cpp
+++ b/src/tools/uic/driver.cpp
@@ -251,6 +251,7 @@ bool Driver::printDependencies(const QString &fileName)
bool Driver::uic(const QString &fileName, DomUI *ui, QTextStream *out)
{
m_option.inputFile = fileName;
+ setUseIdBasedTranslations(ui->attributeIdbasedtr());
QTextStream *oldOutput = m_output;
diff --git a/src/tools/uic/driver.h b/src/tools/uic/driver.h
index 56de89aa05..41c1572860 100644
--- a/src/tools/uic/driver.h
+++ b/src/tools/uic/driver.h
@@ -103,6 +103,9 @@ public:
void insertPixmap(const QString &pixmap);
bool containsPixmap(const QString &pixmap) const;
+ bool useIdBasedTranslations() const { return m_idBasedTranslations; }
+ void setUseIdBasedTranslations(bool u) { m_idBasedTranslations = u; }
+
private:
Option m_option;
QTextStream m_stdout;
@@ -120,6 +123,7 @@ private:
QHash<DomAction*, QString> m_actions;
QHash<QString, bool> m_nameRepository;
QHash<QString, bool> m_pixmaps;
+ bool m_idBasedTranslations = false;
};
QT_END_NAMESPACE
diff --git a/src/tools/uic/ui4.cpp b/src/tools/uic/ui4.cpp
index bc1039871e..7a1d755bb4 100644
--- a/src/tools/uic/ui4.cpp
+++ b/src/tools/uic/ui4.cpp
@@ -72,6 +72,10 @@ void DomUI::read(QXmlStreamReader &reader)
setAttributeDisplayname(attribute.value().toString());
continue;
}
+ if (name == QLatin1String("idbasedtr")) {
+ setAttributeIdbasedtr(attribute.value() == QLatin1String("true"));
+ continue;
+ }
if (name == QLatin1String("stdsetdef")) {
setAttributeStdsetdef(attribute.value().toInt());
continue;
@@ -202,6 +206,9 @@ void DomUI::write(QXmlStreamWriter &writer, const QString &tagName) const
if (hasAttributeDisplayname())
writer.writeAttribute(QStringLiteral("displayname"), attributeDisplayname());
+ if (hasAttributeIdbasedtr())
+ writer.writeAttribute(QStringLiteral("idbasedtr"), (attributeIdbasedtr() ? QLatin1String("true") : QLatin1String("false")));
+
if (hasAttributeStdsetdef())
writer.writeAttribute(QStringLiteral("stdsetdef"), QString::number(attributeStdsetdef()));
@@ -4027,6 +4034,10 @@ void DomStringList::read(QXmlStreamReader &reader)
setAttributeExtraComment(attribute.value().toString());
continue;
}
+ if (name == QLatin1String("id")) {
+ setAttributeId(attribute.value().toString());
+ continue;
+ }
reader.raiseError(QLatin1String("Unexpected attribute ") + name);
}
@@ -4062,6 +4073,9 @@ void DomStringList::write(QXmlStreamWriter &writer, const QString &tagName) cons
if (hasAttributeExtraComment())
writer.writeAttribute(QStringLiteral("extracomment"), attributeExtraComment());
+ if (hasAttributeId())
+ writer.writeAttribute(QStringLiteral("id"), attributeId());
+
for (const QString &v : m_string)
writer.writeTextElement(QStringLiteral("string"), v);
@@ -4461,6 +4475,10 @@ void DomString::read(QXmlStreamReader &reader)
setAttributeExtraComment(attribute.value().toString());
continue;
}
+ if (name == QLatin1String("id")) {
+ setAttributeId(attribute.value().toString());
+ continue;
+ }
reader.raiseError(QLatin1String("Unexpected attribute ") + name);
}
@@ -4496,6 +4514,9 @@ void DomString::write(QXmlStreamWriter &writer, const QString &tagName) const
if (hasAttributeExtraComment())
writer.writeAttribute(QStringLiteral("extracomment"), attributeExtraComment());
+ if (hasAttributeId())
+ writer.writeAttribute(QStringLiteral("id"), attributeId());
+
if (!m_text.isEmpty())
writer.writeCharacters(m_text);
diff --git a/src/tools/uic/ui4.h b/src/tools/uic/ui4.h
index 08a5ed01d5..1710147342 100644
--- a/src/tools/uic/ui4.h
+++ b/src/tools/uic/ui4.h
@@ -164,6 +164,11 @@ public:
inline void setAttributeDisplayname(const QString &a) { m_attr_displayname = a; m_has_attr_displayname = true; }
inline void clearAttributeDisplayname() { m_has_attr_displayname = false; }
+ inline bool hasAttributeIdbasedtr() const { return m_has_attr_idbasedtr; }
+ inline bool attributeIdbasedtr() const { return m_attr_idbasedtr; }
+ inline void setAttributeIdbasedtr(bool a) { m_attr_idbasedtr = a; m_has_attr_idbasedtr = true; }
+ inline void clearAttributeIdbasedtr() { m_has_attr_idbasedtr = false; }
+
inline bool hasAttributeStdsetdef() const { return m_has_attr_stdsetdef; }
inline int attributeStdsetdef() const { return m_attr_stdsetdef; }
inline void setAttributeStdsetdef(int a) { m_attr_stdsetdef = a; m_has_attr_stdsetdef = true; }
@@ -277,6 +282,9 @@ private:
QString m_attr_displayname;
bool m_has_attr_displayname = false;
+ bool m_attr_idbasedtr = false;
+ bool m_has_attr_idbasedtr = false;
+
int m_attr_stdsetdef = 0;
bool m_has_attr_stdsetdef = false;
@@ -2056,6 +2064,11 @@ public:
inline void setAttributeExtraComment(const QString &a) { m_attr_extraComment = a; m_has_attr_extraComment = true; }
inline void clearAttributeExtraComment() { m_has_attr_extraComment = false; }
+ inline bool hasAttributeId() const { return m_has_attr_id; }
+ inline QString attributeId() const { return m_attr_id; }
+ inline void setAttributeId(const QString &a) { m_attr_id = a; m_has_attr_id = true; }
+ inline void clearAttributeId() { m_has_attr_id = false; }
+
// child element accessors
inline QStringList elementString() const { return m_string; }
void setElementString(const QStringList &a);
@@ -2071,6 +2084,9 @@ private:
QString m_attr_extraComment;
bool m_has_attr_extraComment = false;
+ QString m_attr_id;
+ bool m_has_attr_id = false;
+
// child element data
uint m_children = 0;
QStringList m_string;
@@ -2247,6 +2263,11 @@ public:
inline void setAttributeExtraComment(const QString &a) { m_attr_extraComment = a; m_has_attr_extraComment = true; }
inline void clearAttributeExtraComment() { m_has_attr_extraComment = false; }
+ inline bool hasAttributeId() const { return m_has_attr_id; }
+ inline QString attributeId() const { return m_attr_id; }
+ inline void setAttributeId(const QString &a) { m_attr_id = a; m_has_attr_id = true; }
+ inline void clearAttributeId() { m_has_attr_id = false; }
+
private:
QString m_text;
@@ -2259,6 +2280,9 @@ private:
QString m_attr_extraComment;
bool m_has_attr_extraComment = false;
+
+ QString m_attr_id;
+ bool m_has_attr_id = false;
};
class QDESIGNER_UILIB_EXPORT DomPointF {
diff --git a/src/tools/uic/uic.cpp b/src/tools/uic/uic.cpp
index 48756db651..8e4709c831 100644
--- a/src/tools/uic/uic.cpp
+++ b/src/tools/uic/uic.cpp
@@ -198,7 +198,7 @@ bool Uic::write(QIODevice *in)
}
QString language = ui->attributeLanguage();
-
+ driver()->setUseIdBasedTranslations(ui->attributeIdbasedtr());
bool rtn = false;
diff --git a/tests/auto/tools/uic/baseline/idbased.ui b/tests/auto/tools/uic/baseline/idbased.ui
new file mode 100644
index 0000000000..f4db5139c8
--- /dev/null
+++ b/tests/auto/tools/uic/baseline/idbased.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0" idbasedtr="true">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string id="windowTitleId">Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="toolTip">
+ <string id="buttonToolTipId">ButtonToolTip</string>
+ </property>
+ <property name="statusTip">
+ <string id="buttonStatusTipId">ButtonStatusTip</string>
+ </property>
+ <property name="whatsThis">
+ <string id="buttonWhatsThisId">ButtonWhatsThis</string>
+ </property>
+ <property name="text">
+ <string id="buttonTextId">PushButton</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/auto/tools/uic/baseline/idbased.ui.h b/tests/auto/tools/uic/baseline/idbased.ui.h
new file mode 100644
index 0000000000..dbcd92a839
--- /dev/null
+++ b/tests/auto/tools/uic/baseline/idbased.ui.h
@@ -0,0 +1,67 @@
+/********************************************************************************
+** Form generated from reading UI file 'idbased.ui'
+**
+** Created by: Qt User Interface Compiler version 5.11.0
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef IDBASED_H
+#define IDBASED_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QVBoxLayout>
+#include <QtWidgets/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_Form
+{
+public:
+ QVBoxLayout *verticalLayout;
+ QPushButton *pushButton;
+
+ void setupUi(QWidget *Form)
+ {
+ if (Form->objectName().isEmpty())
+ Form->setObjectName(QStringLiteral("Form"));
+ Form->resize(400, 300);
+ verticalLayout = new QVBoxLayout(Form);
+ verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+ pushButton = new QPushButton(Form);
+ pushButton->setObjectName(QStringLiteral("pushButton"));
+
+ verticalLayout->addWidget(pushButton);
+
+
+ retranslateUi(Form);
+
+ QMetaObject::connectSlotsByName(Form);
+ } // setupUi
+
+ void retranslateUi(QWidget *Form)
+ {
+ Form->setWindowTitle(qtTrId("windowTitleId"));
+#ifndef QT_NO_TOOLTIP
+ pushButton->setToolTip(qtTrId("buttonToolTipId"));
+#endif // QT_NO_TOOLTIP
+#ifndef QT_NO_STATUSTIP
+ pushButton->setStatusTip(qtTrId("buttonStatusTipId"));
+#endif // QT_NO_STATUSTIP
+#ifndef QT_NO_WHATSTHIS
+ pushButton->setWhatsThis(qtTrId("buttonWhatsThisId"));
+#endif // QT_NO_WHATSTHIS
+ pushButton->setText(qtTrId("buttonTextId"));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class Form: public Ui_Form {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // IDBASED_H