Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pref controller: prevent false-positive 'dirty' flag #4721

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <QStandardPaths>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QtDebug>

#include "controllers/controller.h"
#include "controllers/controllerlearningeventfilter.h"
Expand Down Expand Up @@ -45,6 +44,7 @@ DlgPrefController::DlgPrefController(QWidget* parent,
m_pInputProxyModel(nullptr),
m_pOutputTableModel(nullptr),
m_pOutputProxyModel(nullptr),
m_GuiInitialized(false),
m_bDirty(false) {
m_ui.setupUi(this);
// Create text color for the file and wiki links
Expand Down Expand Up @@ -451,8 +451,8 @@ void DlgPrefController::slotUpdate() {
enumeratePresets(m_pControllerManager->getConfiguredPresetFileForDevice(
m_pController->getName()));

// enumeratePresets will check the m_ui.chkEnabledDevice checkbox if
// there is a valid mapping saved in the mixxx.cfg file. However, the
// enumeratePresets calls slotPresetSelected which will check the m_ui.chkEnabledDevice
// checkbox if there is a valid mapping saved in the mixxx.cfg file. However, the
// checkbox should only be checked if the device is currently enabled.
m_ui.chkEnabledDevice->setChecked(m_pController->isOpen());

Expand All @@ -462,6 +462,9 @@ void DlgPrefController::slotUpdate() {
m_ui.btnLearningWizard->setEnabled(isMappable);
m_ui.inputMappingsTab->setEnabled(isMappable);
m_ui.outputMappingsTab->setEnabled(isMappable);
// When slotUpdate() is run for the first time, this bool keeps slotPresetSelected()
// from setting a false-postive 'dirty' flag when updating the fresh GUI.
m_GuiInitialized = true;
}

void DlgPrefController::slotResetToDefaults() {
Expand Down Expand Up @@ -532,21 +535,23 @@ QString DlgPrefController::presetPathFromIndex(int index) const {

void DlgPrefController::slotPresetSelected(int chosenIndex) {
QString presetPath = presetPathFromIndex(chosenIndex);
if (presetPath.isEmpty()) {
// User picked "No Preset" item
if (presetPath.isEmpty()) { // User picked "No Preset" item
m_ui.chkEnabledDevice->setEnabled(false);

if (m_ui.chkEnabledDevice->isChecked()) {
m_ui.chkEnabledDevice->setChecked(false);
setDirty(true);
if (m_GuiInitialized) {
setDirty(true);
}
}
} else {
// User picked a preset
} else { // User picked a preset
m_ui.chkEnabledDevice->setEnabled(true);

if (!m_ui.chkEnabledDevice->isChecked()) {
m_ui.chkEnabledDevice->setChecked(true);
setDirty(true);
if (m_GuiInitialized) {
setDirty(true);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ class DlgPrefController : public DlgPreferencePage {
QSortFilterProxyModel* m_pInputProxyModel;
ControllerOutputMappingTableModel* m_pOutputTableModel;
QSortFilterProxyModel* m_pOutputProxyModel;
bool m_GuiInitialized;
bool m_bDirty;
};
3 changes: 0 additions & 3 deletions src/controllers/dlgprefcontrollers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ void DlgPrefControllers::slotOpenLocalFile(const QString& file) {
}

void DlgPrefControllers::slotUpdate() {
for (DlgPrefController* pControllerDlg : qAsConst(m_controllerPages)) {
pControllerDlg->slotUpdate();
}
}

void DlgPrefControllers::slotCancel() {
Expand Down