KTextAddons

translation.h
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5
6 Based on translateLocally code
7*/
8
9#pragma once
10#include "libbergamot_export.h"
11#include <QMetaType>
12#include <QString>
13#include <QVector>
14#include <memory>
15
16namespace slimt
17{
18class Response;
19}
20
21/**
22 * Wrapper around a translation response from the bergamot service. Hides that
23 * interface from the rest of the Qt code, and provides utility functions to
24 * access alignment information with character offsets instead of byte offsets.
25 */
26class LIBBERGAMOT_EXPORT Translation
27{
28public:
30 Translation(slimt::Response &&response);
31
32 /**
33 * Bool operator to check whether this is an initialised translation or just
34 * an empty object.
35 */
36 inline operator bool() const
37 {
38 return !!mResponse;
39 }
40
41 /**
42 * Translation result
43 */
44 [[nodiscard]] QString translation() const;
45
46private:
47 // Note: I would have liked unique_ptr, but that does not go well with
48 // passing Translation objects through Qt signals/slots.
49 std::shared_ptr<slimt::Response> mResponse;
50};
51
52Q_DECLARE_METATYPE(Translation)
Wrapper around a translation response from the bergamot service.
Definition translation.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.