-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathqgisapp.cpp
17350 lines (15038 loc) · 648 KB
/
qgisapp.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
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
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
qgisapp.cpp - description
-------------------
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QObject>
#include <QAction>
#include <QApplication>
#include <QBitmap>
#include <QCheckBox>
#include <QClipboard>
#include <QColor>
#include <QCursor>
#include <QDesktopServices>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDir>
#include <QEvent>
#include <QUrlQuery>
#include <QFile>
#include <QFileInfo>
#include <QImageWriter>
#include <QInputDialog>
#include <QKeyEvent>
#include <QLabel>
#include <QLibrary>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QPainter>
#include <QPixmap>
#include <QPoint>
#include <QProcess>
#include <QProgressBar>
#include <QProgressDialog>
#include <QScreen>
#include <QShortcut>
#include <QSpinBox>
#include <QSplashScreen>
#include <QStandardPaths>
#include <QUrl>
#include <QRegularExpression>
#ifndef QT_NO_SSL
#include <QSslConfiguration>
#endif
#include <QStatusBar>
#include <QStringList>
#include <QSysInfo>
#include <QTcpSocket>
#include <QTextStream>
#include <QtGlobal>
#include <QThread>
#include <QTimer>
#include <QToolButton>
#include <QUuid>
#include <QVBoxLayout>
#include <QWhatsThis>
#include <QWidgetAction>
#include <mutex>
#include <QWindow>
#include <QActionGroup>
#include "qgsscreenhelper.h"
#include "qgssettingsregistrycore.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsapplication.h"
#include "qgslayerstylingwidget.h"
#include "qgsdevtoolspanelwidget.h"
#include "qgstaskmanager.h"
#include "qgsziputils.h"
#include "qgsbrowserguimodel.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsgeometryvalidationservice.h"
#include "qgssourceselectproviderregistry.h"
#include "qgsprovidermetadata.h"
#include "qgsfixattributedialog.h"
#include "qgsprojecttimesettings.h"
#include "qgsgeometrycollection.h"
#include "maptools/qgsappmaptools.h"
#include "qgsexpressioncontextutils.h"
#include "qgsauxiliarystorage.h"
#include "qgsvectortileutils.h"
#include "qgsscaleutils.h"
#include "qgsbrowserwidget.h"
#include "annotations/qgsannotationitempropertieswidget.h"
#include "qgsmaptoolmodifyannotation.h"
#include "qgsannotationlayer.h"
#include "qgsdockablewidgethelper.h"
#include "vertextool/qgsvertexeditor.h"
#include "qgsvectorlayerutils.h"
#include "qgsvectorlayereditutils.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsabstractdatasourcewidget.h"
#include "qgsmeshlayer.h"
#include <geos_c.h>
#include "options/qgscodeeditoroptions.h"
#include "options/qgselevationoptions.h"
#include "options/qgsfontoptions.h"
#include "options/qgsgpsdeviceoptions.h"
#include "options/qgsgpsoptions.h"
#include "options/qgsideoptions.h"
#include "options/qgscustomprojectionoptions.h"
#include "options/qgsrasterrenderingoptions.h"
#include "options/qgsrenderingoptions.h"
#include "options/qgsvectorrenderingoptions.h"
#include "options/qgsuserprofileoptions.h"
#include "qgsbrowserdockwidget_p.h"
#include "raster/qgsrasterelevationpropertieswidget.h"
#include "qgsrasterattributetableapputils.h"
#include "vector/qgsvectorelevationpropertieswidget.h"
#include "mesh/qgsmeshelevationpropertieswidget.h"
#include "elevation/qgselevationprofilewidget.h"
#include "qgstiledscenelayer.h"
#include "layers/qgsapplayerhandling.h"
#include "qgsmaplayerstylemanager.h"
#include "canvas/qgsappcanvasfiltering.h"
#include "canvas/qgscanvasrefreshblocker.h"
#include "qgsdockablewidgethelper.h"
#ifdef HAVE_3D
#include "qgs3d.h"
#include "qgs3danimationsettings.h"
#include "qgs3danimationwidget.h"
#include "qgs3dmapcanvas.h"
#include "qgs3dmapsettings.h"
#include "qgs3dutils.h"
#include "qgscameracontroller.h"
#include "qgsflatterraingenerator.h"
#include "qgslayoutitem3dmap.h"
#include "processing/qgs3dalgorithms.h"
#include "qgs3dmaptoolmeasureline.h"
#include "layout/qgslayout3dmapwidget.h"
#include "layout/qgslayoutviewrubberband.h"
#include "qgsvectorlayer3drendererwidget.h"
#include "qgsmeshlayer3drendererwidget.h"
#include "qgspointcloudlayer3drendererwidget.h"
#include "qgstiledscenelayer3drendererwidget.h"
#include "qgs3dapputils.h"
#include "qgs3doptions.h"
#include "qgsmapviewsmanager.h"
#include "qgs3dmapcanvaswidget.h"
#include "qgs3dmapscene.h"
#include "qgsdirectionallightsettings.h"
#endif
#ifdef HAVE_GEOREFERENCER
#include "georeferencer/qgsgeorefmainwindow.h"
#endif
#include "qgsgui.h"
#include "qgsnative.h"
#include "qgsdatasourceselectdialog.h"
#ifdef HAVE_OPENCL
#include "qgsopenclutils.h"
#endif
#include <QNetworkReply>
#include <QNetworkProxy>
#include <QAuthenticator>
//
// Mac OS X Includes
// Must include before GEOS 3 due to unqualified use of 'Point'
//
#ifdef Q_OS_MACOS
#include <ApplicationServices/ApplicationServices.h>
#include "qgsmacnative.h"
// check macro breaks QItemDelegate
#ifdef check
#undef check
#endif
#endif
//
// QGIS Specific Includes
//
#include "qgscrashhandler.h"
#include "qgisapp.h"
#include "moc_qgisapp.cpp"
#include "qgisappinterface.h"
#include "qgisappstylesheet.h"
#include "qgis.h"
#include "qgsabout.h"
#include "qgsabstractmaptoolhandler.h"
#include "qgsappauthrequesthandler.h"
#include "qgsappbrowserproviders.h"
#include "qgsapplayertreeviewmenuprovider.h"
#include "qgsapplication.h"
#include "qgsappsslerrorhandler.h"
#include "qgsactionmanager.h"
#include "qgsannotationmanager.h"
#include "qgsannotationregistry.h"
#include "qgsattributetabledialog.h"
#include "qgsattributedialog.h"
#include "qgsauthmanager.h"
#include "qgsauthguiutils.h"
#include "qgsauxiliarystorage.h"
#include "qgsappscreenshots.h"
#include "qgsapplicationexitblockerinterface.h"
#include "qgsbookmarks.h"
#include "qgsbookmarkeditordialog.h"
#include "qgsbrowserdockwidget.h"
#include "qgsclipboard.h"
#include "qgsconfigureshortcutsdialog.h"
#include "qgscoordinatetransform.h"
#include "qgscoordinateutils.h"
#include "qgscredentialdialog.h"
#include "qgscustomdrophandler.h"
#include "qgscustomprojectopenhandler.h"
#include "qgscustomization.h"
#include "qgscustomlayerorderwidget.h"
#include "qgsdataitemproviderregistry.h"
#include "qgsdataitemguiproviderregistry.h"
#include "qgsstacdataitems.h"
#include "qgsstacdataitemguiprovider.h"
#include "qgsdatasourceuri.h"
#include "qgsdatumtransformdialog.h"
#include "qgsdoublespinbox.h"
#include "qgsdockwidget.h"
#include "qgsdxfexport.h"
#include "qgsdxfexportdialog.h"
#include "qgsdwgimportdialog.h"
#include "qgsdecorationtitle.h"
#include "qgsdecorationcopyright.h"
#include "qgsdecorationimage.h"
#include "qgsdecorationnortharrow.h"
#include "qgsdecorationscalebar.h"
#include "qgsdecorationgrid.h"
#include "qgsdecorationlayoutextent.h"
#include "qgsdecorationoverlay.h"
#include "qgserror.h"
#include "qgseventtracing.h"
#include "qgsexception.h"
#include "qgsexpressionselectiondialog.h"
#include "qgsfeature.h"
#include "qgsfieldcalculator.h"
#include "qgsfieldformatter.h"
#include "qgsfieldformatterregistry.h"
#include "qgsfileutils.h"
#include "qgsfontmanager.h"
#include "qgsformannotation.h"
#include "qgsguiutils.h"
#include "qgsprojectionselectiondialog.h"
#include "qgsgpsinformationwidget.h"
#include "qgsappgpsconnection.h"
#include "qgsappgpsdigitizing.h"
#include "qgsappgpslogging.h"
#include "qgsappgpssettingsmenu.h"
#include "qgsgpstoolbar.h"
#include "qgsgpscanvasbridge.h"
#include "qgsguivectorlayertools.h"
#include "qgslayerdefinition.h"
#include "qgslayertree.h"
#include "qgslayertreefiltersettings.h"
#include "qgslayertreegrouppropertieswidget.h"
#include "qgslayertreemapcanvasbridge.h"
#include "qgslayertreemodel.h"
#include "qgslayertreemodellegendnode.h"
#include "qgslayertreeregistrybridge.h"
#include "qgslayertreeutils.h"
#include "qgslayertreeview.h"
#include "qgslayertreeviewdefaultactions.h"
#include "qgslayertreeviewembeddedindicator.h"
#include "qgslayertreeviewfilterindicator.h"
#include "qgslayertreeviewlowaccuracyindicator.h"
#include "qgslayertreeviewmemoryindicator.h"
#include "qgslayertreeviewbadlayerindicator.h"
#include "qgslayertreeviewnonremovableindicator.h"
#include "qgslayertreeviewnotesindicator.h"
#include "qgslayertreeviewnocrsindicator.h"
#include "qgslayertreeviewtemporalindicator.h"
#include "qgslayertreeviewofflineindicator.h"
#include "qgsrasterpipe.h"
#include "qgslayoutatlas.h"
#include "qgslayoutcustomdrophandler.h"
#include "qgslayoutdesignerdialog.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutmanager.h"
#include "qgslayoutqptdrophandler.h"
#include "qgslayoutimagedrophandler.h"
#include "qgslayoutguiutils.h"
#include "qgslayoutelevationprofilewidget.h"
#include "qgslocatorwidget.h"
#include "qgslocator.h"
#include "qgsactionlocatorfilter.h"
#include "qgsactivelayerfeatureslocatorfilter.h"
#include "qgsalllayersfeatureslocatorfilter.h"
#include "qgslayermetadatalocatorfilter.h"
#include "qgsbookmarklocatorfilter.h"
#include "qgsexpressioncalculatorlocatorfilter.h"
#include "qgsgotolocatorfilter.h"
#include "qgslayertreelocatorfilter.h"
#include "qgslayoutlocatorfilter.h"
#include "qgsnominatimlocatorfilter.h"
#include "qgssettingslocatorfilter.h"
#include "qgsnominatimgeocoder.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmapcanvasdockwidget.h"
#include "qgsmapcanvassnappingutils.h"
#include "qgsmapcanvastracer.h"
#include "qgsmaplayer.h"
#include "qgsmapoverviewcanvas.h"
#include "qgsmapsettings.h"
#include "qgsmaptip.h"
#include "qgsmbtiles.h"
#include "qgsmergeattributesdialog.h"
#include "qgsmessageviewer.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgsmeshlayer.h"
#include "qgsmeshlayerproperties.h"
#include "qgspointcloudlayer.h"
#include "qgsmemoryproviderutils.h"
#include "qgsmimedatautils.h"
#include "qgsmessagelog.h"
#include "qgsnative.h"
#include "qgsnativealgorithms.h"
#include "qgsnewvectorlayerdialog.h"
#include "qgsnewmemorylayerdialog.h"
#include "qgsnewmeshlayerdialog.h"
#include "options/qgsoptions.h"
#include "qgspluginlayer.h"
#include "qgspluginlayerregistry.h"
#include "qgspluginmanager.h"
#include "qgspluginregistry.h"
#include "qgspointxy.h"
#include "qgspuzzlewidget.h"
#include "qgsruntimeprofiler.h"
#include "qgshandlebadlayers.h"
#include "qgsprintlayout.h"
#include "qgsprocessingregistry.h"
#include "qgsprojutils.h"
#include "qgsproject.h"
#include "qgsprojectlayergroupdialog.h"
#include "qgsprojectproperties.h"
#include "qgsprojectstorage.h"
#include "qgsprojectstorageguiprovider.h"
#include "qgsprojectstorageguiregistry.h"
#include "qgsprojectstorageregistry.h"
#include "qgsproviderregistry.h"
#include "qgsproviderguiregistry.h"
#include "qgspythonrunner.h"
#include "qgsproxyprogresstask.h"
#include "qgsquerybuilder.h"
#include "qgspointcloudquerybuilder.h"
#include "qgsrastercalcdialog.h"
#include "qgsmeshcalculatordialog.h"
#include "qgsrasterfilewriter.h"
#include "qgsrasterfilewritertask.h"
#include "qgsrasterlayer.h"
#include "qgsrasterlayerproperties.h"
#include "qgsrasternuller.h"
#include "qgsbrightnesscontrastfilter.h"
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrasterprojector.h"
#include "qgsrasterrenderer.h"
#include "qgsreadwritecontext.h"
#include "qgsrectangle.h"
#include "qgsrendereditemresults.h"
#include "qgsrenderedlayerstatistics.h"
#include "qgsreport.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsgroupwmsdatadialog.h"
#include "qgsselectbyformdialog.h"
#include "qgselevationshadingrenderersettingswidget.h"
#include "qgsshortcutsmanager.h"
#include "qgssnappingwidget.h"
#include "qgsstackeddiagramproperties.h"
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatusbar.h"
#include "qgsstatusbarcoordinateswidget.h"
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsstatusbarscalewidget.h"
#include "qgsstyle.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgssubsetstringeditorinterface.h"
#include "qgstaskmanager.h"
#include "qgstaskmanagerwidget.h"
#include "qgstiledscenelayer.h"
#include "qgssymbolselectordialog.h"
#include "qgsundowidget.h"
#include "qgsuserinputwidget.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerproperties.h"
#include "qgsvectorlayerdigitizingproperties.h"
#include "qgsvectortilelayer.h"
#include "qgsvectortilelayerproperties.h"
#include "qgspointcloudlayerproperties.h"
#include "qgstiledscenelayerproperties.h"
#include "qgsmapthemes.h"
#include "qgsmessagelogviewer.h"
#include "qgsmaplayeractionregistry.h"
#include "qgswelcomepage.h"
#include "qgsrecentprojectsmenueventfilter.h"
#include "qgsversioninfo.h"
#include "qgslegendfilterbutton.h"
#include "qgsvirtuallayerdefinition.h"
#include "qgsvirtuallayerdefinitionutils.h"
#include "qgstransaction.h"
#include "qgstransactiongroup.h"
#include "qgsvectorlayerjoininfo.h"
#include "qgsvectorlayerutils.h"
#include "qgshelp.h"
#include "qgsvectorfilewritertask.h"
#include "qgsmapsavedialog.h"
#include "qgsmapdecoration.h"
#include "qgsnewnamedialog.h"
#include "qgsgui.h"
#include "qgsdatasourcemanagerdialog.h"
#include "qgsappwindowmanager.h"
#include "qgsvaliditycheckregistry.h"
#include "qgsappcoordinateoperationhandlers.h"
#include "qgsprojectviewsettings.h"
#include "qgslocaldefaultsettings.h"
#include "qgsbearingnumericformat.h"
#include "qgsprojectdisplaysettings.h"
#include "qgstemporalcontrollerdockwidget.h"
#include "qgsnetworklogger.h"
#include "qgsuserprofilemanager.h"
#include "qgsuserprofile.h"
#include "qgsnetworkloggerwidgetfactory.h"
#include "devtools/querylogger/qgsappquerylogger.h"
#include "devtools/querylogger/qgsqueryloggerwidgetfactory.h"
#include "devtools/profiler/qgsprofilerwidgetfactory.h"
#include "browser/qgsinbuiltdataitemproviders.h"
#include "ogr/qgsvectorlayersaveasdialog.h"
#include "qgsannotationitemguiregistry.h"
#include "annotations/qgsannotationlayerproperties.h"
#include "qgscreateannotationitemmaptool.h"
#include "pointcloud/qgspointcloudelevationpropertieswidget.h"
#include "pointcloud/qgspointcloudlayerstylewidget.h"
#include "pointcloud/qgspointcloudlayersaveasdialog.h"
#include "pointcloud/qgspointcloudlayerexporter.h"
#include "tiledscene/qgstiledscenelayerstylewidget.h"
#include "tiledscene/qgstiledsceneelevationpropertieswidget.h"
#include "project/qgsprojectelevationsettingswidget.h"
#include "sensor/qgsprojectsensorsettingswidget.h"
#include "qgsmaptoolsdigitizingtechniquemanager.h"
#include "qgsmaptoolshaperegistry.h"
#include "qgsmaptoolshapecircularstringradius.h"
#include "qgsmaptoolshapecircle2points.h"
#include "qgsmaptoolshapecircle3points.h"
#include "qgsmaptoolshapecircle3tangents.h"
#include "qgsmaptoolshapecircle2tangentspoint.h"
#include "qgsmaptoolshapecirclecenterpoint.h"
#include "qgsmaptoolshapeellipsecenter2points.h"
#include "qgsmaptoolshapeellipsecenterpoint.h"
#include "qgsmaptoolshapeellipseextent.h"
#include "qgsmaptoolshapeellipsefoci.h"
#include "qgsmaptoolshaperectanglecenter.h"
#include "qgsmaptoolshaperectangleextent.h"
#include "qgsmaptoolshaperectangle3points.h"
#include "qgsmaptoolshaperegularpolygon2points.h"
#include "qgsmaptoolshaperegularpolygoncenterpoint.h"
#include "qgsmaptoolshaperegularpolygoncentercorner.h"
#ifdef ENABLE_MODELTEST
#include "modeltest.h"
#endif
//
// GDAL/OGR includes
//
#include <gdal.h>
#include <ogr_api.h>
#include <gdal_version.h>
#include <proj.h>
#ifdef HAVE_PDAL_QGIS
#include <pdal/pdal.hpp>
#if PDAL_VERSION_MAJOR_INT > 2 || ( PDAL_VERSION_MAJOR_INT == 2 && PDAL_VERSION_MINOR_INT >= 5 )
#include "qgspdalalgorithms.h"
#endif
#endif
//
// Other includes
//
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <list>
#include <memory>
#include <vector>
#include "qgsmeasuretool.h"
#include "qgsmapcanvasannotationitem.h"
#include "qgsmaptoolpan.h"
#include "qgsmaptoolidentifyaction.h"
#include "qgsmaptoolpinlabels.h"
#include "qgsmaptoolmeasureangle.h"
#include "qgsmaptoolmeasurebearing.h"
#include "qgsmaptoolrotatepointsymbols.h"
#include "qgsmaptooldigitizefeature.h"
#include "qgsmaptooloffsetpointsymbol.h"
#include "vertextool/qgsvertextool.h"
#include "qgsmaptooleditmeshframe.h"
#include "qgsgeometryvalidationmodel.h"
#include "qgsgeometryvalidationdock.h"
#include "qgslayoutvaliditychecks.h"
// Editor widgets
#include "qgseditorwidgetregistry.h"
//
// Conditional Includes
//
#ifdef HAVE_PGCONFIG
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#include <pg_config.h>
#else
#define PG_VERSION "unknown"
#endif
#include <sqlite3.h>
#ifdef HAVE_SPATIALITE
extern "C"
{
#include <spatialite.h>
}
#include "qgsnewspatialitelayerdialog.h"
#endif
#include "qgsnewgeopackagelayerdialog.h"
#ifdef WITH_BINDINGS
#include "qgspythonutils.h"
#endif
#ifndef Q_OS_WIN
#include <dlfcn.h>
#else
#include <shellapi.h>
#include <dbghelp.h>
#endif
class QTreeWidgetItem;
class QgsUserProfileManager;
class QgsUserProfile;
/**
* Set the application title bar text
*/
static void setTitleBarText_( QWidget &qgisApp )
{
QString caption;
if ( QgsProject::instance()->title().isEmpty() )
{
if ( QgsProject::instance()->fileName().isEmpty() )
{
// new project
caption = QgisApp::tr( "Untitled Project" );
}
else
{
caption = QgsProject::instance()->baseName();
}
}
else
{
caption = QgsProject::instance()->title();
}
if ( !caption.isEmpty() )
{
caption += QStringLiteral( " %1 " ).arg( QChar( 0x2014 ) );
}
if ( QgsProject::instance()->isDirty() )
caption.prepend( '*' );
caption += QgisApp::tr( "QGIS" );
if ( Qgis::version().endsWith( QLatin1String( "Master" ) ) )
{
caption += QStringLiteral( " %1" ).arg( Qgis::devVersion() );
}
// Add current profile (if it's not the default one)
if ( QgisApp::instance()->userProfileManager()->allProfiles().count() > 1 )
{
QgsUserProfile *profile = QgisApp::instance()->userProfileManager()->userProfile();
if ( profile->name() != QgisApp::instance()->userProfileManager()->defaultProfileName() )
caption += QStringLiteral( " [%1]" ).arg( profile->name() );
}
qgisApp.setWindowTitle( caption );
}
/**
* Creator function for output viewer
*/
static QgsMessageOutput *messageOutputViewer_()
{
if ( QThread::currentThread() == qApp->thread() )
return new QgsMessageViewer( QgisApp::instance() );
else
return new QgsMessageOutputConsole();
}
static void customSrsValidation_( QgsCoordinateReferenceSystem &srs )
{
const QgsOptions::UnknownLayerCrsBehavior mode = QgsSettings().enumValue( QStringLiteral( "/projections/unknownCrsBehavior" ), QgsOptions::UnknownLayerCrsBehavior::NoAction, QgsSettings::App );
switch ( mode )
{
case QgsOptions::UnknownLayerCrsBehavior::NoAction:
return;
case QgsOptions::UnknownLayerCrsBehavior::UseDefaultCrs:
srs.createFromOgcWmsCrs( QgsSettings().value( QStringLiteral( "Projections/layerDefaultCrs" ), geoEpsgCrsAuthId() ).toString() );
break;
case QgsOptions::UnknownLayerCrsBehavior::PromptUserForCrs:
case QgsOptions::UnknownLayerCrsBehavior::UseProjectCrs:
// can't take any action immediately for these -- we may be in a background thread
break;
}
if ( QThread::currentThread() != QApplication::instance()->thread() )
{
// Running in a background thread -- we can't queue this connection, because
// srs is a reference and may be deleted before the queued slot is called.
// We also can't do ANY gui related stuff here. Best we can do is log
// a warning and move on...
QgsMessageLog::logMessage( QObject::tr( "Layer has unknown CRS" ) );
}
else
{
QgisApp::instance()->emitCustomCrsValidation( srs );
}
}
void QgisApp::emitCustomCrsValidation( QgsCoordinateReferenceSystem &srs )
{
emit customCrsValidation( srs );
}
void QgisApp::layerTreeViewDoubleClicked( const QModelIndex &index )
{
Q_UNUSED( index )
QgsSettings settings;
switch ( settings.value( QStringLiteral( "qgis/legendDoubleClickAction" ), 0 ).toInt() )
{
case 0:
{
//show properties
if ( mLayerTreeView )
{
// if it's a legend node, open symbol editor directly
if ( QgsSymbolLegendNode *node = qobject_cast<QgsSymbolLegendNode *>( mLayerTreeView->currentLegendNode() ) )
{
const QgsSymbol *originalSymbol = node->symbol();
if ( !originalSymbol )
return;
std::unique_ptr<QgsSymbol> symbol( originalSymbol->clone() );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( node->layerNode()->layer() );
QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vlayer, this );
QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mInfoBar );
dlg.setContext( context );
if ( dlg.exec() )
{
node->setSymbol( symbol.release() );
markDirty();
}
return;
}
}
QgisApp::instance()->layerProperties();
break;
}
case 1:
{
QgsSettings settings;
QgsAttributeTableFilterModel::FilterMode initialMode = settings.enumValue( QStringLiteral( "qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
QgisApp::instance()->attributeTable( initialMode );
break;
}
case 2:
mapStyleDock( true );
break;
default:
break;
}
}
void QgisApp::onActiveLayerChanged( QgsMapLayer *layer )
{
if ( mBlockActiveLayerChanged )
return;
const QList<QgsMapCanvas *> canvases = mapCanvases();
for ( QgsMapCanvas *canvas : canvases )
canvas->setCurrentLayer( layer );
if ( mUndoWidget )
{
if ( layer )
{
mUndoWidget->setUndoStack( layer->undoStack() );
}
else
{
mUndoWidget->unsetStack();
}
updateUndoActions();
}
emit activeLayerChanged( layer );
}
void QgisApp::toggleEventTracing()
{
QgsSettings settings;
if ( !settings.value( QStringLiteral( "qgis/enableEventTracing" ), false ).toBool() )
{
// make sure the setting is available in Options > Advanced
if ( !settings.contains( QStringLiteral( "qgis/enableEventTracing" ) ) )
settings.setValue( QStringLiteral( "qgis/enableEventTracing" ), false );
messageBar()->pushWarning( tr( "Event Tracing" ), tr( "Tracing is not enabled. Look for \"enableEventTracing\" in Options > Advanced." ) );
return;
}
if ( !QgsEventTracing::isTracingEnabled() )
{
messageBar()->pushSuccess( tr( "Event Tracing" ), tr( "Tracing started." ) );
QgsEventTracing::startTracing();
}
else
{
QgsEventTracing::stopTracing();
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save Event Trace..." ), QString(), tr( "Event Traces (*.json)" ) );
if ( !fileName.isEmpty() )
QgsEventTracing::writeTrace( fileName );
}
}
#ifdef HAVE_GEOREFERENCER
void QgisApp::showGeoreferencer()
{
if ( !mGeoreferencer )
mGeoreferencer = new QgsGeoreferencerMainWindow( this );
mGeoreferencer->show();
mGeoreferencer->setFocus();
}
#endif
void QgisApp::annotationItemTypeAdded( int id )
{
if ( QgsGui::annotationItemGuiRegistry()->itemMetadata( id )->flags() & Qgis::AnnotationItemGuiFlag::FlagNoCreationTools )
return;
QString name = QgsGui::annotationItemGuiRegistry()->itemMetadata( id )->visibleName();
QString groupId = QgsGui::annotationItemGuiRegistry()->itemMetadata( id )->groupId();
QToolButton *groupButton = nullptr;
if ( !groupId.isEmpty() )
{
// find existing group toolbutton and submenu, or create new ones if this is the first time the group has been encountered
const QgsAnnotationItemGuiGroup &group = QgsGui::annotationItemGuiRegistry()->itemGroup( groupId );
QIcon groupIcon = group.icon.isNull() ? QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicShape.svg" ) ) : group.icon;
QString groupText = tr( "Create %1" ).arg( group.name );
if ( mAnnotationItemGroupToolButtons.contains( groupId ) )
{
groupButton = mAnnotationItemGroupToolButtons.value( groupId );
}
else
{
QToolButton *groupToolButton = new QToolButton( mAnnotationsToolBar );
groupToolButton->setIcon( groupIcon );
groupToolButton->setCheckable( true );
groupToolButton->setPopupMode( QToolButton::InstantPopup );
groupToolButton->setAutoRaise( true );
groupToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
groupToolButton->setToolTip( groupText );
mAnnotationsToolBar->insertWidget( mAnnotationsItemInsertBefore, groupToolButton );
mAnnotationItemGroupToolButtons.insert( groupId, groupToolButton );
groupButton = groupToolButton;
}
}
// update UI for new item type
QAction *action = new QAction( tr( "Create %1" ).arg( name ), this );
action->setToolTip( tr( "Create %1" ).arg( name ) );
action->setCheckable( true );
action->setData( id );
action->setIcon( QgsGui::annotationItemGuiRegistry()->itemMetadata( id )->creationIcon() );
action->setObjectName( QStringLiteral( "mAction%1" ).arg( name.replace( " ", "" ) ) );
mMapToolGroup->addAction( action );
if ( groupButton )
groupButton->addAction( action );
else
{
mAnnotationsToolBar->insertAction( mAnnotationsItemInsertBefore, action );
}
connect( action, &QAction::toggled, this, [this, action, id]( bool checked ) {
if ( !checked )
return;
QgsCreateAnnotationItemMapToolInterface *tool = QgsGui::annotationItemGuiRegistry()->itemMetadata( id )->createMapTool( mMapCanvas, mAdvancedDigitizingDockWidget );
if ( !tool )
{
action->setChecked( false );
return;
}
tool->mapTool()->setAction( action );
mMapCanvas->setMapTool( tool->mapTool() );
if ( qobject_cast<QgsMapToolCapture *>( tool->mapTool() ) )
{
mDigitizingTechniqueManager->enableDigitizingTechniqueActions( checked, action );
}
connect( tool->mapTool(), &QgsMapTool::deactivated, tool->mapTool(), &QObject::deleteLater );
connect( tool->handler(), &QgsCreateAnnotationItemMapToolHandler::itemCreated, this, [=] {
QgsAnnotationItem *item = tool->handler()->takeCreatedItem();
QgsAnnotationLayer *targetLayer = qobject_cast<QgsAnnotationLayer *>( activeLayer() );
if ( !targetLayer )
targetLayer = QgsProject::instance()->mainAnnotationLayer();
const QString itemId = targetLayer->addItem( item );
// automatically select item in layer styling panel
mMapStyleWidget->setAnnotationItem( targetLayer, itemId );
mMapStylingDock->setUserVisible( true );
mMapStyleWidget->focusDefaultWidget();
QgsProject::instance()->setDirty( true );
// TODO -- possibly automatically deactivate the tool now?
} );
} );
}
void QgisApp::addLayerDefinition()
{
QgsLayerTreeRegistryBridge::InsertionPoint pt = layerTreeInsertionPoint();
QgsAppLayerHandling::addLayerDefinition( &pt );
}
/*
* This function contains forced validation of CRS used in QGIS.
* There are 4 options depending on the settings:
* - ask for CRS using projection selecter
* - use project's CRS
* - use predefined global CRS
* - take no action (leave as unknown CRS)
*/
void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs )
{
static QString sAuthId = QString();
const QgsOptions::UnknownLayerCrsBehavior mode = QgsSettings().enumValue( QStringLiteral( "/projections/unknownCrsBehavior" ), QgsOptions::UnknownLayerCrsBehavior::NoAction, QgsSettings::App );
switch ( mode )
{
case QgsOptions::UnknownLayerCrsBehavior::NoAction:
break;
case QgsOptions::UnknownLayerCrsBehavior::UseDefaultCrs:
{
srs.createFromOgcWmsCrs( QgsSettings().value( QStringLiteral( "Projections/layerDefaultCrs" ), geoEpsgCrsAuthId() ).toString() );
sAuthId = srs.authid();
visibleMessageBar()->pushMessage( tr( "CRS was undefined" ), tr( "defaulting to CRS %1" ).arg( srs.userFriendlyIdentifier() ), Qgis::MessageLevel::Warning );
break;
}
case QgsOptions::UnknownLayerCrsBehavior::PromptUserForCrs:
{
// \note this class is not a descendent of QWidget so we can't pass
// it in the ctor of the layer projection selector
static bool opening = false;
if ( opening )
break;
opening = true;
QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog();
const QString validationHint = srs.validationHint();
if ( !validationHint.isEmpty() )
mySelector->setMessage( validationHint );
else
mySelector->showNoCrsForLayerMessage();
if ( sAuthId.isNull() )
sAuthId = QgsProject::instance()->crs().authid();
QgsCoordinateReferenceSystem defaultCrs( sAuthId );
if ( defaultCrs.isValid() )
{
mySelector->setCrs( defaultCrs );
}
QgsTemporaryCursorRestoreOverride cursorOverride;
if ( mySelector->exec() )
{
QgsDebugMsgLevel( "Layer srs set from dialog: " + QString::number( mySelector->crs().srsid() ), 2 );
srs = mySelector->crs();
sAuthId = srs.authid();
}
delete mySelector;
opening = false;
break;
}
case QgsOptions::UnknownLayerCrsBehavior::UseProjectCrs:
{
// XXX TODO: Change project to store selected CS as 'projectCRS' not 'selectedWkt'
srs = QgsProject::instance()->crs();
sAuthId = srs.authid();
QgsDebugMsgLevel( "Layer srs set from project: " + sAuthId, 2 );
visibleMessageBar()->pushMessage( tr( "CRS was undefined" ), tr( "defaulting to project CRS %1" ).arg( srs.userFriendlyIdentifier() ), Qgis::MessageLevel::Warning );
break;
}
}
}
static bool cmpByText_( QAction *a, QAction *b )
{
return QString::localeAwareCompare( a->text(), b->text() ) < 0;
}
QgisApp *QgisApp::sInstance = nullptr;
// constructor starts here
QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers, bool skipVersionCheck, const QString &rootProfileLocation, const QString &activeProfile, QWidget *parent, Qt::WindowFlags fl )
: QMainWindow( parent, fl )
, mSplash( splash )
{
if ( sInstance )
{
QMessageBox::critical(
this,
tr( "Multiple Instances of QgisApp" ),
tr( "Multiple instances of QGIS application object detected.\nPlease contact the developers.\n" )
);
abort();
}
sInstance = this;
QgsRuntimeProfiler *profiler = QgsApplication::profiler();
QColor splashTextColor = Qgis::releaseName() == QLatin1String( "Master" ) ? QColor( 93, 153, 51 ) : Qt::black;
startProfile( tr( "Create user profile manager" ) );
mUserProfileManager = new QgsUserProfileManager( QString(), this );
mUserProfileManager->setRootLocation( rootProfileLocation );
mUserProfileManager->setActiveUserProfile( activeProfile );
mUserProfileManager->setNewProfileNotificationEnabled( true );
connect( mUserProfileManager, &QgsUserProfileManager::profilesChanged, this, &QgisApp::refreshProfileMenu );
endProfile();
// start the network logger early, we want all requests logged!
startProfile( tr( "Create network logger" ) );