Settings

Description

The Settings object can be used to store settings nonvolatile.

› Inherits:Object

Properties

category

This property holds a custom string which is used to group settings properties. In a group each property name has to be unique, otherwise it would be overwritten.

› Type:String
› Signal:categoryChanged()
› Attributes:Writable

saveInterval

This property holds the interval in which the settings are written to storage if saveMode is set to enumitem{Settings:SaveMode::SavePeriodically}. Otherwise or if it is set to 0 this property does nothing.

› Type:SignedInteger
› Default:0
› Signal:saveIntervalChanged()
› Attributes:Writable

saveMode

This property holds the save mode which should be used.

› Type:SaveMode
› Default:Settings.SaveManually
› Signal:saveModeChanged()
› Attributes:Writable

storage

This property holds the storage where the data will be saved. If left blank a LocalStorage will be used.

› Type:Storage
› Signal:storageChanged()
› Attributes:Writable, Optional

Methods

load()

This method loads all properties from the file and discard possible changes made.

save()

This method saves all properties in the corresponding category

Enumerations

SaveMode

This enumeration describes all available save modes for the settings object.

Name Value Description
Settings.SaveManually 0 save settings manually whenever save() is called.
Settings.SavePeriodically 1 save settings periodically depending on saveInterval.
Settings.SaveOnChange 2 save settings whenever one or more settings have changed.

Example

import InCore.Foundation 2.5

Application {

    Settings {
        id: settings

        property bool updatesEnabled: true
        property int updateInterval: 100
        property var fileName: "file.csv"
        property var sensorNames: [
            "temp1",
            "temp2",
            "temp3"
        ]
        onCompleted: save();
    }

    CsvWriter {
        Repeater on objects {
            model: 3
            Measurement {
                id: measurement
                name: settings.sensorNames[index]
                property var updateTimer : Timer {
                    interval: settings.updateInterval
                    running: settings.updatesEnabled
                    onTriggered: measurement.data = Math.random() * 100;
                }
            }
        }

        output: File {
            fileName: settings.fileName
            storage: LocalStorage { }
            onErrorChanged: console.log(errorString)
        }

        outputMode: CsvWriter.OutputTruncate
        submitMode: CsvWriter.SubmitOnCompleteDataset
    }

}