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
machinetranslator.h
Go to the documentation of this file.
1#ifndef MACHINETRANSLATOR_H
2// Copyright (C) 2025 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
4
5#define MACHINETRANSLATOR_H
6
8
9#include <QString>
10#include <QObject>
11#include <QQueue>
12#include <QMutex>
13
15
16class QNetworkRequest;
17class QNetworkAccessManager;
18class QNetworkReply;
19
21{
23public:
26
27 void translate(const Messages &messages, const QString &userContext = QString());
28 void stop() noexcept { m_stopped = true; }
29 void start() noexcept;
30 void setUrl(const QString &url);
31 void activateTranslationModel(const QString &modelName);
32 void requestModels();
33
37 void modelsReceived(QStringList models);
38
39private:
40 std::atomic_bool m_stopped = false;
41 std::atomic_int m_session = 0;
42 std::unique_ptr<QNetworkRequest> m_request;
43 std::unique_ptr<QNetworkAccessManager> m_manager;
44 std::unique_ptr<TranslationProtocol> m_translator;
45 QQueue<Batch> m_pendingBatches;
46 int m_inFlightCount = 0;
47 QMutex m_queueMutex;
48
49 void translateBatch(Batch b);
50 void translationReceived(QNetworkReply *reply, Batch b, int session);
51 void processNextBatches();
52
53 // Allow up to 6 retries to accommodate JSON format fallback.
54 // Gives 2-3 attempts with JSON format, then some attempts without.
55 static constexpr int s_maxTries = 6;
56 static constexpr int s_maxConcurrentBatches = 6;
57};
58
59QT_END_NAMESPACE
60
61#endif // MACHINETRANSLATOR_H
bool isValid() const
DataModelIterator(TranslationType type, const DataModel *model=0, int groupNo=0, int messageNo=0)
MessageItem * current() const
GroupItem * groupItem(int index, TranslationType type) const
int labelCount() const
int contextCount() const
void setDataModel(MultiDataModel *dm)
void start() noexcept
void translationFailed(QList< const TranslatorMessage * >)
void setUrl(const QString &url)
void translate(const Messages &messages, const QString &userContext=QString())
void activateTranslationModel(const QString &modelName)
void stop() noexcept
void modelsReceived(QStringList models)
const TranslatorMessage & message() const
DataModel * model(int i)
@ IDBASED
@ TEXTBASED
Combined button and popup list for selecting options.