~ubuntu-branches/ubuntu/hardy/qgis/hardy

« back to all changes in this revision

Viewing changes to src/plugins/grass/qgsgrassedit.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    qgsgrassedit.h  -    GRASS Edit
 
3
                             -------------------
 
4
    begin                : March, 2004
 
5
    copyright            : (C) 2004 by Radim Blazek
 
6
    email                : blazek@itc.it
 
7
 ***************************************************************************/
 
8
/***************************************************************************
 
9
 *                                                                         *
 
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.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
#ifndef QGSGRASSEDIT_H
 
17
#define QGSGRASSEDIT_H
 
18
 
 
19
#include <vector>
 
20
//Added by qt3to4:
 
21
#include <QPixmap>
 
22
#include <QCloseEvent>
 
23
#include <QAction>
 
24
 
 
25
class QString;
 
26
class QCloseEvent;
 
27
 
 
28
#include <q3pointarray.h>
 
29
#include <qcursor.h>
 
30
#include <qpen.h>
 
31
#include <qpainter.h>
 
32
 
 
33
// Must be here, so that it is included to moc file
 
34
#include "qgisapp.h"
 
35
#include "qgspoint.h"
 
36
#include "qgisiface.h"
 
37
#include "qgsmaptopixel.h"
 
38
class QgsRubberBand;
 
39
class QgsVertexMarker;
 
40
class QgsVectorLayer;
 
41
class QgsMapTool;
 
42
class QgsGrassEditLayer;
 
43
class QgsGrassAttributes;
 
44
 
 
45
class QgsGrassProvider;
 
46
#include "ui_qgsgrasseditbase.h"
 
47
#include <QMainWindow>
 
48
#include "qgsgrassselect.h"
 
49
 
 
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;
 
61
 
 
62
typedef struct {
 
63
    int field;
 
64
    int maxCat;
 
65
} MaxCat;
 
66
 
 
67
/*! \class QgsGrassEdit
 
68
 *  \brief GRASS vector edit.
 
69
 *
 
70
 */
 
71
class QgsGrassEdit: public QMainWindow, private Ui::QgsGrassEditBase
 
72
{
 
73
    Q_OBJECT;
 
74
 
 
75
public:
 
76
    //! Tools
 
77
    enum EditTools {     
 
78
        NONE,
 
79
        NEW_POINT,
 
80
        NEW_LINE,
 
81
        NEW_BOUNDARY,
 
82
        NEW_CENTROID,
 
83
        MOVE_VERTEX,
 
84
        ADD_VERTEX,
 
85
        DELETE_VERTEX,
 
86
        SPLIT_LINE,
 
87
        MOVE_LINE,
 
88
        DELETE_LINE,
 
89
        EDIT_CATS,
 
90
        EDIT_ATTRIBUTES
 
91
    }; 
 
92
 
 
93
    // Symbology codes */
 
94
    enum SymbCode {
 
95
        SYMB_BACKGROUND,
 
96
        SYMB_HIGHLIGHT,
 
97
        SYMB_DYNAMIC,
 
98
        SYMB_POINT,
 
99
        SYMB_LINE,
 
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 */
 
110
    };
 
111
 
 
112
    enum CatMode {
 
113
        CAT_MODE_NEXT = 0,
 
114
        CAT_MODE_MANUAL,
 
115
        CAT_MODE_NOCAT
 
116
    };
 
117
 
 
118
    //! Constructor
 
119
    QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface, 
 
120
                   QWidget * parent = 0, Qt::WFlags f = 0 );
 
121
 
 
122
    QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface, 
 
123
                   QgsGrassProvider *provider,
 
124
                   QWidget * parent = 0, Qt::WFlags f = 0 );
 
125
 
 
126
    // Shared by constructors
 
127
    void init ();
 
128
 
 
129
    //! Destructor
 
130
    ~QgsGrassEdit();
 
131
 
 
132
    //! Close editing
 
133
    bool isValid (void); 
 
134
 
 
135
    //! Close editing
 
136
    static bool isRunning (void); 
 
137
 
 
138
    //! Set new tool and close old one if any
 
139
    void startTool (int); 
 
140
 
 
141
    //! Add category to selected line 
 
142
    void addCat ( int line ); 
 
143
 
 
144
    //! Delete category from selected line 
 
145
    void deleteCat ( int line, int field, int cat ); 
 
146
 
 
147
    //! Add attributes to current mAttributes 
 
148
    void addAttributes ( int field, int cat ); 
 
149
 
 
150
    //! Increase max cat
 
151
    void increaseMaxCat ( void );
 
152
 
 
153
    //! Check orphan database records
 
154
    void checkOrphan ( int field, int cat );
 
155
 
 
156
    //! pointer to layer
 
157
    QgsVectorLayer *layer() { return mLayer; }
 
158
 
 
159
public slots:
 
