39 #include <QtCore/QStringList>
40 #include <QtCore/QSettings>
41 #include <QtCore/QDebug>
50 m_pm = ExtensionSystem::PluginManager::instance();
53 if (!m_factories.contains(f)) {
54 m_factories.append(f);
56 QString name = f->
name();
57 QIcon icon = f->
icon();
58 m_classIdNameMap.insert(classId, name);
59 m_classIdIconMap.insert(classId, icon);
67 m_pm->removeObject(page);
74 while (!m_configurations.isEmpty()) {
77 qs->beginGroup(
"UAVGadgetConfigurations");
87 configInfo.
notify(tr(
"Migrating UAVGadgetConfigurations from version 1.1.0 to ")
88 + m_versionUAVGadgetConfigurations.
toString());
89 readConfigs_1_1_0(qs);
93 configInfo.
notify(tr(
"You might want to save your old config NOW since it might be "
94 "replaced by broken one when you exit the GCS!"));
96 readConfigs_1_2_0(qs);
100 createOptionsPages();
103 void UAVGadgetInstanceManager::readConfigs_1_2_0(QSettings *qs)
107 foreach (QString classId, m_classIdNameMap.keys()) {
109 qs->beginGroup(classId);
111 QStringList configs = QStringList();
113 configs = qs->childGroups();
114 foreach (QString configName, configs) {
115 qs->beginGroup(configName);
118 qs->beginGroup(
"data");
124 int idx = indexForConfig(m_configurations, classId, configName);
128 m_configurations[
idx] = config;
130 m_configurations.append(config);
138 if (configs.count() == 0) {
143 config->
setName(tr(
"default"));
145 m_configurations.append(config);
152 void UAVGadgetInstanceManager::readConfigs_1_1_0(QSettings *qs)
156 foreach (QString classId, m_classIdNameMap.keys()) {
158 qs->beginGroup(classId);
160 QStringList configs = QStringList();
162 configs = qs->childGroups();
163 foreach (QString configName, configs) {
164 qs->beginGroup(configName);
165 bool locked = qs->value(
"config.locked").toBool();
172 int idx = indexForConfig(m_configurations, classId, configName);
176 m_configurations[
idx] = config;
178 m_configurations.append(config);
184 if (configs.count() == 0) {
189 config->
setName(tr(
"default"));
191 m_configurations.append(config);
201 qs->beginGroup(
"UAVGadgetConfigurations");
203 configInfo =
new UAVConfigInfo(m_versionUAVGadgetConfigurations,
"UAVGadgetConfigurations");
204 configInfo->
save(qs);
208 qs->beginGroup(config->
classId());
209 qs->beginGroup(config->
name());
210 qs->beginGroup(
"data");
213 configInfo->
save(qs);
221 void UAVGadgetInstanceManager::createOptionsPages()
226 while (!m_optionsPages.isEmpty()) {
227 m_pm->removeObject(m_optionsPages.takeLast());
230 QMutableListIterator<IUAVGadgetConfiguration *> ite(m_configurations);
231 while (ite.hasNext()) {
236 emit
splashMessages(QString(tr(
"Loading %1 plugin options page for configuration %2")
238 .arg(config->
name())));
242 m_optionsPages.append(page);
243 m_pm->addObject(page);
245 qWarning() <<
"UAVGadgetInstanceManager::createOptionsPages - failed to create options "
246 "page for configuration "
247 + config->
classId() +
":" + config->
name() +
", configuration will be removed.";
257 bool forceLoadConfiguration)
261 if (f->
classId() !=
"EmptyGadget")
263 QString(tr(
"Creating %1 with %2 configuration").arg(f->
classId()).arg(f->
name())));
269 m_gadgetInstances.append(gadget);
286 if (m_gadgetInstances.contains(gadget)) {
287 m_gadgetInstances.removeOne(gadget);
302 foreach (
IUAVGadget *gadget, m_gadgetInstances) {
303 m_gadgetInstances.removeOne(gadget);
311 foreach (
IUAVGadget *gadget, m_gadgetInstances) {
326 m_provisionalDeletes.append(config);
327 if (m_provisionalConfigs.contains(config)) {
328 int i = m_provisionalConfigs.indexOf(config);
329 m_provisionalConfigs.removeAt(i);
330 m_provisionalOptionsPages.removeAt(i);
331 int j = m_takenNames[config->
classId()].indexOf(config->
name());
332 m_takenNames[config->
classId()].removeAt(j);
334 }
else if (m_configurations.contains(config)) {
342 QString name = suggestName(configToClone->
classId(), configToClone->
name());
346 config->setProvisionalName(name);
351 m_provisionalConfigs.append(config);
352 m_provisionalOptionsPages.append(page);
357 QString UAVGadgetInstanceManager::suggestName(QString classId, QString name)
359 QString suggestedName;
361 QString
last = name.split(
" ").last();
363 int num = last.toInt(&ok);
366 QStringList
n = name.split(
" ");
372 suggestedName = name +
" " + QString::number(i);
374 }
while (m_takenNames[classId].contains(suggestedName));
376 m_takenNames[classId].append(suggestedName);
377 return suggestedName;
382 if (m_provisionalDeletes.contains(config)) {
383 m_provisionalDeletes.removeAt(m_provisionalDeletes.indexOf(config));
384 int i = m_configurations.indexOf(config);
387 int j = m_takenNames[config->
classId()].indexOf(config->
name());
388 m_takenNames[config->
classId()].removeAt(j);
389 m_pm->removeObject(m_optionsPages.at(i));
390 m_configurations.removeAt(i);
391 m_optionsPages.removeAt(i);
399 if (m_configurations.contains(config)) {
401 }
else if (m_provisionalConfigs.contains(config)) {
403 int i = m_provisionalConfigs.indexOf(config);
405 m_configurations.append(config);
406 m_optionsPages.append(page);
407 m_provisionalConfigs.removeAt(i);
408 m_provisionalOptionsPages.removeAt(i);
409 m_pm->addObject(page);
415 bool disable =
false;
420 qDebug() <<
"Two identically named configurations: " << c->
classId() <<
"."
429 qDebug() <<
"An identically named provisional and normal configuration: "
440 qDebug() <<
"Two identically named provisional configurations: " << c->
classId()
447 if (hasText && text ==
"")
456 foreach (QString classId,
classIds())
458 m_settingsDialog = settingsDialog;
463 m_takenNames.clear();
464 m_provisionalConfigs.clear();
465 m_provisionalDeletes.clear();
466 m_provisionalOptionsPages.clear();
469 m_settingsDialog =
nullptr;
476 if (config->
classId() == classId)
477 names.append(config->
name());
484 return m_classIdNameMap.value(classId);
489 return m_classIdIconMap.value(classId);
505 if (config->
classId() == classId)
506 configs->append(config);
512 QString classId, QString configName)
514 for (
int i = 0; i < configurations.length(); ++
i) {
515 if (configurations.at(i)->classId() == classId
516 && configurations.at(i)->name() == configName)
virtual IUAVGadget * createGadget(QWidget *parent)=0
virtual IUAVGadgetConfiguration * createConfiguration(QSettings *)
void settingsDialogRemoved()
UAVGadgetInstanceManager(QObject *parent=nullptr)
void configurationToBeDeleted(IUAVGadgetConfiguration *config)
void setLocked(bool locked)
void disableApplyOk(bool disable)
virtual IOptionsPage * createOptionsPage(IUAVGadgetConfiguration *)
QIcon gadgetIcon(QString classId) const
void updateText(QString text)
IUAVGadget * createGadget(QString classId, QWidget *parent, bool forceLoadConfiguration=false)
void configurationAdded(IUAVGadgetConfiguration *config)
void readSettings(QSettings *qs)
void setVersion(int major, int minor, int patch)
void splashMessages(QString)
void saveSettings(QSettings *qs)
UAVConfigVersion version()
QString provisionalName()
void setName(QString name)
virtual IUAVGadgetConfiguration * clone()=0
void setProvisionalName(QString name)
void configurationNameEdited(QString text, bool hasText=true)
void applyChanges(IUAVGadgetConfiguration *config)
bool standardVersionHandlingOK(UAVConfigVersion programVersion)
Default version handling.
void settingsDialogShown(Core::Internal::SettingsDialog *settingsDialog)
void notify(QString message)
~UAVGadgetInstanceManager()
void deleteConfiguration(IUAVGadgetConfiguration *config)
bool isSingleConfigurationGadget()
void configurationNameChanged(IUAVGadgetConfiguration *config, QString oldName, QString newName)
virtual void saveConfig() const
bool canDeleteConfiguration(IUAVGadgetConfiguration *config)
The Config Info is a helper-class to handle version changes in GCS configuration files.
void cloneConfiguration(IUAVGadgetConfiguration *config)
void removeGadget(IUAVGadget *gadget)
QStringList configurationNames(QString classId) const
QStringList classIds() const
void setNameOfConfigurable(const QString nameOfConfigurable)
void insertPage(IOptionsPage *page)
The IOptionsPage is an interface for providing options pages.
QString gadgetName(QString classId) const
virtual IUAVGadgetConfiguration * activeConfiguration()
void configurationChanged(IUAVGadgetConfiguration *config)