QGIS API Documentation  3.13.0-Master (740be229cb)
qgisinterface.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgisinterface.h
3  Interface class for exposing functions in QgisApp for use by plugins
4  -------------------
5  begin : 2004-02-11
6  copyright : (C) 2004 by Gary E.Sherman
7  email : sherman at mrcc.com
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 #ifndef QGISINTERFACE_H
19 #define QGISINTERFACE_H
20 
21 #include <QObject>
22 #include <map>
23 
24 #include "qgis.h"
25 #include "qgis_sip.h"
26 #include "qgis_gui.h"
29 
30 class QAction;
31 class QDialog;
32 class QFont;
33 class QMenu;
34 class QToolBar;
35 class QDockWidget;
36 class QMainWindow;
37 class QWidget;
38 
40 class QgsAttributeDialog;
43 class QgsFeature;
45 class QgsLayerTreeView;
46 class QgsLayerTreeGroup;
47 class QgsLayout;
50 class QgsMapCanvas;
51 class QgsMapLayer;
52 enum class QgsMapLayerType;
54 class QgsMessageBar;
56 class QgsRasterLayer;
57 class QgsVectorLayer;
60 class QgsLocatorFilter;
61 class QgsStatusBar;
62 class QgsMeshLayer;
63 class QgsBrowserGuiModel;
65 
66 
81 class GUI_EXPORT QgisInterface : public QObject
82 {
83  Q_OBJECT
84 
85  public:
86 
88  QgisInterface() = default;
89 
90  virtual QgsPluginManagerInterface *pluginManagerInterface() = 0;
91 
92  virtual QgsLayerTreeView *layerTreeView() = 0;
93 
106  virtual void addCustomActionForLayerType( QAction *action, QString menu,
107  QgsMapLayerType type, bool allLayers ) = 0;
108 
115  virtual void addCustomActionForLayer( QAction *action, QgsMapLayer *layer ) = 0;
116 
121  virtual bool removeCustomActionForLayerType( QAction *action ) = 0;
122 
127  virtual QList< QgsMapCanvas * > mapCanvases() = 0;
128 
134  virtual QgsMapCanvas *createNewMapCanvas( const QString &name ) = 0;
135 
141  virtual void closeMapCanvas( const QString &name ) = 0;
142 
147  virtual QSize iconSize( bool dockedToolbar = false ) const = 0;
148 
154  virtual QList<QgsMapLayer *> editableLayers( bool modified = false ) const = 0;
155 
157  virtual QgsMapLayer *activeLayer() = 0;
158 
160  virtual QgsMapCanvas *mapCanvas() = 0;
161 
167  virtual QgsLayerTreeMapCanvasBridge *layerTreeCanvasBridge() = 0;
168 
170  virtual QWidget *mainWindow() = 0;
171 
173  virtual QgsMessageBar *messageBar() = 0;
174 
179  virtual QList<QgsLayoutDesignerInterface *> openLayoutDesigners() = 0;
180 
181 
183  virtual QMap<QString, QVariant> defaultStyleSheetOptions() = 0;
184 
186  virtual QFont defaultStyleSheetFont() = 0;
187 
192  virtual QgsAdvancedDigitizingDockWidget *cadDockWidget() = 0;
193 
194  /*
195  * Accessors for inserting items into menus and toolbars.
196  * An item can be inserted before any existing action.
197  */
198 
202  virtual QMenu *projectMenu() = 0;
203 
207  virtual QMenu *editMenu() = 0;
208 
212  virtual QMenu *viewMenu() = 0;
213 
217  virtual QMenu *layerMenu() = 0;
218 
222  virtual QMenu *newLayerMenu() = 0;
223 
228  virtual QMenu *addLayerMenu() = 0;
229 
233  virtual QMenu *settingsMenu() = 0;
234 
238  virtual QMenu *pluginMenu() = 0;
239 
248  virtual QMenu *pluginHelpMenu() = 0;
249 
253  virtual QMenu *rasterMenu() = 0;
254 
258  virtual QMenu *databaseMenu() = 0;
259 
263  virtual QMenu *vectorMenu() = 0;
264 
268  virtual QMenu *webMenu() = 0;
269 
277  virtual QMenu *firstRightStandardMenu() = 0;
278 
282  virtual QMenu *windowMenu() = 0;
283 
287  virtual QMenu *helpMenu() = 0;
288 
289  // ToolBars
290 
294  virtual QToolBar *fileToolBar() = 0;
295 
299  virtual QToolBar *layerToolBar() = 0;
300 
305  virtual QToolBar *dataSourceManagerToolBar() = 0;
306 
310  virtual QToolBar *mapNavToolToolBar() = 0;
311 
315  virtual QToolBar *digitizeToolBar() = 0;
316 
320  virtual QToolBar *advancedDigitizeToolBar() = 0;
321 
326  virtual QToolBar *shapeDigitizeToolBar() = 0;
327 
331  virtual QToolBar *attributesToolBar() = 0;
332 
336  virtual QToolBar *pluginToolBar() = 0;
337 
341  virtual QToolBar *helpToolBar() = 0;
342 
346  virtual QToolBar *rasterToolBar() = 0;
347 
351  virtual QToolBar *vectorToolBar() = 0;
352 
356  virtual QToolBar *databaseToolBar() = 0;
357 
361  virtual QToolBar *webToolBar() = 0;
362 
363  // Project menu actions
365  virtual QAction *actionNewProject() = 0;
367  virtual QAction *actionOpenProject() = 0;
369  virtual QAction *actionSaveProject() = 0;
371  virtual QAction *actionSaveProjectAs() = 0;
373  virtual QAction *actionSaveMapAsImage() = 0;
375  virtual QAction *actionProjectProperties() = 0;
376 
378  virtual QAction *actionCreatePrintLayout() = 0;
379 
381  virtual QAction *actionShowLayoutManager() = 0;
383  virtual QAction *actionExit() = 0;
384 
385  // Edit menu actions
386 
388  virtual QAction *actionCutFeatures() = 0;
390  virtual QAction *actionCopyFeatures() = 0;
392  virtual QAction *actionPasteFeatures() = 0;
394  virtual QAction *actionAddFeature() = 0;
396  virtual QAction *actionDeleteSelected() = 0;
398  virtual QAction *actionMoveFeature() = 0;
400  virtual QAction *actionSplitFeatures() = 0;
402  virtual QAction *actionSplitParts() = 0;
404  virtual QAction *actionAddRing() = 0;
406  virtual QAction *actionAddPart() = 0;
408  virtual QAction *actionSimplifyFeature() = 0;
410  virtual QAction *actionDeleteRing() = 0;
412  virtual QAction *actionDeletePart() = 0;
413 
418  virtual QAction *actionVertexTool() = 0;
419 
425  virtual QAction *actionVertexToolActiveLayer() = 0;
426 
427  // View menu actions
429  virtual QAction *actionPan() = 0;
431  virtual QAction *actionPanToSelected() = 0;
433  virtual QAction *actionZoomIn() = 0;
435  virtual QAction *actionZoomOut() = 0;
437  virtual QAction *actionSelect() = 0;
439  virtual QAction *actionSelectRectangle() = 0;
441  virtual QAction *actionSelectPolygon() = 0;
443  virtual QAction *actionSelectFreehand() = 0;
445  virtual QAction *actionSelectRadius() = 0;
447  virtual QAction *actionIdentify() = 0;
449  virtual QAction *actionFeatureAction() = 0;
451  virtual QAction *actionMeasure() = 0;
453  virtual QAction *actionMeasureArea() = 0;
455  virtual QAction *actionZoomFullExtent() = 0;
457  virtual QAction *actionZoomToLayer() = 0;
459  virtual QAction *actionZoomToSelected() = 0;
461  virtual QAction *actionZoomLast() = 0;
463  virtual QAction *actionZoomNext() = 0;
465  virtual QAction *actionZoomActualSize() = 0;
467  virtual QAction *actionMapTips() = 0;
469  virtual QAction *actionNewBookmark() = 0;
471  virtual QAction *actionShowBookmarks() = 0;
473  virtual QAction *actionDraw() = 0;
474 
475  // Layer menu actions
476  virtual QAction *actionNewVectorLayer() = 0;
477  virtual QAction *actionAddOgrLayer() = 0;
478  virtual QAction *actionAddRasterLayer() = 0;
479  virtual QAction *actionAddPgLayer() = 0;
480  virtual QAction *actionAddWmsLayer() = 0;
482  virtual QAction *actionAddAfsLayer() = 0;
484  virtual QAction *actionAddAmsLayer() = 0;
485  virtual QAction *actionCopyLayerStyle() = 0;
486  virtual QAction *actionPasteLayerStyle() = 0;
487  virtual QAction *actionOpenTable() = 0;
488  virtual QAction *actionOpenFieldCalculator() = 0;
489 
494  virtual QAction *actionOpenStatisticalSummary() = 0;
495 
496  virtual QAction *actionToggleEditing() = 0;
497  virtual QAction *actionSaveActiveLayerEdits() = 0;
498  virtual QAction *actionAllEdits() = 0;
499  virtual QAction *actionSaveEdits() = 0;
500  virtual QAction *actionSaveAllEdits() = 0;
501  virtual QAction *actionRollbackEdits() = 0;
502  virtual QAction *actionRollbackAllEdits() = 0;
503  virtual QAction *actionCancelEdits() = 0;
504  virtual QAction *actionCancelAllEdits() = 0;
505  virtual QAction *actionLayerSaveAs() = 0;
506  virtual QAction *actionDuplicateLayer() = 0;
507  virtual QAction *actionLayerProperties() = 0;
508  virtual QAction *actionAddToOverview() = 0;
509  virtual QAction *actionAddAllToOverview() = 0;
510  virtual QAction *actionRemoveAllFromOverview() = 0;
511  virtual QAction *actionHideAllLayers() = 0;
512  virtual QAction *actionShowAllLayers() = 0;
513  virtual QAction *actionHideSelectedLayers() = 0;
514 
519  virtual QAction *actionHideDeselectedLayers() = 0;
520  virtual QAction *actionShowSelectedLayers() = 0;
521 
522  // Plugin menu actions
523  virtual QAction *actionManagePlugins() = 0;
524  virtual QAction *actionPluginListSeparator() = 0;
525  virtual QAction *actionShowPythonDialog() = 0;
526 
527  // Settings menu actions
528  virtual QAction *actionToggleFullScreen() = 0;
529  virtual QAction *actionOptions() = 0;
530  virtual QAction *actionCustomProjection() = 0;
531 
532  // Help menu actions
533  virtual QAction *actionHelpContents() = 0;
534  virtual QAction *actionQgisHomePage() = 0;
535  virtual QAction *actionCheckQgisVersion() = 0;
536  virtual QAction *actionAbout() = 0;
537 
538  // Shape digitize actions
540  virtual QAction *actionCircle2Points() = 0;
542  virtual QAction *actionCircle3Points() = 0;
544  virtual QAction *actionCircle3Tangents() = 0;
546  virtual QAction *actionCircle2TangentsPoint() = 0;
548  virtual QAction *actionCircleCenterPoint() = 0;
550  virtual QAction *actionEllipseCenter2Points() = 0;
552  virtual QAction *actionEllipseCenterPoint() = 0;
554  virtual QAction *actionEllipseExtent() = 0;
556  virtual QAction *actionEllipseFoci() = 0;
558  virtual QAction *actionRectangleCenterPoint() = 0;
560  virtual QAction *actionRectangleExtent() = 0;
562  virtual QAction *actionRectangle3PointsDistance() = 0;
564  virtual QAction *actionRectangle3PointsProjected() = 0;
566  virtual QAction *actionRegularPolygon2Points() = 0;
568  virtual QAction *actionRegularPolygonCenterPoint() = 0;
570  virtual QAction *actionRegularPolygonCenterCorner() = 0;
571 
579  virtual QgsVectorLayerTools *vectorLayerTools() = 0;
580 
582  virtual int messageTimeout() = 0;
583 
590  virtual QgsStatusBar *statusBarIface() = 0;
591 
599  virtual void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 ) {Q_UNUSED( saveDirectory ) Q_UNUSED( categories );}
600 
606  virtual QgsLayerTreeRegistryBridge::InsertionPoint layerTreeInsertionPoint() = 0;
607 
608  public slots: // TODO: do these functions really need to be slots?
609 
610  /* Exposed functions */
611 
615  virtual void zoomFull() = 0;
616 
620  virtual void zoomToPrevious() = 0;
621 
625  virtual void zoomToNext() = 0;
626 
630  virtual void zoomToActiveLayer() = 0;
631 
635  virtual QgsVectorLayer *addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey ) = 0;
636 
640  virtual QgsRasterLayer *addRasterLayer( const QString &rasterLayerPath, const QString &baseName = QString() ) = 0;
641 
645  virtual QgsRasterLayer *addRasterLayer( const QString &url, const QString &layerName, const QString &providerKey ) = 0;
646 
650  virtual QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey ) = 0;
651 
653  virtual bool addProject( const QString &project ) = 0;
654 
665  virtual bool newProject( bool promptToSaveFlag = false ) = 0;
666 
674  virtual void reloadConnections( ) = 0;
675 
680  virtual bool setActiveLayer( QgsMapLayer * ) = 0;
681 
686  virtual void copySelectionToClipboard( QgsMapLayer * ) = 0;
687 
692  virtual void pasteFromClipboard( QgsMapLayer * ) = 0;
693 
695  virtual int addToolBarIcon( QAction *qAction ) = 0;
696 
705  virtual QAction *addToolBarWidget( QWidget *widget SIP_TRANSFER ) = 0;
706 
708  virtual void removeToolBarIcon( QAction *qAction ) = 0;
709 
718  virtual QAction *addRasterToolBarWidget( QWidget *widget SIP_TRANSFER ) = 0;
719 
721  virtual int addRasterToolBarIcon( QAction *qAction ) = 0;
722 
724  virtual void removeRasterToolBarIcon( QAction *qAction ) = 0;
725 
727  virtual int addVectorToolBarIcon( QAction *qAction ) = 0;
728 
737  virtual QAction *addVectorToolBarWidget( QWidget *widget SIP_TRANSFER ) = 0;
738 
740  virtual void removeVectorToolBarIcon( QAction *qAction ) = 0;
741 
743  virtual int addDatabaseToolBarIcon( QAction *qAction ) = 0;
744 
753  virtual QAction *addDatabaseToolBarWidget( QWidget *widget SIP_TRANSFER ) = 0;
754 
756  virtual void removeDatabaseToolBarIcon( QAction *qAction ) = 0;
757 
759  virtual int addWebToolBarIcon( QAction *qAction ) = 0;
760 
769  virtual QAction *addWebToolBarWidget( QWidget *widget SIP_TRANSFER ) = 0;
770 
772  virtual void removeWebToolBarIcon( QAction *qAction ) = 0;
773 
775  virtual QToolBar *addToolBar( const QString &name ) = 0 SIP_FACTORY;
776 
781  virtual void addToolBar( QToolBar *toolbar SIP_TRANSFER, Qt::ToolBarArea area = Qt::TopToolBarArea ) = 0;
782 
786  virtual void openMessageLog() = 0;
787 
789  virtual void addUserInputWidget( QWidget *widget ) = 0;
790 
795  virtual void showLayoutManager() = 0;
796 
803  virtual QgsLayoutDesignerInterface *openLayoutDesigner( QgsMasterLayoutInterface *layout ) = 0;
804 
810  virtual void showOptionsDialog( QWidget *parent = nullptr, const QString &currentPage = QString() ) = 0;
811 
816  virtual void buildStyleSheet( const QMap<QString, QVariant> &opts ) = 0;
817 
819  virtual void saveStyleSheetOptions( const QMap<QString, QVariant> &opts ) = 0;
820 
822  virtual void addPluginToMenu( const QString &name, QAction *action ) = 0;
823 
825  virtual void removePluginMenu( const QString &name, QAction *action ) = 0;
826 
828  virtual void insertAddLayerAction( QAction *action ) = 0;
829 
831  virtual void removeAddLayerAction( QAction *action ) = 0;
832 
834  virtual void addPluginToDatabaseMenu( const QString &name, QAction *action ) = 0;
835 
837  virtual void removePluginDatabaseMenu( const QString &name, QAction *action ) = 0;
838 
840  virtual void addPluginToRasterMenu( const QString &name, QAction *action ) = 0;
841 
843  virtual void removePluginRasterMenu( const QString &name, QAction *action ) = 0;
844 
846  virtual void addPluginToVectorMenu( const QString &name, QAction *action ) = 0;
847 
849  virtual void removePluginVectorMenu( const QString &name, QAction *action ) = 0;
850 
852  virtual void addPluginToWebMenu( const QString &name, QAction *action ) = 0;
853 
855  virtual void removePluginWebMenu( const QString &name, QAction *action ) = 0;
856 
862  virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dockwidget ) = 0;
863 
869  virtual void removeDockWidget( QDockWidget *dockwidget ) = 0;
870 
872  virtual void showLayerProperties( QgsMapLayer *l ) = 0;
873 
875  virtual QDialog *showAttributeTable( QgsVectorLayer *l, const QString &filterExpression = QString() ) = 0;
876 
881  virtual void addWindow( QAction *action ) = 0;
882 
887  virtual void removeWindow( QAction *action ) = 0;
888 
890  virtual bool registerMainWindowAction( QAction *action, const QString &defaultShortcut ) = 0;
891 
893  virtual bool unregisterMainWindowAction( QAction *action ) = 0;
894 
903  virtual void registerMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory *factory ) = 0;
904 
911  virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory *factory ) = 0;
912 
921  virtual void registerOptionsWidgetFactory( QgsOptionsWidgetFactory *factory ) = 0;
922 
929  virtual void unregisterOptionsWidgetFactory( QgsOptionsWidgetFactory *factory ) = 0;
930 
938  virtual void registerDevToolWidgetFactory( QgsDevToolWidgetFactory *factory ) = 0;
939 
945  virtual void unregisterDevToolWidgetFactory( QgsDevToolWidgetFactory *factory ) = 0;
946 
955  virtual void registerCustomDropHandler( QgsCustomDropHandler *handler ) = 0;
956 
963  virtual void unregisterCustomDropHandler( QgsCustomDropHandler *handler ) = 0;
964 
973  virtual void registerCustomLayoutDropHandler( QgsLayoutCustomDropHandler *handler ) = 0;
974 
981  virtual void unregisterCustomLayoutDropHandler( QgsLayoutCustomDropHandler *handler ) = 0;
982 
983  // TODO is this deprecated in favour of QgsContextHelp?
984 
994 #ifndef Q_MOC_RUN
995  Q_DECL_DEPRECATED
996 #endif
997  virtual void openURL( const QString &url, bool useQgisDocDirectory = true ) = 0 SIP_DEPRECATED;
998 
1007  virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false, bool showModal = true ) = 0;
1008 
1017  virtual QgsAttributeDialog *getFeatureForm( QgsVectorLayer *l, QgsFeature &f ) = 0;
1018 
1031  virtual void preloadForm( const QString &uifile ) = 0;
1032 
1039  virtual void locatorSearch( const QString &searchText ) = 0;
1040 
1049  virtual void registerLocatorFilter( QgsLocatorFilter *filter SIP_TRANSFER ) = 0;
1050 
1061  virtual void deregisterLocatorFilter( QgsLocatorFilter *filter ) = 0;
1062 
1070  virtual void invalidateLocatorResults() = 0;
1071 
1078  virtual bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs ) = 0;
1079 
1085  virtual QgsBrowserGuiModel *browserModel() = 0;
1086 
1087  signals:
1088 
1093  void currentLayerChanged( QgsMapLayer *layer );
1094 
1100  void currentThemeChanged( const QString &theme );
1101 
1107  void layoutDesignerOpened( QgsLayoutDesignerInterface *designer );
1108 
1116  void layoutDesignerWillBeClosed( QgsLayoutDesignerInterface *designer );
1117 
1124  void layoutDesignerClosed();
1125 
1129  void initializationCompleted();
1130 
1137  void projectRead();
1138 
1147  void newProjectCreated();
1148 
1153  void layerSavedAs( QgsMapLayer *l, const QString &path );
1154 
1155 };
1157 
1158 #endif //#ifndef QGISINTERFACE_H
Methods in this class are used to handle basic operations on vector layers.
Layer tree group node serves as a container for layers and further groups.
Base class for all map layer types.
Definition: qgsmaplayer.h:80
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working ...
The QgsLayerTreeMapCanvasBridge class takes care of updates of layer set for QgsMapCanvas from a laye...
Represents a raster layer.
Factory class for creating custom map layer property pages.
Factory class for creating custom developer/debugging tool pages.
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:731
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
A common interface for layout designer dialogs and widgets.
A model for showing available data sources and other items in a structured tree.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Abstract base class that may be implemented to handle new types of data to be dropped in QGIS layouts...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:78
Abstract base class that may be implemented to handle new types of data to be dropped in QGIS...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Abstract base class for filters which collect locator results.
#define SIP_FACTORY
Definition: qgis_sip.h:76
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window&#39;s toolbar icons.
QgisInterface Abstract base class defining interfaces exposed by QgisApp and made available to plugin...
Definition: qgisinterface.h:81
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:732
This class represents a coordinate reference system (CRS).
A factory class for creating custom options pages.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:92
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:67
A structure to define the insertion point to the layer tree.
Interface for master layout type objects, such as print layouts and reports.
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Represents a vector layer which manages a vector based data sets.
virtual void takeAppScreenShots(const QString &saveDirectory, const int categories=0)
Take screenshots for user documentation.
A proxy widget for QStatusBar.
Definition: qgsstatusbar.h:46