QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsquickplugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquickplugin.cpp
3  --------------------------------------
4  Date : Nov 2017
5  Copyright : (C) 2017 by Peter Petrik
6  Email : zilolv at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include <qqml.h>
17 
18 #include <QObject>
19 #include <QQmlEngine>
20 #include <QJSEngine>
21 
22 #include "qgsfeature.h"
23 #include "qgslogger.h"
24 #include "qgsmaplayer.h"
25 #include "qgsmessagelog.h"
26 #include "qgspointxy.h"
27 #include "qgsproject.h"
28 #include "qgsrelationmanager.h"
30 #include "qgsvectorlayer.h"
31 #include "qgsunittypes.h"
32 
33 #include "qgsquickattributeformmodel.h"
34 #include "qgsquickattributeformmodelbase.h"
35 #include "qgsquickattributemodel.h"
38 #include "qgsquickidentifykit.h"
40 #include "qgsquickmapcanvasmap.h"
41 #include "qgsquickmapsettings.h"
42 #include "qgsquickmaptransform.h"
44 #include "qgsquickplugin.h"
45 #include "qgsquickpositionkit.h"
46 #include "qgsquickscalebarkit.h"
47 #include "qgsquicksubmodel.h"
48 #include "qgsquickutils.h"
49 
50 static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine )
51 {
52  Q_UNUSED( engine )
53  Q_UNUSED( scriptEngine )
54  return new QgsQuickUtils(); // the object will be owned by QML engine and destroyed by the engine on exit
55 }
56 
57 void QgsQuickPlugin::registerTypes( const char *uri )
58 {
59  qRegisterMetaType< QList<QgsMapLayer *> >( "QList<QgsMapLayer*>" );
60  qRegisterMetaType< QgsAttributes > ( "QgsAttributes" );
61  qRegisterMetaType< QgsCoordinateReferenceSystem >( "QgsCoordinateReferenceSystem" );
62  qRegisterMetaType< QgsCoordinateTransformContext >( "QgsCoordinateTransformContext" );
63  qRegisterMetaType< QgsFeature > ( "QgsFeature" );
64  qRegisterMetaType< QgsFeatureId > ( "QgsFeatureId" );
65  qRegisterMetaType< QgsPoint >( "QgsPoint" );
66  qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
67  qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );
68  qRegisterMetaType< QgsUnitTypes::SystemOfMeasurement >( "QgsUnitTypes::SystemOfMeasurement" );
69  qRegisterMetaType< QgsUnitTypes::DistanceUnit >( "QgsUnitTypes::DistanceUnit" );
70  qRegisterMetaType< QgsCoordinateFormatter::FormatFlags >( "QgsCoordinateFormatter::FormatFlags" );
71  qRegisterMetaType< QgsCoordinateFormatter::Format >( "QgsCoordinateFormatter::Format" );
72  qRegisterMetaType< QVariant::Type >( "QVariant::Type" );
73 
74  qmlRegisterUncreatableType< QgsUnitTypes >( uri, 0, 1, "QgsUnitTypes", "Only enums from QgsUnitTypes can be used" );
75 
76  qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
77  qmlRegisterType< QgsQuickAttributeFormModel >( uri, 0, 1, "AttributeFormModel" );
78  qmlRegisterType< QgsQuickAttributeModel >( uri, 0, 1, "AttributeModel" );
79  qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
80  qmlRegisterType< QgsQuickCoordinateTransformer >( uri, 0, 1, "CoordinateTransformer" );
81  qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
82  qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
83  qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
84  qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
85  qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
86  qmlRegisterType< QgsQuickPositionKit >( uri, 0, 1, "PositionKit" );
87  qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
88  qmlRegisterType< QgsQuickSubModel >( uri, 0, 1, "SubModel" );
89  qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
90 
91  qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider );
92 }
93 
Encapsulating the common utilies for QgsQuick library.
Definition: qgsquickutils.h:51
void registerTypes(const char *uri)
Registers the QGIS QML types in the given uri.