/
qgsgrassvectormap.h
233 lines (190 loc) · 7.75 KB
/
qgsgrassvectormap.h
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
/***************************************************************************
qgsgrassvectormap.cpp
-------------------
begin : September, 2015
copyright : (C) 2015 by Radim Blazek
email : radim.blazek@gmail.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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRASSVECTORMAP_H
#define QGSGRASSVECTORMAP_H
#include <QDateTime>
#include <QObject>
#include "qgsabstractgeometryv2.h"
#include "qgsgrass.h"
#include "qgsgrassvectormaplayer.h"
class GRASS_LIB_EXPORT QgsGrassVectorMap : public QObject
{
Q_OBJECT
public:
enum TopoSymbol
{
TopoUndefined = 0,
TopoPoint,
TopoLine,
TopoBoundary0,
TopoBoundary1,
TopoBoundary2,
TopoCentroidIn,
TopoCentroidOut,
TopoCentroidDupl,
TopoNode0,
TopoNode1,
TopoNode2
};
QgsGrassVectorMap( const QgsGrassObject & grassObject );
~QgsGrassVectorMap();
QgsGrassObject grassObject() const { return mGrassObject; }
struct Map_info *map() { return mMap; }
bool isValid() const { return mValid; }
bool isFrozen() const { return mFrozen; }
bool isEdited() const { return mIsEdited; }
int version() const { return mVersion; }
int oldNumLines() const { return mOldNumLines; }
// number of instances using this map
int userCount() const;
/** Get current number of lines.
* @return number of lines */
int numLines();
// 3D map with z coordinates
bool is3d() { return mIs3d; }
// Lock open / close
void lockOpenClose();
void unlockOpenClose();
// Lock open / close
void lockOpenCloseLayer();
void unlockOpenCloseLayer();
// Lock reading and writing
void lockReadWrite();
void unlockReadWrite();
QHash<int, int> & oldLids() { return mOldLids; }
QHash<int, int> & newLids() { return mNewLids; }
QHash<int, QgsAbstractGeometryV2*> & oldGeometries() { return mOldGeometries; }
QHash<int, int> & oldTypes() { return mOldTypes; }
QHash<int, int> & newCats() { return mNewCats; }
/** Get geometry of line.
* @return geometry (point,line or polygon(GV_FACE)) or 0 */
QgsAbstractGeometryV2 * lineGeometry( int id );
QgsAbstractGeometryV2 * nodeGeometry( int id );
QgsAbstractGeometryV2 * areaGeometry( int id );
/** Open map if not yet open. Open/close lock */
bool open();
/** Close map. All iterators are closed first. Open/close lock. */
void close();
/** Open GRASS map, no open/close locking */
bool openMap();
/** Close GRASS map, no open/close locking */
void closeMap();
/** Reload layers from (reopened) map. The layers keep field/type. */
void reloadLayers();
bool startEdit();
bool closeEdit( bool newMap );
/** Get layer, layer is created and loaded if not yet.
* @param field
* @return pointer to layer or 0 if layer doe not exist */
QgsGrassVectorMapLayer * openLayer( int field );
/** Close layer and release cached data if there are no more users and close map
* if there are no more map users.
* @param layer */
void closeLayer( QgsGrassVectorMapLayer * layer );
/** Update map. Close and reopen vector and refresh layers.
* Instances of QgsGrassProvider are not updated and should call update() method */
void update();
/** The map is outdated. The map was for example rewritten by GRASS module outside QGIS.
* This function checks internal timestamp stored in QGIS.
*/
bool mapOutdated();
/** The attributes are outdated. The table was for example updated by GRASS module outside QGIS.
* This function checks internal timestamp stored in QGIS.
*/
bool attributesOutdated();
/** Map descripton for debugging */
QString toString();
/** Get topology symbol code
* @param lid line or area number
* @param type geometry type */
TopoSymbol topoSymbol( int lid );
static QString topoSymbolFieldName() { return "topo_symbol" ; }
void printDebug();
signals:
/** Ask all iterators to cancel iteration when possible. Connected to iterators with
* Qt::DirectConnection (non blocking) */
void cancelIterators();
/** Close all iterators. Connected to iterators in different threads with Qt::BlockingQueuedConnection */
void closeIterators();
/** Emited when data were reloaded */
void dataChanged();
private:
/** Close iterators, blocking */
void closeAllIterators();
QgsGrassObject mGrassObject;
// true if map is open, once the map is closed, valid is set to false and no more used
bool mValid;
// Indicates if map is open, it may be open but invalide
bool mOpen;
// Vector temporally disabled. Necessary for GRASS Tools on Windows
bool mFrozen;
// true if the map is opened in update mode
bool mIsEdited;
// version, increased by each closeEdit() and updateMap()
int mVersion;
// last modified time of the vector directory, when the map was opened
QDateTime mLastModified;
// last modified time of the vector 'dbln' file, when the map was opened
// or attributes were updated. The 'dbln' file is updated by v.to.db etc.
QDateTime mLastAttributesModified;
// when attributes are changed
// map header
struct Map_info *mMap;
// Is 3D, has z coordinates
bool mIs3d;
// Vector layers
QList<QgsGrassVectorMapLayer*> mLayers;
// Number of lines in vector before editing started
int mOldNumLines;
// Original line ids of rewritten GRASS lines (new lid -> old lid)
QHash<int, int> mOldLids;
// Current line ids for old line ids (old lid -> new lid)
QHash<int, int> mNewLids;
// Hash of original lines' geometries of lines which were changed, keys are GRASS lid
QHash<int, QgsAbstractGeometryV2*> mOldGeometries;
// Hash of original lines' geometries GRASS types of lines which were changed, keys are GRASS lid
QHash<int, int> mOldTypes;
// New categories attached to new features or old features without category
// fid -> cat, the fid may be old fid without category or new (negative) feature id
QHash<int, int> mNewCats;
// Mutex used to avoid concurrent read/write, used only in editing mode
QMutex mReadWriteMutex;
// Open / close mutex
QMutex mOpenCloseMutex;
// Open / close mutex
QMutex mOpenCloseLayerMutex;
};
class GRASS_LIB_EXPORT QgsGrassVectorMapStore
{
public:
QgsGrassVectorMapStore();
~QgsGrassVectorMapStore();
static QgsGrassVectorMapStore *instance();
// Default instance may be overriden explicitely to avoid (temporarily) to share maps by providers
// This is only used for editing test to have an independent map
static void setStore( QgsGrassVectorMapStore * store ) { mStore = store; }
/** Open map.
* @param grassObject
* @return map, the map may be invalide */
QgsGrassVectorMap * openMap( const QgsGrassObject & grassObject );
private:
/** Open vector maps */
QList<QgsGrassVectorMap*> mMaps;
// Lock open/close map
QMutex mMutex;
static QgsGrassVectorMapStore * mStore;
};
#endif // QGSGRASSVECTORMAP_H