Skip to content

Commit

Permalink
Use signal/slot approach for pluginLoadedChanged
Browse files Browse the repository at this point in the history
Per @Trinitou feedback:

1. pluginLoadedChanged is now a signal of PluginHost

2. Connect MainWindow:: updatePluginMenuItems to this signal

3. Rename updateMenuItems to updatePluginMenuItems (so it specifies it's these are plugin related menu items)

4. Remove i_prefix in function parameter to follow code style

5. Use default argument false for updatePluginMenuItems
  • Loading branch information
NatureIsFrequency committed Feb 12, 2024
1 parent 1410bb3 commit 7017523
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
22 changes: 10 additions & 12 deletions host/main-window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ void MainWindow::createMenu() {
connect(
helpMenu->addAction(tr("About")), &QAction::triggered, this, &MainWindow::showAboutDialog);

updateMenuItems();
updatePluginMenuItems();

assert(_application.engine());
connect(&_application.engine()->pluginHost(), &PluginHost::pluginLoadedChanged, this, &MainWindow::updatePluginMenuItems);
}

void MainWindow::updateMenuItems() {
_loadPluginPresetAction->setEnabled(_pluginLoaded);
_showPluginParametersAction->setEnabled(_pluginLoaded);
_showPluginQuickControlsAction->setEnabled(_pluginLoaded);
_togglePluginWindowVisibilityAction->setEnabled(_pluginLoaded);
_recreatePluginWindowAction->setEnabled(_pluginLoaded);
void MainWindow::updatePluginMenuItems(bool const pluginLoaded /* = false */ ) {
_loadPluginPresetAction->setEnabled(pluginLoaded);
_showPluginParametersAction->setEnabled(pluginLoaded);
_showPluginQuickControlsAction->setEnabled(pluginLoaded);
_togglePluginWindowVisibilityAction->setEnabled(pluginLoaded);
_recreatePluginWindowAction->setEnabled(pluginLoaded);
}

void MainWindow::showSettingsDialog() {
Expand Down Expand Up @@ -137,11 +140,6 @@ void MainWindow::resizePluginView(int width, int height) {
adjustSize();
}

void MainWindow::onPluginLoadChange(bool const i_pluginLoaded) {
_pluginLoaded = i_pluginLoaded;
updateMenuItems();
}

void MainWindow::loadNativePluginPreset() {
auto file = QFileDialog::getOpenFileName(this, tr("Load Plugin Native Preset"));
if (file.isEmpty())
Expand Down
5 changes: 1 addition & 4 deletions host/main-window.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public:
void showPluginParametersWindow();
void showPluginQuickControlsWindow();
void resizePluginView(int width, int height);
void onPluginLoadChange(bool i_pluginLoaded);

void showPluginWindow() { _pluginViewWidget->show(); }

Expand All @@ -42,7 +41,7 @@ private:
void togglePluginWindowVisibility();
void recreatePluginWindow();
void showAboutDialog();
void updateMenuItems();
void updatePluginMenuItems(bool pluginLoaded = false);

Application &_application;
QWindow *_pluginViewWindow = nullptr;
Expand All @@ -54,8 +53,6 @@ private:
QAction *_togglePluginWindowVisibilityAction = nullptr;
QAction *_recreatePluginWindowAction = nullptr;

bool _pluginLoaded = false;

PluginParametersWidget *_pluginParametersWidget = nullptr;
PluginQuickControlsWidget *_pluginRemoteControlsWidget = nullptr;
};
4 changes: 2 additions & 2 deletions host/plugin-host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ bool PluginHost::load(const QString &path, int pluginIndex) {
scanParams();
scanQuickControls();

Application::instance().mainWindow()->onPluginLoadChange(true);
pluginLoadedChanged(true);

return true;
}

void PluginHost::unload() {
checkForMainThread();

Application::instance().mainWindow()->onPluginLoadChange(false);
pluginLoadedChanged(false);

if (!_library.isLoaded())
return;
Expand Down
1 change: 1 addition & 0 deletions host/plugin-host.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ signals:
void quickControlsPagesChanged();
void quickControlsSelectedPageChanged();
void paramAdjusted(clap_id paramId);
void pluginLoadedChanged(bool pluginLoaded);

protected:
/////////////////////////
Expand Down

0 comments on commit 7017523

Please sign in to comment.