summaryrefslogtreecommitdiff
path: root/src/location/doc/snippets/declarative/places_loader.qml
blob: 88e328dba43d85d34ecd28da41b5eb3e0faac47b (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick 2.0
import QtPositioning 5.2
import QtLocation 5.3

Rectangle {
    width: 360
    height: 360
    property variant startCoordinate: QtPositioning.coordinate(-27.46778, 153.02778)

    Plugin {
        id: myPlugin
        name: "osm"
        //specify plugin parameters if necessary
        //PluginParameter {...}
        //PluginParameter {...}
        //...
    }

    PlaceSearchModel {
        id: searchModel

        plugin: myPlugin

        searchTerm: "pizza"
        searchArea: QtPositioning.circle(startCoordinate)

        Component.onCompleted: update()
    }

    //! [Handle Result Types]
    Component {
        id: resultDelegate
        Loader {
            Component {
                id: placeResult

                Column {
                    Text { text: title }
                    Text { text: place.location.address.text }
                }
            }

            Component {
                id: otherResult
                Text { text: title }
            }

            sourceComponent: type == PlaceSearchModel.PlaceResult ? placeResult :
                                                                    otherResult
        }
    }
    //! [Handle Result Types]

    ListView {
        anchors.fill: parent
        model: searchModel
        delegate:  resultDelegate
        spacing: 10
    }

    Connections {
        target: searchModel
        onStatusChanged: {
            if (searchModel.status == PlaceSearchModel.Error)
                console.log(searchModel.errorString());
        }
    }
}