1
/***************************************************************************
2
qgsgrassedit.h - GRASS Edit
5
copyright : (C) 2004 by Radim Blazek
7
***************************************************************************/
8
/***************************************************************************
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
15
***************************************************************************/
16
#ifndef QGSGRASSEDIT_H
17
#define QGSGRASSEDIT_H
22
#include <QCloseEvent>
28
#include <q3pointarray.h>
33
// Must be here, so that it is included to moc file
36
#include "qgisiface.h"
37
#include "qgsmaptopixel.h"
39
class QgsVertexMarker;
42
class QgsGrassEditLayer;
43
class QgsGrassAttributes;
45
class QgsGrassProvider;
46
#include "ui_qgsgrasseditbase.h"
47
#include <QMainWindow>
48
#include "qgsgrassselect.h"
50
// forward declaration of edit tools
51
class QgsGrassEditTool;
52
class QgsGrassEditNewPoint;
53
class QgsGrassEditNewLine;
54
class QgsGrassEditMoveVertex;
55
class QgsGrassEditAddVertex;
56
class QgsGrassEditDeleteVertex;
57
class QgsGrassEditMoveLine;
58
class QgsGrassEditDeleteLine;
59
class QgsGrassEditSplitLine;
60
class QgsGrassEditAttributes;
67
/*! \class QgsGrassEdit
68
* \brief GRASS vector edit.
71
class QgsGrassEdit: public QMainWindow, private Ui::QgsGrassEditBase
100
SYMB_BOUNDARY_0, /* No areas */
101
SYMB_BOUNDARY_1, /* 1 area */
102
SYMB_BOUNDARY_2, /* 2 areas */
103
SYMB_CENTROID_IN, /* Centroid in area */
104
SYMB_CENTROID_OUT, /* Centroid outside area */
105
SYMB_CENTROID_DUPL, /* Duplicate centroid in area */
106
SYMB_NODE_0, /* Node without lines (points or centroids) */
107
SYMB_NODE_1, /* Node with 1 line */
108
SYMB_NODE_2, /* Node with 2 lines */
109
SYMB_COUNT /* MUST BE LAST, number of symbology layers */
119
QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
120
QWidget * parent = 0, Qt::WFlags f = 0 );
122
QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
123
QgsGrassProvider *provider,
124
QWidget * parent = 0, Qt::WFlags f = 0 );
126
// Shared by constructors
136
static bool isRunning (void);
138
//! Set new tool and close old one if any
139
void startTool (int);
141
//! Add category to selected line
142
void addCat ( int line );
144
//! Delete category from selected line
145
void deleteCat ( int line, int field, int cat );
147
//! Add attributes to current mAttributes
148
void addAttributes ( int field, int cat );
151
void increaseMaxCat ( void );
153
//! Check orphan database records
154
void checkOrphan ( int field, int cat );
157
QgsVectorLayer *layer() { return mLayer; }
160
// TODO: once available in QGIS, use only one reciver for all signals
162
//! Called when rendering is finished
163
void postRender ( QPainter * );
165
// Slots to start tools (is it possible to pass tool to startTool() directly from GUI ?)
166
void newPoint (void); // digitize new point
167
void newLine (void); // digitize new line
168
void newBoundary (void); // digitize new boundary
169
void newCentroid (void); // digitize new centroid
170
void moveVertex (void); // move vertex of existing line/boundary
171
void addVertex (void); // add new vertex to existing line/boundary
172
void deleteVertex (void); // delete vertex of existing line/boundary
173
void splitLine (void); // split existing line/boundary
174
void moveLine (void); // move existing line/boundary
175
void deleteLine (void); // delete existing line/boundary
176
void editCats (void); // edit element categories
177
void editAttributes (void); // edit element attributes
179
//! Category mode was changed
180
void on_mCatModeBox_activated() { catModeChanged(); }
181
void catModeChanged();
183
//! Field was changed
184
void on_mFieldBox_activated() { fieldChanged(); }
187
// Change attribute table
188
void on_mTableField_activated() { attributeTableFieldChanged(); }
189
void attributeTableFieldChanged();
192
void on_mAddColumnButton_clicked() { addColumn(); }
196
void on_mAlterTableButton_clicked() { alterTable(); }
202
void changeSymbology( Q3ListViewItem * item, const QPoint & pnt, int col );
204
//! width/size changed
205
void lineWidthChanged();
206
void markerSizeChanged();
207
void on_mLineWidthSpinBox_valueChanged() { lineWidthChanged(); }
208
void on_mMarkerSizeSpinBox_valueChanged() { markerSizeChanged(); }
210
// The type of column was changed
211
void columnTypeChanged ( int row, int col );
214
void closeEvent(QCloseEvent *e);
216
static bool isEditable ( QgsMapLayer *layer );
218
//! Window with attributes closed
219
void attributesClosed();
221
//! Recieve key press from different widget
222
void keyPress(QKeyEvent *e);
228
//! Editing is already running
229
static bool mRunning;
231
//! Pointer to edited layer
232
QgsVectorLayer *mLayer;
234
//! Pointer to toolbar
237
//! Point / node size (later make editable array of Sizes)
240
//! Transform from layer coordinates to canvas including reprojection
241
QgsPoint transformLayerToCanvas ( QgsPoint point);
243
//! Transform from layer coordinates to current projection
244
QgsPoint transformLayerToMap ( QgsPoint point);
246
//! Display all lines and nodes
251
* @param x x coordinate in map units
252
* @param y y coordinate in map units
253
* @param type ICON_CROSS, ICON_X
254
* @param size size in pixels, should be odd number
256
void displayIcon (double x, double y, const QPen & pen, int type, int size, QPainter *painter = 0);
259
* Display dynamic drawing (XOR)
260
* Old drawing (in mLastDynamicPoints) is deleted first, and new one is drawn and
261
* mLastDynamicPoints is set to Points.
262
* SYMB_DYNAMIC color is used
264
void displayDynamic ( struct line_pnts *Points );
266
/** Display dynamic icon */
267
void displayDynamic ( double x, double y, int type, int size );
269
/* Display dynamic points + icon */
270
void displayDynamic ( struct line_pnts *Points, double x, double y, int type, int size );
273
void eraseDynamic ( void );
276
* Display map element (lines and points)
277
* @param line line number
279
void displayElement (int line, const QPen & pen, int size, QPainter *painter = 0);
282
* Erase element and its nodes using SYMB_BACKGROUD
283
* @param line line number
285
void eraseElement ( int line );
289
* @param painter pointer to painter or 0
290
* @param node node number
291
* @param size size in pixels, should be odd number
293
void displayNode ( int node, const QPen & pen, int size, QPainter *painter = 0);
295
//! Status: true - active vector was successfully opened for editing
298
//! Initialization complete
304
//! Pointer to the QGIS interface object
307
//! Pointer to canvas
308
QgsMapCanvas *mCanvas;
310
//! Pointer to vector provider
311
QgsGrassProvider *mProvider;
313
//! Current tool (EditTools)
316
//! If tool is not closed and another QGIS tool is selected, suspend is set to true.
317
// GRASS Edit will continue if the same tool is selected later.
320
//! Currently digitized line points,
321
// points of currently mooving line (original coordinates)
322
struct line_pnts *mEditPoints;
324
//! Working structure for line points
325
struct line_pnts *mPoints;
327
//! Working category structure
328
struct line_cats *mCats;
330
//! Vector of maximum used category values for each field
331
std::vector<MaxCat> mMaxCats;
336
//! Copy of background from canvas pixmap before any draw
337
//QPixmap *mBackgroundPixmap;
340
QgsMapToPixel *mTransform;
342
//! Last point where user clicked (map units)
345
//! Selected line or 0
348
//! Selected segment or vertex (first is 0) (MOVE_VERTEX, ADD_VERTEX, DELETE_VERTEX)
351
//! Appand a new vertex at the end (not insert into existing segment)
354
//! Vector of symbology codes for lines, indexes of lines start at 1, always resize nlines+1
355
std::vector<int> mLineSymb;
357
//! Vector of symbology codes for nodes, indexes of nodes start at 1, always resize nnodes+1
358
std::vector<int> mNodeSymb;
360
//! Vector of pens for symbology codes
361
std::vector<QPen> mSymb;
363
//! Display this type
364
std::vector<bool> mSymbDisplay;
367
std::vector<QString> mSymbName;
376
* Read line symbology from map
377
* @return symbology code
379
int lineSymbFromMap ( int line );
382
* Read node symbology from map
383
* @return symbology code
385
int nodeSymbFromMap ( int node );
388
* Set symbology of updated lines and nodes from map
390
void updateSymb ( void );
393
* Display updated lines and nodes
395
void displayUpdated ( void );
397
/** Write new element. Current field category is taken.
400
int writeLine ( int type, struct line_pnts *Points );
402
/** Get Current threshold in map units */
403
double threshold ( void );
405
/** Snap to nearest node in current threshold */
406
void snap ( QgsPoint & point );
407
void snap ( double *x, double *y);
408
/** Snap point line considering line starting point */
409
void snap ( QgsPoint & point, double startX, double startY);
412
QgsGrassAttributes *mAttributes;
414
void restorePosition(void);
416
void saveWindowLocation(void);
418
// Set attribute table
419
void setAttributeTable(int field);
421
// Pront which should be displayed in status bar when mouse is in canvas
422
QString mCanvasPrompt;
424
// Set prompt for mouse buttons
425
void setCanvasPropmt ( QString left, QString mid, QString rigth);
427
// New map, add new layers on exit
431
QAction *mNewPointAction;
432
QAction *mNewLineAction;
433
QAction *mNewBoundaryAction;
434
QAction *mNewCentroidAction;
435
QAction *mMoveVertexAction;
436
QAction *mAddVertexAction;
437
QAction *mDeleteVertexAction;
438
QAction *mMoveLineAction;
439
QAction *mSplitLineAction;
440
QAction *mDeleteLineAction;
441
QAction *mEditAttributesAction;
442
QAction *mCloseEditAction;
445
QgsMapTool *mMapTool;
447
// Is projection enabled?
448
bool mProjectionEnabled;
451
QgsRubberBand *mRubberBandLine;
452
QgsVertexMarker *mRubberBandIcon;
453
QgsGrassEditLayer* mCanvasEdit;
455
// edit tools are friend classes so they can
456
// access proteced/private members of QgsGrassEdit
457
friend class QgsGrassEditTool;
458
friend class QgsGrassEditNewPoint;
459
friend class QgsGrassEditNewLine;
460
friend class QgsGrassEditMoveVertex;
461
friend class QgsGrassEditAddVertex;
462
friend class QgsGrassEditDeleteVertex;
463
friend class QgsGrassEditMoveLine;
464
friend class QgsGrassEditDeleteLine;
465
friend class QgsGrassEditSplitLine;
466
friend class QgsGrassEditAttributes;
469
#endif // QGSGRASSEDIT_H