KTextAddons

bergamotenginesettingswidget.cpp
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6#include "bergamotenginesettingswidget.h"
7#include <KLocalizedString>
8#include <QCheckBox>
9#include <QComboBox>
10#include <QFormLayout>
11#include <QGroupBox>
12#include <QVBoxLayout>
13#include <thread>
14
15BergamotEngineSettingsWidget::BergamotEngineSettingsWidget(QWidget *parent)
16 : QWidget{parent}
17 , mNumberThreads(new QComboBox(this))
18 , mMemoryByThreads(new QComboBox(this))
19 , mUseLocalCache(new QCheckBox(i18nc("@option:check", "Use translation cache"), this))
20{
21 auto mainLayout = new QVBoxLayout(this);
22 mainLayout->setObjectName(QStringLiteral("mainLayout"));
23 mainLayout->setContentsMargins({});
24
25 auto resourceBox = new QGroupBox(i18n("Resource Usage"), this);
26 resourceBox->setObjectName(QStringLiteral("resourceBox"));
27 mainLayout->addWidget(resourceBox);
28
29 mNumberThreads->setObjectName(QStringLiteral("mNumberThreads"));
30 mMemoryByThreads->setObjectName(QStringLiteral("mMemoryByThreads"));
31
32 mUseLocalCache->setObjectName(QStringLiteral("mUseLocalCache"));
33
34 auto formLayout = new QFormLayout;
35 formLayout->setObjectName(QStringLiteral("formLayout"));
36 resourceBox->setLayout(formLayout);
37 formLayout->addRow(i18n("Thread:"), mNumberThreads);
38 formLayout->addRow(i18n("Memory by Thread:"), mMemoryByThreads);
39 formLayout->addWidget(mUseLocalCache);
40 fillCombobox();
41}
42
43BergamotEngineSettingsWidget::~BergamotEngineSettingsWidget() = default;
44
45void BergamotEngineSettingsWidget::setSettingsInfo(const BergamotEngineUtils::SettingsInfo &info)
46{
47 mNumberThreads->setCurrentIndex(mNumberThreads->findData(info.numberOfThread));
48 mMemoryByThreads->setCurrentIndex(mMemoryByThreads->findData(info.memoryByThread));
49 mUseLocalCache->setChecked(info.useLocalCache);
50}
51
52BergamotEngineUtils::SettingsInfo BergamotEngineSettingsWidget::settingsInfo() const
53{
54 BergamotEngineUtils::SettingsInfo info;
55 info.memoryByThread = mMemoryByThreads->currentData().toInt();
56 info.numberOfThread = mNumberThreads->currentData().toInt();
57 info.useLocalCache = mUseLocalCache->isChecked();
58 return info;
59}
60
61void BergamotEngineSettingsWidget::fillCombobox()
62{
63 const auto processorCount = std::thread::hardware_concurrency();
64
65 for (int cores = processorCount; cores > 0; cores -= 2) {
66 mNumberThreads->addItem(QString::number(cores), cores);
67 }
68
69 const QList<int> memorys = {64, 128, 256, 512, 768, 1024, 1280, 1536, 1762, 2048};
70 for (const int memory : memorys) {
71 mMemoryByThreads->addItem(QString::number(memory), memory);
72 }
73}
74
75#include "moc_bergamotenginesettingswidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void setChecked(bool)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void setCurrentIndex(int index)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
void setObjectName(QAnyStringView name)
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.