summaryrefslogtreecommitdiffstats
path: root/src/interfaceframework/qifconfiguration.cpp
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2022-11-10 11:20:58 +0100
committerDominik Holland <dominik.holland@qt.io>2022-12-07 11:28:56 +0100
commitd93246f6a831a40b72dc4416b50442aa6092b683 (patch)
tree8a24db2e0b33480bb534541bdb0df9e546fdd2a2 /src/interfaceframework/qifconfiguration.cpp
parenteea4201099a9c3ec6b66138990670fd2cd1f2e30 (diff)
Improve the auto discovery system
The auto discovery system works fine when only a single production or a single simulation backend were found. In case multiple backends were found the first backend was used, which was not always the desired backend. The QIfServiceManager can now also use an additional list of preferred backends. This list can contain wildcards and tries to find a single matching backend. A new preferredBackends property is also added to QIfAbstractFeature and QIfAbstractFeatureListModel. Task-number: QTBUG-99081 Task-number: QTBUG-99082 Change-Id: Ic5834c826f157d9b457dea769ef88c29ab90f617 Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'src/interfaceframework/qifconfiguration.cpp')
-rw-r--r--src/interfaceframework/qifconfiguration.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/interfaceframework/qifconfiguration.cpp b/src/interfaceframework/qifconfiguration.cpp
index d152a10e..062e1273 100644
--- a/src/interfaceframework/qifconfiguration.cpp
+++ b/src/interfaceframework/qifconfiguration.cpp
@@ -76,6 +76,8 @@ void QIfConfigurationManager::readInitialSettings()
settingsObject->simulationFile = settings.value("simulationFile").toString();
settingsObject->simulationDataFileSet = settings.contains("simulationDataFile");
settingsObject->simulationDataFile = settings.value("simulationDataFile").toString();
+ settingsObject->preferredBackendsSet = settings.contains("preferredBackends");
+ settingsObject->preferredBackends = settings.value("preferredBackends").toStringList();
QVariant discoveryModeVariant = settings.value("discoveryMode");
settings.endGroup();
@@ -124,6 +126,19 @@ void QIfConfigurationManager::readInitialSettings()
so->discoveryModeSet = true;
so->discoveryModeEnvOverride = true;
});
+
+ parseEnv(qgetenv("QTIF_PREFERRED_BACKENDS_OVERRIDE"), [this](const QString &group, const QString& value) {
+ auto *so = settingsObject(group, true);
+ auto preferredBackends = value.split(u',', Qt::SkipEmptyParts);
+ if (preferredBackends.isEmpty()) {
+ qCWarning(qLcIfConfig, "Ignoring malformed override: List is empty or couldn't be parsed: '%s'", value.toUtf8().constData());
+ return;
+ }
+
+ so->preferredBackends = preferredBackends;
+ so->preferredBackendsSet = true;
+ so->preferredBackendsEnvOverride = true;
+ });
}
QIfSettingsObject *QIfConfigurationManager::settingsObject(const QString &group, bool create)
@@ -172,6 +187,11 @@ void QIfConfigurationManager::addAbstractFeature(const QString &group, QIfAbstra
qCDebug(qLcIfConfig) << "Updating discoveryMode of" << feature << "with" << so->discoveryMode;
feature->setDiscoveryMode(so->discoveryMode);
}
+
+ if (so->preferredBackendsSet) {
+ qCDebug(qLcIfConfig) << "Updating preferredBackends of" << feature << "with" << so->preferredBackends;
+ feature->setPreferredBackends(so->preferredBackends);
+ }
}
void QIfConfigurationManager::removeAbstractFeature(const QString &group, QIfAbstractFeature *feature)
@@ -241,6 +261,25 @@ bool QIfConfigurationManager::setDiscoveryMode(QIfSettingsObject *so, QIfAbstrac
return true;
}
+bool QIfConfigurationManager::setPreferredBackends(QIfSettingsObject *so, const QStringList &preferredBackends)
+{
+ Q_ASSERT(so);
+ if (so->preferredBackendsEnvOverride) {
+ qWarning("Changing the preferredBackends is not possible, because the QTIF_PREFERRED_BACKENDS_OVERRIDE env variable has been set.");
+ return false;
+ }
+ so->preferredBackends = preferredBackends;
+ so->preferredBackendsSet = true;
+
+ for (auto &feature : qAsConst(so->features)) {
+ if (!feature)
+ continue;
+ qCDebug(qLcIfConfig) << "Updating preferredBackends of" << feature << "with" << preferredBackends;
+ feature->setPreferredBackends(so->preferredBackends);
+ }
+ return true;
+}
+
void QIfConfigurationManager::parseEnv(const QByteArray &rulesSrc, std::function<void(const QString &, const QString &)> func)
{
const QString content = QString::fromLocal8Bit(rulesSrc);
@@ -333,6 +372,15 @@ QIfAbstractFeature::DiscoveryMode QIfConfiguration::discoveryMode() const
return d->m_settingsObject->discoveryMode;
}
+QStringList QIfConfiguration::preferredBackends() const
+{
+ Q_D(const QIfConfiguration);
+
+ Q_CHECK_SETTINGSOBJECT(QStringList());
+
+ return d->m_settingsObject->preferredBackends;
+}
+
bool QIfConfiguration::setName(const QString &name)
{
Q_D(QIfConfiguration);
@@ -426,6 +474,23 @@ bool QIfConfiguration::setDiscoveryMode(QIfAbstractFeature::DiscoveryMode discov
return false;
}
+bool QIfConfiguration::setPreferredBackends(const QStringList &preferredBackends)
+{
+ Q_D(QIfConfiguration);
+
+ Q_CHECK_SETTINGSOBJECT(false);
+
+ if (d->m_settingsObject->preferredBackends == preferredBackends)
+ return false;
+
+ if (QIfConfigurationManager::instance()->setPreferredBackends(d->m_settingsObject, preferredBackends)) {
+ emit preferredBackendsChanged(preferredBackends);
+ return true;
+ }
+
+ return false;
+}
+
void QIfConfiguration::classBegin()
{
@@ -523,6 +588,24 @@ bool QIfConfiguration::isDiscoveryModeSet(const QString &group)
return so ? so->discoveryModeSet : false;
}
+QStringList QIfConfiguration::preferredBackends(const QString &group)
+{
+ QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
+ return so ? so->preferredBackends : QStringList();
+}
+
+bool QIfConfiguration::setPreferredBackends(const QString &group, const QStringList &preferredBackends)
+{
+ QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
+ return QIfConfigurationManager::instance()->setPreferredBackends(so, preferredBackends);
+}
+
+bool QIfConfiguration::arePreferredBackendsSet(const QString &group)
+{
+ QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
+ return so ? so->preferredBackendsSet : false;
+}
+
QT_END_NAMESPACE