Clipboard QML Type

Provides access to the system clipboard. More...

Import Statement: import ArcGIS.AppFramework 1.0

Properties

Signals

Methods

Detailed Description

The Clipboard component provides access to the system's clipboard, offering a simple mechanism to copy and paste data as well as to display information about the data currently stored.

This code sample demonstrates using this component to display the size and data type of the clipboard's contents.

Item {
        property BinaryData binaryData: dataTypeComboBox.currentIndex >= 0 ? AppFramework.clipboard.data(dataTypeComboBox.currentText) : null
        property var dataSize: binaryData ? binaryData.size : "N/A"

        onBinaryDataChanged: {
                dataText.text = "";
        }

        ColumnLayout {
                visible: AppFramework.clipboard.dataAvailable
                anchors {
                        fill: parent
                        margins: 5
                }

                GroupBox {
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        implicitWidth: parent.width

                        ColumnLayout {
                                anchors.fill: parent

                                RowLayout {
                                        Layout.fillWidth: true

                                        Text {
                                                text: "Data types"
                                        }

                                        ComboBox {
                                                id: dataTypeComboBox
                                                Layout.fillWidth: true
                                                model: AppFramework.clipboard.dataTypes
                                        }
                                }

                                RowLayout {
                                        Layout.fillWidth: true

                                        Text {
                                                Layout.fillWidth: true

                                                text: "size: %1 bytes".arg(dataSize)
                                        }
                                }
                        }
                }

                GroupBox {
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        implicitWidth: parent.width
                        title: "Plain text"

                        ColumnLayout {
                                anchors.fill: parent

                                TextArea {
                                        id: textArea

                                        Layout.fillWidth: true
                                        Layout.fillHeight: true

                                        text: AppFramework.clipboard.text
                                        readOnly: true
                                }
                        }
                }
        }
}

Property Documentation

color : color

If color content is available on the clipboard, returns it as an application/x-color MIME type. Otherwise, returns an empty string or can set text to the clipboard as HTML.


[read-only] dataAvailable : bool

Returns true if there is any data on the clipboard. Otherwise, returns false.


[read-only] dataTypes : QStringList

Returns a string array of MIME data formats available on the clipboard.


html : string

If HTML content is available on the clipboard, returns it as a string of HTML. Otherwise, returns an empty string or can set text to the clipboard as HTML.


[read-only] supportsShare : bool

Returns true if the device supports sharing via the clipboard. Otherwise, returns false.


text : string

If text is available on the clipboard, returns it as a string. Otherwise, returns an empty string or can set text to the clipboard.


Signal Documentation

dataChanged()

Signal emitted when the data kept on the clipboard has been changed.

Note: The corresponding handler is onDataChanged.


Method Documentation

clear()

Clears the clipboard.


bool copy(var data)

Copies the supplied value to the clipboard. This function performs different actions according to the type of value provided:

Strings are copied to the clipboard as text. Numbers, boolean values and dates are converted to strings before being copied to the clipboard. URLs are copied as the uri MIME type. Colors are copied as the application/x-color MIME type. JavaScript objects are converted into string JSON representation before being copied. And items are captured as an image snapshot, after which the image is copied to the clipboard.

The data parameter

The data being copied to the clipboard.


BinaryData data(string mimeType)

Returns the requested data as specified by the give mimeType. If the data is not available, returns either a BinaryData object or null.

The mimeType parameter

The format of data to retrieve from the clipboard.

See also setData().


bool setData(string mimeType, const binarydata data)

Sets the given BinaryData object data to the clipboard, as the specified mimeType.

The mimeType parameter

The data type to set the data to the clipboard as.

The data parameter

The data being saved to the clipboard.

See also data().


share(var payload)

Opens a native interface to share the payload data across apps, including email and social media.

This functionality is only supported on iOS, macOS, and Android.

This code sample demonstrates a common usage of sharing a file through providing a file URL, by using DocumentDialog to select a file on your device, then using resolvedPathURL to convert the resulting filepath to a file URL.

Make sure that you have enabled the External Storage and File Sharing capabilities in the Capabilities tab of the Settings tool in order to save a file.

Item {
property url shareURL
property bool storagePermissionGranted

        Column {
                Button {
                        text: qsTr("Select a File")
                        onClicked: {
                                if (storagePermissionGranted === false) {
                                        permissionDialog.open()
                                }

                                else {
                                        doc.open()
                                }
                        }
                }

                Button {
                        text: qsTr("View and Share a File")
                        onClicked: {
                                AppFramework.clipboard.share(shareURL)
                        }
                }
        }

        PermissionDialog {
                id: permissionDialog
                openSettingsWhenDenied: true
                permission: PermissionDialog.PermissionDialogTypeStorage

                onAccepted: {
                        doc.open()
                }
        }


        DocumentDialog {
                id: doc
                onAccepted: {
                        shareURL = AppFramework.resolvedPathUrl(filePath)
                }
        }

        // check for storage permission
        Component.onCompleted: {
                storagePermissionGranted = Permission.checkPermission(Permission.PermissionTypeStorage) === Permission.PermissionResultGranted
        }
}

The payload parameter

The data to share across apps. Currently, this supports text and URL data types. If the URL is to a file, the file itself will be shared.

Be aware that on Android devices, files saved in cloud-based storage cannot be shared directly. The file must be saved locally.


share()

If data is available on the clipboard, opens a native interface to share this data across apps, including email and social media.

This functionality is only supported on iOS, macOS, and Android.

Item {
        property url urlInfo: "https://appstudio.arcgis.com/"

        Text {
                id: sampleURL
                text: urlInfo
        }

        Button {
                id: copyURL
                anchors.top: sampleURL.bottom
                text: "Copy as URL"

                onClicked: {
                        AppFramework.clipboard.copy(sampleURL.text)
                }
        }

        Button {
                id: shareURL
                anchors.top: copyURL.bottom
                text: "Share as URL"

                onClicked: {
                        AppFramework.clipboard.share()
                }
        }
}

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