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-10 12:09:37 +00:00
|
|
|
Category* parent, QMutex* mutex, const std::string& key, const QString& label, std::string_view default_)
|
2022-07-11 16:41:07 +00:00
|
|
|
: Setting(parent, mutex, key, label)
|
|
|
|
, mDefault(default_)
|
|
|
|
, 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
|
|
|
{
|
2021-04-15 19:34:25 +00:00
|
|
|
mWidget = new QLineEdit(QString::fromUtf8(mDefault.c_str()), 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-11-10 12:28:10 +00:00
|
|
|
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget, .mLayout = nullptr };
|
2021-04-14 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::StringSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
|
|
|
{
|
2022-07-11 16:41:07 +00:00
|
|
|
mWidget->setText(QString::fromStdString(Settings::Manager::getString(getKey(), getParent()->getKey())));
|
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
|
|
|
{
|
|
|
|
{
|
|
|
|
QMutexLocker lock(getMutex());
|
2022-07-11 16:41:07 +00:00
|
|
|
Settings::Manager::setString(getKey(), getParent()->getKey(), text.toStdString());
|
2021-04-14 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getParent()->getState()->update(*this);
|
|
|
|
}
|