summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp
blob: 483a599266a87d688f69d5fbc9f332302819da4f (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later 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 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativegeoserviceprovider_p.h"
#include <QtQml/QQmlInfo>
#include <QtQml/QQmlEngine>

QT_BEGIN_NAMESPACE

/*!
    \qmltype Plugin
    //! \instantiates QDeclarativeGeoServiceProvider
    \inqmlmodule QtLocation
    \ingroup qml-QtLocation5-common
    \since QtLocation 5.5

    \brief The Plugin type describes a Location based services plugin.

    The Plugin type is used to declaratively specify which available
    GeoServices plugin should be used for various tasks in the Location API.
    Plugins are used by \l Map, \l RouteModel, and \l GeocodeModel
    types, as well as a variety of others.

    Plugins recognized by the system have a \l name property, a simple string
    normally indicating the name of the service that the Plugin retrieves
    data from. They also have a variety of features, which can be test for using the
    \l {supportsRouting()}, \l {supportsGeocoding()}, \l {supportsMapping()},
    \l {supportsPlaces()} and \l {supportsNavigation()} methods.

    When a Plugin object is created, it is "detached" and not associated with
    any actual service plugin. Once it has received information via setting
    its \l name, \l preferred, or \l required properties, it will choose an
    appropriate service plugin to attach to. Plugin objects can only be
    attached once; to use multiple plugins, create multiple Plugin objects.

    \section2 Example Usage

    The following snippet shows a Plugin object being created with the
    \l required and \l preferred properties set. This Plugin will attach to the
    first found plugin that supports both mapping and geocoding, and will
    prefer plugins named "here" or "osm" to any others.

    \code
    Plugin {
        id: plugin
        preferred: ["here", "osm"]
        required: Plugin.AnyMappingFeatures | Plugin.AnyGeocodingFeatures
    }
    \endcode
*/

QDeclarativeGeoServiceProvider::QDeclarativeGeoServiceProvider(QObject *parent)
:   QObject(parent),
    sharedProvider_(0),
    required_(new QDeclarativeGeoServiceProviderRequirements),
    complete_(false),
    experimental_(false)
{
    locales_.append(QLocale().name());
}

QDeclarativeGeoServiceProvider::~QDeclarativeGeoServiceProvider()
{
    delete required_;
    delete sharedProvider_;
}



/*!
    \qmlproperty string Plugin::name

    This property holds the name of the plugin. Setting this property
    will cause the Plugin to only attach to a plugin with exactly this
    name. The value of \l required will be ignored.
*/
void QDeclarativeGeoServiceProvider::setName(const QString &name)
{
    if (name_ == name)
        return;

    name_ = name;

    if (complete_)
        tryAttach();

    emit nameChanged(name_);
}

/*!
    \internal
*/
bool QDeclarativeGeoServiceProvider::parametersReady() {
    for (const QDeclarativePluginParameter *p: qAsConst(parameters_)) {
        if (!p->isInitialized())
            return false;
    }
    return true;
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProvider::tryAttach()
{
    if (!parametersReady())
        return;

    delete sharedProvider_;
    sharedProvider_ = nullptr;

    if (name_.isEmpty())
        return;

    sharedProvider_ = new QGeoServiceProvider(name_, parameterMap());
    sharedProvider_->setQmlEngine(qmlEngine(this));
    sharedProvider_->setLocale(locales_.at(0));
    sharedProvider_->setAllowExperimental(experimental_);

    emit attached();
}

QString QDeclarativeGeoServiceProvider::name() const
{
    return name_;
}


/*!
    \qmlproperty stringlist Plugin::availableServiceProviders

    This property holds a list of all available service plugins' names. This
    can be used to manually enumerate the available plugins if the
    control provided by \l name and \l required is not sufficient for your
    needs.
*/
QStringList QDeclarativeGeoServiceProvider::availableServiceProviders()
{
    return QGeoServiceProvider::availableServiceProviders();
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProvider::componentComplete()
{
    complete_ = true;

    for (QDeclarativePluginParameter *p: qAsConst(parameters_)) {
        if (!p->isInitialized()) {
            connect(p, &QDeclarativePluginParameter::initialized,
                    this, &QDeclarativeGeoServiceProvider::tryAttach);
        }
    }

    if (!name_.isEmpty()) {
        tryAttach();
    } else if (!prefer_.isEmpty()
            || required_->mappingRequirements() != NoMappingFeatures
            || required_->routingRequirements() != NoRoutingFeatures
            || required_->geocodingRequirements() != NoGeocodingFeatures
            || required_->placesRequirements() != NoPlacesFeatures
            || required_->navigationRequirements() != NoNavigationFeatures) {

        QStringList providers = QGeoServiceProvider::availableServiceProviders();

        /* first check any preferred plugins */
        foreach (const QString &name, prefer_) {
            if (providers.contains(name)) {
                // so we don't try it again later
                providers.removeAll(name);

                QGeoServiceProvider sp(name, parameterMap(), experimental_);
                if (required_->matches(&sp)) {
                    setName(name);
                    return;
                }
            }
        }

        /* then try the rest */
        foreach (const QString &name, providers) {
            QGeoServiceProvider sp(name, parameterMap(), experimental_);
            if (required_->matches(&sp)) {
                setName(name);
                return;
            }
        }

        qmlWarning(this) << "Could not find a plugin with the required features to attach to";
    }
}

/*!
    \qmlmethod bool Plugin::supportsGeocoding(GeocodingFeatures features)

    This method returns a boolean indicating whether the specified set of \a features are supported
    by the geo service provider plugin. \c True is returned if all specified \a features are
    supported; otherwise \c false is returned.

    The \a features parameter can be any flag combination of:
    \table
        \header
            \li Feature
            \li Description
        \row
            \li Plugin.NoGeocodingFeatures
            \li No geocoding features are supported.
        \row
            \li Plugin.OnlineGeocodingFeature
            \li Online geocoding is supported.
        \row
            \li Plugin.OfflineGeocodingFeature
            \li Offline geocoding is supported.
        \row
            \li Plugin.ReverseGeocodingFeature
            \li Reverse geocoding is supported.
        \row
            \li Plugin.LocalizedGeocodingFeature
            \li Supports returning geocoding results with localized addresses.
        \row
            \li Plugin.AnyGeocodingFeatures
            \li Matches a geo service provider that provides any geocoding features.
    \endtable
*/
bool QDeclarativeGeoServiceProvider::supportsGeocoding(const GeocodingFeatures &feature) const
{
    QGeoServiceProvider *sp = sharedGeoServiceProvider();
    QGeoServiceProvider::GeocodingFeatures f =
            static_cast<QGeoServiceProvider::GeocodingFeature>(int(feature));
    if (f == QGeoServiceProvider::AnyGeocodingFeatures)
        return (sp && (sp->geocodingFeatures() != QGeoServiceProvider::NoGeocodingFeatures));
    else
        return (sp && (sp->geocodingFeatures() & f) == f);
}

/*!
    \qmlmethod bool Plugin::supportsMapping(MappingFeatures features)

    This method returns a boolean indicating whether the specified set of \a features are supported
    by the geo service provider plugin.  True is returned if all specified \a features are
    supported; otherwise false is returned.

    The \a features parameter can be any flag combination of:
    \table
        \header
            \li Feature
            \li Description
        \row
            \li Plugin.NoMappingFeatures
            \li No mapping features are supported.
        \row
            \li Plugin.OnlineMappingFeature
            \li Online mapping is supported.
        \row
            \li Plugin.OfflineMappingFeature
            \li Offline mapping is supported.
        \row
            \li Plugin.LocalizedMappingFeature
            \li Supports returning localized map data.
        \row
            \li Plugin.AnyMappingFeatures
            \li Matches a geo service provider that provides any mapping features.
    \endtable
*/
bool QDeclarativeGeoServiceProvider::supportsMapping(const MappingFeatures &feature) const
{
    QGeoServiceProvider *sp = sharedGeoServiceProvider();
    QGeoServiceProvider::MappingFeatures f =
            static_cast<QGeoServiceProvider::MappingFeature>(int(feature));
    if (f == QGeoServiceProvider::AnyMappingFeatures)
        return (sp && (sp->mappingFeatures() != QGeoServiceProvider::NoMappingFeatures));
    else
        return (sp && (sp->mappingFeatures() & f) == f);
}

/*!
    \qmlmethod bool Plugin::supportsRouting(RoutingFeatures features)

    This method returns a boolean indicating whether the specified set of \a features are supported
    by the geo service provider plugin.  True is returned if all specified \a features are
    supported; otherwise false is returned.

    The \a features parameter can be any flag combination of:
    \table
        \header
            \li Feature
            \li Description
        \row
            \li Plugin.NoRoutingFeatures
            \li No routing features are supported.
        \row
            \li Plugin.OnlineRoutingFeature
            \li Online routing is supported.
        \row
            \li Plugin.OfflineRoutingFeature
            \li Offline routing is supported.
        \row
            \li Plugin.LocalizedRoutingFeature
            \li Supports returning routes with localized addresses and instructions.
        \row
            \li Plugin.RouteUpdatesFeature
            \li Updating an existing route based on the current position is supported.
        \row
            \li Plugin.AlternativeRoutesFeature
            \li Supports returning alternative routes.
        \row
            \li Plugin.ExcludeAreasRoutingFeature
            \li Supports specifying a areas which the returned route must not cross.
        \row
            \li Plugin.AnyRoutingFeatures
            \li Matches a geo service provider that provides any routing features.
    \endtable
*/
bool QDeclarativeGeoServiceProvider::supportsRouting(const RoutingFeatures &feature) const
{
    QGeoServiceProvider *sp = sharedGeoServiceProvider();
    QGeoServiceProvider::RoutingFeatures f =
            static_cast<QGeoServiceProvider::RoutingFeature>(int(feature));
    if (f == QGeoServiceProvider::AnyRoutingFeatures)
        return (sp && (sp->routingFeatures() != QGeoServiceProvider::NoRoutingFeatures));
    else
        return (sp && (sp->routingFeatures() & f) == f);
}

/*!
    \qmlmethod bool Plugin::supportsPlaces(PlacesFeatures features)

    This method returns a boolean indicating whether the specified set of \a features are supported
    by the geo service provider plugin.  True is returned if all specified \a features are
    supported; otherwise false is returned.

    The \a features parameter can be any flag combination of:
    \table
        \header
            \li Feature
            \li Description
        \row
            \li Plugin.NoPlacesFeatures
            \li No places features are supported.
        \row
            \li Plugin.OnlinePlacesFeature
            \li Online places is supported.
        \row
            \li Plugin.OfflinePlacesFeature
            \li Offline places is supported.
        \row
            \li Plugin.SavePlaceFeature
            \li Saving categories is supported.
        \row
            \li Plugin.RemovePlaceFeature
            \li Removing or deleting places is supported.
        \row
            \li Plugin.PlaceRecommendationsFeature
            \li Searching for recommended places similar to another place is supported.
        \row
            \li Plugin.SearchSuggestionsFeature
            \li Search suggestions is supported.
        \row
            \li Plugin.LocalizedPlacesFeature
            \li Supports returning localized place data.
        \row
            \li Plugin.NotificationsFeature
            \li Notifications of place and category changes is supported.
        \row
            \li Plugin.PlaceMatchingFeature
            \li Supports matching places from two different geo service providers.
        \row
            \li Plugin.AnyPlacesFeatures
            \li Matches a geo service provider that provides any places features.
    \endtable
*/
bool QDeclarativeGeoServiceProvider::supportsPlaces(const PlacesFeatures &feature) const
{
    QGeoServiceProvider *sp = sharedGeoServiceProvider();
    QGeoServiceProvider::PlacesFeatures f =
            static_cast<QGeoServiceProvider::PlacesFeature>(int(feature));
    if (f == QGeoServiceProvider::AnyPlacesFeatures)
        return (sp && (sp->placesFeatures() != QGeoServiceProvider::NoPlacesFeatures));
    else
        return (sp && (sp->placesFeatures() & f) == f);
}

/*!
    \qmlmethod bool Plugin::supportsNavigation(NavigationFeatures features)

    This method returns a boolean indicating whether the specified set of \a features are supported
    by the geo service provider plugin.  True is returned if all specified \a features are
    supported; otherwise false is returned.

    The \a features parameter can be any flag combination of:
    \table
        \header
            \li Feature
            \li Description
        \row
            \li Plugin.NoNavigationFeatures
            \li No navigation features are supported.
        \row
            \li Plugin.OnlineNavigationFeature
            \li Online navigation is supported.
        \row
            \li Plugin.OfflineNavigationFeature
            \li Offline navigation is supported.
        \row
            \li Plugin.AnyNavigationFeatures
            \li Matches a geo service provider that provides any navigation features.
    \endtable
*/
bool QDeclarativeGeoServiceProvider::supportsNavigation(const QDeclarativeGeoServiceProvider::NavigationFeature &feature) const
{
    QGeoServiceProvider *sp = sharedGeoServiceProvider();
    QGeoServiceProvider::NavigationFeatures f =
            static_cast<QGeoServiceProvider::NavigationFeature>(int(feature));
    if (f == QGeoServiceProvider::AnyNavigationFeatures)
        return (sp && (sp->navigationFeatures() != QGeoServiceProvider::NoNavigationFeatures));
    else
        return (sp && (sp->navigationFeatures() & f) == f);
}

/*!
    \qmlproperty enumeration Plugin::required

    This property contains the set of features that will be required by the
    Plugin object when choosing which service plugin to attach to. If the
    \l name property is set, this has no effect.

    Any of the following values or a bitwise combination of multiple values
    may be set:

    \list
    \li Plugin.NoFeatures
    \li Plugin.GeocodingFeature
    \li Plugin.ReverseGeocodingFeature
    \li Plugin.RoutingFeature
    \li Plugin.MappingFeature
    \li Plugin.AnyPlacesFeature
    \endlist
*/
QDeclarativeGeoServiceProviderRequirements *QDeclarativeGeoServiceProvider::requirements() const
{
    return required_;
}

void QDeclarativeGeoServiceProvider::setRequirements(QDeclarativeGeoServiceProviderRequirements *req)
{
    if (!name().isEmpty() || !req)
        return;

    if (required_ && *required_ == *req)
        return;

    delete required_;
    required_ = req;
    QQmlEngine::setObjectOwnership(req, QQmlEngine::CppOwnership); // To prevent the engine from making this object disappear
}

/*!
    \qmlproperty stringlist Plugin::preferred

    This property contains an ordered list of preferred plugin names, which
    will be checked for the required features set in \l{Plugin::required}{required}
    before any other available plugins are checked.
*/
QStringList QDeclarativeGeoServiceProvider::preferred() const
{
    return prefer_;
}

void QDeclarativeGeoServiceProvider::setPreferred(const QStringList &val)
{
    prefer_ = val;
    emit preferredChanged(prefer_);
}

/*!
    \qmlproperty bool Plugin::isAttached

    This property indicates if the Plugin item is attached to a geoservice provider plugin.
*/
bool QDeclarativeGeoServiceProvider::isAttached() const
{
    return (sharedProvider_ != 0);
}

/*!
    \qmlproperty bool Plugin::allowExperimental

    This property indicates if experimental plugins can be used.
*/
bool QDeclarativeGeoServiceProvider::allowExperimental() const
{
    return experimental_;
}

void QDeclarativeGeoServiceProvider::setAllowExperimental(bool allow)
{
    if (experimental_ == allow)
        return;

    experimental_ = allow;
    if (sharedProvider_)
        sharedProvider_->setAllowExperimental(allow);

    emit allowExperimentalChanged(allow);
}

/*!
    \internal
*/
QGeoServiceProvider *QDeclarativeGeoServiceProvider::sharedGeoServiceProvider() const
{
    return sharedProvider_;
}

/*!
    \qmlproperty stringlist Plugin::locales

    This property contains an ordered list of preferred plugin locales.  If the first locale cannot be accommodated, then
    the backend falls back to using the second, and so on.  By default the locales property contains the system locale.

    The locales are specified as strings which have the format
    "language[_script][_country]" or "C", where:

    \list
    \li language is a lowercase, two-letter, ISO 639 language code,
    \li script is a titlecase, four-letter, ISO 15924 script code,
    \li country is an uppercase, two- or three-letter, ISO 3166 country code (also "419" as defined by United Nations),
    \li the "C" locale is identical in behavior to English/UnitedStates as per QLocale
    \endlist

    If the first specified locale cannot be accommodated, the \l {Plugin} falls back to the next and so forth.
    Some \l {Plugin} backends may not support a set of locales which are rigidly defined.  An arbitrary
    example is that some \l {Place}'s in France could have French and English localizations, while
    certain areas in America may only have the English localization available.  In the above scenario,
    the set of supported locales is context dependent on the search location.

    If the \l {Plugin} cannot accommodate any of the preferred locales, the manager falls
    back to using a supported language that is backend specific.

    For \l {Plugin}'s that do not support locales, the locales list is always empty.

    The following code demonstrates how to set a single and multiple locales:
    \snippet declarative/plugin.qml Plugin locale
*/
QStringList QDeclarativeGeoServiceProvider::locales() const
{
    return locales_;
}

void QDeclarativeGeoServiceProvider::setLocales(const QStringList &locales)
{
    if (locales_ == locales)
        return;

    locales_ = locales;

    if (locales_.isEmpty())
        locales_.append(QLocale().name());

    if (sharedProvider_)
        sharedProvider_->setLocale(locales_.at(0));

    emit localesChanged();
}

/*!
    \qmlproperty list<PluginParameter> Plugin::parameters
    \default

    This property holds the list of plugin parameters.
*/
QQmlListProperty<QDeclarativePluginParameter> QDeclarativeGeoServiceProvider::parameters()
{
    return QQmlListProperty<QDeclarativePluginParameter>(this,
            0,
            parameter_append,
            parameter_count,
            parameter_at,
            parameter_clear);
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProvider::parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *parameter)
{
    QDeclarativeGeoServiceProvider *p = static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
    p->parameters_.append(parameter);
    if (p->sharedProvider_)
        p->sharedProvider_->setParameters(p->parameterMap());
}

/*!
    \internal
*/
int QDeclarativeGeoServiceProvider::parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop)
{
    return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_.count();
}

/*!
    \internal
*/
QDeclarativePluginParameter *QDeclarativeGeoServiceProvider::parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, int index)
{
    return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_[index];
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProvider::parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop)
{
    QDeclarativeGeoServiceProvider *p = static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
    p->parameters_.clear();
    if (p->sharedProvider_)
        p->sharedProvider_->setParameters(p->parameterMap());
}

/*!
    \internal
*/
QVariantMap QDeclarativeGeoServiceProvider::parameterMap() const
{
    QVariantMap map;

    for (int i = 0; i < parameters_.size(); ++i) {
        QDeclarativePluginParameter *parameter = parameters_.at(i);
        map.insert(parameter->name(), parameter->value());
    }

    return map;
}

/*******************************************************************************
*******************************************************************************/

QDeclarativeGeoServiceProviderRequirements::QDeclarativeGeoServiceProviderRequirements(QObject *parent)
    : QObject(parent),
      mapping_(QDeclarativeGeoServiceProvider::NoMappingFeatures),
      routing_(QDeclarativeGeoServiceProvider::NoRoutingFeatures),
      geocoding_(QDeclarativeGeoServiceProvider::NoGeocodingFeatures),
      places_(QDeclarativeGeoServiceProvider::NoPlacesFeatures),
      navigation_(QDeclarativeGeoServiceProvider::NoNavigationFeatures)
{
}

QDeclarativeGeoServiceProviderRequirements::~QDeclarativeGeoServiceProviderRequirements()
{
}

/*!
    \internal
*/
QDeclarativeGeoServiceProvider::MappingFeatures QDeclarativeGeoServiceProviderRequirements::mappingRequirements() const
{
    return mapping_;
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProviderRequirements::setMappingRequirements(const QDeclarativeGeoServiceProvider::MappingFeatures &features)
{
    if (mapping_ == features)
        return;

    mapping_ = features;
    emit mappingRequirementsChanged(mapping_);
    emit requirementsChanged();
}

/*!
    \internal
*/
QDeclarativeGeoServiceProvider::RoutingFeatures QDeclarativeGeoServiceProviderRequirements::routingRequirements() const
{
    return routing_;
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProviderRequirements::setRoutingRequirements(const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
{
    if (routing_ == features)
        return;

    routing_ = features;
    emit routingRequirementsChanged(routing_);
    emit requirementsChanged();
}

/*!
    \internal
*/
QDeclarativeGeoServiceProvider::GeocodingFeatures QDeclarativeGeoServiceProviderRequirements::geocodingRequirements() const
{
    return geocoding_;
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProviderRequirements::setGeocodingRequirements(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
{
    if (geocoding_ == features)
        return;

    geocoding_ = features;
    emit geocodingRequirementsChanged(geocoding_);
    emit requirementsChanged();
}

/*!
    \internal

    */
QDeclarativeGeoServiceProvider::PlacesFeatures QDeclarativeGeoServiceProviderRequirements::placesRequirements() const
{
    return places_;
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProviderRequirements::setPlacesRequirements(const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
{
    if (places_ == features)
        return;

    places_ = features;
    emit placesRequirementsChanged(places_);
    emit requirementsChanged();
}

/*!
    \internal
*/
QDeclarativeGeoServiceProvider::NavigationFeatures QDeclarativeGeoServiceProviderRequirements::navigationRequirements() const
{
    return navigation_;
}

/*!
    \internal
*/
void QDeclarativeGeoServiceProviderRequirements::setNavigationRequirements(const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
{
    if (navigation_ == features)
        return;

    navigation_ = features;
    emit navigationRequirementsChanged(navigation_);
    emit requirementsChanged();
}

/*!
    \internal
*/
bool QDeclarativeGeoServiceProviderRequirements::matches(const QGeoServiceProvider *provider) const
{
    QGeoServiceProvider::MappingFeatures mapping =
            static_cast<QGeoServiceProvider::MappingFeatures>(int(mapping_));

    // extra curlies here to avoid "dangling" else, which could belong to either if
    // same goes for all the rest of these blocks
    if (mapping == QGeoServiceProvider::AnyMappingFeatures) {
        if (provider->mappingFeatures() == QGeoServiceProvider::NoMappingFeatures)
            return false;
    } else {
        if ((provider->mappingFeatures() & mapping) != mapping)
            return false;
    }

    QGeoServiceProvider::RoutingFeatures routing =
            static_cast<QGeoServiceProvider::RoutingFeatures>(int(routing_));

    if (routing == QGeoServiceProvider::AnyRoutingFeatures) {
        if (provider->routingFeatures() == QGeoServiceProvider::NoRoutingFeatures)
            return false;
    } else {
        if ((provider->routingFeatures() & routing) != routing)
            return false;
    }

    QGeoServiceProvider::GeocodingFeatures geocoding =
            static_cast<QGeoServiceProvider::GeocodingFeatures>(int(geocoding_));

    if (geocoding == QGeoServiceProvider::AnyGeocodingFeatures) {
        if (provider->geocodingFeatures() == QGeoServiceProvider::NoGeocodingFeatures)
            return false;
    } else {
        if ((provider->geocodingFeatures() & geocoding) != geocoding)
            return false;
    }

    QGeoServiceProvider::PlacesFeatures places =
            static_cast<QGeoServiceProvider::PlacesFeatures>(int(places_));

    if (places == QGeoServiceProvider::AnyPlacesFeatures) {
        if (provider->placesFeatures() == QGeoServiceProvider::NoPlacesFeatures)
            return false;
    } else {
        if ((provider->placesFeatures() & places) != places)
            return false;
    }

    QGeoServiceProvider::NavigationFeatures navigation =
            static_cast<QGeoServiceProvider::NavigationFeatures>(int(navigation_));

    if (navigation == QGeoServiceProvider::AnyNavigationFeatures) {
        if (provider->navigationFeatures() == QGeoServiceProvider::NoNavigationFeatures)
            return false;
    } else {
        if ((provider->navigationFeatures() & navigation) != navigation)
            return false;
    }

    return true;
}

bool QDeclarativeGeoServiceProviderRequirements::operator == (const QDeclarativeGeoServiceProviderRequirements &rhs) const
{
    return (mapping_ == rhs.mapping_ && routing_ == rhs.routing_
            && geocoding_ == rhs.geocoding_ && places_ == rhs.places_
            && navigation_ == rhs.navigation_);
}

/*******************************************************************************
*******************************************************************************/

/*!
    \qmltype PluginParameter
    //! \instantiates QDeclarativePluginParameter
    \inqmlmodule QtLocation
    \ingroup qml-QtLocation5-common
    \since QtLocation 5.5

    \brief The PluginParameter type describes a parameter for a plugin, either
    geo service \l Plugin, or \l{Qt Positioning plugins}{position Plugin}.

    The PluginParameter object is used to provide a parameter of some kind
    to a plugin. Typically these parameters contain details like an application
    token for access to a service, or a proxy server to use for network access,
    or the serial port to which a serial GPS receiver is connected.

    To set such a parameter, declare a PluginParameter inside an element that accepts
    plugin parameters as configuration objects, such as a \l Plugin object, or a
    \l PositionSource object, and give it \l{name} and \l{value} properties. A list of valid
    parameter names for each plugin is available from the
    \l {Qt Location#Plugin References and Parameters}{plugin reference pages} for geoservice plugins,
    and \l {Qt Positioning plugins#Default plugins} for position plugins.

    \section2 Example Usage

    The following example shows an instantiation of the \l {Qt Location HERE Plugin}{HERE} plugin
    with a mapping API \e app_id and \e token pair specific to the application.

    \code
    Plugin {
        name: "here"
        PluginParameter { name: "here.app_id"; value: "EXAMPLE_API_ID" }
        PluginParameter { name: "here.token"; value: "EXAMPLE_TOKEN_123" }
    }
    \endcode
*/

/*!
    \qmlproperty string PluginParameter::name

    This property holds the name of the plugin parameter as a single formatted string.
    This property is a write-once property.
*/

/*!
    \qmlproperty QVariant PluginParameter::value

    This property holds the value of the plugin parameter which support different types of values (variant).
    This property is a write-once property.
*/

/*******************************************************************************
 *  Implementation now in positioningquick
*******************************************************************************/

QT_END_NAMESPACE