7#include <QtCore/QCoreApplication>
8#include <QtCore/QDebug>
10#include <QtCore/QString>
11#include <QtCore/QXmlStreamReader>
15using namespace Qt::StringLiterals;
22 m_translator(translator),
26 m_insideStringList(
false)
33 QStringView qName,
const QXmlStreamAttributes &atts)
override;
34 bool endElement(QStringView namespaceURI, QStringView localName,
35 QStringView qName)
override;
37 bool fatalError(qint64 line, qint64 column,
const QString &message)
override;
40 void readTranslationAttributes(
const QXmlStreamAttributes &atts);
47 QString m_extracomment;
54 bool m_insideStringList;
58 QStringView qName,
const QXmlStreamAttributes &atts)
60 Q_UNUSED(namespaceURI);
63 if (qName ==
"string"_L1) {
65 if (!m_insideStringList)
66 readTranslationAttributes(atts);
67 }
else if (qName ==
"stringlist"_L1) {
69 m_insideStringList =
true;
70 readTranslationAttributes(atts);
71 }
else if (qName ==
"ui"_L1) {
72 m_label = QString(atts.value(
"label"));
81 Q_UNUSED(namespaceURI);
84 m_accum.replace(
"\r\n"_L1,
"\n"_L1);
86 if (qName ==
"class"_L1) {
87 if (m_context.isEmpty())
89 }
else if (qName ==
"string"_L1 && m_isTrString) {
91 }
else if (qName ==
"comment"_L1) {
94 }
else if (qName ==
"stringlist"_L1) {
95 m_insideStringList =
false;
104 m_accum += ch.toString();
110 QString msg = QStringLiteral(
"XML error: Parse error at line %1, column %2 (%3).")
114 m_cd.appendError(msg);
120 if ((!m_context.isEmpty() || !m_id.isEmpty()) && !m_source.isEmpty()) {
122 m_comment, QString(), m_cd.m_sourceFileName,
123 m_lineNumber, QStringList());
124 msg.setExtraComment(m_extracomment);
125 msg.setLabel(m_label);
132 if (!m_insideStringList) {
134 m_extracomment.clear();
139void UiReader::readTranslationAttributes(
const QXmlStreamAttributes &atts)
141 const auto notr = atts.value(QStringLiteral(
"notr"));
142 if (notr.isEmpty() || notr != QStringLiteral(
"true")) {
144 m_comment = atts.value(QStringLiteral(
"comment")).toString();
145 m_extracomment = atts.value(QStringLiteral(
"extracomment")).toString();
146 m_id = atts.value(QStringLiteral(
"id")).toString();
149 if (!m_cd.m_noUiLines)
150 m_lineNumber =
static_cast<
int>(reader.lineNumber());
152 m_isTrString =
false;
158 cd.m_sourceFileName = filename;
159 QFile file(filename);
160 if (!file.open(QIODevice::ReadOnly)) {
161 cd.appendError(
"Cannot open %1: %2"_L1.arg(filename, file.errorString()));
165 QXmlStreamReader reader(&file);
166 reader.setNamespaceProcessing(
false);
168 UiReader uiReader(translator, cd, reader);
169 bool result = uiReader
.parse();
171 cd.appendError(u"Parse error in UI file"_s);
void extend(const TranslatorMessage &msg, ConversionData &cd)
UiReader(Translator &translator, ConversionData &cd, QXmlStreamReader &reader)
bool fatalError(qint64 line, qint64 column, const QString &message) override
bool startElement(QStringView namespaceURI, QStringView localName, QStringView qName, const QXmlStreamAttributes &atts) override
bool endElement(QStringView namespaceURI, QStringView localName, QStringView qName) override
bool characters(QStringView ch) override
~UiReader() override=default
Combined button and popup list for selecting options.
bool loadUI(Translator &translator, const QString &filename, ConversionData &cd)