1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtLocation module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qplacesearchresult.h"
38#include "qplacesearchresult_p.h"
39#include "qplaceresult.h"
40#include <QtCore/qnumeric.h>
41
42QT_USE_NAMESPACE
43
44template<> QPlaceSearchResultPrivate *QSharedDataPointer<QPlaceSearchResultPrivate>::clone()
45{
46 return d->clone();
47}
48
49inline QPlaceSearchResultPrivate *QPlaceSearchResult::d_func()
50{
51 return static_cast<QPlaceSearchResultPrivate *>(d_ptr.data());
52}
53
54inline const QPlaceSearchResultPrivate *QPlaceSearchResult::d_func() const
55{
56 return static_cast<const QPlaceSearchResultPrivate *>(d_ptr.constData());
57}
58
59bool QPlaceSearchResultPrivate::compare(const QPlaceSearchResultPrivate *other) const
60{
61 return title == other->title
62 && icon == other->icon;
63}
64
65/*!
66 \class QPlaceSearchResult
67 \inmodule QtLocation
68 \ingroup QtLocation-places
69 \ingroup QtLocation-places-data
70 \since 5.6
71
72 \brief The QPlaceSearchResult class is the base class for search results.
73
74 A list of search results can be retrieved from the QPlaceSearchReply after it has
75 successfully completed the request. Common to all search results are the
76 \l {QPlaceSearchResult::title()} {title} and \l {QPlaceSearchResult::icon()}{icon},
77 which can be used to present the search result to the user.
78
79 The intended usage is that depending on the \l {QPlaceSearchResult::type()} {type},
80 the search result can be converted to a more detailed subclass like so:
81
82 \snippet places/requesthandler.h Convert search result
83
84 The implementation is handled in such a way that object slicing is not an issue.
85 It is not expected that client applications or backend plugins instantiate
86 a QPlaceSearchResult directly, but rather client applications simply convert
87 to search result subclasses and backend plugins only instantiate subclasses.
88
89 \sa QPlaceResult
90*/
91
92/*!
93 \enum QPlaceSearchResult::SearchResultType
94
95 Defines the type of search result
96
97 \value UnknownSearchResult The contents of the search result are unknown.
98 \value PlaceResult The search result contains a place.
99 \value ProposedSearchResult The search result contains a proposed search which may be relevant.
100*/
101
102/*!
103 Constructs a new search result.
104*/
105QPlaceSearchResult::QPlaceSearchResult()
106 : d_ptr(new QPlaceSearchResultPrivate)
107{
108}
109
110/*!
111 Constructs a copy of \a other
112*/
113QPlaceSearchResult::QPlaceSearchResult(const QPlaceSearchResult &other)
114 :d_ptr(other.d_ptr)
115{
116}
117
118/*!
119 Destroys the search result.
120*/
121QPlaceSearchResult::~QPlaceSearchResult()
122{
123}
124
125/*!
126 Assigns \a other to this search result and returns a reference to this
127 search result.
128*/
129QPlaceSearchResult &QPlaceSearchResult::operator =(const QPlaceSearchResult &other)
130{
131 if (this == &other)
132 return *this;
133
134 d_ptr = other.d_ptr;
135 return *this;
136}
137
138/*!
139 Returns true if \a other is equal to this search result, otherwise
140 returns false.
141*/
142bool QPlaceSearchResult::operator==(const QPlaceSearchResult &other) const
143{
144 // An unknown object is only equal to another unknown search result
145 if (!d_ptr)
146 return !other.d_ptr;
147
148 if (type() != other.type())
149 return false;
150
151 return d_ptr->compare(other: other.d_ptr);
152}
153
154/*!
155 \fn bool QPlaceSearchResult::operator!=(const QPlaceSearchResult &other) const
156 Returns true if \a other not equal to this search result, otherwise
157 returns false.
158*/
159
160/*!
161 Returns the result type.
162*/
163QPlaceSearchResult::SearchResultType QPlaceSearchResult::type() const
164{
165 if (!d_ptr)
166 return UnknownSearchResult;
167 return d_ptr->type();
168}
169
170/*!
171 Returns the title of the search result. This string can be used to display the search result
172 to the user.
173*/
174QString QPlaceSearchResult::title() const
175{
176 Q_D(const QPlaceSearchResult);
177 return d->title;
178}
179
180/*!
181 Sets the title of the search result to \a title.
182*/
183void QPlaceSearchResult::setTitle(const QString &title)
184{
185 Q_D(QPlaceSearchResult);
186 d->title = title;
187}
188
189/*!
190 Returns an icon that can be used to represent the search result.
191*/
192QPlaceIcon QPlaceSearchResult::icon() const
193{
194 Q_D(const QPlaceSearchResult);
195 return d->icon;
196}
197
198/*!
199 Sets the icon of the search result to \a icon.
200*/
201void QPlaceSearchResult::setIcon(const QPlaceIcon &icon)
202{
203 Q_D(QPlaceSearchResult);
204 d->icon = icon;
205}
206
207/*!
208 \internal
209 Constructs a new search result from the given pointer \a d.
210*/
211QPlaceSearchResult::QPlaceSearchResult(QPlaceSearchResultPrivate *d)
212 :d_ptr(d)
213{
214}
215

source code of qtlocation/src/location/places/qplacesearchresult.cpp