-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsgrassplugin.cpp
749 lines (630 loc) · 21 KB
/
qgsgrassplugin.cpp
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
/***************************************************************************
qgsgrassplugin.cpp - GRASS menu
-------------------
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. *
* *
***************************************************************************/
#include "qgsgrassplugin.h"
#include "qgis.h"
#include "qgsgrass.h"
//the gui subclass
#include "qgsgrassedit.h"
#include "qgsgrassnewmapset.h"
#include "qgsgrassregion.h"
#include "qgsgrassselect.h"
#include "qgsgrasstools.h"
#include "qgsgrassutils.h"
// includes
#include "qgisinterface.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayerregistry.h"
#include <QAction>
#include <QFileInfo>
#include <QMessageBox>
#include <QSettings>
#include <QToolBar>
extern "C"
{
#if GRASS_VERSION_MAJOR < 7
#include <grass/Vect.h>
#else
#include <grass/vector.h>
#endif
#include <grass/version.h>
}
static const QString pluginName = QObject::tr( "GRASS %1" ).arg( GRASS_VERSION_MAJOR );
static const QString pluginDescription = QObject::tr( "GRASS %1 (Geographic Resources Analysis Support System)" ).arg( GRASS_VERSION_MAJOR );
static const QString pluginCategory = QObject::tr( "Plugins" );
static const QString pluginVersion = QObject::tr( "Version 2.0" );
static const QString pluginIcon = ":/images/themes/default/grass/grass_tools.png";
/**
* Constructor for the plugin. The plugin is passed a pointer to the main app
* and an interface object that provides access to exposed functions in QGIS.
* @param theQGisApp Pointer to the QGIS main window
* @param theQgisInterFace Pointer to the QGIS interface object
*/
QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )
: mToolBarPointer( 0 )
, qGisInterface( theQgisInterFace )
, mCanvas( 0 )
, mRegionAction( 0 )
, mRegionBand( 0 )
, mTools( 0 )
, mNewMapset( 0 )
, mEdit( 0 )
, mOpenMapsetAction( 0 )
, mNewMapsetAction( 0 )
, mCloseMapsetAction( 0 )
, mOpenToolsAction( 0 )
, mEditAction( 0 )
, mNewVectorAction( 0 )
{
}
QgsGrassPlugin::~QgsGrassPlugin()
{
QgsDebugMsg( "entered." );
// When main app is closed, QgsGrassTools (probably because of dock widget) are destroyed before QgsGrassPlugin
// -> do not call mTools here
//if ( mTools )
// mTools->closeTools();
if ( mEdit )
{
mEdit->closeEdit();
}
disconnect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), this, SLOT( mapsetChanged() ) );
QgsGrass::instance()->closeMapsetWarn();
}
/* Following functions return name, description, version, and type for the plugin */
QString QgsGrassPlugin::name()
{
return pluginName;
}
QString QgsGrassPlugin::version()
{
return pluginVersion;
}
QString QgsGrassPlugin::description()
{
return pluginDescription;
}
QString QgsGrassPlugin::category()
{
return pluginCategory;
}
void QgsGrassPlugin::help()
{
//TODO
}
int QgsGrassPlugin::type()
{
return QgisPlugin::UI;
}
/*
* Initialize the GUI interface for the plugin
*/
void QgsGrassPlugin::initGui()
{
mToolBarPointer = 0;
mTools = 0;
mNewMapset = 0;
QSettings settings;
QgsGrass::init();
mCanvas = qGisInterface->mapCanvas();
QWidget* qgis = qGisInterface->mainWindow();
connect( mCanvas, SIGNAL( destinationCrsChanged() ), this, SLOT( setTransform() ) );
// Connect project
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
connect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
// Create region rubber band
mRegionBand = new QgsRubberBand( mCanvas, QGis::Polygon );
mRegionBand->setZValue( 20 );
// Create the action for tool (the icons are set later by calling setCurrentTheme)
mOpenMapsetAction = new QAction( QIcon(), tr( "Open Mapset" ), this );
mOpenMapsetAction->setObjectName( "mOpenMapsetAction" );
mNewMapsetAction = new QAction( QIcon(), tr( "New Mapset" ), this );
mNewMapsetAction->setObjectName( "mNewMapsetAction" );
mCloseMapsetAction = new QAction( QIcon(), tr( "Close Mapset" ), this );
mCloseMapsetAction->setObjectName( "mCloseMapsetAction" );
mOpenToolsAction = new QAction( QIcon(), tr( "Open GRASS Tools" ), this );
mOpenToolsAction->setObjectName( "mOpenToolsAction" );
mOpenToolsAction->setWhatsThis( tr( "Open GRASS tools" ) );
mRegionAction = new QAction( QIcon(), tr( "Display Current Grass Region" ), this );
mRegionAction->setObjectName( "mRegionAction" );
mRegionAction->setWhatsThis( tr( "Displays the current GRASS region as a rectangle on the map canvas" ) );
mRegionAction->setCheckable( true );
mEditAction = new QAction( QIcon(), tr( "Edit Grass Vector layer" ), this );
mEditAction->setObjectName( "mEditAction" );
mEditAction->setWhatsThis( tr( "Edit the currently selected GRASS vector layer." ) );
mNewVectorAction = new QAction( QIcon(), tr( "Create New Grass Vector" ), this );
mNewVectorAction->setObjectName( "mNewVectorAction" );
// Connect the action
connect( mOpenToolsAction, SIGNAL( triggered() ), this, SLOT( openTools() ) );
connect( mEditAction, SIGNAL( triggered() ), this, SLOT( edit() ) );
connect( mNewVectorAction, SIGNAL( triggered() ), this, SLOT( newVector() ) );
connect( mRegionAction, SIGNAL( toggled( bool ) ), this, SLOT( switchRegion( bool ) ) );
connect( mOpenMapsetAction, SIGNAL( triggered() ), this, SLOT( openMapset() ) );
connect( mNewMapsetAction, SIGNAL( triggered() ), this, SLOT( newMapset() ) );
connect( mCloseMapsetAction, SIGNAL( triggered() ), SLOT( closeMapset() ) );
// Add actions to a GRASS plugin menu
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenMapsetAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewMapsetAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mCloseMapsetAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewVectorAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mEditAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenToolsAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mRegionAction );
// Add the toolbar to the main window
mToolBarPointer = qGisInterface->addToolBar( tr( "GRASS" ) );
mToolBarPointer->setObjectName( "GRASS" );
// Add to the toolbar
mToolBarPointer->addAction( mOpenMapsetAction );
mToolBarPointer->addAction( mNewMapsetAction );
mToolBarPointer->addAction( mCloseMapsetAction );
mToolBarPointer->addSeparator();
mToolBarPointer->addAction( mNewVectorAction );
mToolBarPointer->addAction( mEditAction );
mToolBarPointer->addAction( mOpenToolsAction );
mToolBarPointer->addAction( mRegionAction );
// Set icons to current theme
setCurrentTheme( "" );
// Connect theme change signal
connect( qGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
// Connect display region
connect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
setEditAction();
connect( qGisInterface, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SLOT( setEditAction() ) );
connect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), SLOT( mapsetChanged() ) );
connect( QgsGrass::instance(), SIGNAL( regionChanged() ), SLOT( displayRegion() ) );
connect( QgsGrass::instance(), SIGNAL( regionPenChanged() ), SLOT( displayRegion() ) );
mapsetChanged();
// open tools when plugin is loaded so that main app restores tools dock widget state
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow() );
qGisInterface->addDockWidget( Qt::RightDockWidgetArea, mTools );
}
void QgsGrassPlugin::mapsetChanged()
{
QgsDebugMsg( "entered" );
if ( !QgsGrass::activeMode() )
{
mRegionAction->setEnabled( false );
mRegionBand->reset();
mCloseMapsetAction->setEnabled( false );
mNewVectorAction->setEnabled( false );
}
else
{
mRegionAction->setEnabled( true );
mCloseMapsetAction->setEnabled( true );
mNewVectorAction->setEnabled( true );
QSettings settings;
bool on = settings.value( "/GRASS/region/on", true ).toBool();
mRegionAction->setChecked( on );
switchRegion( on );
QString gisdbase = QgsGrass::getDefaultGisdbase();
QString location = QgsGrass::getDefaultLocation();
try
{
mCrs = QgsGrass::crsDirect( gisdbase, location );
}
catch ( QgsGrass::Exception &e )
{
Q_UNUSED( e );
QgsDebugMsg( "Cannot read GRASS CRS : " + QString( e.what() ) );
mCrs = QgsCoordinateReferenceSystem();
}
QgsDebugMsg( "mCrs: " + mCrs.toWkt() );
setTransform();
redrawRegion();
}
if ( mTools )
{
mTools->mapsetChanged();
}
}
// Open tools
void QgsGrassPlugin::openTools()
{
#if 0
if ( !mTools )
{
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow(), 0, Qt::Dialog );
connect( mTools, SIGNAL( regionChanged() ), this, SLOT( redrawRegion() ) );
}
#endif
mTools->show();
}
// Start vector editing
void QgsGrassPlugin::edit()
{
if ( QgsGrassEdit::isRunning() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "GRASS Edit is already running." ) );
return;
}
mEditAction->setEnabled( false );
mEdit = new QgsGrassEdit( qGisInterface, qGisInterface->activeLayer(), false,
qGisInterface->mainWindow(), Qt::Dialog );
if ( mEdit->isValid() )
{
mEdit->show();
mCanvas->refresh();
connect( mEdit, SIGNAL( finished() ), this, SLOT( setEditAction() ) );
connect( mEdit, SIGNAL( finished() ), this, SLOT( cleanUp() ) );
connect( mEdit, SIGNAL( destroyed() ), this, SLOT( editClosed() ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( closeEdit( QString ) ) );
}
else
{
delete mEdit;
mEdit = NULL;
mEditAction->setEnabled( true );
}
}
void QgsGrassPlugin::setEditAction()
{
// QgsDebugMsg("entered.");
QgsMapLayer *layer = ( QgsMapLayer * ) qGisInterface->activeLayer();
if ( QgsGrassEdit::isEditable( layer ) )
{
mEditAction->setEnabled( true );
}
else
{
mEditAction->setEnabled( false );
}
}
void QgsGrassPlugin::closeEdit( QString layerId )
{
if ( mEdit->layer()->id() == layerId )
{
mEdit->closeEdit();
}
}
void QgsGrassPlugin::editClosed()
{
if ( mEdit == sender() )
mEdit = 0;
}
void QgsGrassPlugin::cleanUp()
{
disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( closeEdit( QString ) ) );
}
void QgsGrassPlugin::newVector()
{
// QgsDebugMsg("entered.");
if ( QgsGrassEdit::isRunning() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "GRASS Edit is already running." ) );
return;
}
bool ok;
QString name;
QgsGrassElementDialog dialog( qGisInterface->mainWindow() );
name = dialog.getItem( "vector", tr( "New vector name" ),
tr( "New vector name" ), "", "", &ok );
if ( !ok )
return;
// Create new map
QgsGrass::setMapset( QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(),
QgsGrass::getDefaultMapset() );
try
{
struct Map_info Map;
Vect_open_new( &Map, name.toUtf8().data(), 0 );
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
Vect_build( &Map );
#else
Vect_build( &Map, stderr );
#endif
Vect_set_release_support( &Map );
Vect_close( &Map );
}
catch ( QgsGrass::Exception &e )
{
QMessageBox::warning( 0, tr( "Warning" ),
tr( "Cannot create new vector: %1" ).arg( e.what() ) );
return;
}
// Open in GRASS vector provider
QString uri = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset() + "/"
+ name + "/0_point";
QgsVectorLayer* layer = new QgsVectorLayer( uri, name, "grass" );
if ( !layer )
{
QMessageBox::warning( 0, tr( "Warning" ),
tr( "New vector created but cannot be opened by data provider." ) );
return;
}
QgsGrassEdit *ed = new QgsGrassEdit( qGisInterface, layer, true,
qGisInterface->mainWindow(), Qt::Dialog );
if ( ed->isValid() )
{
ed->show();
mCanvas->refresh();
}
else
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot start editing." ) );
delete ed;
}
#if 0
if ( !( mProvider->startEdit() ) )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector for update." ) );
return;
}
#endif
}
void QgsGrassPlugin::postRender( QPainter *painter )
{
Q_UNUSED( painter );
// We have to redraw rectangle, because canvas->mapRenderer()->destinationCrs is set after GRASS plugin constructor! This way it is redrawn also if canvas CRS has changed.
displayRegion();
// QgsDebugMsg("entered.");
}
void QgsGrassPlugin::displayRegion()
{
QgsDebugMsg( "entered" );
mRegionBand->reset();
if ( !mRegionAction->isChecked() )
{
return;
}
// Display region of current mapset if in active mode
if ( !QgsGrass::activeMode() )
{
return;
}
struct Cell_head window;
try
{
QgsGrass::region( &window );
}
catch ( QgsGrass::Exception &e )
{
QgsGrass::warning( e );
return;
}
QgsRectangle rect( QgsPoint( window.west, window.north ), QgsPoint( window.east, window.south ) );
QPen regionPen = QgsGrass::regionPen();
mRegionBand->setColor( regionPen.color() );
mRegionBand->setWidth( regionPen.width() );
QgsGrassRegionEdit::drawRegion( mCanvas, mRegionBand, rect, &mCoordinateTransform );
}
void QgsGrassPlugin::switchRegion( bool on )
{
// QgsDebugMsg("entered.");
QSettings settings;
settings.setValue( "/GRASS/region/on", on );
if ( on )
{
displayRegion();
}
else
{
mRegionBand->reset();
}
}
void QgsGrassPlugin::redrawRegion()
{
// QgsDebugMsg("entered.");
displayRegion();
}
void QgsGrassPlugin::openMapset()
{
// QgsDebugMsg("entered.");
QString element;
QgsGrassSelect *sel = new QgsGrassSelect( qGisInterface->mainWindow(), QgsGrassSelect::MAPSET );
if ( !sel->exec() )
return;
QString err = QgsGrass::openMapset( sel->gisdbase,
sel->location, sel->mapset );
if ( !err.isNull() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open the mapset. %1" ).arg( err ) );
return;
}
QgsGrass::saveMapset();
}
void QgsGrassPlugin::closeMapset()
{
QgsGrass::instance()->closeMapsetWarn();
QgsGrass::saveMapset();
}
void QgsGrassPlugin::newMapset()
{
if ( !QgsGrassNewMapset::isRunning() )
{
mNewMapset = new QgsGrassNewMapset( qGisInterface,
this, qGisInterface->mainWindow() );
}
mNewMapset->show();
mNewMapset->raise();
}
void QgsGrassPlugin::projectRead()
{
QgsDebugMsg( "entered." );
bool ok;
QString gisdbase = QgsProject::instance()->readPath(
QgsProject::instance()->readEntry(
"GRASS", "/WorkingGisdbase", "", &ok ).trimmed()
);
QString location = QgsProject::instance()->readEntry(
"GRASS", "/WorkingLocation", "", &ok ).trimmed();
QString mapset = QgsProject::instance()->readEntry(
"GRASS", "/WorkingMapset", "", &ok ).trimmed();
if ( gisdbase.isEmpty() || location.isEmpty() || mapset.isEmpty() )
{
return;
}
QgsDebugMsg( "Working mapset specified" );
QString currentPath = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset();
QString newPath = gisdbase + "/" + location + "/" + mapset;
if ( QFileInfo( currentPath ).canonicalPath() ==
QFileInfo( newPath ).canonicalPath() )
{
// The same mapset is already open
return;
}
QgsGrass::instance()->closeMapsetWarn();
QString err = QgsGrass::openMapset( gisdbase, location, mapset );
QgsGrass::saveMapset();
if ( !err.isNull() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS mapset. %1" ).arg( err ) );
return;
}
}
void QgsGrassPlugin::newProject()
{
// QgsDebugMsg("entered.");
}
// Unload the plugin by cleaning up the GUI
void QgsGrassPlugin::unload()
{
// Close mapset
QgsGrass::instance()->closeMapsetWarn();
// remove the GUI
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenMapsetAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mNewMapsetAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mCloseMapsetAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenToolsAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mRegionAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mEditAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mNewVectorAction );
delete mOpenMapsetAction;
delete mNewMapsetAction;
delete mCloseMapsetAction;
delete mOpenToolsAction;
delete mRegionAction;
delete mEditAction;
delete mNewVectorAction;
delete mToolBarPointer;
mToolBarPointer = 0;
// disconnect slots of QgsGrassPlugin so they're not fired also after unload
disconnect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
disconnect( qGisInterface, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SLOT( setEditAction() ) );
QWidget* qgis = qGisInterface->mainWindow();
disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
disconnect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
delete mTools;
mTools = 0;
}
// Set icons to the current theme
void QgsGrassPlugin::setCurrentTheme( QString theThemeName )
{
Q_UNUSED( theThemeName );
if ( mToolBarPointer )
{
mOpenMapsetAction->setIcon( getThemeIcon( "grass_open_mapset.png" ) );
mNewMapsetAction->setIcon( getThemeIcon( "grass_new_mapset.png" ) );
mCloseMapsetAction->setIcon( getThemeIcon( "grass_close_mapset.png" ) );
mOpenToolsAction->setIcon( getThemeIcon( "grass_tools.png" ) );
mRegionAction->setIcon( getThemeIcon( "grass_region.png" ) );
mEditAction->setIcon( getThemeIcon( "grass_edit.png" ) );
mNewVectorAction->setIcon( getThemeIcon( "grass_new_vector_layer.png" ) );
}
}
// Note this code is duplicated from qgisapp.cpp because
// I didnt want to make plugins dependent on qgsapplication
// and because it needs grass specific path into
// the GRASS plugin resource bundle [TS]
QIcon QgsGrassPlugin::getThemeIcon( const QString &theName )
{
QString myCurThemePath = QgsApplication::activeThemePath() + "/grass/" + theName;
QString myDefThemePath = QgsApplication::defaultThemePath() + "/grass/" + theName;
QString myQrcPath = ":/default/grass/" + theName;
if ( QFile::exists( myCurThemePath ) )
{
return QIcon( myCurThemePath );
}
else if ( QFile::exists( myDefThemePath ) )
{
return QIcon( myDefThemePath );
}
else if ( QFile::exists( myQrcPath ) )
{
return QIcon( myQrcPath );
}
else
{
return QIcon();
}
}
void QgsGrassPlugin::setTransform()
{
if ( mCrs.isValid() && mCanvas->mapSettings().destinationCrs().isValid() )
{
QgsDebugMsg( "srcCrs: " + mCrs.toWkt() );
QgsDebugMsg( "destCrs " + mCanvas->mapSettings().destinationCrs().toWkt() );
mCoordinateTransform.setSourceCrs( mCrs );
mCoordinateTransform.setDestCRS( mCanvas->mapSettings().destinationCrs() );
}
}
/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
* of the plugin class
*/
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
{
return new QgsGrassPlugin( theQgisInterfacePointer );
}
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
{
return pluginName;
}
// Return the description
QGISEXTERN QString description()
{
return pluginDescription;
}
// Return the category
QGISEXTERN QString category()
{
return pluginCategory;
}
// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return QgisPlugin::UI;
}
// Return the version number for the plugin
QGISEXTERN QString version()
{
return pluginVersion;
}
QGISEXTERN QString icon()
{
return pluginIcon;
}
// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
delete thePluginPointer;
}