Exemplo n.º 1
0
// 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 );
  }
}
Exemplo n.º 2
0
/*
 * Initialize the GUI interface for the plugin
 */
void QgsGrassPlugin::initGui()
{
  toolBarPointer = 0;
  mTools = 0;
  mNewMapset = 0;
  mRegion = 0;

  QSettings settings;
  QgsGrass::init();
  mCanvas = qGisInterface->mapCanvas();
  QWidget* qgis = qGisInterface->mainWindow();

  connect( mCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), 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 );
  mNewMapsetAction = new QAction( QIcon(), tr( "New mapset" ), this );
  mCloseMapsetAction = new QAction( QIcon(), tr( "Close mapset" ), this );

  mAddVectorAction = new QAction( QIcon(), tr( "Add GRASS vector layer" ), this );
  mAddRasterAction = new QAction( QIcon(), tr( "Add GRASS raster layer" ), this );
  mOpenToolsAction = new QAction( QIcon(), tr( "Open GRASS tools" ), this );

  mRegionAction = new QAction( QIcon(), tr( "Display Current Grass Region" ), this );
  mRegionAction->setCheckable( true );

  mEditRegionAction = new QAction( QIcon(), tr( "Edit Current Grass Region" ), this );
  mEditAction = new QAction( QIcon(), tr( "Edit Grass Vector layer" ), this );
  mNewVectorAction = new QAction( QIcon(), tr( "Create new Grass Vector" ), this );

  mAddVectorAction->setWhatsThis( tr( "Adds a GRASS vector layer to the map canvas" ) );
  mAddRasterAction->setWhatsThis( tr( "Adds a GRASS raster layer to the map canvas" ) );
  mOpenToolsAction->setWhatsThis( tr( "Open GRASS tools" ) );
  mRegionAction->setWhatsThis( tr( "Displays the current GRASS region as a rectangle on the map canvas" ) );
  mEditRegionAction->setWhatsThis( tr( "Edit the current GRASS region" ) );
  mEditAction->setWhatsThis( tr( "Edit the currently selected GRASS vector layer." ) );

  // Connect the action
  connect( mAddVectorAction, SIGNAL( triggered() ), this, SLOT( addVector() ) );
  connect( mAddRasterAction, SIGNAL( triggered() ), this, SLOT( addRaster() ) );
  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( mEditRegionAction, SIGNAL( triggered() ), this, SLOT( changeRegion() ) );
  connect( mOpenMapsetAction, SIGNAL( triggered() ), this, SLOT( openMapset() ) );
  connect( mNewMapsetAction, SIGNAL( triggered() ), this, SLOT( newMapset() ) );
  connect( mCloseMapsetAction, SIGNAL( triggered() ), this, 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" ), mAddVectorAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mAddRasterAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewVectorAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mEditAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenToolsAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mRegionAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mEditRegionAction );

  // Add the toolbar to the main window
  toolBarPointer = qGisInterface->addToolBar( tr( "GRASS" ) );
  toolBarPointer->setObjectName( "GRASS" );

  // Add to the toolbar
  toolBarPointer->addAction( mOpenMapsetAction );
  toolBarPointer->addAction( mNewMapsetAction );
  toolBarPointer->addAction( mCloseMapsetAction );
  toolBarPointer->addSeparator();
  toolBarPointer->addAction( mAddVectorAction );
  toolBarPointer->addAction( mAddRasterAction );
  toolBarPointer->addAction( mNewVectorAction );
  toolBarPointer->addAction( mEditAction );
  toolBarPointer->addAction( mOpenToolsAction );
  toolBarPointer->addAction( mRegionAction );
  toolBarPointer->addAction( mEditRegionAction );

  // 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() ) );

  // Init Region symbology
  mRegionPen.setColor( QColor( settings.value( "/GRASS/region/color", "#ff0000" ).toString() ) );
  mRegionPen.setWidth( settings.value( "/GRASS/region/width", 0 ).toInt() );
  mRegionBand->setColor( mRegionPen.color() );
  mRegionBand->setWidth( mRegionPen.width() );

  mapsetChanged();
}
Exemplo n.º 3
0
/*
 * Initialize the GUI interface for the plugin
 */
void QgsGrassPlugin::initGui()
{
  if ( !QgsGrass::init() )
  {
    qGisInterface->messageBar()->pushMessage( tr( "GRASS error" ), QgsGrass::errorMessage(), QgsMessageBar::WARNING );
    // TODO: add a widget with warning
    return;
  }

  mToolBarPointer = 0;
  mTools = 0;
  mNewMapset = 0;

  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 );
}