2021-04-14 21:37:00 +00:00
|
|
|
|
|
|
|
#include "stringsetting.hpp"
|
|
|
|
|
2021-04-15 19:34:25 +00:00
|
|
|
#include <QLineEdit>
|
2021-04-14 21:37:00 +00:00
|
|
|
#include <QMutexLocker>
|
|
|
|
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <apps/opencs/model/prefs/setting.hpp>
|
|
|
|
|
2021-04-14 21:37:00 +00:00
|
|
|
#include "category.hpp"
|
|
|
|
#include "state.hpp"
|
|
|
|
|
2022-07-11 16:41:07 +00:00
|
|
|
CSMPrefs::StringSetting::StringSetting(
|
2023-11-15 08:32:18 +00:00
|
|
|
Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index)
|
2023-11-11 23:52:09 +00:00
|
|
|
: TypedSetting(parent, mutex, key, label, index)
|
2022-07-11 16:41:07 +00:00
|
|
|
, mWidget(nullptr)
|
2021-04-14 21:37:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip(const std::string& tooltip)
|
|
|
|
{
|
|
|
|
mTooltip = tooltip;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-11-10 12:28:10 +00:00
|
|
|
CSMPrefs::SettingWidgets CSMPrefs::StringSetting::makeWidgets(QWidget* parent)
|
2021-04-14 21:37:00 +00:00
|
|
|
{
|
2023-11-11 23:52:09 +00:00
|
|
|
mWidget = new QLineEdit(QString::fromStdString(getValue()), parent);
|
2021-04-14 21:37:00 +00:00
|
|
|
|
|
|
|
if (!mTooltip.empty())
|
|
|
|
{
|
|
|
|
QString tooltip = QString::fromUtf8(mTooltip.c_str());
|
|
|
|
mWidget->setToolTip(tooltip);
|
|
|
|
}
|
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mWidget, &QLineEdit::textChanged, this, &StringSetting::textChanged);
|
2021-04-14 21:37:00 +00:00
|
|
|
|
2023-12-13 23:28:43 +00:00
|
|
|
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget };
|
2021-04-14 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::StringSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
2023-11-11 23:52:09 +00:00
|
|
|
mWidget->setText(QString::fromStdString(getValue()));
|
2021-04-14 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 19:34:25 +00:00
|
|
|
void CSMPrefs::StringSetting::textChanged(const QString& text)
|
2021-04-14 21:37:00 +00:00
|
|
|
{
|
2023-11-11 23:52:09 +00:00
|
|
|
setValue(text.toStdString());
|
2021-04-14 21:37:00 +00:00
|
|
|
getParent()->getState()->update(*this);
|
|
|
|
}
|