QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgstransaction.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstransaction.h
3  ----------------
4  begin : May 5, 2014
5  copyright : (C) 2014 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSTRANSACTION_H
19 #define QGSTRANSACTION_H
20 
21 #include <QSet>
22 #include <QString>
23 #include <QObject>
24 
26 class QgsVectorLayer;
27 
49 class CORE_EXPORT QgsTransaction : public QObject
50 {
51  Q_OBJECT
52 
53  public:
55  static QgsTransaction* create( const QString& connString, const QString& providerKey );
56 
59  static QgsTransaction* create( const QStringList& layerIds );
60 
61  virtual ~QgsTransaction();
62 
64  bool addLayer( const QString& layerId );
65 
67  bool addLayer( QgsVectorLayer* layer );
68 
77  bool begin( QString& errorMsg, int statementTimeout = 20 );
78 
80  bool commit( QString& errorMsg );
81 
83  bool rollback( QString& errorMsg );
84 
86  virtual bool executeSql( const QString& sql, QString& error ) = 0;
87 
91  static bool supportsTransaction( const QgsVectorLayer* layer );
92 
93  signals:
97  void afterRollback();
98 
99  private slots:
100  void onLayersDeleted( const QStringList& layerids );
101 
102  protected:
103  QgsTransaction( const QString& connString );
104 
106 
107  private:
108  QgsTransaction( const QgsTransaction& other );
109  const QgsTransaction& operator=( const QgsTransaction& other );
110 
111  bool mTransactionActive;
112  QSet<QgsVectorLayer*> mLayers;
113 
114  void setLayerTransactionIds( QgsTransaction *transaction );
115 
116  virtual bool beginTransaction( QString& error, int statementTimeout ) = 0;
117  virtual bool commitTransaction( QString& error ) = 0;
118  virtual bool rollbackTransaction( QString& error ) = 0;
119 };
120 
121 #endif // QGSTRANSACTION_H
This class allows including a set of layers in a database-side transaction, provided the layer data p...
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.