Skip to content

Commit

Permalink
Merge pull request #10821 from ronso0/pref-controller__2.3
Browse files Browse the repository at this point in the history
Preferences > Controller: a few UX fixes
  • Loading branch information
ferranpujolcamins authored Aug 30, 2022
2 parents f12c639 + 057ad01 commit 8947421
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/controllers/controllerinputmappingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void ControllerInputMappingTableModel::onPresetLoaded() {
m_midiInputMappings = m_pMidiPreset->getInputMappings().values();
endInsertRows();
}
connect(this,
&QAbstractTableModel::dataChanged,
this,
[this]() {
m_pMidiPreset->setDirty(true);
});
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/controllers/controlleroutputmappingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ void ControllerOutputMappingTableModel::onPresetLoaded() {
m_midiOutputMappings = m_pMidiPreset->getOutputMappings().values();
endInsertRows();
}
connect(this,
&QAbstractTableModel::dataChanged,
this,
[this]() {
m_pMidiPreset->setDirty(true);
});
}
}

Expand Down
37 changes: 27 additions & 10 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,11 @@ void DlgPrefController::slotApply() {
bEnabled = m_ui.chkEnabledDevice->isChecked();

if (m_pPreset->isDirty()) {
savePreset();
if (savePreset()) {
// We might have saved the previous preset with a new name,
// so update the preset combobox.
enumeratePresets(m_pPreset->filePath());
}
}
}
m_ui.chkEnabledDevice->setChecked(bEnabled);
Expand Down Expand Up @@ -562,12 +566,13 @@ void DlgPrefController::slotPresetSelected(int chosenIndex) {
}

applyPresetChanges();
bool previousPresetSaved = false;
if (m_pPreset && m_pPreset->isDirty()) {
if (QMessageBox::question(this,
tr("Mapping has been edited"),
tr("Do you want to save the changes?")) ==
QMessageBox::Yes) {
savePreset();
previousPresetSaved = savePreset();
}
}

Expand All @@ -578,17 +583,23 @@ void DlgPrefController::slotPresetSelected(int chosenIndex) {
DEBUG_ASSERT(!pPreset->isDirty());
}

slotShowPreset(pPreset);
if (previousPresetSaved) {
// We might have saved the previous preset with a new name, so update
// the preset combobox.
enumeratePresets(presetPath);
} else {
slotShowPreset(pPreset);
}
}

void DlgPrefController::savePreset() {
bool DlgPrefController::savePreset() {
VERIFY_OR_DEBUG_ASSERT(m_pPreset) {
return;
return false;
}

if (!m_pPreset->isDirty()) {
qDebug() << "Mapping is not dirty, no need to save it.";
return;
return false;
}

QString oldFilePath = m_pPreset->filePath();
Expand Down Expand Up @@ -634,7 +645,7 @@ void DlgPrefController::savePreset() {
m_pOverwritePresets.insert(m_pPreset->filePath(), true);
}
} else if (overwriteMsgBox.close()) {
return;
return false;
}
}

Expand All @@ -646,21 +657,26 @@ void DlgPrefController::savePreset() {
newFilePath = oldFilePath;
} else {
presetName = askForPresetName(presetName);
if (presetName.isEmpty()) {
// QInputDialog was closed
qDebug() << "Mapping not saved, new name is empty";
return false;
}
newFilePath = presetNameToPath(m_pUserDir, presetName);
m_pPreset->setName(presetName);
qDebug() << "Mapping renamed to" << m_pPreset->name();
}

if (!m_pPreset->savePreset(newFilePath)) {
qDebug() << "Failed to save mapping as" << newFilePath;
return;
return false;
}
qDebug() << "Mapping saved as" << newFilePath;

m_pPreset->setFilePath(newFilePath);
m_pPreset->setDirty(false);

enumeratePresets(m_pPreset->filePath());
return true;
}

QString DlgPrefController::askForPresetName(const QString& prefilledName) const {
Expand Down Expand Up @@ -688,7 +704,8 @@ QString DlgPrefController::askForPresetName(const QString& prefilledName) const
.remove(rxRemove)
.trimmed();
if (!ok) {
continue;
// Return empty string if the dialog was canceled. Callers will deal with this.
return QString();
}
if (presetName.isEmpty()) {
QMessageBox::warning(nullptr,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DlgPrefController : public DlgPreferencePage {
QString presetPathFromIndex(int index) const;
QString askForPresetName(const QString& prefilledName = QString()) const;
void applyPresetChanges();
void savePreset();
bool savePreset();
void initTableView(QTableView* pTable);

/// Set dirty state (i.e. changes have been made).
Expand Down

0 comments on commit 8947421

Please sign in to comment.