Branch data Line data Source code
1 : : /*************************************************************************** 2 : : qgsvectorlayertools.h 3 : : -------------------------------------- 4 : : Date : 29.5.2013 5 : : Copyright : (C) 2013 Matthias Kuhn 6 : : Email : matthias at opengis dot ch 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 : : #ifndef QGSVECTORLAYERTOOLS_H 17 : : #define QGSVECTORLAYERTOOLS_H 18 : : 19 : : #include "qgis_core.h" 20 : : #include "qgis_sip.h" 21 : : #include <QObject> 22 : : 23 : : #include "qgsfeature.h" 24 : : #include "qgsgeometry.h" 25 : : 26 : : class QgsFeatureRequest; 27 : : class QgsVectorLayer; 28 : : 29 : : /** 30 : : * \ingroup core 31 : : * \brief Methods in this class are used to handle basic operations on vector layers. 32 : : * With an implementation of this class, parts of the application can ask for 33 : : * an operation to be done and the implementation will then take care of it. 34 : : * 35 : : * Reimplement this class, if you need to have custom checks or GUI elements 36 : : * in your application. 37 : : * 38 : : */ 39 : : class CORE_EXPORT QgsVectorLayerTools : public QObject 40 : : { 41 : 0 : Q_OBJECT 42 : : 43 : : public: 44 : : QgsVectorLayerTools(); 45 : : 46 : : // TODO QGIS 4: remove const qualifier 47 : : 48 : : /** 49 : : * This method should/will be called, whenever a new feature will be added to the layer 50 : : * 51 : : * \param layer The layer to which the feature should be added 52 : : * \param defaultValues Default values for the feature to add 53 : : * \param defaultGeometry A default geometry to add to the feature 54 : : * \param feature Updated feature after adding will be written back to this 55 : : * \returns TRUE in case of success, FALSE if the operation failed/was aborted 56 : : * 57 : : */ 58 : : virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature SIP_OUT = nullptr ) const = 0; 59 : : 60 : : // TODO QGIS 4: remove const qualifier 61 : : 62 : : /** 63 : : * This will be called, whenever a vector layer should be switched to edit mode. Check the providers 64 : : * capability to edit in here. 65 : : * If successful layer->startEditing() will be called and TRUE returned. 66 : : * 67 : : * \param layer The layer on which to start an edit session 68 : : * 69 : : * \returns TRUE, if the editing session was started 70 : : * 71 : : */ 72 : : virtual bool startEditing( QgsVectorLayer *layer ) const = 0; 73 : : 74 : : // TODO QGIS 4: remove const qualifier 75 : : 76 : : /** 77 : : * Will be called, when an editing session is ended and the features should be committed. 78 : : * Appropriate dialogs should be shown like 79 : : * 80 : : * \param layer The layer to commit 81 : : * \param allowCancel TRUE if a cancel button should be offered 82 : : * \returns TRUE if successful 83 : : * 84 : : */ 85 : : virtual bool stopEditing( QgsVectorLayer *layer, bool allowCancel = true ) const = 0; 86 : : 87 : : // TODO QGIS 4: remove const qualifier 88 : : 89 : : /** 90 : : * Should be called, when the features should be committed but the editing session is not ended. 91 : : * 92 : : * \param layer The layer to commit 93 : : * \returns TRUE if successful 94 : : * 95 : : */ 96 : : virtual bool saveEdits( QgsVectorLayer *layer ) const = 0; 97 : : 98 : : // TODO QGIS 4: remove const qualifier 99 : : 100 : : /** 101 : : * Copy and move features with defined translation. 102 : : * 103 : : * \param layer The layer 104 : : * \param request The request for the features to be moved. It will be assigned to a new feature request with the newly copied features. 105 : : * \param dx The translation on x 106 : : * \param dy The translation on y 107 : : * \param errorMsg If given, it will contain the error message 108 : : * \param topologicalEditing If TRUE, the function will perform topological 109 : : * editing of the vertices of \a layer on \a layer and \a topologicalLayer 110 : : * \param topologicalLayer The layer where vertices from the moved features of \a layer will be added 111 : : * \returns TRUE if all features could be copied. 112 : : * 113 : : */ 114 : : virtual bool copyMoveFeatures( QgsVectorLayer *layer, QgsFeatureRequest &request SIP_INOUT, double dx = 0, double dy = 0, QString *errorMsg SIP_OUT = nullptr, const bool topologicalEditing = false, QgsVectorLayer *topologicalLayer = nullptr ) const; 115 : : 116 : : /** 117 : : * Returns force suppress form popup status. 118 : : * 119 : : * \returns TRUE if force suppress form popup is set. 120 : : * \since QGIS 3.14 121 : : */ 122 : : bool forceSuppressFormPopup() const; 123 : : 124 : : /** 125 : : * Sets force suppress form popup status to \a forceSuppressFormPopup. 126 : : * 127 : : * This flag will override the layer and general settings regarding the automatic 128 : : * opening of the attribute form dialog when digitizing is completed. 129 : : * 130 : : * \since QGIS 3.14 131 : : */ 132 : : void setForceSuppressFormPopup( bool forceSuppressFormPopup ); 133 : : 134 : : private: 135 : : 136 : : bool mForceSuppressFormPopup { false }; 137 : : 138 : : 139 : : }; 140 : : 141 : : #endif // QGSVECTORLAYERTOOLS_H