comparison widgets/PluginPathConfigurator.cpp @ 1293:6dd15b5c14f9 plugin-path-config

Various logic fixes, and use new setter-class structures
author Chris Cannam
date Fri, 25 May 2018 16:05:51 +0100
parents 41824255ddf2
children 9f9a7edd7d89
comparison
equal deleted inserted replaced
1292:41824255ddf2 1293:6dd15b5c14f9
24 #include <QFileDialog> 24 #include <QFileDialog>
25 25
26 #include "IconLoader.h" 26 #include "IconLoader.h"
27 #include "WidgetScale.h" 27 #include "WidgetScale.h"
28 28
29 #include "plugin/PluginPathSetter.h"
30
29 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) : 31 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
30 QFrame(parent) 32 QFrame(parent)
31 { 33 {
32 m_layout = new QGridLayout; 34 m_layout = new QGridLayout;
33 setLayout(m_layout); 35 setLayout(m_layout);
57 m_delete->setToolTip(tr("Remove the selected location from the list")); 59 m_delete->setToolTip(tr("Remove the selected location from the list"));
58 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked())); 60 connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
59 buttons->addWidget(m_delete); 61 buttons->addWidget(m_delete);
60 62
61 m_reset = new QPushButton; 63 m_reset = new QPushButton;
62 m_reset->setText(tr("Reset")); 64 m_reset->setText(tr("Reset to Default"));
63 m_reset->setToolTip(tr("Reset the list for this plugin type to its default")); 65 m_reset->setToolTip(tr("Reset the list for this plugin type to its default"));
64 connect(m_reset, SIGNAL(clicked()), this, SLOT(resetClicked())); 66 connect(m_reset, SIGNAL(clicked()), this, SLOT(resetClicked()));
65 buttons->addWidget(m_reset); 67 buttons->addWidget(m_reset);
66 68
67 int row = 0; 69 int row = 0;
83 m_layout->setRowStretch(row, 20); 85 m_layout->setRowStretch(row, 20);
84 connect(m_list, SIGNAL(currentRowChanged(int)), 86 connect(m_list, SIGNAL(currentRowChanged(int)),
85 this, SLOT(currentLocationChanged(int))); 87 this, SLOT(currentLocationChanged(int)));
86 ++row; 88 ++row;
87 89
88 m_layout->addLayout(buttons, row, 0, Qt::AlignLeft); 90 m_layout->addLayout(buttons, row, 0, 1, 2, Qt::AlignLeft);
89 91
90 m_seePlugins = new QPushButton; 92 m_seePlugins = new QPushButton;
91 m_seePlugins->setText(tr("Review plugins...")); 93 m_seePlugins->setText(tr("Review plugins..."));
92 connect(m_seePlugins, SIGNAL(clicked()), this, SLOT(seePluginsClicked())); 94 connect(m_seePlugins, SIGNAL(clicked()), this, SLOT(seePluginsClicked()));
93 m_layout->addWidget(m_seePlugins, row, 2); 95 m_layout->addWidget(m_seePlugins, row, 2);
104 PluginPathConfigurator::~PluginPathConfigurator() 106 PluginPathConfigurator::~PluginPathConfigurator()
105 { 107 {
106 } 108 }
107 109
108 void 110 void
109 PluginPathConfigurator::setPaths(Paths paths) 111 PluginPathConfigurator::setPaths(PluginPathSetter::Paths paths)
110 { 112 {
111 m_paths = paths; 113 m_paths = paths;
112 if (m_originalPaths.empty()) { 114
113 m_originalPaths = paths; 115 m_defaultPaths = PluginPathSetter::getDefaultPaths();
114 }
115 116
116 m_pluginTypeSelector->clear(); 117 m_pluginTypeSelector->clear();
117 for (const auto &p: paths) { 118 for (const auto &p: paths) {
118 m_pluginTypeSelector->addItem(p.first); 119 m_pluginTypeSelector->addItem(p.first);
119 } 120 }
167 QString type = m_pluginTypeSelector->currentText(); 168 QString type = m_pluginTypeSelector->currentText();
168 QStringList path = m_paths.at(type).directories; 169 QStringList path = m_paths.at(type).directories;
169 m_up->setEnabled(i > 0); 170 m_up->setEnabled(i > 0);
170 m_down->setEnabled(i >= 0 && i + 1 < path.size()); 171 m_down->setEnabled(i >= 0 && i + 1 < path.size());
171 m_delete->setEnabled(i >= 0 && i < path.size()); 172 m_delete->setEnabled(i >= 0 && i < path.size());
172 m_reset->setEnabled(path != m_originalPaths.at(type).directories); 173 m_reset->setEnabled(path != m_defaultPaths.at(type).directories);
173 } 174 }
174 175
175 void 176 void
176 PluginPathConfigurator::currentTypeChanged(QString type) 177 PluginPathConfigurator::currentTypeChanged(QString type)
177 { 178 {
187 188
188 auto newEntry = m_paths.at(type); 189 auto newEntry = m_paths.at(type);
189 newEntry.useEnvVariable = useEnvVariable; 190 newEntry.useEnvVariable = useEnvVariable;
190 m_paths[type] = newEntry; 191 m_paths[type] = newEntry;
191 192
192 emit pathsChanged(m_paths); 193 emit pathsChanged();
193 } 194 }
194 195
195 void 196 void
196 PluginPathConfigurator::upClicked() 197 PluginPathConfigurator::upClicked()
197 { 198 {
216 newEntry.directories = newPath; 217 newEntry.directories = newPath;
217 m_paths[type] = newEntry; 218 m_paths[type] = newEntry;
218 219
219 populateFor(type, current - 1); 220 populateFor(type, current - 1);
220 221
221 emit pathsChanged(m_paths); 222 emit pathsChanged();
222 } 223 }
223 224
224 void 225 void
225 PluginPathConfigurator::downClicked() 226 PluginPathConfigurator::downClicked()
226 { 227 {
245 newEntry.directories = newPath; 246 newEntry.directories = newPath;
246 m_paths[type] = newEntry; 247 m_paths[type] = newEntry;
247 248
248 populateFor(type, current + 1); 249 populateFor(type, current + 1);
249 250
250 emit pathsChanged(m_paths); 251 emit pathsChanged();
251 } 252 }
252 253
253 void 254 void
254 PluginPathConfigurator::addClicked() 255 PluginPathConfigurator::addClicked()
255 { 256 {
264 newEntry.directories.push_back(newDir); 265 newEntry.directories.push_back(newDir);
265 m_paths[type] = newEntry; 266 m_paths[type] = newEntry;
266 267
267 populateFor(type, newEntry.directories.size() - 1); 268 populateFor(type, newEntry.directories.size() - 1);
268 269
269 emit pathsChanged(m_paths); 270 emit pathsChanged();
270 } 271 }
271 272
272 void 273 void
273 PluginPathConfigurator::deleteClicked() 274 PluginPathConfigurator::deleteClicked()
274 { 275 {
289 newEntry.directories = newPath; 290 newEntry.directories = newPath;
290 m_paths[type] = newEntry; 291 m_paths[type] = newEntry;
291 292
292 populateFor(type, current < newPath.size() ? current : current-1); 293 populateFor(type, current < newPath.size() ? current : current-1);
293 294
294 emit pathsChanged(m_paths); 295 emit pathsChanged();
295 } 296 }
296 297
297 void 298 void
298 PluginPathConfigurator::resetClicked() 299 PluginPathConfigurator::resetClicked()
299 { 300 {
300 QString type = m_pluginTypeSelector->currentText(); 301 QString type = m_pluginTypeSelector->currentText();
301 m_paths[type] = m_originalPaths[type]; 302 m_paths[type] = m_defaultPaths[type];
302 populateFor(type, -1); 303 populateFor(type, -1);
303 304
304 emit pathsChanged(m_paths); 305 emit pathsChanged();
305 } 306 }
306 307
307 void 308 void
308 PluginPathConfigurator::seePluginsClicked() 309 PluginPathConfigurator::seePluginsClicked()
309 { 310 {