160
    // TODO: once available in QGIS, use only one reciver for all signals
 
161
    
 
162
    //! Called when rendering is finished
 
163
    void postRender ( QPainter * ); 
 
164
 
 
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
 
178
 
 
179
    //! Category mode was changed
 
180
    void on_mCatModeBox_activated() { catModeChanged(); }
 
181
    void catModeChanged();
 
182
 
 
183
    //! Field was changed
 
184
    void on_mFieldBox_activated() { fieldChanged(); }
 
185
    void fieldChanged();
 
186
 
 
187
    // Change attribute table
 
188
    void on_mTableField_activated() { attributeTableFieldChanged(); }
 
189
    void attributeTableFieldChanged();
 
190
 
 
191
    // Add column
 
192
    void on_mAddColumnButton_clicked() { addColumn(); }
 
193
    void addColumn();
 
194
 
 
195
    // Alter table
 
196
    void on_mAlterTableButton_clicked() { alterTable(); }
 
197
    void alterTable();
 
198
 
 
199
    //! Close editing
 
200
    void closeEdit(); 
 
201
 
 
202
    void changeSymbology( Q3ListViewItem * item, const QPoint & pnt, int col );
 
203
 
 
204
    //! width/size changed
 
205
    void lineWidthChanged();
 
206
    void markerSizeChanged();
 
207
    void on_mLineWidthSpinBox_valueChanged() { lineWidthChanged(); }
 
208
    void on_mMarkerSizeSpinBox_valueChanged() { markerSizeChanged(); }
 
209
 
 
210
    // The type of column was changed
 
211
    void columnTypeChanged ( int row, int col );
 
212
 
 
213
    // ! Close event
 
214
    void closeEvent(QCloseEvent *e);
 
215
 
 
216
    static bool isEditable ( QgsMapLayer *layer );
 
217
 
 
218
    //! Window with attributes closed
 
219
    void attributesClosed();
 
220
 
 
221
    //! Recieve key press from different widget 
 
222
    void keyPress(QKeyEvent *e); 
 
223
 
 
224
signals:
 
225
    void finished(); 
 
226
 
 
227
private:
 
228
    //! Editing is already running
 
229
    static bool mRunning;
 
230
 
 
231
    //! Pointer to edited layer
 
232
    QgsVectorLayer *mLayer;
 
233
 
 
234
    //! Pointer to toolbar
 
235
    QToolBar *mToolBar;
 
236
    
 
237
    //! Point / node size (later make editable array of Sizes)
 
238
    int mSize;
 
239
 
 
240
    //! Transform from layer coordinates to canvas including reprojection
 
241
    QgsPoint transformLayerToCanvas ( QgsPoint point);
 
242
 
 
243
    //! Transform from layer coordinates to current projection
 
244
    QgsPoint transformLayerToMap ( QgsPoint point);
 
245
 
 
246
    //! Display all lines and nodes
 
247
    void displayMap (); 
 
248
 
 
249
    /** 
 
250
     *  Display icon 
 
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
 
255
     */
 
256
    void displayIcon (double x, double y, const QPen & pen, int type, int size, QPainter *painter = 0); 
 
257
 
 
258
    /** 
 
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
 
263
     */
 
264
    void displayDynamic ( struct line_pnts *Points );
 
265
 
 
266
    /** Display dynamic icon */
 
267
    void displayDynamic ( double x, double y, int type, int size ); 
 
268
 
 
269
    /* Display dynamic points + icon */
 
270
    void displayDynamic ( struct line_pnts *Points, double x, double y, int type, int size ); 
 
271
 
 
272
    /** Erase dynamic */
 
273
    void eraseDynamic ( void ); 
 
274
 
 
275
    /** 
 
276
     *  Display map element (lines and points)
 
277
     *  @param line line number
 
278
     */
 
279
    void displayElement (int line, const QPen & pen, int size, QPainter *painter = 0); 
 
280
 
 
281
    /** 
 
282
     *  Erase element and its nodes using SYMB_BACKGROUD
 
283
     *  @param line line number
 
284
     */
 
285
    void eraseElement ( int line ); 
 
286
 
 
287
    /** 
 
288
     *  Display one node 
 
289
     *  @param painter pointer to painter or 0
 
290
     *  @param node node number
 
291
     *  @param size size in pixels, should be odd number
 
292
     */
 
293
    void displayNode ( int node, const QPen & pen, int size, QPainter *painter = 0); 
 
294
 
 
295
    //! Status: true - active vector was successfully opened for editing
 
296
    bool mValid;
 
297
 
 
298
    //! Initialization complete
 
299
    bool mInited;
 
300
    
 
301
    //! QGIS application
 
302
    QgisApp *mQgisApp; 
 
303
    
 
304
    //! Pointer to the QGIS interface object
 
305
    QgisIface *mIface;
 
