Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplace.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 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
5
#
include
"qplace.h"
6
#
include
"qplace_p.h"
7
8
#
include
<
QtPositioning
/
QGeoLocation
>
9
10
#
ifdef
QPLACE_DEBUG
11
#
include
<
QDebug
>
12
#
endif
13
14
#
include
<
QStringList
>
15
16
QT_BEGIN_NAMESPACE
17
18
template
<>
19
QPlacePrivate *QSharedDataPointer<QPlacePrivate>::clone()
20
{
21
return
d->clone();
22
}
23
24
QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QPlacePrivate)
25
26
/*!
27
\class QPlace
28
\inmodule QtLocation
29
\ingroup QtLocation-places
30
\ingroup QtLocation-places-data
31
\since 5.6
32
33
\brief The QPlace class represents a set of data about a place.
34
35
\input place-definition.qdocinc
36
37
\section1 Contact Information
38
The contact information of a place is based around a common set of
39
\l {Contact Types}{contact types}. To retrieve all the phone numbers
40
of a place, one would do:
41
42
\snippet places/requesthandler.h Phone numbers
43
44
The contact types are string values by design to allow for providers
45
to introduce new contact types.
46
47
For convenience there are a set of functions which return the value
48
of the first contact detail of each type.
49
\list
50
\li QPlace::primaryPhone()
51
\li QPlace::primaryEmail()
52
\li QPlace::primaryWebsite()
53
\li QPlace::primaryFax()
54
\endlist
55
56
\section1 Extended Attributes
57
Places may have additional attributes which are not covered in the formal API.
58
Similar to contacts attributes are based around a common set of
59
\l {Attribute Types}{attribute types}. To retrieve an extended attribute one
60
would do:
61
\snippet places/requesthandler.h Opening hours
62
63
The attribute types are string values by design to allow providers
64
to introduce new attribute types.
65
66
\section1 Content
67
The QPlace object is only meant to be a convenient container to hold
68
rich content such as images, reviews and so on. Retrieval of content
69
should happen via QPlaceManager::getPlaceContent().
70
71
The content is stored as a QPlaceContent::Collection which contains
72
both the index of the content, as well as the content itself. This enables
73
developers to check whether a particular item has already been retrieved
74
and if not, then request that content.
75
76
\section2 Attribution
77
Places have a field for a rich text attribution string. Some providers
78
may require that the attribution be shown when a place is displayed
79
to a user.
80
81
\section2 Categories
82
Different categories may be assigned to a place to indicate that the place
83
is associated with those categories. When saving a place, the only meaningful
84
data is the category id, the rest of the category data is effectively ignored.
85
The category must already exist before saving the place (it is not possible
86
to create a new category, assign it to the place, save the place and expect
87
the category to be created).
88
89
\section1 Saving Caveats
90
\input place-caveats.qdocinc
91
*/
92
93
/*!
94
Constructs an empty place object.
95
*/
96
QPlace::QPlace()
97
: d_ptr(
new
QPlacePrivateDefault())
98
{
99
}
100
101
/*!
102
Constructs an place object using \a dd as private implementation.
103
*/
104
QPlace::QPlace(
const
QSharedDataPointer<QPlacePrivate> &dd): d_ptr(dd)
105
{
106
}
107
108
109
/*!
110
Constructs a copy of \a other.
111
*/
112
QPlace::QPlace(
const
QPlace &other)
noexcept
=
default
;
113
114
/*!
115
Destroys this place.
116
*/
117
QPlace::~QPlace() =
default
;
118
119
/*!
120
Assigns \a other to this place and returns a reference
121
to this place.
122
*/
123
QPlace &QPlace::operator= (
const
QPlace & other)
noexcept
124
{
125
if
(
this
== &other)
126
return
*
this
;
127
128
d_ptr = other.d_ptr;
129
return
*
this
;
130
}
131
132
inline
QPlacePrivate *QPlace::d_func()
133
{
134
return
static_cast
<QPlacePrivate *>(d_ptr.data());
135
}
136
137
inline
const
QPlacePrivate *QPlace::d_func()
const
138
{
139
return
static_cast
<
const
QPlacePrivate *>(d_ptr.constData());
140
}
141
142
/*!
143
\fn bool QPlace::operator==(const QPlace &lhs, const QPlace &rhs) noexcept
144
145
Returns true if \a lhs is equal to \a rhs,
146
otherwise returns false.
147
*/
148
149
/*!
150
\fn bool QPlace::operator!=(const QPlace &lhs, const QPlace &rhs) noexcept
151
152
Returns true if \a lhs is not equal to \a rhs,
153
otherwise returns false.
154
*/
155
156
bool
QPlace::isEqual(
const
QPlace &other)
const
noexcept
157
{
158
return
( (d_ptr.constData() == other.d_ptr.constData())
159
|| (*d_ptr) == (*other.d_ptr));
160
}
161
162
/*!
163
Returns categories that this place belongs to.
164
*/
165
QList<QPlaceCategory> QPlace::categories()
const
166
{
167
return
d_ptr->categories();
168
}
169
170
/*!
171
Sets a single \a category that this place belongs to.
172
*/
173
void
QPlace::setCategory(
const
QPlaceCategory &category)
174
{
175
d_ptr->setCategories(QList<QPlaceCategory>());
176
d_ptr->setCategories(QList<QPlaceCategory>() << category);
177
}
178
179
/*!
180
Sets the \a categories that this place belongs to.
181
*/
182
void
QPlace::setCategories(
const
QList<QPlaceCategory> &categories)
183
{
184
d_ptr->setCategories(categories);
185
}
186
187
/*!
188
Returns the location of the place.
189
*/
190
QGeoLocation QPlace::location()
const
191
{
192
return
d_ptr->location();
193
}
194
195
/*!
196
Sets the \a location of the place.
197
*/
198
void
QPlace::setLocation(
const
QGeoLocation &location)
199
{
200
d_ptr->setLocation(location);
201
}
202
203
/*!
204
Returns an aggregated rating of the place.
205
*/
206
QPlaceRatings QPlace::ratings()
const
207
{
208
return
d_ptr->ratings();
209
}
210
211
/*!
212
Sets the aggregated \a rating of the place.
213
*/
214
void
QPlace::setRatings(
const
QPlaceRatings &rating)
215
{
216
d_ptr->setRatings(rating);
217
}
218
219
/*!
220
Returns the supplier of this place.
221
*/
222
QPlaceSupplier QPlace::supplier()
const
223
{
224
return
d_ptr->supplier();
225
}
226
227
/*!
228
Sets the supplier of this place to \a supplier.
229
*/
230
void
QPlace::setSupplier(
const
QPlaceSupplier &supplier)
231
{
232
d_ptr->setSupplier(supplier);
233
}
234
235
/*!
236
Returns a collection of content associated with a place.
237
This collection is a map with the key being the index of the content object
238
and value being the content object itself.
239
240
The \a type specifies which kind of content is to be retrieved.
241
*/
242
QPlaceContent::Collection QPlace::content(QPlaceContent::Type type)
const
243
{
244
return
d_ptr->m_contentCollections.value(type);
245
}
246
247
/*!
248
Sets a collection of \a content for the given \a type.
249
*/
250
void
QPlace::setContent(QPlaceContent::Type type,
const
QPlaceContent::Collection &content)
251
{
252
d_ptr->m_contentCollections.insert(type, content);
253
}
254
255
/*!
256
Adds a collection of \a content of the given \a type to the place. Any index in \a content
257
that already exists is overwritten.
258
*/
259
void
QPlace::insertContent(QPlaceContent::Type type,
const
QPlaceContent::Collection &content)
260
{
261
for
(
auto
iter = content.cbegin(), end = content.cend(); iter != end; ++iter)
262
d_ptr->m_contentCollections[type].insert(iter.key(), iter.value());
263
}
264
265
/*!
266
Returns the total count of content objects of the given \a type.
267
This total count indicates how many the manager/provider should have available.
268
(As opposed to how many objects this place instance is currently assigned).
269
270
A negative count indicates that the total number of items is unknown.
271
By default the total content count is set to 0.
272
*/
273
int
QPlace::totalContentCount(QPlaceContent::Type type)
const
274
{
275
return
d_ptr->m_contentCounts.value(type, 0);
276
}
277
278
/*!
279
Sets the \a totalCount of content objects of the given \a type.
280
*/
281
void
QPlace::setTotalContentCount(QPlaceContent::Type type,
int
totalCount)
282
{
283
d_ptr->m_contentCounts.insert(type, totalCount);
284
}
285
286
/*!
287
Returns the name of the place.
288
*/
289
QString QPlace::name()
const
290
{
291
return
d_ptr->name();
292
}
293
294
/*!
295
Sets the \a name of the place.
296
*/
297
void
QPlace::setName(
const
QString &name)
298
{
299
d_ptr->setName(name);
300
}
301
302
/*!
303
Returns the identifier of the place. The place identifier is only meaningful to the QPlaceManager that
304
generated it and is not transferable between managers. The place identifier is not guaranteed
305
to be universally unique, but unique for the manager that generated it.
306
*/
307
QString QPlace::placeId()
const
308
{
309
return
d_ptr->placeId();
310
}
311
312
/*!
313
Sets the \a identifier of the place.
314
*/
315
void
QPlace::setPlaceId(
const
QString &identifier)
316
{
317
d_ptr->setPlaceId(identifier);
318
}
319
320
/*!
321
Returns a rich text attribution string of the place. Note, some providers may have a
322
requirement where the attribution must be shown whenever a place is displayed to an end user.
323
*/
324
QString QPlace::attribution()
const
325
{
326
return
d_ptr->attribution();
327
}
328
329
/*!
330
Sets the \a attribution string of the place.
331
*/
332
void
QPlace::setAttribution(
const
QString &attribution)
333
{
334
d_ptr->setAttribution(attribution);
335
}
336
337
/*!
338
Returns the icon of the place.
339
*/
340
QPlaceIcon QPlace::icon()
const
341
{
342
return
d_ptr->icon();
343
}
344
345
/*!
346
Sets the \a icon of the place.
347
*/
348
void
QPlace::setIcon(
const
QPlaceIcon &icon)
349
{
350
d_ptr->setIcon(icon);
351
}
352
353
/*!
354
Returns the primary phone number for this place. This accesses the first contact detail
355
of the \l {QPlaceContactDetail::Phone}{phone number type}. If no phone details exist, then an empty string is returned.
356
*/
357
QString QPlace::primaryPhone()
const
358
{
359
QList<QPlaceContactDetail> phoneNumbers = d_ptr->contacts().value(QPlaceContactDetail::Phone);
360
if
(!phoneNumbers.isEmpty())
361
return
phoneNumbers.at(0).value();
362
else
363
return
QString();
364
}
365
366
/*!
367
Returns the primary fax number for this place. This convenience function accesses the first contact
368
detail of the \l {QPlaceContactDetail::Fax}{fax type}. If no fax details exist, then an empty string is returned.
369
*/
370
QString QPlace::primaryFax()
const
371
{
372
QList<QPlaceContactDetail> faxNumbers = d_ptr->contacts().value(QPlaceContactDetail::Fax);
373
if
(!faxNumbers.isEmpty())
374
return
faxNumbers.at(0).value();
375
else
376
return
QString();
377
}
378
379
/*!
380
Returns the primary email address for this place. This convenience function accesses the first
381
contact detail of the \l {QPlaceContactDetail::Email}{email type}. If no email addresses exist, then
382
an empty string is returned.
383
*/
384
QString QPlace::primaryEmail()
const
385
{
386
QList<QPlaceContactDetail> emailAddresses = d_ptr->contacts().value(QPlaceContactDetail::Email);
387
if
(!emailAddresses.isEmpty())
388
return
emailAddresses.at(0).value();
389
else
390
return
QString();
391
}
392
393
/*!
394
Returns the primary website of the place. This convenience function accesses the first
395
contact detail of the \l {QPlaceContactDetail::Website}{website type}. If no websites exist,
396
then an empty string is returned.
397
*/
398
QUrl QPlace::primaryWebsite()
const
399
{
400
QList<QPlaceContactDetail> websites = d_ptr->contacts().value(QPlaceContactDetail::Website);
401
if
(!websites.isEmpty())
402
return
QUrl(websites.at(0).value());
403
else
404
return
{};
405
}
406
407
/*!
408
Returns true if the details of this place have been fetched,
409
otherwise returns false.
410
*/
411
bool
QPlace::detailsFetched()
const
412
{
413
return
d_ptr->detailsFetched();
414
}
415
416
/*!
417
Sets whether the details of this place have been \a fetched or not.
418
*/
419
void
QPlace::setDetailsFetched(
bool
fetched)
420
{
421
d_ptr->setDetailsFetched(fetched);
422
}
423
424
/*!
425
Returns the types of extended attributes that this place has.
426
*/
427
QStringList QPlace::extendedAttributeTypes()
const
428
{
429
return
d_ptr->extendedAttributes().keys();
430
}
431
432
/*!
433
Returns the exteded attribute corresponding to the specified \a attributeType.
434
If the place does not have that particular attribute type, a default constructed
435
QPlaceExtendedAttribute is returned.
436
*/
437
QPlaceAttribute QPlace::extendedAttribute(
const
QString &attributeType)
const
438
{
439
return
d_ptr->extendedAttribute(attributeType);
440
}
441
442
/*!
443
Assigns an \a attribute of the given \a attributeType to a place. If the given \a attributeType
444
already exists in the place, then it is overwritten.
445
446
If \a attribute is a default constructed QPlaceAttribute, then the \a attributeType
447
is removed from the place which means it will not be listed by QPlace::extendedAttributeTypes().
448
*/
449
void
QPlace::setExtendedAttribute(
const
QString &attributeType,
450
const
QPlaceAttribute &attribute)
451
{
452
if
(attribute == QPlaceAttribute())
453
d_ptr->extendedAttributes().remove(attributeType);
454
else
455
d_ptr->extendedAttributes().insert(attributeType, attribute);
456
}
457
458
/*!
459
Remove the attribute of \a attributeType from the place.
460
461
The attribute will no longer be listed by QPlace::extendedAttributeTypes()
462
*/
463
void
QPlace::removeExtendedAttribute(
const
QString &attributeType)
464
{
465
setExtendedAttribute(attributeType, QPlaceAttribute());
466
}
467
468
/*!
469
Returns the type of contact details this place has.
470
471
See QPlaceContactDetail for a list of common \l {QPlaceContactDetail::Email}{contact types}.
472
*/
473
QStringList QPlace::contactTypes()
const
474
{
475
return
d_ptr->contacts().keys();
476
}
477
478
/*!
479
Returns a list of contact details of the specified \a contactType.
480
481
See QPlaceContactDetail for a list of common \l {QPlaceContactDetail::Email}{contact types}.
482
*/
483
QList<QPlaceContactDetail> QPlace::contactDetails(
const
QString &contactType)
const
484
{
485
return
d_ptr->contacts().value(contactType);
486
}
487
488
/*!
489
Sets the contact \a details of a specified \a contactType.
490
491
If \a details is empty, then the \a contactType is removed from the place such
492
that it is no longer returned by QPlace::contactTypes().
493
494
See QPlaceContactDetail for a list of common \l {QPlaceContactDetail::Email}{contact types}.
495
*/
496
void
QPlace::setContactDetails(
const
QString &contactType, QList<QPlaceContactDetail> details)
497
{
498
if
(details.isEmpty())
499
d_ptr->contacts().remove(contactType);
500
else
501
d_ptr->contacts().insert(contactType, details);
502
}
503
504
/*!
505
Appends a contact \a detail of a specified \a contactType.
506
507
See QPlaceContactDetail for a list of common \l {QPlaceContactDetail::Email}{contact types}.
508
*/
509
void
QPlace::appendContactDetail(
const
QString &contactType,
const
QPlaceContactDetail &detail)
510
{
511
QList<QPlaceContactDetail> details = d_ptr->contacts().value(contactType);
512
details.append(detail);
513
d_ptr->contacts().insert(contactType, details);
514
}
515
516
/*!
517
Removes all the contact details of a given \a contactType.
518
519
The \a contactType is no longer returned when QPlace::contactTypes() is called.
520
*/
521
void
QPlace::removeContactDetails(
const
QString &contactType)
522
{
523
d_ptr->contacts().remove(contactType);
524
}
525
526
/*!
527
Sets the visibility of the place to \a visibility.
528
*/
529
void
QPlace::setVisibility(QLocation::Visibility visibility)
530
{
531
d_ptr->setVisibility(visibility);
532
}
533
534
/*!
535
Returns the visibility of the place.
536
537
The default visibility of a new place is set to QtLocatin::Unspecified visibility.
538
If a place is saved with unspecified visibility the backend chooses an appropriate
539
default visibility to use when saving.
540
*/
541
QLocation::Visibility QPlace::visibility()
const
542
{
543
return
d_ptr->visibility();
544
}
545
546
/*!
547
Returns a boolean indicating whether the all the fields of the place are empty or not.
548
*/
549
bool
QPlace::isEmpty()
const
550
{
551
return
d_ptr->isEmpty();
552
}
553
554
/*******************************************************************************
555
*******************************************************************************/
556
557
QPlacePrivate::QPlacePrivate()
558
: QSharedData()
559
{
560
}
561
562
QPlacePrivate::QPlacePrivate(
const
QPlacePrivate &other)
563
: QSharedData(other),
564
m_contentCollections(other.m_contentCollections),
565
m_contentCounts(other.m_contentCounts)
566
{
567
}
568
569
QPlacePrivate::~QPlacePrivate() {}
570
571
bool
QPlacePrivate::operator== (
const
QPlacePrivate &other)
const
572
{
573
return
(categories() == other.categories()
574
&& location() == other.location()
575
&& ratings() == other.ratings()
576
&& supplier() == other.supplier()
577
&& m_contentCollections == other.m_contentCollections
578
&& m_contentCounts == other.m_contentCounts
579
&& name() == other.name()
580
&& placeId() == other.placeId()
581
&& attribution() == other.attribution()
582
&& contacts() == other.contacts()
583
&& extendedAttributes() == other.extendedAttributes()
584
&& visibility() == other.visibility()
585
&& icon() == other.icon()
586
);
587
}
588
589
590
bool
QPlacePrivate::isEmpty()
const
591
{
592
return
(categories().isEmpty()
593
&& location().isEmpty()
594
&& ratings().isEmpty()
595
&& supplier().isEmpty()
596
&& m_contentCollections.isEmpty()
597
&& m_contentCounts.isEmpty()
598
&& name().isEmpty()
599
&& placeId().isEmpty()
600
&& attribution().isEmpty()
601
&& contacts().isEmpty()
602
&& extendedAttributes().isEmpty()
603
&& QLocation::UnspecifiedVisibility == visibility()
604
&& icon().isEmpty()
605
);
606
}
607
608
QPlaceAttribute QPlacePrivate::extendedAttribute(
const
QString &attributeType)
const
609
{
610
return
extendedAttributes().value(attributeType);
611
}
612
613
614
615
//
616
// Default implementation
617
//
618
619
QPlacePrivateDefault::QPlacePrivateDefault()
620
: QPlacePrivate(), m_visibility(QLocation::UnspecifiedVisibility), m_detailsFetched(
false
)
621
{
622
}
623
624
QPlacePrivateDefault::QPlacePrivateDefault(
const
QPlacePrivateDefault &other)
625
: QPlacePrivate(other),
626
m_categories(other.m_categories),
627
m_location(other.m_location),
628
m_ratings(other.m_ratings),
629
m_supplier(other.m_supplier),
630
m_name(other.m_name),
631
m_placeId(other.m_placeId),
632
m_attribution(other.m_attribution),
633
m_extendedAttributes(other.m_extendedAttributes),
634
m_contacts(other.m_contacts),
635
m_visibility(other.m_visibility),
636
m_icon(other.m_icon),
637
m_detailsFetched(other.m_detailsFetched)
638
{
639
}
640
641
QPlacePrivateDefault::~QPlacePrivateDefault()
642
{
643
}
644
645
QPlacePrivate *QPlacePrivateDefault::clone()
646
{
647
return
new
QPlacePrivateDefault(*
this
);
648
}
649
650
QList<QPlaceCategory> QPlacePrivateDefault::categories()
const
651
{
652
return
m_categories;
653
}
654
655
void
QPlacePrivateDefault::setCategories(
const
QList<QPlaceCategory> &categories)
656
{
657
m_categories = categories;
658
}
659
660
QGeoLocation QPlacePrivateDefault::location()
const
661
{
662
return
m_location;
663
}
664
665
void
QPlacePrivateDefault::setLocation(
const
QGeoLocation &location)
666
{
667
m_location = location;
668
}
669
670
QPlaceRatings QPlacePrivateDefault::ratings()
const
671
{
672
return
m_ratings;
673
}
674
675
void
QPlacePrivateDefault::setRatings(
const
QPlaceRatings &ratings)
676
{
677
m_ratings = ratings;
678
}
679
680
QPlaceSupplier QPlacePrivateDefault::supplier()
const
681
{
682
return
m_supplier;
683
}
684
685
void
QPlacePrivateDefault::setSupplier(
const
QPlaceSupplier &supplier)
686
{
687
m_supplier = supplier;
688
}
689
690
QString QPlacePrivateDefault::name()
const
691
{
692
return
m_name;
693
}
694
695
void
QPlacePrivateDefault::setName(
const
QString &name)
696
{
697
m_name = name;
698
}
699
700
QString QPlacePrivateDefault::placeId()
const
701
{
702
return
m_placeId;
703
}
704
705
void
QPlacePrivateDefault::setPlaceId(
const
QString &placeIdentifier)
706
{
707
m_placeId = placeIdentifier;
708
}
709
710
QString QPlacePrivateDefault::attribution()
const
711
{
712
return
m_attribution;
713
}
714
715
void
QPlacePrivateDefault::setAttribution(
const
QString &attribution)
716
{
717
m_attribution = attribution;
718
}
719
720
QLocation::Visibility QPlacePrivateDefault::visibility()
const
721
{
722
return
m_visibility;
723
}
724
725
void
QPlacePrivateDefault::setVisibility(QLocation::Visibility visibility)
726
{
727
m_visibility = visibility;
728
}
729
730
QPlaceIcon QPlacePrivateDefault::icon()
const
731
{
732
return
m_icon;
733
}
734
735
void
QPlacePrivateDefault::setIcon(
const
QPlaceIcon &icon)
736
{
737
m_icon = icon;
738
}
739
740
bool
QPlacePrivateDefault::detailsFetched()
const
741
{
742
return
m_detailsFetched;
743
}
744
745
void
QPlacePrivateDefault::setDetailsFetched(
bool
fetched)
746
{
747
m_detailsFetched = fetched;
748
}
749
750
QMap<QString, QPlaceAttribute> QPlacePrivateDefault::extendedAttributes()
const
751
{
752
return
m_extendedAttributes;
753
}
754
755
QMap<QString, QPlaceAttribute> &QPlacePrivateDefault::extendedAttributes()
756
{
757
return
m_extendedAttributes;
758
}
759
760
QMap<QString, QList<QPlaceContactDetail> > QPlacePrivateDefault::contacts()
const
761
{
762
return
m_contacts;
763
}
764
765
QMap<QString, QList<QPlaceContactDetail> > &QPlacePrivateDefault::contacts()
766
{
767
return
m_contacts;
768
}
769
770
771
772
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtlocation
src
location
places
qplace.cpp
Generated on
for Qt by
1.18.0