-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsgrassedit.h
435 lines (343 loc) · 12 KB
/
qgsgrassedit.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
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
/***************************************************************************
qgsgrassedit.h - GRASS Edit
-------------------
begin : March, 2004
copyright : (C) 2004 by Radim Blazek
email : blazek@itc.it
***************************************************************************/
/***************************************************************************
* *
* 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 QGSGRASSEDIT_H
#define QGSGRASSEDIT_H
#include <vector>
//Added by qt3to4:
#include <QPixmap>
#include <QCloseEvent>
#include <QAction>
class QString;
class QCloseEvent;
#include <q3pointarray.h>
#include <qcursor.h>
#include <qpen.h>
#include <qpainter.h>
// Must be here, so that it is included to moc file
#include "qgisapp.h"
#include "qgspoint.h"
#include "qgisiface.h"
#include "qgsmaptopixel.h"
class QgsRubberBand;
class QgsVertexMarker;
class QgsGrassEditLayer;
class QgsGrassAttributes;
class QgsGrassProvider;
#include "ui_qgsgrasseditbase.h"
#include <QMainWindow>
#include "qgsgrassselect.h"
// forward declaration of edit tools
class QgsGrassEditTool;
class QgsGrassEditNewPoint;
class QgsGrassEditNewLine;
class QgsGrassEditMoveVertex;
class QgsGrassEditAddVertex;
class QgsGrassEditDeleteVertex;
class QgsGrassEditMoveLine;
class QgsGrassEditDeleteLine;
class QgsGrassEditSplitLine;
class QgsGrassEditAttributes;
typedef struct {
int field;
int maxCat;
} MaxCat;
/*! \class QgsGrassEdit
* \brief GRASS vector edit.
*
*/
class QgsGrassEdit: public QMainWindow, private Ui::QgsGrassEditBase
{
Q_OBJECT;
public:
//! Tools
enum EditTools {
NONE,
NEW_POINT,
NEW_LINE,
NEW_BOUNDARY,
NEW_CENTROID,
MOVE_VERTEX,
ADD_VERTEX,
DELETE_VERTEX,
SPLIT_LINE,
MOVE_LINE,
DELETE_LINE,
EDIT_CATS,
EDIT_ATTRIBUTES
};
// Symbology codes */
enum SymbCode {
SYMB_BACKGROUND,
SYMB_HIGHLIGHT,
SYMB_DYNAMIC,
SYMB_POINT,
SYMB_LINE,
SYMB_BOUNDARY_0, /* No areas */
SYMB_BOUNDARY_1, /* 1 area */
SYMB_BOUNDARY_2, /* 2 areas */
SYMB_CENTROID_IN, /* Centroid in area */
SYMB_CENTROID_OUT, /* Centroid outside area */
SYMB_CENTROID_DUPL, /* Duplicate centroid in area */
SYMB_NODE_0, /* Node without lines (points or centroids) */
SYMB_NODE_1, /* Node with 1 line */
SYMB_NODE_2, /* Node with 2 lines */
SYMB_COUNT /* MUST BE LAST, number of symbology layers */
};
enum CatMode {
CAT_MODE_NEXT = 0,
CAT_MODE_MANUAL,
CAT_MODE_NOCAT
};
//! Constructor
QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
QWidget * parent = 0, Qt::WFlags f = 0 );
QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
QgsGrassProvider *provider,
QWidget * parent = 0, Qt::WFlags f = 0 );
// Shared by constructors
void init ();
//! Destructor
~QgsGrassEdit();
//! Close editing
bool isValid (void);
//! Close editing
static bool isRunning (void);
//! Set new tool and close old one if any
void startTool (int);
//! Add category to selected line
void addCat ( int line );
//! Delete category from selected line
void deleteCat ( int line, int field, int cat );
//! Add attributes to current mAttributes
void addAttributes ( int field, int cat );
//! Increase max cat
void increaseMaxCat ( void );
//! Check orphan database records
void checkOrphan ( int field, int cat );
public slots:
// TODO: once available in QGIS, use only one reciver for all signals
//! Called when rendering is finished
void postRender ( QPainter * );
// Slots to start tools (is it possible to pass tool to startTool() directly from GUI ?)
void newPoint (void); // digitize new point
void newLine (void); // digitize new line
void newBoundary (void); // digitize new boundary
void newCentroid (void); // digitize new centroid
void moveVertex (void); // move vertex of existing line/boundary
void addVertex (void); // add new vertex to existing line/boundary
void deleteVertex (void); // delete vertex of existing line/boundary
void splitLine (void); // split existing line/boundary
void moveLine (void); // move existing line/boundary
void deleteLine (void); // delete existing line/boundary
void editCats (void); // edit element categories
void editAttributes (void); // edit element attributes
//! Category mode was changed
void on_mCatModeBox_activated() { catModeChanged(); }
void catModeChanged();
//! Field was changed
void on_mFieldBox_activated() { fieldChanged(); }
void fieldChanged();
// Change attribute table
void on_mTableField_activated() { attributeTableFieldChanged(); }
void attributeTableFieldChanged();
// Add column
void on_mAddColumnButton_clicked() { addColumn(); }
void addColumn();
// Alter table
void on_mAlterTableButton_clicked() { alterTable(); }
void alterTable();
//! Close editing
void closeEdit();
void changeSymbology( Q3ListViewItem * item, const QPoint & pnt, int col );
//! width/size changed
void lineWidthChanged();
void markerSizeChanged();
void on_mLineWidthSpinBox_valueChanged() { lineWidthChanged(); }
void on_mMarkerSizeSpinBox_valueChanged() { markerSizeChanged(); }
// The type of column was changed
void columnTypeChanged ( int row, int col );
// ! Close event
void closeEvent(QCloseEvent *e);
static bool isEditable ( QgsMapLayer *layer );
signals:
void finished();
private:
//! Editing is already running
static bool mRunning;
//! Point / node size (later make editable array of Sizes)
int mSize;
//! Display all lines and nodes
void displayMap ();
/**
* Display icon
* @param x x coordinate in map units
* @param y y coordinate in map units
* @param type ICON_CROSS, ICON_X
* @param size size in pixels, should be odd number
*/
void displayIcon (double x, double y, const QPen & pen, int type, int size, QPainter *painter = 0);
/**
* Display dynamic drawing (XOR)
* Old drawing (in mLastDynamicPoints) is deleted first, and new one is drawn and
* mLastDynamicPoints is set to Points.
* SYMB_DYNAMIC color is used
*/
void displayDynamic ( struct line_pnts *Points );
/** Display dynamic icon */
void displayDynamic ( double x, double y, int type, int size );
/* Display dynamic points + icon */
void displayDynamic ( struct line_pnts *Points, double x, double y, int type, int size );
/** Erase dynamic */
void eraseDynamic ( void );
/**
* Display map element (lines and points)
* @param line line number
*/
void displayElement (int line, const QPen & pen, int size, QPainter *painter = 0);
/**
* Erase element and its nodes using SYMB_BACKGROUD
* @param line line number
*/
void eraseElement ( int line );
/**
* Display one node
* @param painter pointer to painter or 0
* @param node node number
* @param size size in pixels, should be odd number
*/
void displayNode ( int node, const QPen & pen, int size, QPainter *painter = 0);
//! Status: true - active vector was successfully opened for editing
bool mValid;
//! QGIS application
QgisApp *mQgisApp;
//! Pointer to the QGIS interface object
QgisIface *mIface;
//! Pointer to canvas
QgsMapCanvas *mCanvas;
//! Pointer to vector provider
QgsGrassProvider *mProvider;
//! Current tool (EditTools)
int mTool;
//! If tool is not closed and another QGIS tool is selected, suspend is set to true.
// GRASS Edit will continue if the same tool is selected later.
bool mSuspend;
//! Currently digitized line points,
// points of currently mooving line (original coordinates)
struct line_pnts *mEditPoints;
//! Working structure for line points
struct line_pnts *mPoints;
//! Working category structure
struct line_cats *mCats;
//! Vector of maximum used category values for each field
std::vector<MaxCat> mMaxCats;
//! Canvas pixmap
QPixmap *mPixmap;
//! Copy of background from canvas pixmap before any draw
//QPixmap *mBackgroundPixmap;
//! Transformation
QgsMapToPixel *mTransform;
//! Last point where user clicked (map units)
QgsPoint mLastPoint;
//! Selected line or 0
int mSelectedLine;
//! Selected segment or vertex (first is 0) (MOVE_VERTEX, ADD_VERTEX, DELETE_VERTEX)
int mSelectedPart;
//! Appand a new vertex at the end (not insert into existing segment)
bool mAddVertexEnd;
//! Vector of symbology codes for lines, indexes of lines start at 1, always resize nlines+1
std::vector<int> mLineSymb;
//! Vector of symbology codes for nodes, indexes of nodes start at 1, always resize nnodes+1
std::vector<int> mNodeSymb;
//! Vector of pens for symbology codes
std::vector<QPen> mSymb;
//! Display this type
std::vector<bool> mSymbDisplay;
//! Symbology name
std::vector<QString> mSymbName;
//! Line width
int mLineWidth;
//! Marker size
int mMarkerSize;
/**
* Read line symbology from map
* @return symbology code
*/
int lineSymbFromMap ( int line );
/**
* Read node symbology from map
* @return symbology code
*/
int nodeSymbFromMap ( int node );
/**
* Set symbology of updated lines and nodes from map
*/
void updateSymb ( void );
/**
* Display updated lines and nodes
*/
void displayUpdated ( void );
/** Write new element. Current field category is taken.
* return line number
*/
int writeLine ( int type, struct line_pnts *Points );
/** Get Current threshold in map units */
double threshold ( void );
/** Snap to nearest node in current threshold */
void snap ( QgsPoint & point );
void snap ( double *x, double *y);
/** Attributes */
QgsGrassAttributes *mAttributes;
void restorePosition(void);
void saveWindowLocation(void);
// Set attribute table
void setAttributeTable(int field);
// Pront which should be displayed in status bar when mouse is in canvas
QString mCanvasPrompt;
// Set prompt for mouse buttons
void setCanvasPropmt ( QString left, QString mid, QString rigth);
// New map, add new layers on exit
bool mNewMap;
// Actions
QAction *mNewPointAction;
QAction *mNewLineAction;
QAction *mNewBoundarytAction;
QAction *mNewCentroidAction;
QAction *mMoveVertexAction;
QAction *mAddVertexAction;
QAction *mDeleteVertexAction;
QAction *mMoveLineAction;
QAction *mSplitLineAction;
QAction *mDeleteLineAction;
QAction *mEditAttributesAction;
QAction *mCloseEditAction;
// Canvas items
QgsRubberBand *mRubberBandLine;
QgsVertexMarker *mRubberBandIcon;
QgsGrassEditLayer* mCanvasEdit;
// edit tools are friend classes so they can
// access proteced/private members of QgsGrassEdit
friend class QgsGrassEditTool;
friend class QgsGrassEditNewPoint;
friend class QgsGrassEditNewLine;
friend class QgsGrassEditMoveVertex;
friend class QgsGrassEditAddVertex;
friend class QgsGrassEditDeleteVertex;
friend class QgsGrassEditMoveLine;
friend class QgsGrassEditDeleteLine;
friend class QgsGrassEditSplitLine;
friend class QgsGrassEditAttributes;
};
#endif // QGSGRASSEDIT_H