summaryrefslogtreecommitdiffstats
path: root/src/interfaceframework/qifconfiguration.cpp
blob: 8b0b09c0c714e0aa57c365276be52bed1edb6f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qifconfiguration.h"
#include "qifconfiguration_p.h"
#include "qifabstractfeature.h"

#include "qifqmlconversion_helper.h"

#include <QLibraryInfo>
#include <QDir>

using namespace Qt::StringLiterals;

QT_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(qLcIfConfig, "qt.if.configuration");

#define Q_CHECK_SETTINGSOBJECT(return_value) \
if (!d->m_settingsObject) { \
    qtif_qmlOrCppWarning(this, "Configuration Object is not usable until the name has been configured"); \
    return return_value; \
}

QIfConfigurationManager::QIfConfigurationManager()
{
    const QString configFileName = u"qtifconfig.ini"_s;

    const QString configPath
                = QDir(QLibraryInfo::path(QLibraryInfo::DataPath)).absoluteFilePath(configFileName);
    readInitialSettings(configPath);
}

QIfConfigurationManager *QIfConfigurationManager::instance()
{
    static QIfConfigurationManager s_manager;
    return &s_manager;
}


QIfAbstractFeature::DiscoveryMode discoveryModeFromString(const QString &modeString)
{
    QMetaEnum me = QMetaEnum::fromType<QIfAbstractFeature::DiscoveryMode>();
    QByteArray modeStringUtf8 = modeString.toUtf8();
    bool ok = false;
    int value = me.keyToValue(modeStringUtf8, &ok);
    if (ok) {
        return static_cast<QIfAbstractFeature::DiscoveryMode>(value);
    } else {
        QByteArray values;
        for (int i=0; i<me.keyCount();i++) {
            if (i == 0)
                values += me.key(i);
            else
                values += QByteArray(", ") + me.key(i);
        }
        qCWarning(qLcIfConfig, "Ignoring malformed discoveryMode: '%s'. Possible values are: '%s'", modeString.toUtf8().constData(), values.constData());
    }

    return QIfAbstractFeature::InvalidAutoDiscovery;
}

QVariantMap QIfConfigurationManager::readGroup(QSettings *settings, QAnyStringView group)
{
    QVariantMap map;
    settings->beginGroup(group);
    const auto keys = settings->childKeys();
    const auto groups = settings->childGroups();
    for (const QString& key : keys)
        map.insert(key, settings->value(key));
    for (const QString& group : groups)
        map.insert(group, readGroup(settings, group));
    settings->endGroup();
    return map;
}

