Skip to content

Commit

Permalink
Controller preferences: recreate control menus when decks/samplers ar…
Browse files Browse the repository at this point in the history
…e added
  • Loading branch information
ronso0 committed Feb 6, 2024
1 parent 2251a2e commit 5a5d206
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DlgPrefController::DlgPrefController(
// Create text color for the file and wiki links
createLinkColor();

m_pControlPickerMenu = new ControlPickerMenu(this);
m_pControlPickerMenu = make_parented<ControlPickerMenu>(this);

initTableView(m_ui.m_pInputMappingTableView);
initTableView(m_ui.m_pOutputMappingTableView);
Expand Down Expand Up @@ -169,6 +169,10 @@ DlgPrefController::DlgPrefController(
DlgPrefController::~DlgPrefController() {
}

void DlgPrefController::slotRecreateControlPickerMenu() {
m_pControlPickerMenu = make_parented<ControlPickerMenu>(this);
}

void DlgPrefController::showLearningWizard() {
if (isDirty()) {
QMessageBox::StandardButton result = QMessageBox::question(this,
Expand Down
14 changes: 8 additions & 6 deletions src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
#include "controllers/ui_dlgprefcontrollerdlg.h"
#include "preferences/dialog/dlgpreferencepage.h"
#include "preferences/usersettings.h"
#include "util/parented_ptr.h"

// Forward declarations
class Controller;
class ControllerManager;
class MappingInfoEnumerator;
class ControlPickerMenu;
class DlgControllerLearning;
class ControllerInputMappingTableModel;
class ControllerMappingTableProxyModel;
class ControllerManager;
class ControllerOutputMappingTableModel;
class ControllerMappingTableProxyModel;
class ControlPickerMenu;
class DlgControllerLearning;
class MappingInfoEnumerator;

/// Configuration dialog for a single DJ controller
class DlgPrefController : public DlgPreferencePage {
Expand All @@ -40,6 +40,8 @@ class DlgPrefController : public DlgPreferencePage {
/// Called when the user clicks the global "Reset to Defaults" button.
void slotResetToDefaults() override;

void slotRecreateControlPickerMenu();

signals:
void applyMapping(Controller* pController,
std::shared_ptr<LegacyControllerMapping> pMapping,
Expand Down Expand Up @@ -119,7 +121,7 @@ class DlgPrefController : public DlgPreferencePage {
const QString m_pUserDir;
std::shared_ptr<ControllerManager> m_pControllerManager;
Controller* m_pController;
ControlPickerMenu* m_pControlPickerMenu;
parented_ptr<ControlPickerMenu> m_pControlPickerMenu;
DlgControllerLearning* m_pDlgControllerLearning;
std::shared_ptr<LegacyControllerMapping> m_pMapping;
QMap<QString, bool> m_pOverwriteMappings;
Expand Down
16 changes: 15 additions & 1 deletion src/controllers/dlgprefcontrollers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QDesktopServices>

#include "control/controlproxy.h"
#include "controllers/controller.h"
#include "controllers/controllermanager.h"
#include "controllers/defs_controllers.h"
Expand All @@ -11,6 +12,10 @@
#include "preferences/dialog/dlgpreferences.h"
#include "util/string.h"

namespace {
const QString kAppGroup = QStringLiteral("[App]");
} // namespace

DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
UserSettingsPointer pConfig,
std::shared_ptr<ControllerManager> pControllerManager,
Expand All @@ -19,7 +24,11 @@ DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
m_pDlgPreferences(pPreferences),
m_pConfig(pConfig),
m_pControllerManager(pControllerManager),
m_pControllersRootItem(pControllersRootItem) {
m_pControllersRootItem(pControllersRootItem),
m_pNumDecks(make_parented<ControlProxy>(
kAppGroup, QStringLiteral("num_decks"), this)),
m_pNumSamplers(make_parented<ControlProxy>(
kAppGroup, QStringLiteral("num_samplers"), this)) {
setupUi(this);
// Create text color for the cue mode link "?" to the manual
createLinkColor();
Expand Down Expand Up @@ -178,6 +187,11 @@ void DlgPrefControllers::setupControllerWidgets() {
&DlgPrefController::mappingEnded,
m_pDlgPreferences,
&DlgPreferences::show);
// Recreate the control picker menus when decks or samplers are added
m_pNumDecks->connectValueChanged(pControllerDlg,
&DlgPrefController::slotRecreateControlPickerMenu);
m_pNumSamplers->connectValueChanged(pControllerDlg,
&DlgPrefController::slotRecreateControlPickerMenu);

m_controllerPages.append(pControllerDlg);

Expand Down
5 changes: 5 additions & 0 deletions src/controllers/dlgprefcontrollers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "controllers/ui_dlgprefcontrollersdlg.h"
#include "preferences/dialog/dlgpreferencepage.h"
#include "preferences/usersettings.h"
#include "util/parented_ptr.h"

class ControlProxy;
class DlgPreferences;
class DlgPrefController;
class ControllerManager;
Expand Down Expand Up @@ -52,4 +54,7 @@ class DlgPrefControllers : public DlgPreferencePage, public Ui::DlgPrefControlle
QTreeWidgetItem* m_pControllersRootItem;
QList<DlgPrefController*> m_controllerPages;
QList<QTreeWidgetItem*> m_controllerTreeItems;

const parented_ptr<ControlProxy> m_pNumDecks;
const parented_ptr<ControlProxy> m_pNumSamplers;
};

0 comments on commit 5a5d206

Please sign in to comment.