Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplacesearchresult.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7#include "qplaceresult.h"
8#include <QtCore/qnumeric.h>
9
10QT_USE_NAMESPACE
11
12template<> QPlaceSearchResultPrivate *QSharedDataPointer<QPlaceSearchResultPrivate>::clone()
13{
14 return d->clone();
15}
16
17inline QPlaceSearchResultPrivate *QPlaceSearchResult::d_func()
18{
19 return static_cast<QPlaceSearchResultPrivate *>(d_ptr.data());
20}
21
22inline const QPlaceSearchResultPrivate *QPlaceSearchResult::d_func() const
23{
24 return static_cast<const QPlaceSearchResultPrivate *>(d_ptr.constData());
25}
26
27bool QPlaceSearchResultPrivate::compare(const QPlaceSearchResultPrivate *other) const
28{
29 return title == other->title
30 && icon == other->icon;
31}
32
33/*!
34 \class QPlaceSearchResult
35 \inmodule QtLocation
36 \ingroup QtLocation-places
37 \ingroup QtLocation-places-data
38 \since 5.6
39
40 \brief The QPlaceSearchResult class is the base class for search results.
41
42 A list of search results can be retrieved from the QPlaceSearchReply after it has
43 successfully completed the request. Common to all search results are the
44 \l {QPlaceSearchResult::title()} {title} and \l {QPlaceSearchResult::icon()}{icon},
45 which can be used to present the search result to the user.
46
47 The intended usage is that depending on the \l {QPlaceSearchResult::type()} {type},
48 the search result can be converted to a more detailed subclass like so:
49
50 \snippet places/requesthandler.h Convert search result
51
52 The implementation is handled in such a way that object slicing is not an issue.
53 It is not expected that client applications or backend plugins instantiate
54 a QPlaceSearchResult directly, but rather client applications simply convert
55 to search result subclasses and backend plugins only instantiate subclasses.
56
57 \sa QPlaceResult
58*/
59
60/*!
61 \enum QPlaceSearchResult::SearchResultType
62
63 Defines the type of search result
64
65 \value UnknownSearchResult The contents of the search result are unknown.
66 \value PlaceResult The search result contains a place.
67 \value ProposedSearchResult The search result contains a proposed search which may be relevant.
68*/
69
70/*!
71 Constructs a new search result.
72*/
73QPlaceSearchResult::QPlaceSearchResult()
74 : d_ptr(new QPlaceSearchResultPrivate)
75{
76}
77
78/*!
79 Constructs a copy of \a other
80*/
81QPlaceSearchResult::QPlaceSearchResult(const QPlaceSearchResult &other)
82 :d_ptr(other.d_ptr)
83{
84}
85
86/*!
87 Destroys the search result.
88*/
89QPlaceSearchResult::~QPlaceSearchResult()
90{
91}
92
93/*!
94 Assigns \a other to this search result and returns a reference to this
95 search result.
96*/
97QPlaceSearchResult &QPlaceSearchResult::operator =(const QPlaceSearchResult &other)
98{
99 if (this == &other)
100 return *this;
101
102 d_ptr = other.d_ptr;
103 return *this;
104}
105
106/*!
107 Returns true if \a other is equal to this search result, otherwise
108 returns false.
109*/
110bool QPlaceSearchResult::operator==(const QPlaceSearchResult &other) const
111{
112 // An unknown object is only equal to another unknown search result
113 if (!d_ptr)
114 return !other.d_ptr;
115
116 if (type() != other.type())
117 return false;
118
119 return d_ptr->compare(other.d_ptr);
120}
121
122/*!
123 \fn bool QPlaceSearchResult::operator!=(const QPlaceSearchResult &other) const
124 Returns true if \a other not equal to this search result, otherwise
125 returns false.
126*/
127
128/*!
129 Returns the result type.
130*/
131QPlaceSearchResult::SearchResultType QPlaceSearchResult::type() const
132{
133 if (!d_ptr)
134 return UnknownSearchResult;
135 return d_ptr->type();
136}
137
138/*!
139 Returns the title of the search result. This string can be used to display the search result
140 to the user.
141*/
142QString QPlaceSearchResult::title() const
143{
144 Q_D(const QPlaceSearchResult);
145 return d->title;
146}
147
148/*!
149 Sets the title of the search result to \a title.
150*/
151void QPlaceSearchResult::setTitle(const QString &title)
152{
153 Q_D(QPlaceSearchResult);
154 d->title = title;
155}
156
157/*!
158 Returns an icon that can be used to represent the search result.
159*/
160QPlaceIcon QPlaceSearchResult::icon() const
161{
162 Q_D(const QPlaceSearchResult);
163 return d->icon;
164}
165
166/*!
167 Sets the icon of the search result to \a icon.
168*/
169void QPlaceSearchResult::setIcon(const QPlaceIcon &icon)
170{
171 Q_D(QPlaceSearchResult);
172 d->icon = icon;
173}
174
175/*!
176 \internal
177 Constructs a new search result from the given pointer \a d.
178*/
179QPlaceSearchResult::QPlaceSearchResult(QPlaceSearchResultPrivate *d)
180 :d_ptr(d)
181{
182}