This repository has been archived by the owner on Aug 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
112 lines (93 loc) · 3.95 KB
/
main.cpp
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
/***************************************************************************
main.cpp
--------------------------------------
Date : Oct 2018
Copyright : (C) 2018 by Peter Petrik
Email : zilolv at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#define STR1(x) #x
#define STR(x) STR1(x)
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include <QtDebug>
#include <QQmlError>
#include <QDesktopWidget>
#include <QQmlContext>
#include <QQuickWindow>
#include <qqml.h>
#include "qgsquickutils.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsquickplugin.h"
#include "qgslayertree.h"
int main(int argc, char *argv[])
{
QgsApplication app(argc, argv, true);
QgsApplication::init();
QgsApplication::initQgis();
if (!QgsApplication::createDatabase())
qDebug("Can't create qgis user DB!!!");
// REQUIRED FOR IOS - to load QgsQuick C++ classes
QgsQuickPlugin plugin;
plugin.registerTypes("QgsQuick");
QQmlEngine engine;
// REQUIRED FOR IOS - to load QgsQuick/*.qml files defined in qmldir
engine.addImportPath("qrc:///");
QgsVectorLayer* mVL3 = new QgsVectorLayer( QStringLiteral( "Point" ), QStringLiteral( "Point Layer" ), QStringLiteral( "memory" ) );
{
QgsVectorDataProvider *pr = mVL3->dataProvider();
QList<QgsField> attrs;
attrs << QgsField( QStringLiteral( "test_attr" ), QVariant::Int );
pr->addAttributes( attrs );
QgsFields fields;
fields.append( attrs.back() );
QList<QgsFeature> features;
for (int i = 0; i< 100; ++i)
{
QgsFeature f1( fields, 1 );
f1.setAttribute( 0, 1 );
QgsGeometry f1G = QgsGeometry::fromPointXY( QgsPointXY( i, i ) );
f1.setGeometry( f1G );
features << f1;
}
pr->addFeatures( features );
mVL3->updateFields();
}
QgsProject::instance()->addMapLayer( mVL3 );
engine.addImportPath( QgsApplication::qmlImportPath() );
engine.rootContext()->setContextProperty( "__project", QgsProject::instance() );
engine.rootContext()->setContextProperty( "__layers", QVariant::fromValue( QgsProject::instance()->layerTreeRoot()->layerOrder() ) );
QQmlComponent component(&engine, QUrl("qrc:/main.qml"));
QObject *object = component.create();
if (!component.errors().isEmpty()) {
qDebug("%s", QgsApplication::showSettings().toLocal8Bit().data());
qDebug() << "****************************************";
qDebug() << "***** QML errors: *****";
qDebug() << "****************************************";
for(const QQmlError& error: component.errors()) {
qDebug() << " " << error;
}
qDebug() << "****************************************";
qDebug() << "****************************************";
}
if( object == 0 )
{
qDebug() << "FATAL ERROR: unable to create mymap.qml";
return EXIT_FAILURE;
}
// Set up the QSettings environment must be done after qapp is created
QCoreApplication::setOrganizationName( "Lutra Consulting" );
QCoreApplication::setOrganizationDomain( "lutraconsulting.co.uk" );
QCoreApplication::setApplicationName( "IOSQUICKTEST" );
QCoreApplication::setApplicationVersion("0.1");
QgsApplication::messageLog()->logMessage(QgsQuickUtils().dumpScreenInfo());
return app.exec();
}