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