Environment QML Type

A component for handling environment values. More...

Import Statement: import ArcGIS.AppFramework 1.0

Signals

Methods

  • bool isEmpty(string name)
  • bool isSet(string name)
  • var remove(string name)
  • var setValue(string name, var value)
  • var value(string variable)
  • var value(string variable, var defaultValue)

Detailed Description

The Environment component provides means to set, access, or remove environment values that exist within the system environment. This is useful for assigning variables that are needed to manage other components of your app.

This code sample demonstrates usage of the Environment component. A 'scripts' folder is appended to your PATH environment variable, which has already been set in your system. The value method is used to read the current value, while the setValue method is used to set a new value.

ListView {
    id: listView

    anchors.fill: parent

    delegate: ItemDelegate {
        text: modelData
    }

    function getPathSeparator() {
        var windowsPathSeparator = ";";
        var unixPathSeparator = ":";
        if (Qt.platform.os === "windows") {
            return windowsPathSeparator;
        } else {
            return unixPathSeparator;
        }
    }

    function getPathArray() {
        return AppFramework.environment.value("PATH").split(getPathSeparator());
    }

    function appendPath(newPath) {
        var pathArray = getPathArray();
        if (pathArray.indexOf(newPath) !== -1) {
            console.log("2b");
            return;
        }
        pathArray.push(newPath);
        AppFramework.environment.setValue("PATH", pathArray.join(getPathSeparator()));
    }

    function getScriptsPath() {
        var scriptsPath = AppFramework.userHomeFolder.filePath("scripts");
        if (Qt.platform.os === "windows") {
            var windowsDirSeparator = "\\";
            scriptsPath = scriptsPath.replace(/\//g, windowsDirSeparator);
        }
        return scriptsPath;
    }

    Component.onCompleted: {
        var scriptsPath = getScriptsPath();
        appendPath(scriptsPath);
        listView.model = getPathArray();
    }
}

Signal Documentation

valueChanged(string name, var value)

Signal emitted when an environment variable has been changed.

Note: The corresponding handler is onValueChanged.


Method Documentation

bool isEmpty(string name)

Returns true if the environmental variable named is empty.

The name parameter

The name of the variable to check.


bool isSet(string name)

Returns true if the named environment variable has been set. Otherwise, returns false.

The name parameter

The name of the environment variable to check.


var remove(string name)

Returns, and then deletes, the named variable from the environment.

The name parameter

The name of the environment variable to delete.


var setValue(string name, var value)

Sets the named environment variable to the given value.

The name parameter

The name of the variable to set.

The value parameter

The contents of the value to set.

See also value().


var value(string variable)

Returns the value the named environment variable is set to.

The variable parameter

The name of the environment variable to return.


var value(string variable, var defaultValue)

Returns the value the named environment variable is set to. If a variable is not declared, returns the default value.

The variable parameter

The name of the environment variable to return.

The defaultValue parameter

The default value to return if the environment variable is not declared.

See also setValue().


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.