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>bb10
parent
1c8f7082f7
commit
d4079b0797
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ bool Uic::write(QIODevice *in)
|
|||
}
|
||||
|
||||
QString language = ui->attributeLanguage();
|
||||
|
||||
driver()->setUseIdBasedTranslations(ui->attributeIdbasedtr());
|
||||
|
||||
bool rtn = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue