QGIS API Documentation  3.23.0-Master (dd0cd13a00)
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 "qgscoordinateformatter.h"
31 #include "qgsvectorlayer.h"
32 #include "qgsunittypes.h"
33 
34 #include "qgsquickmapcanvasmap.h"
35 #include "qgsquickmapsettings.h"
36 #include "qgsquickmaptransform.h"
37 #include "qgsquickplugin.h"
38 #include "qgsquickutils.h"
39 
40 static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine )
41 {
42  Q_UNUSED( engine )
43  Q_UNUSED( scriptEngine )
44  return new QgsQuickUtils(); // the object will be owned by QML engine and destroyed by the engine on exit
45 }
46 
47 void QgsQuickPlugin::registerTypes( const char *uri )
48 {
49  qRegisterMetaType< QList<QgsMapLayer *> >( "QList<QgsMapLayer*>" );
50  qRegisterMetaType< QgsAttributes > ( "QgsAttributes" );
51  qRegisterMetaType< QgsCoordinateReferenceSystem >( "QgsCoordinateReferenceSystem" );
52  qRegisterMetaType< QgsCoordinateTransformContext >( "QgsCoordinateTransformContext" );
53  qRegisterMetaType< QgsFeature > ( "QgsFeature" );
54  qRegisterMetaType< QgsFeatureId > ( "QgsFeatureId" );
55  qRegisterMetaType< QgsPoint >( "QgsPoint" );
56  qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
57  qRegisterMetaType< QgsUnitTypes::SystemOfMeasurement >( "QgsUnitTypes::SystemOfMeasurement" );
58  qRegisterMetaType< QgsUnitTypes::DistanceUnit >( "QgsUnitTypes::DistanceUnit" );
59  qRegisterMetaType< QgsCoordinateFormatter::FormatFlags >( "QgsCoordinateFormatter::FormatFlags" );
60  qRegisterMetaType< QgsCoordinateFormatter::Format >( "QgsCoordinateFormatter::Format" );
61  qRegisterMetaType< QVariant::Type >( "QVariant::Type" );
62 
63  qmlRegisterUncreatableType< QgsUnitTypes >( uri, 0, 1, "QgsUnitTypes", "Only enums from QgsUnitTypes can be used" );
64  qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
65  qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
66  qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
67  qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
68  qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
69 
70  qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider );
71 }
72 
void registerTypes(const char *uri)
Registers the QGIS QML types in the given uri.
Encapsulating the common utilities for QgsQuick library.
Definition: qgsquickutils.h:53