38
38
#include < q3table.h>
39
39
#include < qstatusbar.h>
40
40
#include < qglobal.h>
41
- // Added by qt3to4:
41
+
42
+ #include < QActionGroup>
42
43
#include < QCloseEvent>
44
+ #include < QToolBar>
43
45
44
46
#include " qgis.h"
47
+ #include " qgsapplication.h"
45
48
#include " qgsmapcanvas.h"
46
49
#include " qgsmaplayer.h"
47
50
#include " qgsvectorlayer.h"
@@ -63,15 +66,15 @@ extern "C" {
63
66
bool QgsGrassEdit::mRunning = false ;
64
67
65
68
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
66
- QWidget * parent, const char * name, Qt::WFlags f )
67
- // :QgsGrassEditBase (parent,f) //commented out by Tim during ui port FIXME
68
- :QgsGrassEditBase ()
69
+ QWidget * parent, Qt::WFlags f )
70
+ :QMainWindow(parent,f), QgsGrassEditBase ()
69
71
{
70
- setupUi (this );
71
72
#ifdef QGISDEBUG
72
73
std::cerr << " QgsGrassEdit()" << std::endl;
73
74
#endif
74
75
76
+ setupUi (this );
77
+
75
78
mRunning = true ;
76
79
mValid = false ;
77
80
mTool = QgsGrassEdit::NONE;
@@ -114,15 +117,115 @@ QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
114
117
// TODO dynamic_cast ?
115
118
mProvider = (QgsGrassProvider *) vector->getDataProvider ();
116
119
120
+ QString myIconPath = QgsApplication::themePath () + " /grass/" ;
121
+
122
+ QActionGroup *ag = new QActionGroup ( this );
123
+
124
+ QToolBar *tb = addToolBar (tr (" Edit tools" ));
125
+
126
+ QAction *mNewPointAction = new QAction (
127
+ QIcon (myIconPath+" grass_new_point.png" ), tr (" New point" ), this );
128
+ mNewPointAction ->setCheckable ( true );
129
+ mNewPointAction ->setShortcut ( QKeySequence (Qt::Key_F1) );
130
+ ag->addAction ( mNewPointAction );
131
+ tb->addAction ( mNewPointAction );
132
+ connect ( mNewPointAction , SIGNAL (triggered ()), this , SLOT (newPoint ()) );
133
+
134
+ QAction *mNewLineAction = new QAction (
135
+ QIcon (myIconPath+" grass_new_line.png" ), tr (" New line" ), this );
136
+ mNewLineAction ->setCheckable ( true );
137
+ mNewLineAction ->setShortcut ( QKeySequence (Qt::Key_F2) );
138
+ ag->addAction ( mNewLineAction );
139
+ tb->addAction ( mNewLineAction );
140
+ connect ( mNewLineAction , SIGNAL (triggered ()), this , SLOT (newLine ()) );
141
+
142
+ QAction *mNewBoundaryAction = new QAction (
143
+ QIcon (myIconPath+" grass_new_boundary.png" ), tr (" New boundary" ), this );
144
+ mNewBoundaryAction ->setCheckable ( true );
145
+ mNewBoundaryAction ->setShortcut ( QKeySequence (Qt::Key_F3) );
146
+ ag->addAction ( mNewBoundaryAction );
147
+ tb->addAction ( mNewBoundaryAction );
148
+ connect ( mNewBoundaryAction , SIGNAL (triggered ()), this , SLOT (newBoundary ()) );
149
+
150
+ QAction *mNewCentroidAction = new QAction (
151
+ QIcon (myIconPath+" grass_new_centroid.png" ), tr (" New centroid" ), this );
152
+ mNewCentroidAction ->setCheckable ( true );
153
+ mNewCentroidAction ->setShortcut ( QKeySequence (Qt::Key_F4) );
154
+ ag->addAction ( mNewCentroidAction );
155
+ tb->addAction ( mNewCentroidAction );
156
+ connect ( mNewCentroidAction , SIGNAL (triggered ()), this , SLOT (newCentroid ()) );
157
+
158
+ QAction *mMoveVertexAction = new QAction (
159
+ QIcon (myIconPath+" grass_move_vertex.png" ), tr (" Move vertex" ), this );
160
+ mMoveVertexAction ->setCheckable ( true );
161
+ mMoveVertexAction ->setShortcut ( QKeySequence (Qt::Key_F5) );
162
+ ag->addAction ( mMoveVertexAction );
163
+ tb->addAction ( mMoveVertexAction );
164
+ connect ( mMoveVertexAction , SIGNAL (triggered ()), this , SLOT (moveVertex ()) );
165
+
166
+ QAction *mAddVertexAction = new QAction (
167
+ QIcon (myIconPath+" grass_add_vertex.png" ), tr (" Add vertex" ), this );
168
+ mAddVertexAction ->setCheckable ( true );
169
+ mAddVertexAction ->setShortcut ( QKeySequence (Qt::Key_F6) );
170
+ ag->addAction ( mAddVertexAction );
171
+ tb->addAction ( mAddVertexAction );
172
+ connect ( mAddVertexAction , SIGNAL (triggered ()), this , SLOT (addVertex ()) );
173
+
174
+ QAction *mDeleteVertexAction = new QAction (
175
+ QIcon (myIconPath+" grass_delete_vertex.png" ), tr (" Delete vertex" ), this );
176
+ mDeleteVertexAction ->setCheckable ( true );
177
+ mDeleteVertexAction ->setShortcut ( QKeySequence (Qt::Key_F7) );
178
+ ag->addAction ( mDeleteVertexAction );
179
+ tb->addAction ( mDeleteVertexAction );
180
+ connect ( mDeleteVertexAction , SIGNAL (triggered ()), this , SLOT (deleteVertex ()) );
181
+
182
+ QAction *mMoveLineAction = new QAction (
183
+ QIcon (myIconPath+" grass_move_line.png" ), tr (" Split line" ), this );
184
+ mMoveLineAction ->setCheckable ( true );
185
+ mMoveLineAction ->setShortcut ( QKeySequence (Qt::Key_F9) );
186
+ ag->addAction ( mMoveLineAction );
187
+ tb->addAction ( mMoveLineAction );
188
+ connect ( mMoveLineAction , SIGNAL (triggered ()), this , SLOT (moveLine ()) );
189
+
190
+ QAction *mSplitLineAction = new QAction (
191
+ QIcon (myIconPath+" grass_split_line.png" ), tr (" Move line" ), this );
192
+ mSplitLineAction ->setCheckable ( true );
193
+ mSplitLineAction ->setShortcut ( QKeySequence (Qt::Key_F10) );
194
+ ag->addAction ( mSplitLineAction );
195
+ tb->addAction ( mSplitLineAction );
196
+ connect ( mSplitLineAction , SIGNAL (triggered ()), this , SLOT (splitLine ()) );
197
+
198
+ QAction *mDeleteLineAction = new QAction (
199
+ QIcon (myIconPath+" grass_delete_line.png" ), tr (" Delete line" ), this );
200
+ mDeleteLineAction ->setCheckable ( true );
201
+ mDeleteLineAction ->setShortcut ( QKeySequence (Qt::Key_F11) );
202
+ ag->addAction ( mDeleteLineAction );
203
+ tb->addAction ( mDeleteLineAction );
204
+ connect ( mDeleteLineAction , SIGNAL (triggered ()), this , SLOT (deleteLine ()) );
205
+
206
+ QAction *mEditAttributesAction = new QAction (
207
+ QIcon (myIconPath+" grass_edit_attributes.png" ), tr (" Edit attributes" ), this );
208
+ mEditAttributesAction ->setCheckable ( true );
209
+ ag->addAction ( mEditAttributesAction );
210
+ tb->addAction ( mEditAttributesAction );
211
+ connect ( mEditAttributesAction , SIGNAL (triggered ()), this , SLOT (editAttributes ()) );
212
+
213
+ QAction *mCloseEditAction = new QAction (
214
+ QIcon (myIconPath+" grass_close_edit.png" ), tr (" Close" ), this );
215
+ mCloseEditAction ->setCheckable ( true );
216
+ tb->addAction ( mCloseEditAction );
217
+ connect ( mCloseEditAction , SIGNAL (triggered ()), this , SLOT (closeEdit ()) );
218
+
117
219
init ();
220
+
221
+ mNewPointAction ->setOn (true );
222
+ startTool (QgsGrassEdit::NEW_POINT);
118
223
}
119
224
120
225
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
121
226
QgsGrassProvider *provider,
122
- QWidget * parent, const char * name, Qt::WFlags f )
123
- // :QgsGrassEditBase ( parent, name, f )
124
- // commented out params duting qt4 ui port FIXME - Tim
125
- :QgsGrassEditBase ()
227
+ QWidget * parent, Qt::WFlags f )
228
+ :QMainWindow(parent, 0 , f), QgsGrassEditBase ()
126
229
{
127
230
#ifdef QGISDEBUG
128
231
std::cerr << " QgsGrassEdit()" << std::endl;
@@ -211,7 +314,7 @@ void QgsGrassEdit::init()
211
314
mSymbName .resize (SYMB_COUNT);
212
315
mSymbName [SYMB_BACKGROUND] = " Background" ;
213
316
mSymbName [SYMB_HIGHLIGHT] = " Highlight" ;
214
- mSymbName [SYMB_DYNAMIC] = " Dynamic (XOR mode) " ;
317
+ mSymbName [SYMB_DYNAMIC] = " Dynamic" ;
215
318
mSymbName [SYMB_POINT] = " Point" ;
216
319
mSymbName [SYMB_LINE] = " Line" ;
217
320
mSymbName [SYMB_BOUNDARY_0] = " Boundary (no area)" ;
@@ -334,6 +437,7 @@ void QgsGrassEdit::init()
334
437
connect ( mCanvas , SIGNAL (renderComplete (QPainter *)), this , SLOT (postRender (QPainter *)));
335
438
336
439
mPixmap = mCanvas ->canvasPixmap ();
440
+ mBackgroundPixmap = new QPixmap ( *mPixmap );
337
441
338
442
// Init GUI values
339
443
mCatModeBox ->insertItem ( " Next not used" , CAT_MODE_NEXT );
@@ -697,6 +801,8 @@ QgsGrassEdit::~QgsGrassEdit()
697
801
if ( mValid )
698
802
eraseDynamic ();
699
803
804
+ delete mBackgroundPixmap ;
805
+
700
806
saveWindowLocation ();
701
807
mRunning = false ;
702
808
}
@@ -1776,6 +1882,9 @@ void QgsGrassEdit::postRender(QPainter *painter)
1776
1882
1777
1883
displayMap ();
1778
1884
1885
+ delete mBackgroundPixmap ;
1886
+ mBackgroundPixmap = new QPixmap ( *mPixmap );
1887
+
1779
1888
// Redisplay highlighted
1780
1889
if ( mSelectedLine ) {
1781
1890
displayElement ( mSelectedLine , mSymb [SYMB_HIGHLIGHT], mSize );
@@ -1795,7 +1904,7 @@ void QgsGrassEdit::displayMap (void)
1795
1904
1796
1905
1797
1906
QPainter *painter = new QPainter ();
1798
- painter->begin ( mPixmap );
1907
+ painter->begin ( mBackgroundPixmap );
1799
1908
1800
1909
// Display lines
1801
1910
int nlines = mProvider ->numLines ();
@@ -1820,6 +1929,9 @@ void QgsGrassEdit::displayMap (void)
1820
1929
}
1821
1930
1822
1931
painter->end ();
1932
+ painter->begin (mPixmap );
1933
+ painter->drawPixmap ( 0 , 0 , *mBackgroundPixmap );
1934
+
1823
1935
mCanvas ->repaint (false );
1824
1936
}
1825
1937
@@ -1832,7 +1944,7 @@ void QgsGrassEdit::displayUpdated (void)
1832
1944
mTransform = mCanvas ->getCoordinateTransform ();
1833
1945
1834
1946
QPainter *painter = new QPainter ();
1835
- painter->begin (mPixmap );
1947
+ painter->begin (mBackgroundPixmap );
1836
1948
1837
1949
// Display lines
1838
1950
int nlines = mProvider ->numUpdatedLines ();
@@ -1854,6 +1966,9 @@ void QgsGrassEdit::displayUpdated (void)
1854
1966
}
1855
1967
1856
1968
painter->end ();
1969
+ painter->begin (mPixmap );
1970
+ painter->drawPixmap ( 0 , 0 , *mBackgroundPixmap );
1971
+
1857
1972
mCanvas ->repaint (false );
1858
1973
}
1859
1974
@@ -1871,7 +1986,7 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
1871
1986
QPainter *myPainter;
1872
1987
if ( !painter ) {
1873
1988
myPainter = new QPainter ();
1874
- myPainter->begin (mPixmap );
1989
+ myPainter->begin (mBackgroundPixmap );
1875
1990
} else {
1876
1991
myPainter = painter;
1877
1992
}
@@ -1896,6 +2011,9 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
1896
2011
1897
2012
if ( !painter ) {
1898
2013
myPainter->end ();
2014
+ myPainter->begin (mPixmap );
2015
+ myPainter->drawPixmap ( 0 , 0 , *mBackgroundPixmap );
2016
+
1899
2017
mCanvas ->repaint (false );
1900
2018
delete myPainter;
1901
2019
}
@@ -1978,14 +2096,14 @@ void QgsGrassEdit::displayLastDynamic ( void )
1978
2096
std::cerr << " QgsGrassEdit::displayLastDynamic" << std::endl;
1979
2097
#endif
1980
2098
1981
- #if QT_VERSION < 0x040000
1982
2099
QPainter myPainter;
1983
2100
myPainter.begin (mPixmap );
1984
2101
1985
- // Use of XOR can result in repeated :
1986
- // 'QPainter: Internal error; no available GC '
1987
- // which is probably only false warning, see qt/src/kernel/qpainter_x11.cpp
1988
- myPainter.setRasterOp (Qt::XorROP); // Must be after begin()
2102
+ // Note: QPainter.setCompositionMode only works for QImage device
2103
+
2104
+ // Redraw background
2105
+ myPainter.drawPixmap ( 0 , 0 , *mBackgroundPixmap );
2106
+
1989
2107
myPainter.setPen ( mSymb [SYMB_DYNAMIC] );
1990
2108
1991
2109
Q3PointArray pa ( mLastDynamicPoints ->n_points );
@@ -2004,9 +2122,6 @@ void QgsGrassEdit::displayLastDynamic ( void )
2004
2122
}
2005
2123
2006
2124
myPainter.end ();
2007
- #else
2008
- // TODO: Qt4 uses QRubberBand, need to refactor.
2009
- #endif
2010
2125
2011
2126
}
2012
2127
@@ -2046,7 +2161,7 @@ void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
2046
2161
QPainter *myPainter;
2047
2162
if ( !painter ) {
2048
2163
myPainter = new QPainter ();
2049
- myPainter->begin (mPixmap );
2164
+ myPainter->begin (mBackgroundPixmap );
2050
2165
} else {
2051
2166
myPainter = painter;
2052
2167
}
@@ -2085,6 +2200,8 @@ void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
2085
2200
2086
2201
if ( !painter ) {
2087
2202
myPainter->end ();
2203
+ myPainter->begin (mPixmap );
2204
+ myPainter->drawPixmap ( 0 , 0 , *mBackgroundPixmap );
2088
2205
mCanvas ->repaint (false );
2089
2206
delete myPainter;
2090
2207
}
0 commit comments