Mercurial > hg > svgui
comparison widgets/PluginPathConfigurator.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
1288:4683b6ffb76a | 1289:ed04d3666d33 |
---|---|
15 #include "PluginPathConfigurator.h" | 15 #include "PluginPathConfigurator.h" |
16 | 16 |
17 #include <QPushButton> | 17 #include <QPushButton> |
18 #include <QListWidget> | 18 #include <QListWidget> |
19 #include <QGridLayout> | 19 #include <QGridLayout> |
20 #include <QComboBox> | |
20 #include <QLabel> | 21 #include <QLabel> |
21 | 22 |
22 #include "IconLoader.h" | 23 #include "IconLoader.h" |
23 #include "WidgetScale.h" | 24 #include "WidgetScale.h" |
24 | 25 |
28 m_layout = new QGridLayout; | 29 m_layout = new QGridLayout; |
29 setLayout(m_layout); | 30 setLayout(m_layout); |
30 | 31 |
31 int row = 0; | 32 int row = 0; |
32 | 33 |
33 QLabel *header = new QLabel; | 34 m_header = new QLabel; |
34 header->setText(tr("Plugin locations")); | 35 m_header->setText(tr("Plugin locations")); |
35 m_layout->addWidget(header, row, 0); | 36 m_layout->addWidget(m_header, row, 0); |
37 | |
38 m_pluginTypeSelector = new QComboBox; | |
39 m_layout->addWidget(m_pluginTypeSelector, row, 1); | |
40 connect(m_pluginTypeSelector, SIGNAL(currentTextChanged(QString)), | |
41 this, SLOT(currentTypeChanged(QString))); | |
42 | |
36 ++row; | 43 ++row; |
37 | 44 |
38 m_list = new QListWidget; | 45 m_list = new QListWidget; |
39 m_layout->addWidget(m_list, row, 0, 1, 2); | 46 m_layout->addWidget(m_list, row, 0, 1, 2); |
40 m_layout->setRowStretch(row, 10); | 47 m_layout->setRowStretch(row, 10); |
73 PluginPathConfigurator::~PluginPathConfigurator() | 80 PluginPathConfigurator::~PluginPathConfigurator() |
74 { | 81 { |
75 } | 82 } |
76 | 83 |
77 void | 84 void |
78 PluginPathConfigurator::setPath(QStringList directories, QString envVariable) | 85 PluginPathConfigurator::setPaths(Paths paths) |
79 { | 86 { |
80 m_path = directories; | 87 m_paths = paths; |
81 m_var = envVariable; | 88 |
89 m_pluginTypeSelector->clear(); | |
90 for (const auto &p: paths) { | |
91 m_pluginTypeSelector->addItem(p.first); | |
92 } | |
93 | |
82 populate(); | 94 populate(); |
83 } | 95 } |
84 | 96 |
85 void | 97 void |
86 PluginPathConfigurator::populate(int makeCurrent) | 98 PluginPathConfigurator::populate() |
87 { | 99 { |
88 m_list->clear(); | 100 m_list->clear(); |
89 | 101 |
90 for (int i = 0; i < m_path.size(); ++i) { | 102 if (m_paths.empty()) return; |
91 m_list->addItem(m_path[i]); | 103 |
92 } | 104 populateFor(m_paths.begin()->first, 0); |
93 | 105 } |
94 if (makeCurrent >= 0 && makeCurrent < m_path.size()) { | 106 |
107 void | |
108 PluginPathConfigurator::populateFor(QString type, int makeCurrent) | |
109 { | |
110 m_list->clear(); | |
111 | |
112 for (int i = 0; i < m_pluginTypeSelector->count(); ++i) { | |
113 if (type == m_pluginTypeSelector->itemText(i)) { | |
114 m_pluginTypeSelector->setCurrentIndex(i); | |
115 } | |
116 } | |
117 | |
118 QStringList path = m_paths.at(type).directories; | |
119 | |
120 for (int i = 0; i < path.size(); ++i) { | |
121 m_list->addItem(path[i]); | |
122 } | |
123 | |
124 if (makeCurrent >= 0 && makeCurrent < path.size()) { | |
95 m_list->setCurrentRow(makeCurrent); | 125 m_list->setCurrentRow(makeCurrent); |
96 } | 126 } |
97 } | 127 } |
98 | 128 |
99 void | 129 void |
100 PluginPathConfigurator::currentLocationChanged(int i) | 130 PluginPathConfigurator::currentLocationChanged(int i) |
101 { | 131 { |
132 QString type = m_pluginTypeSelector->currentText(); | |
133 QStringList path = m_paths.at(type).directories; | |
102 m_up->setEnabled(i > 0); | 134 m_up->setEnabled(i > 0); |
103 m_down->setEnabled(i + 1 < m_path.size()); | 135 m_down->setEnabled(i + 1 < path.size()); |
104 m_delete->setEnabled(i < m_path.size()); | 136 m_delete->setEnabled(i < path.size()); |
137 } | |
138 | |
139 void | |
140 PluginPathConfigurator::currentTypeChanged(QString type) | |
141 { | |
142 populateFor(type, 0); | |
105 } | 143 } |
106 | 144 |
107 void | 145 void |
108 PluginPathConfigurator::upClicked() | 146 PluginPathConfigurator::upClicked() |
109 { | 147 { |
148 QString type = m_pluginTypeSelector->currentText(); | |
149 QStringList path = m_paths.at(type).directories; | |
150 QString variable = m_paths.at(type).envVariable; | |
151 | |
110 int current = m_list->currentRow(); | 152 int current = m_list->currentRow(); |
111 if (current <= 0) return; | 153 if (current <= 0) return; |
112 | 154 |
113 QStringList newPath; | 155 QStringList newPath; |
114 for (int i = 0; i < m_path.size(); ++i) { | 156 for (int i = 0; i < path.size(); ++i) { |
115 if (i + 1 == current) { | 157 if (i + 1 == current) { |
116 newPath.push_back(m_path[i+1]); | 158 newPath.push_back(path[i+1]); |
117 newPath.push_back(m_path[i]); | 159 newPath.push_back(path[i]); |
118 ++i; | 160 ++i; |
119 } else { | 161 } else { |
120 newPath.push_back(m_path[i]); | 162 newPath.push_back(path[i]); |
121 } | 163 } |
122 } | 164 } |
123 m_path = newPath; | 165 m_paths[type] = { newPath, variable }; |
124 | 166 |
125 populate(current - 1); | 167 populateFor(type, current - 1); |
126 } | 168 } |
127 | 169 |
128 void | 170 void |
129 PluginPathConfigurator::downClicked() | 171 PluginPathConfigurator::downClicked() |
130 { | 172 { |
173 QString type = m_pluginTypeSelector->currentText(); | |
174 QStringList path = m_paths.at(type).directories; | |
175 QString variable = m_paths.at(type).envVariable; | |
176 | |
131 int current = m_list->currentRow(); | 177 int current = m_list->currentRow(); |
132 if (current < 0 || current + 1 >= m_path.size()) return; | 178 if (current < 0 || current + 1 >= path.size()) return; |
133 | 179 |
134 QStringList newPath; | 180 QStringList newPath; |
135 for (int i = 0; i < m_path.size(); ++i) { | 181 for (int i = 0; i < path.size(); ++i) { |
136 if (i == current) { | 182 if (i == current) { |
137 newPath.push_back(m_path[i+1]); | 183 newPath.push_back(path[i+1]); |
138 newPath.push_back(m_path[i]); | 184 newPath.push_back(path[i]); |
139 ++i; | 185 ++i; |
140 } else { | 186 } else { |
141 newPath.push_back(m_path[i]); | 187 newPath.push_back(path[i]); |
142 } | 188 } |
143 } | 189 } |
144 m_path = newPath; | 190 m_paths[type] = { newPath, variable }; |
145 | 191 |
146 populate(current + 1); | 192 populateFor(type, current + 1); |
147 } | 193 } |
148 | 194 |
149 void | 195 void |
150 PluginPathConfigurator::deleteClicked() | 196 PluginPathConfigurator::deleteClicked() |
151 { | 197 { |
198 QString type = m_pluginTypeSelector->currentText(); | |
199 QStringList path = m_paths.at(type).directories; | |
200 QString variable = m_paths.at(type).envVariable; | |
201 | |
152 int current = m_list->currentRow(); | 202 int current = m_list->currentRow(); |
153 | 203 |
154 QStringList newPath; | 204 QStringList newPath; |
155 for (int i = 0; i < m_path.size(); ++i) { | 205 for (int i = 0; i < path.size(); ++i) { |
156 if (i != current) { | 206 if (i != current) { |
157 newPath.push_back(m_path[i]); | 207 newPath.push_back(path[i]); |
158 } | 208 } |
159 } | 209 } |
160 m_path = newPath; | 210 m_paths[type] = { newPath, variable }; |
161 | 211 |
162 populate(current < m_path.size() ? current : current-1); | 212 populateFor(type, current < newPath.size() ? current : current-1); |
163 } | 213 } |