306
 
 
307
    //! Pointer to canvas 
 
308
    QgsMapCanvas *mCanvas;
 
309
 
 
310
    //! Pointer to vector provider 
 
311
    QgsGrassProvider *mProvider;
 
312
    
 
313
    //! Current tool (EditTools)
 
314
    int mTool;
 
315
    
 
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.
 
318
    bool mSuspend;
 
319
 
 
320
    //! Currently digitized line points, 
 
321
    //  points of currently mooving line (original coordinates)
 
322
    struct line_pnts *mEditPoints;
 
323
 
 
324
    //! Working structure for line points
 
325
    struct line_pnts *mPoints;
 
326
 
 
327
    //! Working category structure
 
328
    struct line_cats *mCats;
 
329
 
 
330
    //! Vector of maximum used category values for each field
 
331
    std::vector<MaxCat> mMaxCats;
 
332
 
 
333
    //! Canvas pixmap
 
334
    QPixmap *mPixmap;
 
335
 
 
336
    //! Copy of background from canvas pixmap before any draw
 
337
    //QPixmap *mBackgroundPixmap;
 
338
 
 
339
    //! Transformation
 
340
    QgsMapToPixel *mTransform;
 
341
 
 
342
    //! Last point where user clicked (map units)
 
343
    QgsPoint mLastPoint;
 
344
 
 
345
    //! Selected line or 0
 
346
    int mSelectedLine;
 
347
 
 
348
    //! Selected segment or vertex (first is 0) (MOVE_VERTEX, ADD_VERTEX, DELETE_VERTEX)
 
349
    int mSelectedPart;
 
350
 
 
351
    //! Appand a new vertex at the end (not insert into existing segment)
 
352
    bool mAddVertexEnd;
 
353
 
 
354
    //! Vector of symbology codes for lines, indexes of lines start at 1, always resize nlines+1
 
355
    std::vector<int> mLineSymb;
 
356
 
 
357
    //! Vector of symbology codes for nodes, indexes of nodes start at 1, always resize nnodes+1
 
358
    std::vector<int> mNodeSymb;
 
359
 
 
360
    //! Vector of pens for symbology codes
 
361
    std::vector<QPen> mSymb;
 
362
 
 
363
    //! Display this type
 
364
    std::vector<bool> mSymbDisplay;
 
365
 
 
366
    //! Symbology name
 
367
    std::vector<QString> mSymbName;
 
368
 
 
369
    //! Line width
 
370
    int mLineWidth;
 
371
 
 
372
    //! Marker size
 
373
    int mMarkerSize;
 
374
 
 
375
    /** 
 
376
     *  Read line symbology from map
 
377
     *  @return symbology code
 
378
     */
 
379
    int lineSymbFromMap ( int line );
 
380
 
 
381
    /** 
 
382
     *  Read node symbology from map
 
383
     *  @return symbology code
 
384
     */
 
385
    int nodeSymbFromMap ( int node );
 
386
 
 
387
    /** 
 
388
     *  Set symbology of updated lines and nodes from map
 
389
     */
 
390
    void updateSymb ( void );
 
391
 
 
392
    /** 
 
393
     *  Display updated lines and nodes
 
394
     */
 
395
    void displayUpdated ( void );
 
396
 
 
397
    /** Write new element. Current field category is taken. 
 
398
     * return line number
 
399
     */
 
400
    int writeLine (  int type, struct line_pnts *Points );
 
401
 
 
402
    /** Get Current threshold in map units */
 
403
    double threshold ( void );
 
404
 
 
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);
 
410
 
 
411
    /** Attributes */
 
412
    QgsGrassAttributes *mAttributes;
 
413
 
 
414
    void restorePosition(void);
 
415
 
 
416
    void saveWindowLocation(void);
 
417
 
 
418
    // Set attribute table
 
419
    void setAttributeTable(int field);
 
420
 
 
421
    // Pront which should be displayed in status bar when mouse is in canvas
 
422
    QString mCanvasPrompt;
 
423
    
 
424
    // Set prompt for mouse buttons
 
425
    void setCanvasPropmt ( QString left, QString mid, QString rigth);
 
426
 
 
427
    // New map, add new layers on exit
 
428
    bool mNewMap;
 
429
 
 
430
    // Actions 
 
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;
 
443
 
 
444
    // Current map tool
 
445
    QgsMapTool  *mMapTool;
 
446
 
 
447
    // Is projection enabled?
 
448
    bool mProjectionEnabled;
 
449
 
 
450
    // Canvas items
 
451
    QgsRubberBand *mRubberBandLine;
 
452
    QgsVertexMarker *mRubberBandIcon;
 
453
    QgsGrassEditLayer* mCanvasEdit;
 
454
    
 
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;
 
467
};
 
468
 
 
469
#endif // QGSGRASSEDIT_H