Mercurial > hg > svgui
changeset 1289:ed04d3666d33 plugin-path-config
Toward more than one plugin type in this widget
author | Chris Cannam |
---|---|
date | Mon, 21 May 2018 16:15:36 +0100 |
parents | 4683b6ffb76a |
children | 050eca637c19 |
files | widgets/PluginPathConfigurator.cpp widgets/PluginPathConfigurator.h |
diffstat | 2 files changed, 102 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/widgets/PluginPathConfigurator.cpp Tue May 15 15:25:04 2018 +0100 +++ b/widgets/PluginPathConfigurator.cpp Mon May 21 16:15:36 2018 +0100 @@ -17,6 +17,7 @@ #include <QPushButton> #include <QListWidget> #include <QGridLayout> +#include <QComboBox> #include <QLabel> #include "IconLoader.h" @@ -30,9 +31,15 @@ int row = 0; - QLabel *header = new QLabel; - header->setText(tr("Plugin locations")); - m_layout->addWidget(header, row, 0); + m_header = new QLabel; + m_header->setText(tr("Plugin locations")); + m_layout->addWidget(m_header, row, 0); + + m_pluginTypeSelector = new QComboBox; + m_layout->addWidget(m_pluginTypeSelector, row, 1); + connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)), + this, SLOT(currentTypeChanged(QString))); + ++row; m_list = new QListWidget; @@ -75,23 +82,46 @@ } void -PluginPathConfigurator::setPath(QStringList directories, QString envVariable) +PluginPathConfigurator::setPaths(Paths paths) { - m_path = directories; - m_var = envVariable; + m_paths = paths; + + m_pluginTypeSelector->clear(); + for (const auto &p: paths) { + m_pluginTypeSelector->addItem(p.first); + } + populate(); } void -PluginPathConfigurator::populate(int makeCurrent) +PluginPathConfigurator::populate() { m_list->clear(); - for (int i = 0; i < m_path.size(); ++i) { - m_list->addItem(m_path[i]); + if (m_paths.empty()) return; + + populateFor(m_paths.begin()->first, 0); +} + +void +PluginPathConfigurator::populateFor(QString type, int makeCurrent) +{ + m_list->clear(); + + for (int i = 0; i < m_pluginTypeSelector->count(); ++i) { + if (type == m_pluginTypeSelector->itemText(i)) { + m_pluginTypeSelector->setCurrentIndex(i); + } + } + + QStringList path = m_paths.at(type).directories; + + for (int i = 0; i < path.size(); ++i) { + m_list->addItem(path[i]); } - if (makeCurrent >= 0 && makeCurrent < m_path.size()) { + if (makeCurrent >= 0 && makeCurrent < path.size()) { m_list->setCurrentRow(makeCurrent); } } @@ -99,65 +129,85 @@ void PluginPathConfigurator::currentLocationChanged(int i) { + QString type = m_pluginTypeSelector->currentText(); + QStringList path = m_paths.at(type).directories; m_up->setEnabled(i > 0); - m_down->setEnabled(i + 1 < m_path.size()); - m_delete->setEnabled(i < m_path.size()); + m_down->setEnabled(i + 1 < path.size()); + m_delete->setEnabled(i < path.size()); +} + +void +PluginPathConfigurator::currentTypeChanged(QString type) +{ + populateFor(type, 0); } void PluginPathConfigurator::upClicked() { + QString type = m_pluginTypeSelector->currentText(); + QStringList path = m_paths.at(type).directories; + QString variable = m_paths.at(type).envVariable; + int current = m_list->currentRow(); if (current <= 0) return; QStringList newPath; - for (int i = 0; i < m_path.size(); ++i) { + for (int i = 0; i < path.size(); ++i) { if (i + 1 == current) { - newPath.push_back(m_path[i+1]); - newPath.push_back(m_path[i]); + newPath.push_back(path[i+1]); + newPath.push_back(path[i]); ++i; } else { - newPath.push_back(m_path[i]); + newPath.push_back(path[i]); } } - m_path = newPath; + m_paths[type] = { newPath, variable }; - populate(current - 1); + populateFor(type, current - 1); } void PluginPathConfigurator::downClicked() { + QString type = m_pluginTypeSelector->currentText(); + QStringList path = m_paths.at(type).directories; + QString variable = m_paths.at(type).envVariable; + int current = m_list->currentRow(); - if (current < 0 || current + 1 >= m_path.size()) return; - + if (current < 0 || current + 1 >= path.size()) return; + QStringList newPath; - for (int i = 0; i < m_path.size(); ++i) { + for (int i = 0; i < path.size(); ++i) { if (i == current) { - newPath.push_back(m_path[i+1]); - newPath.push_back(m_path[i]); + newPath.push_back(path[i+1]); + newPath.push_back(path[i]); ++i; } else { - newPath.push_back(m_path[i]); + newPath.push_back(path[i]); } } - m_path = newPath; + m_paths[type] = { newPath, variable }; - populate(current + 1); + populateFor(type, current + 1); } void PluginPathConfigurator::deleteClicked() { + QString type = m_pluginTypeSelector->currentText(); + QStringList path = m_paths.at(type).directories; + QString variable = m_paths.at(type).envVariable; + int current = m_list->currentRow(); - + QStringList newPath; - for (int i = 0; i < m_path.size(); ++i) { + for (int i = 0; i < path.size(); ++i) { if (i != current) { - newPath.push_back(m_path[i]); + newPath.push_back(path[i]); } } - m_path = newPath; + m_paths[type] = { newPath, variable }; - populate(current < m_path.size() ? current : current-1); + populateFor(type, current < newPath.size() ? current : current-1); }
--- a/widgets/PluginPathConfigurator.h Tue May 15 15:25:04 2018 +0100 +++ b/widgets/PluginPathConfigurator.h Mon May 21 16:15:36 2018 +0100 @@ -23,6 +23,7 @@ class QListWidget; class QPushButton; class QGridLayout; +class QComboBox; class PluginPathConfigurator : public QFrame { @@ -32,29 +33,43 @@ PluginPathConfigurator(QWidget *parent = 0); ~PluginPathConfigurator(); - void setPath(QStringList directories, QString envVariable); - QStringList getPath() const; + // Text used to identify a plugin type to the user. + // e.g. "LADSPA", "Vamp", or potentially transliterations thereof + typedef QString PluginTypeLabel; + + struct PathConfig { + QStringList directories; + QString envVariable; // e.g. "LADSPA_PATH" etc + }; + + typedef std::map<PluginTypeLabel, PathConfig> Paths; + + void setPaths(Paths paths); + Paths getPaths() const; signals: - void pathChanged(QStringList); + void pathsChanged(const Paths &paths); private slots: void upClicked(); void downClicked(); void deleteClicked(); + void currentTypeChanged(QString); void currentLocationChanged(int); private: QGridLayout *m_layout; + QLabel *m_header; + QComboBox *m_pluginTypeSelector; QListWidget *m_list; QPushButton *m_up; QPushButton *m_down; QPushButton *m_delete; - QStringList m_path; - QString m_var; + Paths m_paths; - void populate(int makeCurrent = 0); + void populate(); + void populateFor(QString type, int makeCurrent); }; #endif