void QIfConfigurationManager::readInitialSettings(const QString &configPath)
{
    qCDebug(qLcIfConfig) << "Loading initial settings from " << configPath;

    QSettings settings(configPath, QSettings::IniFormat);

    const auto groups = settings.childGroups();
    for (const QString& group : groups) {
        auto settingsObject = new QIfSettingsObject;

        settings.beginGroup(group);
        settingsObject->simulationFileSet = settings.contains("simulationFile");
        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");

        if (settings.childGroups().contains("serviceSettings")) {
            settingsObject->serviceSettingsSet = true;
            settingsObject->serviceSettings = readGroup(&settings, "serviceSettings");
        }
        settings.endGroup();

        if (discoveryModeVariant.isValid()) {
            auto discoveryMode = discoveryModeFromString(discoveryModeVariant.toString());
            if (discoveryMode == QIfAbstractFeature::InvalidAutoDiscovery)
                return;
            settingsObject->discoveryMode = discoveryMode;
            settingsObject->discoveryModeSet = true;
        }

        m_settingsHash.insert(group, settingsObject);
    }

    parseEnv(qgetenv("QTIF_SIMULATION_OVERRIDE"), [this](const QString &group, const QString& value) {
        if (!QFile::exists(value)) {
            qCWarning(qLcIfConfig, "Ignoring malformed override: File does not exist: '%s'", value.toUtf8().constData());
            return;
        }

        auto *so = settingsObject(group, true);
        so->simulationFile = value;
        so->simulationFileSet = true;
        so->simulationFileEnvOverride = true;
    });

    parseEnv(qgetenv("QTIF_SIMULATION_DATA_OVERRIDE"), [this](const QString &group, const QString& value) {
        if (!QFile::exists(value)) {
            qCWarning(qLcIfConfig, "Ignoring malformed override: File does not exist: '%s'", value.toUtf8().constData());
            return;
        }

        auto *so = settingsObject(group, true);
        so->simulationDataFile = value;
        so->simulationDataFileSet = true;
        so->simulationDataFileEnvOverride = true;
    });

    parseEnv(qgetenv("QTIF_DISCOVERY_MODE_OVERRIDE"), [this](const QString &group, const QString& value) {
        auto *so = settingsObject(group, true);
        auto discoveryMode = discoveryModeFromString(value);
        if (discoveryMode == QIfAbstractFeature::InvalidAutoDiscovery)
            return;

        so->discoveryMode = discoveryMode;
        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)
{
    QIfSettingsObject *settingsObject = nullptr;
    if (m_settingsHash.contains(group)) {
        settingsObject = m_settingsHash.value(group);
    } else if (create) {
        settingsObject = new QIfSettingsObject;
        m_settingsHash.insert(group, settingsObject);
    }
    return settingsObject;
}

void QIfConfigurationManager::addServiceObject(const QString &group, QIfProxyServiceObject *serviceObject)
{
    Q_ASSERT(serviceObject);
    QIfSettingsObject *so = settingsObject(group, true);
    Q_ASSERT(so);

    so->serviceObjects.append(serviceObject);
    if (so->serviceSettingsSet) {
        qCDebug(qLcIfConfig) << "Updating Service Settings of" << serviceObject << "with" << so->serviceSettings;
        serviceObject->updateServiceSettings(so->serviceSettings);
    }
}

void QIfConfigurationManager::removeServiceObject(const QString &group, QIfProxyServiceObject *serviceObject)
{
    Q_ASSERT(serviceObject);
    QIfSettingsObject *so = settingsObject(group);
    if (!so)
        return;

    so->serviceObjects.removeAll(serviceObject);
}

void QIfConfigurationManager::addAbstractFeature(const QString &group, QIfAbstractFeature *feature)
{
    Q_ASSERT(feature);
    QIfSettingsObject *so = settingsObject(group, true);
    Q_ASSERT(so);

    so->features.append(feature);
    if (so->discoveryModeSet) {
        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);
    }

    if (so->serviceObjectSet) {
        qCDebug(qLcIfConfig) << "Updating serviceObject of" << feature << "with" << so->serviceObject;
        feature->setServiceObject(so->serviceObject);
    }
}

void QIfConfigurationManager::removeAbstractFeature(const QString &group, QIfAbstractFeature *feature)
{
    Q_ASSERT(feature);
    QIfSettingsObject *so = settingsObject(group);
    Q_ASSERT(so);

    so->features.removeAll(feature);
}

bool QIfConfigurationManager::setServiceSettings(QIfSettingsObject *so, const QVariantMap &serviceSettings)
{
    Q_ASSERT(so);
    so->serviceSettings = serviceSettings;
    so->serviceSettingsSet = true;

    for (auto &serviceObject : std::as_const(so->serviceObjects)) {
        if (!serviceObject)
            continue;
        qCDebug(qLcIfConfig) << "Updating Service Settings of" << serviceObject << "with" << serviceSettings;
        serviceObject->updateServiceSettings(serviceSettings);
    }
    return true;
}

bool QIfConfigurationManager::setSimulationFile(QIfConfiguration *config, QIfSettingsObject *so, const QString &simulationFile)
{
    Q_ASSERT(so);
    if (so->simulationFileEnvOverride) {
        if (!config || !config->ignoreOverrideWarnings())
            qtif_qmlOrCppWarning(config, "Changing the simulationFile is not possible, because the QTIF_SIMULATION_OVERRIDE env variable has been set.");
        return false;
    }
    so->simulationFile = simulationFile;
    so->simulationFileSet = true;
    return true;
}

bool QIfConfigurationManager::setSimulationDataFile(QIfConfiguration *config, QIfSettingsObject *so, const QString &simulationDataFile)
{
    Q_ASSERT(so);
    if (so->simulationDataFileEnvOverride) {
        if (!config || !config->ignoreOverrideWarnings())
            qtif_qmlOrCppWarning(config, "Changing the simulationDataFile is not possible, because the QTIF_SIMULATION_DATA_OVERRIDE env variable has been set.");
        return false;
    }
    so->simulationDataFile = simulationDataFile;
    so->simulationDataFileSet = true;
    return true;
}

bool QIfConfigurationManager::setDiscoveryMode(QIfConfiguration *config, QIfSettingsObject *so, QIfAbstractFeature::DiscoveryMode discoveryMode)
{
    Q_ASSERT(so);
    if (so->discoveryModeEnvOverride) {
        if (!config || !config->ignoreOverrideWarnings())
            qtif_qmlOrCppWarning(config, "Changing the discoveryMode is not possible, because the QTIF_DISCOVERY_MODE_OVERRIDE env variable has been set.");
        return false;
    }
    so->discoveryMode = discoveryMode;
    so->discoveryModeSet = true;

    for (auto &feature : std::as_const(so->features)) {
        if (!feature)
            continue;
        qCDebug(qLcIfConfig) << "Updating discoveryMode of" << feature << "with" << discoveryMode;
        feature->setDiscoveryMode(so->discoveryMode);
    }
    return true;
}

bool QIfConfigurationManager::setPreferredBackends(QIfConfiguration *config, QIfSettingsObject *so, const QStringList &preferredBackends)
{
    Q_ASSERT(so);
    if (so->preferredBackendsEnvOverride) {
        if (!config || !config->ignoreOverrideWarnings())
            qtif_qmlOrCppWarning(config, "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 : std::as_const(so->features)) {
        if (!feature)
            continue;
        qCDebug(qLcIfConfig) << "Updating preferredBackends of" << feature << "with" << preferredBackends;
        feature->setPreferredBackends(so->preferredBackends);
    }
    return true;
}

bool QIfConfigurationManager::setServiceObject(QIfSettingsObject *so, QIfServiceObject *serviceObject)
{
    Q_ASSERT(so);
    so->serviceObject = serviceObject;
    so->serviceObjectSet = true;

    for (auto &feature : std::as_const(so->features)) {
        if (!feature)
            continue;
        qCDebug(qLcIfConfig) << "Updating serviceObject of" << feature << "with" << serviceObject;
        feature->setServiceObject(so->serviceObject);
    }
    return true;
}

void QIfConfigurationManager::parseEnv(const QByteArray &rulesSrc, const std::function<void(const QString &, const QString &)> &func)
{
    const QString content = QString::fromLocal8Bit(rulesSrc);
    const auto lines = content.split(QLatin1Char(';'));
    for (auto line : lines) {
        // Remove whitespace at start and end of line:
        line = line.trimmed();

        int equalPos = int(line.indexOf(QLatin1Char('=')));
        if (equalPos != -1) {
            if (line.lastIndexOf(QLatin1Char('=')) == equalPos) {
                const auto key = line.left(equalPos).trimmed();
                const auto valueStr = line.mid(equalPos + 1).trimmed();

                func(key, valueStr);
            } else {
                qCWarning(qLcIfConfig, "Ignoring malformed override: '%s'", line.toUtf8().constData());
            }
        }
    }
}



QIfConfigurationPrivate::QIfConfigurationPrivate(QIfConfiguration *parent)
    : q_ptr(parent)
    , m_ignoreOverrideWarnings(false)
    , m_settingsObject(nullptr)
    , m_qmlCreation(false)
{
}


/*!
    \class QIfConfiguration
    \inmodule QtInterfaceFramework
    \since 6.5
    \brief QIfConfiguration provides settings for QIfAbstractFeature, QIfServiceObject and
    QIfSimulationEngine.

    QIfConfiguration provides settings for \l QIfAbstractFeature, \l QIfServiceObject and
    \l QIfSimulationEngine.
    All settings configured with QIfConfiguration are applied to all objects with a matching
    \c configurationId. For \l QIfSimulationEngine the identifier acts as \c configurationId.

    Once a new instance of any of the supported classes is created, and its \c configurationId matches
    with a configuration which has been created before, all settings within the configuration are
    also applied to the new instance.

    \note Reading values from QIfConfiguration does NOT read the current values of all instances
    matching the \c configurationId. It only returns the value stored in the configuration, which can
    be different, as it is still possible to change values directly without involving QIfConfiguration.
    It acts as a WRITE ONLY interface towards all matching instances.

    The following snippet shows how a configuration can be created:

    \code
    // Create a class based on QIfAbstractFeature and set it's configuration id to "group1"
    auto feature1 = new AbstractFeatureBasedClass;
    feature1.setConfigurationId("group1");

    // Create another one, but with configuration id "group2"
    auto feature2 = new AbstractFeatureBasedClass;
    feature2.setConfigurationId("group2");

    // The discoveryMode of all feature based instances in "group1" should be LoadOnlyProductionBackends
    QIfConfiguration::setDiscoveryMode("group1", QIfAbstractFeature::LoadOnlyProductionBackends);

    qDebug() << feature1.discoveryMode() << feature2.discoveryMode();
    \endcode

    The configuration is only applied to 'feature1' and NOT to 'feature2', because the latter is
    NOT in 'group1' and 'group2' doesn't have any configured value (yet).

    By adding an additional configuration the feature2 can be changed as well:

    \code
    QIfConfiguration config("group2");
    config.setDiscoeryMode(QIfAbstractFeature::LoadOnlyProductionBackends);

    qDebug() << feature1.discoveryMode() << feature2.discoveryMode();
    \endcode

    Now 'feature1' and 'feature2' have the same discoveryMode. Using an instance of QIfConfiguration
    is an alternative way instead of using the static functions.

    \note Destroying a QIfConfiguration doesn't reset the configured values.

    \section1 QML integration

    A configuration can be created from QML by instantiating the \l InterfaceFrameworkConfiguration
    element and assigning a name to it. Without a name the configuration is not valid and the
    assigned values will have no effect.

    \section1 Settings file

    In addition to creating configurations at runtime, it is also possible to provide the initial
    configuration values in a configuration file.

    If it exists, the following file is parsed at startup:

    [QLibraryInfo::DataPath]/qtifconfig.ini

    The configuration file uses the INI format and is applicable for all types which can also be
    saved as a string. This excludes the \l serviceObject setting for example. See
    \l{Settings Overview} for a list of all settings and how they can be set/overwritten.

    Following an example, which configures group1 and group2:

    \badcode
    [group1]
    preferredBackends=backend1,backend2
    serviceSettings/key1=value1
    serviceSettings/key2=value2
    [group2]
    discoveryMode=LoadOnlySimulationBackends
    \endcode

    For the \l serviceSettings setting, multiple values cannot be assigned in one statement. Instead
    every key-value pair needs to be assigned separately. The key follows the \c serviceSettings keyword
    followed by a slash as separator.
    In a similar fashion, nested key-value pairs can be created:

    \badcode
    [group1]
    serviceSettings/key1/nested1=value1
    serviceSettings/key1/nested2=value2
    \endcode

    \section1 Environment Overrides

    For testing scenarios it is sometimes useful to overwrite certain settings. This can be done
    by using one of the \c OVERRIDE environment variables. Once an override has been set, the value
    cannot be changed at runtime anymore and a warning will be shown when trying to change it.
    See the \l{ignoreOverrideWarnings} property on how this can be turned off.

    All \c OVERRIDE environment variables always have to be in the following form:

    \badcode
    OVERRIDE=<CONFIGURATIONID>=<VALUE>[;<CONFIGURATIONID>=<VALUE>]
    \endcode

    See \l{Settings Overview} for a list of all settings and how they can be set/overwritten.

    \section1 Settings Overview

    \table
        \header
            \li Setting
            \li Affected Classes
            \li Supports Initial Values
            \li Override Environment Variable
        \row
            \li \l serviceSettings
            \li \l QIfServiceObject
            \li yes
            \li -
        \row
            \li \l simulationFile
            \li \l QIfSimulationEngine
            \li yes
            \li QTIF_SIMULATION_OVERRIDE
        \row
            \li \l simulationDataFile
            \li \l QIfSimulationEngine
            \li yes
            \li QTIF_SIMULATION_DATA_OVERRIDE
        \row
            \li \l discoveryMode
            \li \l QIfAbstractFeature \l QIfAbstractFeatureListModel
            \li yes
            \li QTIF_DISCOVERY_MODE_OVERRIDE
        \row
            \li \l preferredBackends
            \li \l QIfAbstractFeature \l QIfAbstractFeatureListModel
            \li yes
            \li QTIF_PREFERRED_BACKENDS_OVERRIDE
        \row
            \li \l serviceObject
            \li \l QIfAbstractFeature \l QIfAbstractFeatureListModel
            \li no
            \li -
    \endtable
*/

/*!
    \qmltype InterfaceFrameworkConfiguration
    \instantiates QIfConfiguration
    \inqmlmodule QtInterfaceFramework
    \since 6.5

    \brief InterfaceFrameworkConfiguration is the QML version of \l QIfConfiguration.

    InterfaceFrameworkConfiguration provides settings for \l QIfAbstractFeature,
    \l QIfServiceObject and \l QIfSimulationEngine.
    All settings configured with InterfaceFrameworkConfiguration are applied to all objects with a
    matching \c configurationId. For \l QIfSimulationEngine the identifier acts as \c configurationId.

    Once a new instance of any of the supported classes is created, and its \c configurationId matches
    with a configuration which has been created before, all settings within the configuration are
    also applied to the new instance.

    \note Reading values from InterfaceFrameworkConfiguration does NOT read the current values of
    all instances matching the \c configurationId. It only returns the value stored in the
    configuration, which can be different, as it is still possible to change values directly without
    involving InterfaceFrameworkConfiguration.
    It acts as a WRITE ONLY interface towards all matching instances.

    The following snippet shows how a configuration can be created:

    \code
    Item {
        AbstractFeatureBasedItem {
            id: feature
            configurationId: "group1"
        }

        InterfaceFrameworkConfiguration {
            name: "group1"
            discoveryMode: AbstractFeature.LoadOnlyProductionBackends
        }

        Component.onCompleted: {
            console.log("DiscoveryMode:", feature.discoveryMode)
        }
    }
    \endcode

    It is also possible to provide settings to the current backend of an interface using the
    \c serviceSettings property. In the following example, the \c connectionUrl of a QtRO backend
    is set for all backends inside the \c cluster group.

    \code
    Item {
        InterfaceFrameworkConfiguration {
            name: "cluster"
            serviceSettings: {
                connectionUrl: "tcp://127.0.0.1:1234"
            }
        }
    }
    \endcode

    See \l{QIfConfiguration} for more information how to provide initial settings and overrides.
*/

/*!
    Constructs a QIfConfiguration instance with a \a name and a \a parent
*/
QIfConfiguration::QIfConfiguration(const QString &name, QObject *parent)
    : QObject(*new QIfConfigurationPrivate(this), parent)
{
    if (!name.isNull())
        setName(name);
}

QIfConfiguration::~QIfConfiguration()
{
    Q_D(const QIfConfiguration);
    if (!d->m_name.isEmpty())
        QIfConfigurationManager::instance()->m_configurationHash.remove(d->m_name);
}

/*!
    \qmlproperty boolean InterfaceFrameworkConfiguration::valid

    Returns \c true when the configuration instance is valid.

    A configuration is only valid if it was created with a name.
*/
/*!
    \property QIfConfiguration::valid

    Returns \c true when the configuration instance is valid.

    A configuration is only valid if it was created with a name.
*/
bool QIfConfiguration::isValid() const
{
    Q_D(const QIfConfiguration);
    return d->m_settingsObject != nullptr;
}

/*!
    \qmlproperty boolean InterfaceFrameworkConfiguration::ignoreOverrideWarnings

    When enabled, all override warnings will be ignored and not logged.

    \sa {Environment Overrides}
*/
/*!
    \property QIfConfiguration::ignoreOverrideWarnings

    When enabled, all override warnings will be ignored and not logged.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::ignoreOverrideWarnings() const
{
    Q_D(const QIfConfiguration);
    return d->m_ignoreOverrideWarnings;
}

/*!
    \qmlproperty string InterfaceFrameworkConfiguration::name

    Holds the name of the configuration. The name is used to find objects with a matching
    configurationId in order to apply settings to them.

    \note Once a name has been set, it cannot be changed afterwards.
*/
/*!
    \property QIfConfiguration::name

    Holds the name of the configuration. The name is used to find objects with a matching
    configurationId in order to apply settings to them.

    \note Once a name has been set, it cannot be changed afterwards.
*/
QString QIfConfiguration::name() const
{
    Q_D(const QIfConfiguration);
    return d->m_name;
}

/*!
    \qmlproperty object InterfaceFrameworkConfiguration::serviceSettings

    Holds the serviceSettings of the configuration. The serviceSettings are applied to all
    QIfServiceObject instances with a matching configurationId.
    The serviceSettings are applied when a new matching QIfServiceObject instance is created and
    they are also applied to all existing QIfServiceObject instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfServiceObject::serviceSettings
*/
/*!
    \property QIfConfiguration::serviceSettings

    Holds the serviceSettings of the configuration. The serviceSettings are applied to all
    QIfServiceObject instances with a matching configurationId.
    The serviceSettings are applied when a new matching QIfServiceObject instance is created and
    they are also applied to all existing QIfServiceObject instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfServiceObject::serviceSettings
*/
QVariantMap QIfConfiguration::serviceSettings() const
{
    Q_D(const QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(QVariantMap());

    return d->m_settingsObject->serviceSettings;
}

/*!
    \qmlproperty string InterfaceFrameworkConfiguration::simulationFile

    Holds the simulationFile of the configuration. The simulationFile is set as override for all
    matching QIfSimulationEngine instances.

    If the matching QIfSimulationeEngine is already running, updating the value doesn't have any
    effect and the simulation will continue to run as it is.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfSimulationEngine::loadSimulation()
*/
/*!
    \property QIfConfiguration::simulationFile

    Holds the simulationFile of the configuration. The simulationFile is set as override for all
    matching QIfSimulationEngine instances.

    If the matching QIfSimulationeEngine is already running, updating the value doesn't have any
    effect and the simulation will continue to run as it is.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfSimulationEngine::loadSimulation()
*/
QString QIfConfiguration::simulationFile() const
{
    Q_D(const QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(QString());

    return d->m_settingsObject->simulationFile;
}

/*!
    \qmlproperty string InterfaceFrameworkConfiguration::simulationDataFile

    Holds the simulationDataFile of the configuration. The simulationDataFile is set as override
    for all matching QIfSimulationEngine instances.

    If the matching QIfSimulationeEngine is already running, updating the value doesn't have any
    effect and the simulation will continue to run as it is.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfSimulationEngine::loadSimulationData()
*/
/*!
    \property QIfConfiguration::simulationDataFile

    Holds the simulationDataFile of the configuration. The simulationDataFile is set as override
    for all matching QIfSimulationEngine instances.

    If the matching QIfSimulationeEngine is already running, updating the value doesn't have any
    effect and the simulation will continue to run as it is.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfSimulationEngine::loadSimulationData()
*/
QString QIfConfiguration::simulationDataFile() const
{
    Q_D(const QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(QString());

    return d->m_settingsObject->simulationDataFile;
}

/*!
    \qmlproperty enumeration InterfaceFrameworkConfiguration::discoveryMode

    Holds the discoveryMode of the configuration. The discoveryMode is applied to all
    AbstractFeature or AbstractFeatureListModel instances with a matching configurationId.
    The discoveryMode is applied when a new matching instance is created and
    they are also applied to all existing instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa AbstractFeature::discoveryMode AbstractFeatureListModel::discoveryMode
*/
/*!
    \property QIfConfiguration::discoveryMode

    Holds the discoveryMode of the configuration. The discoveryMode is applied to all
    QIfAbstractFeature or QIfAbstractFeatureListModel instances with a matching configurationId.
    The discoveryMode is applied when a new matching instance is created and
    they are also applied to all existing instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfAbstractFeature::discoveryMode QIfAbstractFeatureListModel::discoveryMode
*/
QIfAbstractFeature::DiscoveryMode QIfConfiguration::discoveryMode() const
{
    Q_D(const QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(QIfAbstractFeature::DiscoveryMode());

    return d->m_settingsObject->discoveryMode;
}

/*!
    \qmlproperty list<string> InterfaceFrameworkConfiguration::preferredBackends

    Holds the preferredBackends of the configuration. The preferredBackends are applied to all
    AbstractFeature or AbstractFeatureListModel instances with a matching configurationId.
    The preferredBackends are applied when a new matching instance is created and
    it is also applied to all existing instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa AbstractFeature::preferredBackends AbstractFeatureListModel::preferredBackends
*/
/*!
    \property QIfConfiguration::preferredBackends

    Holds the preferredBackends of the configuration. The preferredBackends are applied to all
    QIfAbstractFeature or QIfAbstractFeatureListModel instances with a matching configurationId.
    The preferredBackends are applied when a new matching instance is created and
    it is also applied to all existing instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfAbstractFeature::preferredBackends QIfAbstractFeatureListModel::preferredBackends
*/
QStringList QIfConfiguration::preferredBackends() const
{
    Q_D(const QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(QStringList());

    return d->m_settingsObject->preferredBackends;
}

/*!
    \qmlproperty ServiceObject InterfaceFrameworkConfiguration::serviceObject

    Holds the serviceObject of the configuration. The serviceObject is applied to all
    AbstractFeature or AbstractFeatureListModel instances with a matching configurationId.
    The serviceObject is applied when a new matching instance is created and
    it is also applied to all existing instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa AbstractFeature::serviceObject AbstractFeatureListModel::serviceObject
*/
/*!
    \property QIfConfiguration::serviceObject

    Holds the serviceObject of the configuration. The serviceObject is applied to all
    QIfAbstractFeature or QIfAbstractFeatureListModel instances with a matching configurationId.
    The serviceObject is applied when a new matching instance is created and
    it is also applied to all existing instances.

    See \l{Settings Overview} for how to provide initial values and overrides.

    \sa QIfAbstractFeature::serviceObject QIfAbstractFeatureListModel::serviceObject
*/
QIfServiceObject *QIfConfiguration::serviceObject() const
{
    Q_D(const QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(nullptr);

    return d->m_settingsObject->serviceObject;
}

void QIfConfiguration::setIgnoreOverrideWarnings(bool ignoreOverrideWarnings)
{
    Q_D(QIfConfiguration);

    if (d->m_ignoreOverrideWarnings == ignoreOverrideWarnings)
        return;

    d->m_ignoreOverrideWarnings = ignoreOverrideWarnings;
    emit ignoreOverrideWarningsChanged(ignoreOverrideWarnings);
}

/*!
    Sets the \a name of the configuration.

    The name is used to find objects with a matching
    configurationId in order to apply all settings of this configuration to them.

    Returns \c false if setting the name failed e.g. when a instance with this name already exists or
    when the instance already has a name set. The name of an instance can't be changed once it has
    been set. Returns \c true otherwise.
*/
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;
    }

    if (QIfConfigurationManager::instance()->m_configurationHash.contains(name)) {
        qtif_qmlOrCppWarning(this, "A Configuration Object with this name already exists.");
        return false;
    }

    d->m_name = name;
    d->m_settingsObject = QIfConfigurationManager::instance()->settingsObject(name, true);

    QIfConfigurationManager::instance()->m_configurationHash.insert(name, this);

    emit nameChanged(name);
    emit isValidChanged(true);

    return true;
}

/*!
    Sets the \a serviceSettings of this configuration and applies it to all QIfServiceObject instances
    with a matching configurationId.

    Returns \c false if setting the serviceObject failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setServiceSettings(const QVariantMap &serviceSettings)
{
    Q_D(QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(false);

    if (d->m_settingsObject->serviceSettings == serviceSettings)
        return false;

    if (QIfConfigurationManager::instance()->setServiceSettings(d->m_settingsObject, serviceSettings)) {
        emit serviceSettingsChanged(serviceSettings);
        return true;
    }

    return false;
}

/*!
    Sets the \a simulationFile of this configuration and applies it to all QIfSimulationEngine instances
    with a matching configurationId.

    Returns \c false if setting the simulationFile failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setSimulationFile(const QString &simulationFile)
{
    Q_D(QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(false);

    if (d->m_settingsObject->simulationFile == simulationFile)
        return false;

    if (QIfConfigurationManager::instance()->setSimulationFile(this, d->m_settingsObject, simulationFile)) {
        emit simulationFileChanged(simulationFile);
        return true;
    }

    return false;
}

/*!
    Sets the \a simulationDataFile of this configuration and applies it to all QIfSimulationEngine instances
    with a matching configurationId.

    Returns \c false if setting the simulationDataFile failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setSimulationDataFile(const QString &simulationDataFile)
{
    Q_D(QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(false);

    if (d->m_settingsObject->simulationDataFile == simulationDataFile)
        return false;

    if (QIfConfigurationManager::instance()->setSimulationDataFile(this, d->m_settingsObject, simulationDataFile)) {
        emit simulationDataFileChanged(simulationDataFile);
        return true;
    }

    return false;
}

/*!
    Sets the \a discoveryMode of this configuration and applies it to all QIfAbstractFeature or
    QIfAbstractFeatureListModel instances with a matching configurationId.

    Returns \c false if setting the discoveryMode failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setDiscoveryMode(QIfAbstractFeature::DiscoveryMode discoveryMode)
{
    Q_D(QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(false);

    if (d->m_settingsObject->discoveryMode == discoveryMode)
        return false;

    if (QIfConfigurationManager::instance()->setDiscoveryMode(this, d->m_settingsObject, discoveryMode)) {
        emit discoveryModeChanged(discoveryMode);
        return true;
    }

    return false;
}

/*!
    Sets the \a preferredBackends of this configuration and applies it to all QIfAbstractFeature or
    QIfAbstractFeatureListModel instances with a matching configurationId.

    Returns \c false if setting the preferredBackends failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
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(this, d->m_settingsObject, preferredBackends)) {
        emit preferredBackendsChanged(preferredBackends);
        return true;
    }

    return false;
}

/*!
    Sets the \a serviceObject of this configuration and applies it to all QIfAbstractFeature or
    QIfAbstractFeatureListModel instances with a matching configurationId.

    Returns \c false if setting the serviceObject failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setServiceObject(QIfServiceObject *serviceObject)
{
    Q_D(QIfConfiguration);

    Q_CHECK_SETTINGSOBJECT(false);

    if (d->m_settingsObject->serviceObject == serviceObject)
        return false;

    if (QIfConfigurationManager::instance()->setServiceObject(d->m_settingsObject, serviceObject)) {
        emit serviceObjectChanged(serviceObject);
        return true;
    }

    return false;
}

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(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)
    : QObject(dd, parent)
{
}

// static member

/*!
    Returns \c true if the configuration \a group exists.

    A configuration is created once a single value has been set in it.
*/
bool QIfConfiguration::exists(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so != nullptr;
}

/*!
    Returns the current service settings of the configuration \a group.

    \note The returned value is what is stored inside the configuration, not the current value of all
    QIfServiceObject instances with a matching configurationId.
*/
QVariantMap QIfConfiguration::serviceSettings(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->serviceSettings : QVariantMap();
}

/*!
    Sets the \a serviceSettings of the configuration \a group and applies it to all QIfServiceObject
    instances with a matching configurationId.

    Returns \c false if setting the serviceObject failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setServiceSettings(const QString &group, const QVariantMap &serviceSettings)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
    return QIfConfigurationManager::instance()->setServiceSettings(so, serviceSettings);
}

/*!
    Returns \c true when service settings have been set in the configuration named \a group and
    false otherwise.

    A value is considered as "set" when the corresponding setter was called, a valid value was set
    in the global ini file or the corresponding override is active.

    \sa {Settings file}
*/
bool QIfConfiguration::areServiceSettingsSet(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->serviceSettingsSet : false;
}

/*!
    Returns the current simulation file of the configuration \a group.

    \note The returned value is what is stored inside the configuration, not the current value of all
    QIfSimulationEngine instances with a matching configurationId.
*/
QString QIfConfiguration::simulationFile(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->simulationFile : QString();
}

/*!
    Sets the \a simulationFile of the configuration \a group and applies it to all
    QIfSimulationEngine instances with a matching configurationId.

    Returns \c false if setting the simulationDataFile failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setSimulationFile(const QString &group, const QString &simulationFile)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
    return QIfConfigurationManager::instance()->setSimulationFile(nullptr, so, simulationFile);
}

/*!
    Returns \c true when the simulation file have been set in the configuration named \a group and
    false otherwise.

    A value is considered as "set" when the corresponding setter was called, a valid value was set
    in the global ini file or the corresponding override is active.

    \sa {Settings file}
*/
bool QIfConfiguration::isSimulationFileSet(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->simulationFileSet : false;
}

/*!
    Returns the current simulation data file of the configuration \a group.

    \note The returned value is what is stored inside the configuration, not the current value of all
    QIfSimulationEngine instances with a matching configurationId.
*/
QString QIfConfiguration::simulationDataFile(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->simulationDataFile : QString();
}

/*!
    Sets the \a simulationDataFile of the configuration \a group and applies it to all
    QIfSimulationEngine instances with a matching configurationId.

    Returns \c false if setting the simulationDataFile failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setSimulationDataFile(const QString &group, const QString &simulationDataFile)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
    return QIfConfigurationManager::instance()->setSimulationDataFile(nullptr, so, simulationDataFile);
}

/*!
    Returns \c true when the simulation data file have been set in the configuration named \a group and
    false otherwise.

    A value is considered as "set" when the corresponding setter was called, a valid value was set
    in the global ini file or the corresponding override is active.

    \sa {Settings file}
*/
bool QIfConfiguration::isSimulationDataFileSet(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->simulationDataFileSet : false;
}

/*!
    Returns the current discovery mode of the configuration \a group.

    \note The returned value is what is stored inside the configuration, not the current value of all
    QIfAbstractFeature or QIfAbstractFeatureListModel instances with a matching configurationId.
*/
QIfAbstractFeature::DiscoveryMode QIfConfiguration::discoveryMode(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->discoveryMode : QIfAbstractFeature::InvalidAutoDiscovery;
}

/*!
    Sets the \a discoveryMode of the configuration \a group and applies it to all QIfAbstractFeature or
    QIfAbstractFeatureListModel instances with a matching configurationId.

    Returns \c false if setting the serviceObject failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setDiscoveryMode(const QString &group, QIfAbstractFeature::DiscoveryMode discoveryMode)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
    return QIfConfigurationManager::instance()->setDiscoveryMode(nullptr, so, discoveryMode);
}

/*!
    Returns \c true when the discovery mode have been set in the configuration named \a group and
    false otherwise.

    A value is considered as "set" when the corresponding setter was called, a valid value was set
    in the global ini file or the corresponding override is active.

    \sa {Settings file}
*/
bool QIfConfiguration::isDiscoveryModeSet(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->discoveryModeSet : false;
}

/*!
    Returns the current preferred backends of the configuration \a group.

    \note The returned value is what is stored inside the configuration, not the current value of all
    QIfAbstractFeature or QIfAbstractFeatureListModel instances with a matching configurationId.
*/
QStringList QIfConfiguration::preferredBackends(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->preferredBackends : QStringList();
}

/*!
    Sets the \a preferredBackends of the configuration \a group and applies it to all QIfAbstractFeature or
    QIfAbstractFeatureListModel instances with a matching configurationId.

    Returns \c false if setting the serviceObject failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setPreferredBackends(const QString &group, const QStringList &preferredBackends)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
    return QIfConfigurationManager::instance()->setPreferredBackends(nullptr, so, preferredBackends);
}

/*!
    Returns \c true when the preferred backends have been set in the configuration named \a group and
    false otherwise.

    A value is considered as "set" when the corresponding setter was called, a valid value was set
    in the global ini file or the corresponding override is active.

    \sa {Settings file}
*/
bool QIfConfiguration::arePreferredBackendsSet(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->preferredBackendsSet : false;
}

/*!
    Returns the current service object of the configuration \a group.

    \note The returned value is what is stored inside the configuration, not the current value of all
    QIfAbstractFeature or QIfAbstractFeatureListModel instances with a matching configurationId.
*/
QIfServiceObject *QIfConfiguration::serviceObject(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->serviceObject : nullptr;
}

/*!
    Sets the \a serviceObject of the configuration \a group and applies it to all QIfAbstractFeature or
    QIfAbstractFeatureListModel instances with a matching configurationId.

    Returns \c false if setting the serviceObject failed because an override was active, returns \c true
    otherwise.

    \sa {Environment Overrides}
*/
bool QIfConfiguration::setServiceObject(const QString &group, QIfServiceObject *serviceObject)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group, true);
    return QIfConfigurationManager::instance()->setServiceObject(so, serviceObject);
}

/*!
    Returns \c true when the service object have been set in the configuration named \a group and
    false otherwise.

    A value is considered as "set" when the corresponding setter was called, a valid value was set
    in the global ini file or the corresponding override is active.

    \sa {Settings file}
*/
bool QIfConfiguration::isServiceObjectSet(const QString &group)
{
    QIfSettingsObject *so = QIfConfigurationManager::instance()->settingsObject(group);
    return so ? so->serviceObjectSet : false;
}


QT_END_NAMESPACE

#include "moc_qifconfiguration.cpp"