Skip to content

Commit

Permalink
refactor(preferences): avoid static_casts<int> for preferences::const…
Browse files Browse the repository at this point in the history
…ants
  • Loading branch information
Swiftb0y committed Feb 12, 2024
1 parent 76450d0 commit 89e4f89
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/preferences/colorpalettesettings.cpp
src/preferences/colorpalettesettings.cpp
src/preferences/configobject.cpp
src/preferences/constants.cpp
src/preferences/dialog/dlgprefautodj.cpp
src/preferences/dialog/dlgprefautodjdlg.ui
src/preferences/dialog/dlgprefbeats.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/preferences/constants.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// just a stub so the MOC file can be included somewhere
#include "constants.h"

#include "moc_constants.cpp"
10 changes: 10 additions & 0 deletions src/preferences/constants.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#pragma once

// required for Qt-Macros
#include <QObject>

namespace mixxx {

namespace preferences {

namespace constants {
Q_NAMESPACE

// In order for this Q_NAMESPACE to work, all members of the namespace must
// be declared here. see QTBUG-68611

// Don't change these constants since they are stored in user configuration
// files.
Expand All @@ -13,13 +20,15 @@ enum class Tooltips {
On = 1,
OnlyInLibrary = 2,
};
Q_ENUM_NS(Tooltips);

// Settings to enable or disable the prevention to run the screensaver.
enum class ScreenSaver {
Off = 0,
On = 1,
OnPlay = 2
};
Q_ENUM_NS(ScreenSaver);

enum class MultiSamplingMode {
Disabled = 0,
Expand All @@ -28,6 +37,7 @@ enum class MultiSamplingMode {
Eight = 8,
Sixteen = 16
};
Q_ENUM_NS(MultiSamplingMode);

} // namespace constants
} // namespace preferences
Expand Down
36 changes: 19 additions & 17 deletions src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "control/controlproxy.h"
#include "defs_urls.h"
#include "moc_dlgprefinterface.cpp"
#include "preferences/constants.h"
#include "preferences/usersettings.h"
#include "skin/legacy/legacyskinparser.h"
#include "skin/skin.h"
Expand Down Expand Up @@ -173,14 +174,14 @@ DlgPrefInterface::DlgPrefInterface(
// Screensaver mode
comboBoxScreensaver->clear();
comboBoxScreensaver->addItem(tr("Allow screensaver to run"),
static_cast<int>(constants::ScreenSaver::Off));
QVariant::fromValue(constants::ScreenSaver::Off));
comboBoxScreensaver->addItem(tr("Prevent screensaver from running"),
static_cast<int>(constants::ScreenSaver::On));
QVariant::fromValue((constants::ScreenSaver::On)));
comboBoxScreensaver->addItem(tr("Prevent screensaver while playing"),
static_cast<int>(constants::ScreenSaver::OnPlay));
QVariant::fromValue(constants::ScreenSaver::OnPlay));

int inhibitsettings = static_cast<int>(m_pScreensaverManager->status());
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings));
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(
QVariant::fromValue(m_pScreensaverManager->status())));

// Multi-Sampling
#ifdef MIXXX_USE_QML
Expand All @@ -201,7 +202,7 @@ DlgPrefInterface::DlgPrefInterface(
ConfigKey(kPreferencesGroup, kMultiSamplingKey),
constants::MultiSamplingMode::Four);
int multiSamplingIndex = multiSamplingComboBox->findData(
static_cast<int>(m_multiSampling));
QVariant::fromValue((m_multiSampling)));
if (multiSamplingIndex != -1) {
multiSamplingComboBox->setCurrentIndex(multiSamplingIndex);
} else {
Expand Down Expand Up @@ -312,8 +313,8 @@ void DlgPrefInterface::slotUpdate() {

loadTooltipPreferenceFromConfig();

int inhibitsettings = static_cast<int>(m_pScreensaverManager->status());
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings));
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(
QVariant::fromValue(m_pScreensaverManager->status())));
}

void DlgPrefInterface::slotResetToDefaults() {
Expand All @@ -335,11 +336,12 @@ void DlgPrefInterface::slotResetToDefaults() {

// Inhibit the screensaver
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(
static_cast<int>(constants::ScreenSaver::On)));
QVariant::fromValue(constants::ScreenSaver::On)));

#ifdef MIXXX_USE_QML
multiSamplingComboBox->setCurrentIndex(multiSamplingComboBox->findData(
static_cast<int>(constants::MultiSamplingMode::Four))); // 4x MSAA
multiSamplingComboBox->setCurrentIndex(
multiSamplingComboBox->findData(QVariant::fromValue(
constants::MultiSamplingMode::Four))); // 4x MSAA
#endif

#ifdef Q_OS_IOS
Expand Down Expand Up @@ -449,16 +451,16 @@ void DlgPrefInterface::slotApply() {
m_pConfig->set(ConfigKey(kConfigGroup, kStartInFullscreenKey),
ConfigValue(checkBoxStartFullScreen->isChecked()));

m_pConfig->set(ConfigKey(kControlsGroup, kTooltipsKey),
ConfigValue(static_cast<int>(m_tooltipMode)));
m_pConfig->setValue(ConfigKey(kControlsGroup, kTooltipsKey),
m_tooltipMode);
emit tooltipModeChanged(m_tooltipMode);

// screensaver mode update
int screensaverComboBoxState = comboBoxScreensaver->currentData().toInt();
int screensaverConfiguredState = static_cast<int>(m_pScreensaverManager->status());
const auto screensaverComboBoxState =
comboBoxScreensaver->currentData().value<constants::ScreenSaver>();
const auto screensaverConfiguredState = m_pScreensaverManager->status();
if (screensaverComboBoxState != screensaverConfiguredState) {
m_pScreensaverManager->setStatus(
static_cast<constants::ScreenSaver>(screensaverComboBoxState));
m_pScreensaverManager->setStatus(screensaverComboBoxState);
}

#ifdef MIXXX_USE_QML
Expand Down

0 comments on commit 89e4f89

Please sign in to comment.