summaryrefslogtreecommitdiff
path: root/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel.cpp
blob: 4d64bb2c13b67371f9fdc487b5c3d230bca3154c (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
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: http://www.qt-project.org/
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativerecommendationmodel_p.h"
#include "qdeclarativeplace_p.h"

#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeInfo>
#include <QtLocation/QGeoServiceProvider>
#include <QtLocation/QPlaceManager>

#include <QtLocation/QPlaceSearchReply>
#include <QtLocation/QPlaceMatchRequest>
#include <QtLocation/QPlaceMatchReply>

QT_USE_NAMESPACE

/*!
    \qmlclass PlaceRecommendationModel QDeclarativeRecommenadationModel
    \inqmlmodule QtLocation 5
    \ingroup qml-QtLocation5-places
    \since QtLocation 5.0

    \brief The PlaceRecommendationModel element provides a model of place recommendations.

    PlaceRecommendationModel provides a model of place recommendation results within the \l searchArea,
    that are similar to the place identified by the \l placeId property.

    The \l offset and \l limit properties can be used to access paged search results.  When the
    \l offset and \l limit properties are set the search results between \l offset and
    (\l offset + \l limit - 1) will be returned.

    The model returns data for the following roles:

    \table
        \header
            \o Role
            \o Type
            \o Description
        \row
            \o distance
            \o real
            \o The distance to the place.
        \row
            \o place
            \o \l Place
            \o The place.
    \endtable

    The following example shows how to use the PlaceRecommendationModel to search for recommendations in
    close proximity of a given position.

    \snippet snippets/declarative/places.qml QtQuick import
    \snippet snippets/declarative/places.qml QtLocation import
    \codeline
    \snippet snippets/declarative/places.qml RecommendationModel

    \sa PlaceSearchModel, CategoryModel, {QPlaceManager}
*/

/*!
    \qmlproperty Plugin PlaceRecommendationModel::plugin

    This property holds the \l Plugin which will be used to perform the search.
*/

/*!
    \qmlproperty Plugin PlaceRecommendationModel::favoritesPlugin

    This property holds the \l Plugin which will be used to look for favorites.
    Any places from the recommendation search which can be cross-referenced/matched
    in the favorites \l Plugin will have their \l {Place::favorite}{favorite} property
    set with the \l Place from the favorites \l Plugin.

    If the favoritesPlugin is not set, the \l {Place::favorite}{favorite} property
    of the places in the results will always be null.

    \sa Favorites
*/

/*!
    \qmlproperty VariantMap PlaceRecommendationModel::favoritesMatchParameters

    This property holds a set of parameters used to specify how recommended places
    are matched to favorites in the favoritesPlugin.

    By default the parameter map is empty and implies that the favorites plugin
    matches by \l {Alternative Id cross-referencing}{alternative ids}.  Generally,
    an application developer will not need to set this property.

    In cases where the favorites plugin does not support matching by alternative ids,
    then the \l {Information about plugins} {backend plugin documentation} should be consulted
    to see precisely what key-value parameters to set.
*/

/*!
    \qmlproperty BoundingArea PlaceRecommendationModel::searchArea

    This property holds the search area.  Search results returned by the model will be within the
    search area.

    If this property is set to a \l BoundingCircle its \l {BoundingCircle::radius}{radius} property
    may be left unset, in which case the \l Plugin will choose an appropriate radius for the
    search.
*/

/*!
    \qmlproperty int PlaceRecommendationModel::offset

    This property holds the index of the first search result in the model.

    \sa limit
*/

/*!
    \qmlproperty int PlaceRecommendationModel::limit

    This property holds the limit of the number of items that will be returned.

    \sa offset
*/

/*!
    \qmlproperty enum PlaceRecommendationModel::status

    This property holds the status of the model.  It can be one of:

    \table
        \row
            \o PlaceRecommendationModel.Ready
            \o The search query has completed and the result are available.
        \row
            \o PlaceRecommendationModel.Executing
            \o A search query is currently being executed.
        \row
            \o PlaceRecommendationModel.Error
            \o An error occurred when executing the previous search query.
    \endtable
*/

/*!
    \qmlmethod PlaceRecommendationModel::execute()

    Executes a recommendation search query for places similar to the place identified by the
    \l placeId property.  Once the query completes the model items are updated with the search
    results.

    \sa cancel(), status
*/

/*!
    \qmlmethod PlaceRecommendationModel::cancel()

    Cancels an ongoing search query.

    \sa execute(), status
*/

QDeclarativeRecommendationModel::QDeclarativeRecommendationModel(QObject *parent)
:   QDeclarativeResultModelBase(parent)
{
}

QDeclarativeRecommendationModel::~QDeclarativeRecommendationModel()
{
}

/*!
    \qmlproperty string PlaceRecommendationModel::placeId

    This property holds place id used in the recommendation search query.
*/
QString QDeclarativeRecommendationModel::placeId() const
{
    return m_placeId;
}

void QDeclarativeRecommendationModel::setPlaceId(const QString &placeId)
{
    if (m_placeId == placeId)
        return;

    m_placeId = placeId;
    emit placeIdChanged();
}

/*!
    \qmlproperty string PlaceRecommendationModel::count

    This properties holds the number of results the model has.
*/

/*!
    \qmlmethod PlaceRecommendationModel::data(int index, string role)

    Returns the data for a given \a role at the specified row \a index.
*/

QPlaceReply *QDeclarativeRecommendationModel::sendQuery(QPlaceManager *manager,
                                                        const QPlaceSearchRequest &request)
{
    return manager->recommendations(m_placeId, request);
}