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 3daa394
Show file tree
Hide file tree
Showing 4 changed files with 37 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"
11 changes: 11 additions & 0 deletions src/preferences/constants.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#pragma once

// #include <qtmetamacros.h>
// 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 +21,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 +38,7 @@ enum class MultiSamplingMode {
Eight = 8,
Sixteen = 16
};
Q_ENUM_NS(MultiSamplingMode);

} // namespace constants
} // namespace preferences
Expand Down
38 changes: 21 additions & 17 deletions src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "preferences/dialog/dlgprefinterface.h"

#include <qt5/QtCore/qvariant.h>

Check failure on line 3 in src/preferences/dialog/dlgprefinterface.cpp

View workflow job for this annotation

GitHub Actions / clazy

'qt5/QtCore/qvariant.h' file not found

Check failure on line 3 in src/preferences/dialog/dlgprefinterface.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

qt5/QtCore/qvariant.h: No such file or directory

Check failure on line 3 in src/preferences/dialog/dlgprefinterface.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

'qt5/QtCore/qvariant.h' file not found

Check failure on line 3 in src/preferences/dialog/dlgprefinterface.cpp

View workflow job for this annotation

GitHub Actions / coverage

qt5/QtCore/qvariant.h: No such file or directory

Check failure on line 3 in src/preferences/dialog/dlgprefinterface.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

'qt5/QtCore/qvariant.h' file not found

#include <QDir>
#include <QList>
#include <QLocale>
Expand All @@ -11,6 +13,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 +176,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 +204,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 +315,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 +338,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 +453,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 3daa394

Please sign in to comment.