Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
recorddirectory.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef RECORDDIRECTORY_H
5#define RECORDDIRECTORY_H
6
7#include <QHash>
8#include <QMap>
9#include <QSet>
10#include <QString>
11
12#include <map>
13#include <memory>
14#include <unordered_set>
15#include <set>
16
17QT_BEGIN_NAMESPACE
18
19class TranslatorMessage;
20
21using namespace Qt::StringLiterals;
22
23extern const char *meta_id_key;
24struct MessageItem
25{
30 int lineNo = 0;
31 int startOffset = 0;
32 int endOffset = 0;
33 bool plural = 0;
34 bool hasMetaId = 0;
35 bool operator==(const MessageItem &mi) const noexcept
36 {
37 return sourceText == mi.sourceText && context == mi.context && comment == mi.comment;
38 }
39};
40
42{
43 bool operator()(const std::shared_ptr<MessageItem> &lhs,
44 const std::shared_ptr<MessageItem> &rhs) const noexcept
45 {
46 if (lhs->lineNo != rhs->lineNo)
47 return lhs->lineNo < rhs->lineNo;
48 else
49 return lhs->startOffset < rhs->endOffset;
50 }
51};
52
53QT_END_NAMESPACE
54
55namespace std {
56template <>
58{
59 std::size_t operator()(const MessageItem &key) const
60 {
61 std::size_t h1 = qHash(key.context);
62 std::size_t h2 = qHash(key.sourceText);
63 std::size_t h3 = qHash(key.comment);
64 return h1 ^ (h2 << 1) ^ (h3 << 2);
65 }
66};
67} // namespace std
68
69QT_BEGIN_NAMESPACE
70
71class RecordDirectory
72{
73public:
74 using MsgLocations = QHash<QString, std::set<std::shared_ptr<MessageItem>, MsgPtrComp>>;
75 using ErrorLocations = QHash<QString, QMap<int, QString>>;
76
77 void recordMessage(const TranslatorMessage &msg);
78 QString id(const TranslatorMessage &msg) const;
79 void recordExistingId(const QString &id);
80 void recordError(const QString &file, int line, const QString &error);
81 void recordNonSupported(const QString &file, int line) { m_nonSupporteds[file].insert(line); }
82 void recordAddedLines(const QString &file, int fromLine, int addedLines);
83 bool isNonSupported(const QString &file, int line) const
84 {
85 return m_nonSupporteds[file].contains(line);
86 }
87 int addedLines(const QString &file, int line) const;
88 bool containsFile(const QString &filename) const noexcept;
89 const MsgLocations &messageLocations() const noexcept { return m_msgLocations; }
90 const ErrorLocations &errors() const noexcept { return m_errors; }
91 QString calculateId(const TranslatorMessage &msg) const;
92 ;
93
94private:
95 std::unordered_set<MessageItem> m_messages;
96 MsgLocations m_msgLocations;
97 QHash<QString, QSet<int>> m_nonSupporteds;
98 ErrorLocations m_errors;
99 std::unordered_map<QString, std::map<int, int>> m_fileAddedLines;
100 std::unordered_set<QString> m_existingIds;
101};
102
103QT_END_NAMESPACE
104
105#endif // RECORDDIRECTORY_H
bool m_sourceIsUtf16
Definition translator.h:44
bool transformTsFiles(const QStringList &translations, bool sortMessages)
FileTransformer(RecordDirectory &records, bool labels, bool quiet)
bool updateTsFiles(const QStringList &translations)
static const QSet< QString > otherExtensions
static const QSet< QString > cppExtensions
void verifySources(const QStringList &sources, ConversionData &cd)
FileVerifier(const RecordDirectory &records, bool quiet)
bool verifyTs(const QString &tsFile, QSet< QString > &transformedIds)
QString sourceText
bool operator==(const MessageItem &mi) const noexcept
Combined button and popup list for selecting options.
QStringList readLines(const QString &filename)
Definition utils.cpp:54
void printOut(const QString &out)
Definition utils.cpp:22
void printErr(const QString &out)
Definition utils.cpp:17
void writeLines(const QString &filename, const QStringList &lines)
Definition utils.cpp:65
QString getIndentation(const QString &line)
Definition utils.cpp:43
QMultiHash< QString, QString > getIncludeOptions(const QFileInfo &root, const QStringList &paths)
Definition utils.cpp:27
const char * meta_id_key
int main(int argc, char *argv[])
[ctor_close]
bool operator()(const std::shared_ptr< MessageItem > &lhs, const std::shared_ptr< MessageItem > &rhs) const noexcept
std::size_t operator()(const MessageItem &key) const