@@ -166,6 +166,29 @@ bool QgsGrassEdit::isEditable ( QgsMapLayer *layer )
166
166
return true ;
167
167
}
168
168
169
+ void QgsGrassEdit::keyPress (QKeyEvent *e)
170
+ {
171
+ std::cerr << " QgsGrassEdit::keyPress" << std::endl;
172
+ // This does not work:
173
+ // keyPressEvent(e);
174
+
175
+ // TODO: this is not optimal
176
+ switch ( e->key () )
177
+ {
178
+ case Qt::Key_F1: newPoint (); break ;
179
+ case Qt::Key_F2: newLine (); break ;
180
+ case Qt::Key_F3: newBoundary (); break ;
181
+ case Qt::Key_F4: newCentroid (); break ;
182
+ case Qt::Key_F5: moveVertex (); break ;
183
+ case Qt::Key_F6: addVertex (); break ;
184
+ case Qt::Key_F7: deleteVertex (); break ;
185
+ case Qt::Key_F9: moveLine (); break ;
186
+ case Qt::Key_F10: splitLine (); break ;
187
+ case Qt::Key_F11: deleteLine (); break ;
188
+ default : break ;
189
+ }
190
+ }
191
+
169
192
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
170
193
QgsGrassProvider *provider,
171
194
QWidget * parent, Qt::WFlags f )
@@ -207,79 +230,80 @@ void QgsGrassEdit::init()
207
230
return ;
208
231
}
209
232
210
- QString myIconPath = QgsApplication::themePath () + " /grass/ " ;
233
+ connect ( mCanvas , SIGNAL ( keyPressed (QKeyEvent *)), this , SLOT ( keyPress (QKeyEvent *)) ) ;
211
234
235
+ QString myIconPath = QgsApplication::themePath () + " /grass/" ;
212
236
213
- QToolBar *tb = addToolBar (tr (" Edit tools" ));
237
+ mToolBar = addToolBar (tr (" Edit tools" ));
214
238
215
239
mNewPointAction = new QAction (
216
240
QIcon (myIconPath+" grass_new_point.png" ), tr (" New point" ), this );
217
241
mNewPointAction ->setShortcut ( QKeySequence (Qt::Key_F1) );
218
- tb ->addAction ( mNewPointAction );
242
+ mToolBar ->addAction ( mNewPointAction );
219
243
connect ( mNewPointAction , SIGNAL (triggered ()), this , SLOT (newPoint ()) );
220
244
221
245
mNewLineAction = new QAction (
222
246
QIcon (myIconPath+" grass_new_line.png" ), tr (" New line" ), this );
223
247
mNewLineAction ->setShortcut ( QKeySequence (Qt::Key_F2) );
224
- tb ->addAction ( mNewLineAction );
248
+ mToolBar ->addAction ( mNewLineAction );
225
249
connect ( mNewLineAction , SIGNAL (triggered ()), this , SLOT (newLine ()) );
226
250
227
251
mNewBoundaryAction = new QAction (
228
252
QIcon (myIconPath+" grass_new_boundary.png" ), tr (" New boundary" ), this );
229
253
mNewBoundaryAction ->setShortcut ( QKeySequence (Qt::Key_F3) );
230
- tb ->addAction ( mNewBoundaryAction );
254
+ mToolBar ->addAction ( mNewBoundaryAction );
231
255
connect ( mNewBoundaryAction , SIGNAL (triggered ()), this , SLOT (newBoundary ()) );
232
256
233
257
mNewCentroidAction = new QAction (
234
258
QIcon (myIconPath+" grass_new_centroid.png" ), tr (" New centroid" ), this );
235
259
mNewCentroidAction ->setShortcut ( QKeySequence (Qt::Key_F4) );
236
- tb ->addAction ( mNewCentroidAction );
260
+ mToolBar ->addAction ( mNewCentroidAction );
237
261
connect ( mNewCentroidAction , SIGNAL (triggered ()), this , SLOT (newCentroid ()) );
238
262
239
263
mMoveVertexAction = new QAction (
240
264
QIcon (myIconPath+" grass_move_vertex.png" ), tr (" Move vertex" ), this );
241
265
mMoveVertexAction ->setShortcut ( QKeySequence (Qt::Key_F5) );
242
- tb ->addAction ( mMoveVertexAction );
266
+ mToolBar ->addAction ( mMoveVertexAction );
243
267
connect ( mMoveVertexAction , SIGNAL (triggered ()), this , SLOT (moveVertex ()) );
244
268
245
269
mAddVertexAction = new QAction (
246
270
QIcon (myIconPath+" grass_add_vertex.png" ), tr (" Add vertex" ), this );
247
271
mAddVertexAction ->setShortcut ( QKeySequence (Qt::Key_F6) );
248
- tb ->addAction ( mAddVertexAction );
272
+ mToolBar ->addAction ( mAddVertexAction );
249
273
connect ( mAddVertexAction , SIGNAL (triggered ()), this , SLOT (addVertex ()) );
250
274
251
275
mDeleteVertexAction = new QAction (
252
276
QIcon (myIconPath+" grass_delete_vertex.png" ), tr (" Delete vertex" ), this );
253
277
mDeleteVertexAction ->setShortcut ( QKeySequence (Qt::Key_F7) );
254
- tb ->addAction ( mDeleteVertexAction );
278
+ mToolBar ->addAction ( mDeleteVertexAction );
255
279
connect ( mDeleteVertexAction , SIGNAL (triggered ()), this , SLOT (deleteVertex ()) );
256
280
257
281
mMoveLineAction = new QAction (
258
282
QIcon (myIconPath+" grass_move_line.png" ), tr (" Move element" ), this );
259
283
mMoveLineAction ->setShortcut ( QKeySequence (Qt::Key_F9) );
260
- tb ->addAction ( mMoveLineAction );
284
+ mToolBar ->addAction ( mMoveLineAction );
261
285
connect ( mMoveLineAction , SIGNAL (triggered ()), this , SLOT (moveLine ()) );
262
286
263
287
mSplitLineAction = new QAction (
264
288
QIcon (myIconPath+" grass_split_line.png" ), tr (" Split line" ), this );
265
289
mSplitLineAction ->setShortcut ( QKeySequence (Qt::Key_F10) );
266
- tb ->addAction ( mSplitLineAction );
290
+ mToolBar ->addAction ( mSplitLineAction );
267
291
connect ( mSplitLineAction , SIGNAL (triggered ()), this , SLOT (splitLine ()) );
268
292
269
293
mDeleteLineAction = new QAction (
270
294
QIcon (myIconPath+" grass_delete_line.png" ), tr (" Delete element" ), this );
271
295
mDeleteLineAction ->setShortcut ( QKeySequence (Qt::Key_F11) );
272
- tb ->addAction ( mDeleteLineAction );
296
+ mToolBar ->addAction ( mDeleteLineAction );
273
297
connect ( mDeleteLineAction , SIGNAL (triggered ()), this , SLOT (deleteLine ()) );
274
298
275
299
mEditAttributesAction = new QAction (
276
300
QIcon (myIconPath+" grass_edit_attributes.png" ), tr (" Edit attributes" ), this );
277
- tb ->addAction ( mEditAttributesAction );
301
+ mToolBar ->addAction ( mEditAttributesAction );
278
302
connect ( mEditAttributesAction , SIGNAL (triggered ()), this , SLOT (editAttributes ()) );
279
303
280
304
mCloseEditAction = new QAction (
281
305
QIcon (myIconPath+" grass_close_edit.png" ), tr (" Close" ), this );
282
- tb ->addAction ( mCloseEditAction );
306
+ mToolBar ->addAction ( mCloseEditAction );
283
307
connect ( mCloseEditAction , SIGNAL (triggered ()), this , SLOT (closeEdit ()) );
284
308
285
309
mNewPointAction ->setCheckable ( true );
@@ -1164,10 +1188,6 @@ void QgsGrassEdit::snap ( QgsPoint & point, double startX, double startY )
1164
1188
nodeDist = hypot ( x-nodeX, y-nodeY);
1165
1189
nodeIn = true ;
1166
1190
}
1167
- std::cerr << " startIn = " << startIn << std::endl;
1168
- std::cerr << " nodeIn = " << nodeIn << std::endl;
1169
- std::cerr << " startDist = " << startDist << std::endl;
1170
- std::cerr << " nodeDist = " << nodeDist << std::endl;
1171
1191
1172
1192
// Choose
1173
1193
if ( (startIn && !nodeIn) || (startIn && nodeIn && startDist < nodeDist) )
0 commit comments