mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
core: activate qPrefDisplay in SettingsObjectWrapper
add the prepared class qPrefDisplay to SettingsObjectWrapper and thereby making it active. As a consequence of the uniform naming standard desktop-widgets/preferences_defaults.cpp and tests/testpreferences.cpp have been updated. Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
parent
d7fed0bcb7
commit
da61c1714f
7 changed files with 26 additions and 111 deletions
|
@ -15,6 +15,7 @@ static qPref *self = new qPref;
|
|||
|
||||
void qPref::loadSync(bool doSync)
|
||||
{
|
||||
qPrefDisplay::instance()->loadSync(doSync);
|
||||
}
|
||||
|
||||
const QString qPref::canonical_version() const
|
||||
|
|
|
@ -20,6 +20,8 @@ public:
|
|||
|
||||
// Load/Sync local settings (disk) and struct preference
|
||||
void loadSync(bool doSync);
|
||||
void load() { loadSync(false); };
|
||||
void sync() { loadSync(true); };
|
||||
|
||||
public:
|
||||
enum cloud_status {
|
||||
|
|
|
@ -19,6 +19,8 @@ public:
|
|||
|
||||
// Load/Sync local settings (disk) and struct preference
|
||||
void loadSync(bool doSync);
|
||||
void load() { loadSync(false); };
|
||||
void sync() { loadSync(true); };
|
||||
|
||||
public:
|
||||
const QString divelist_font() const;
|
||||
|
|
|
@ -1913,75 +1913,6 @@ void GeneralSettingsObjectWrapper::setAutoRecalculateThumbnails(bool value)
|
|||
emit autoRecalculateThumbnailsChanged(value);
|
||||
}
|
||||
|
||||
DisplaySettingsObjectWrapper::DisplaySettingsObjectWrapper(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString DisplaySettingsObjectWrapper::divelistFont() const
|
||||
{
|
||||
return prefs.divelist_font;
|
||||
}
|
||||
|
||||
double DisplaySettingsObjectWrapper::fontSize() const
|
||||
{
|
||||
return prefs.font_size;
|
||||
}
|
||||
|
||||
bool DisplaySettingsObjectWrapper::displayInvalidDives() const
|
||||
{
|
||||
return prefs.display_invalid_dives;
|
||||
}
|
||||
|
||||
void DisplaySettingsObjectWrapper::setDivelistFont(const QString& value)
|
||||
{
|
||||
|
||||
QString newValue = value;
|
||||
if (value.contains(","))
|
||||
newValue = value.left(value.indexOf(","));
|
||||
|
||||
if (newValue == prefs.divelist_font)
|
||||
return;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("divelist_font", value);
|
||||
|
||||
if (!subsurface_ignore_font(qPrintable(newValue))) {
|
||||
free((void *)prefs.divelist_font);
|
||||
prefs.divelist_font = copy_qstring(newValue);
|
||||
qApp->setFont(QFont(newValue));
|
||||
}
|
||||
emit divelistFontChanged(newValue);
|
||||
}
|
||||
|
||||
void DisplaySettingsObjectWrapper::setFontSize(double value)
|
||||
{
|
||||
if (value == prefs.font_size)
|
||||
return;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("font_size", value);
|
||||
prefs.font_size = value;
|
||||
QFont defaultFont = qApp->font();
|
||||
defaultFont.setPointSizeF(prefs.font_size);
|
||||
qApp->setFont(defaultFont);
|
||||
emit fontSizeChanged(value);
|
||||
}
|
||||
|
||||
void DisplaySettingsObjectWrapper::setDisplayInvalidDives(bool value)
|
||||
{
|
||||
if (value == prefs.display_invalid_dives)
|
||||
return;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("displayinvalid", value);
|
||||
prefs.display_invalid_dives = value;
|
||||
emit displayInvalidDivesChanged(value);
|
||||
}
|
||||
|
||||
LanguageSettingsObjectWrapper::LanguageSettingsObjectWrapper(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
@ -2194,7 +2125,7 @@ QObject(parent),
|
|||
planner_settings(new DivePlannerSettings(this)),
|
||||
unit_settings(new UnitsSettings(this)),
|
||||
general_settings(new GeneralSettingsObjectWrapper(this)),
|
||||
display_settings(new DisplaySettingsObjectWrapper(this)),
|
||||
display_settings(new qPrefDisplay(this)),
|
||||
language_settings(new LanguageSettingsObjectWrapper(this)),
|
||||
animation_settings(new AnimationsSettingsObjectWrapper(this)),
|
||||
location_settings(new LocationServiceSettingsObjectWrapper(this)),
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QDate>
|
||||
|
||||
#include "core/pref.h"
|
||||
#include "core/settings/qPref.h"
|
||||
|
||||
/* Wrapper class for the Settings. This will allow
|
||||
* seamlessy integration of the settings with the QML
|
||||
|
@ -594,28 +595,6 @@ private:
|
|||
const QString group = QStringLiteral("GeneralSettings");
|
||||
};
|
||||
|
||||
class DisplaySettingsObjectWrapper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString divelist_font READ divelistFont WRITE setDivelistFont NOTIFY divelistFontChanged)
|
||||
Q_PROPERTY(double font_size READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
||||
Q_PROPERTY(bool display_invalid_dives READ displayInvalidDives WRITE setDisplayInvalidDives NOTIFY displayInvalidDivesChanged)
|
||||
public:
|
||||
DisplaySettingsObjectWrapper(QObject *parent);
|
||||
QString divelistFont() const;
|
||||
double fontSize() const;
|
||||
bool displayInvalidDives() const;
|
||||
public slots:
|
||||
void setDivelistFont(const QString& value);
|
||||
void setFontSize(double value);
|
||||
void setDisplayInvalidDives(bool value);
|
||||
signals:
|
||||
void divelistFontChanged(const QString& value);
|
||||
void fontSizeChanged(double value);
|
||||
void displayInvalidDivesChanged(bool value);
|
||||
private:
|
||||
const QString group = QStringLiteral("Display");
|
||||
};
|
||||
|
||||
class LanguageSettingsObjectWrapper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
|
||||
|
@ -709,7 +688,7 @@ class SettingsObjectWrapper : public QObject {
|
|||
Q_PROPERTY(UnitsSettings* units MEMBER unit_settings CONSTANT)
|
||||
|
||||
Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT)
|
||||
Q_PROPERTY(DisplaySettingsObjectWrapper* display MEMBER display_settings CONSTANT)
|
||||
Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT)
|
||||
Q_PROPERTY(LanguageSettingsObjectWrapper* language MEMBER language_settings CONSTANT)
|
||||
Q_PROPERTY(AnimationsSettingsObjectWrapper* animation MEMBER animation_settings CONSTANT)
|
||||
Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT)
|
||||
|
@ -728,7 +707,7 @@ public:
|
|||
DivePlannerSettings *planner_settings;
|
||||
UnitsSettings *unit_settings;
|
||||
GeneralSettingsObjectWrapper *general_settings;
|
||||
DisplaySettingsObjectWrapper *display_settings;
|
||||
qPrefDisplay *display_settings;
|
||||
LanguageSettingsObjectWrapper *language_settings;
|
||||
AnimationsSettingsObjectWrapper *animation_settings;
|
||||
LocationServiceSettingsObjectWrapper *location_settings;
|
||||
|
|
|
@ -88,10 +88,10 @@ void PreferencesDefaults::syncSettings()
|
|||
else if (ui->cloudDefaultFile->isChecked())
|
||||
general->setDefaultFileBehavior(CLOUD_DEFAULT_FILE);
|
||||
|
||||
auto display = SettingsObjectWrapper::instance()->display_settings;
|
||||
display->setDivelistFont(ui->font->currentFont().toString());
|
||||
display->setFontSize(ui->fontsize->value());
|
||||
display->setDisplayInvalidDives(ui->displayinvalid->isChecked());
|
||||
auto display = qPrefDisplay::instance();
|
||||
display->set_divelist_font(ui->font->currentFont().toString());
|
||||
display->set_font_size(ui->fontsize->value());
|
||||
display->set_display_invalid_dives(ui->displayinvalid->isChecked());
|
||||
|
||||
auto animation = SettingsObjectWrapper::instance()->animation_settings;
|
||||
animation->setAnimationSpeed(ui->velocitySlider->value());
|
||||
|
|
|
@ -445,22 +445,22 @@ void TestPreferences::testPreferences()
|
|||
TEST(general->pscrRatio(), 1);
|
||||
TEST(general->useDefaultFile(), false);
|
||||
|
||||
auto display = pref->display_settings;
|
||||
display->setDivelistFont("comic");
|
||||
display->setFontSize(10.0);
|
||||
display->setDisplayInvalidDives(true);
|
||||
auto display = qPrefDisplay::instance();
|
||||
display->set_divelist_font("comic");
|
||||
display->set_font_size(10.0);
|
||||
display->set_display_invalid_dives(true);
|
||||
|
||||
TEST(display->divelistFont(),QStringLiteral("comic"));
|
||||
TEST(display->fontSize(), 10.0);
|
||||
TEST(display->displayInvalidDives(), true);
|
||||
TEST(display->divelist_font(),QStringLiteral("comic"));
|
||||
TEST(display->font_size(), 10.0);
|
||||
TEST(display->display_invalid_dives(), true);
|
||||
|
||||
display->setDivelistFont("helvetica");
|
||||
display->setFontSize(14.0);
|
||||
display->setDisplayInvalidDives(false);
|
||||
display->set_divelist_font("helvetica");
|
||||
display->set_font_size(14.0);
|
||||
display->set_display_invalid_dives(false);
|
||||
|
||||
TEST(display->divelistFont(),QStringLiteral("helvetica"));
|
||||
TEST(display->fontSize(), 14.0);
|
||||
TEST(display->displayInvalidDives(), false);
|
||||
TEST(display->divelist_font(),QStringLiteral("helvetica"));
|
||||
TEST(display->font_size(), 14.0);
|
||||
TEST(display->display_invalid_dives(), false);
|
||||
|
||||
auto language = pref->language_settings;
|
||||
language->setLangLocale ("en_US");
|
||||
|
|
Loading…
Add table
Reference in a new issue