diff options
| author | Dominik Holland <dominik.holland@qt.io> | 2022-11-24 16:50:49 +0100 |
|---|---|---|
| committer | Dominik Holland <dominik.holland@qt.io> | 2022-12-07 11:29:26 +0100 |
| commit | 753b402d099b25ceefbcbf5815edd694e35c6615 (patch) | |
| tree | 22addf9b0c33942d5c8706d8cf9562cada228602 /src/interfaceframework/qifconfiguration.cpp | |
| parent | 5085f5f1ec3c194afec2aef77a6519bc151bcccd (diff) | |
QIfConfiguration: Fix creation from within QML
A QIfConfiguration always needs to have a name until
it is valid.
For usage in QML we need to store all values internally
and check for the name once the component has been
completed.
Change-Id: Ifeb16a73eaa1acd8c4df21e71fd98991508a1ee4
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'src/interfaceframework/qifconfiguration.cpp')
| -rw-r--r-- | src/interfaceframework/qifconfiguration.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/interfaceframework/qifconfiguration.cpp b/src/interfaceframework/qifconfiguration.cpp index 4215dccc..6d23194d 100644 --- a/src/interfaceframework/qifconfiguration.cpp +++ b/src/interfaceframework/qifconfiguration.cpp @@ -344,6 +344,7 @@ QIfConfigurationPrivate::QIfConfigurationPrivate(QIfConfiguration *parent) : q_ptr(parent) , m_ignoreOverrideWarnings(false) , m_settingsObject(nullptr) + , m_qmlCreation(false) { } @@ -448,6 +449,18 @@ bool QIfConfiguration::setName(const QString &name) { Q_D(QIfConfiguration); + if (name.isEmpty()) + return false; + + // Skip all checks during QML creation + // All values will be stored in a temporary SettingsObject until componentComplete is called + if (d->m_qmlCreation) { + d->m_name = name; + emit nameChanged(name); + emit isValidChanged(true); + return true; + } + if (d->m_settingsObject) { qtif_qmlOrCppWarning(this, "The name of the Configuration Object can't be changed once it has been set."); return false; @@ -573,14 +586,33 @@ bool QIfConfiguration::setServiceObject(QIfServiceObject *serviceObject) void QIfConfiguration::classBegin() { - + Q_D(QIfConfiguration); + d->m_qmlCreation = true; + // storage for all settings until we can resolve the real settingsobject in compoentComplete + d->m_settingsObject = new QIfSettingsObject(); } void QIfConfiguration::componentComplete() { - Q_D(const QIfConfiguration); + Q_D(QIfConfiguration); + + d->m_qmlCreation = false; + + QScopedPointer<QIfSettingsObject> tempSettings(d->m_settingsObject); + d->m_settingsObject = nullptr; + // Resolve the real settingsObject; + if (!setName(d->m_name)) + return; Q_CHECK_SETTINGSOBJECT(void()); + + //Copy all values from the tempObject + setServiceSettings(tempSettings->serviceSettings); + setSimulationFile(tempSettings->simulationFile); + setSimulationDataFile(tempSettings->simulationDataFile); + setPreferredBackends(tempSettings->preferredBackends); + setDiscoveryMode(tempSettings->discoveryMode); + setServiceObject(tempSettings->serviceObject); } QIfConfiguration::QIfConfiguration(QIfConfigurationPrivate &dd, QObject *parent) |
