⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgsgrassplugin.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  }  mEditAction->setEnabled(false);  QgsGrassEdit *ed = new QgsGrassEdit( qGisInterface, qGisInterface->activeLayer(), false,    qGisInterface->getMainWindow(), Qt::WType_Dialog );  if ( ed->isValid() ) {    ed->show();    mCanvas->refresh();    connect(ed, SIGNAL(finished()), this, SLOT(setEditAction()));  } else {    delete ed;    mEditAction->setEnabled(true);  }}void QgsGrassPlugin::setEditAction(){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::setEditAction()" << std::endl;#endif  QgsMapLayer *layer = (QgsMapLayer *) qGisInterface->activeLayer();  if ( QgsGrassEdit::isEditable(layer) )  {    mEditAction->setEnabled(true);  }  else  {    mEditAction->setEnabled(false);  }}void QgsGrassPlugin::newVector(){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::newVector()" << std::endl;#endif  if ( QgsGrassEdit::isRunning() ) {    QMessageBox::warning( 0, tr("Warning"), tr("GRASS Edit is already running." ) );    return;  }  bool ok;  QString name;  QgsGrassElementDialog dialog;  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() );  QgsGrass::resetError();  struct Map_info Map;  Vect_open_new ( &Map, (char *) name.ascii(), 0);  if ( QgsGrass::getError() == QgsGrass::FATAL )   {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot create new vector: ")      + QgsGrass::getErrorMessage() );    return;  }  Vect_build ( &Map, stderr );  Vect_set_release_support ( &Map );  Vect_close ( &Map );  // 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->getMainWindow(), Qt::WType_Dialog );  if ( ed->isValid() ) {    ed->show();    mCanvas->refresh();  } else {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot start editing." ) );    delete ed;  }  /*  if ( !(mProvider->startEdit()) ) {  QMessageBox::warning( 0, tr("Warning"), tr("Cannot open vector for update.") );  return;  }  */}void QgsGrassPlugin::postRender(QPainter *painter){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::postRender()" << std::endl;#endif}void QgsGrassPlugin::displayRegion(){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::displayRegion()" << std::endl;#endif  mRegionBand->reset();  // Display region of current mapset if in active mode  if ( !QgsGrass::activeMode() ) return;  QString gisdbase = QgsGrass::getDefaultGisdbase();  QString location = QgsGrass::getDefaultLocation();  QString mapset   = QgsGrass::getDefaultMapset();  if ( gisdbase.isEmpty() || location.isEmpty() || mapset.isEmpty() ) {    QMessageBox::warning( 0, tr("Warning"), tr("GISDBASE, LOCATION_NAME or MAPSET is not set, "      "cannot display current region.") );    return;  }  QgsGrass::setLocation ( gisdbase, location );  struct Cell_head window;  char *err = G__get_window ( &window, (char *)"", (char *)"WIND", (char *) mapset.latin1() );  if ( err ) {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot read current region: ") + QString(err) );    return;  }  std::vector<QgsPoint> points;  points.resize(5);  points[0].setX(window.west); points[0].setY(window.south);  points[1].setX(window.east); points[1].setY(window.south);  points[2].setX(window.east); points[2].setY(window.north);  points[3].setX(window.west); points[3].setY(window.north);  points[4].setX(window.west); points[4].setY(window.south);  for ( int i = 0; i < 5; i++ )   {    mRegionBand->addPoint( points[i] );      }}void QgsGrassPlugin::switchRegion(bool on){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::switchRegion()" << std::endl;#endif  QSettings settings;  settings.writeEntry ("/GRASS/region/on", on );  if ( on ) {    displayRegion();  } else {    mRegionBand->reset();  }}void QgsGrassPlugin::redrawRegion(){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::redrawRegion()" << std::endl;#endif  if ( mRegionAction->isOn() )  {    displayRegion();  }}void QgsGrassPlugin::changeRegion(void){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::changeRegion()" << std::endl;#endif  if ( mRegion ) { // running    mRegion->show();    return;   }  // Warning: don't use Qt::WType_Dialog, it would ignore restorePosition  mRegion = new QgsGrassRegion(this, qGisInterface, qGisInterface->getMainWindow(), Qt::Window );  connect ( mRegion, SIGNAL(destroyed(QObject *)), this, SLOT( regionClosed() ));  mRegion->show();}void QgsGrassPlugin::regionClosed() {  mRegion = 0;}QPen & QgsGrassPlugin::regionPen(){  return mRegionPen;}void QgsGrassPlugin::setRegionPen(QPen & pen){  mRegionPen = pen;  mRegionBand->setColor ( mRegionPen.color() );  mRegionBand->setWidth ( mRegionPen.width() );  QSettings settings;  settings.writeEntry ("/GRASS/region/color", mRegionPen.color().name() );  settings.writeEntry ("/GRASS/region/width", (int) mRegionPen.width() );}void QgsGrassPlugin::openMapset(){#ifdef QGISDEBUG  std::cerr << "QgsGrassPlugin::openMapset()" << std::endl;#endif  QString element;  QgsGrassSelect *sel = new QgsGrassSelect( 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. ") + err );    return;  }  saveMapset();  mapsetChanged();}void QgsGrassPlugin::closeMapset(){#ifdef QGISDEBUG  std::cerr << "QgsGrassPlugin::closeMapset()" << std::endl;#endif  QString err = QgsGrass::closeMapset ();  if ( !err.isNull() )  {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot close mapset. ") + err );    return;  }  saveMapset();  mapsetChanged();}void QgsGrassPlugin::newMapset(){  if ( !QgsGrassNewMapset::isRunning() )  {    mNewMapset = new QgsGrassNewMapset ( qGisInterface,       this, qGisInterface->getMainWindow() );  }  mNewMapset->show();  mNewMapset->raise();}void QgsGrassPlugin::projectRead(){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::projectRead" << std::endl;#endif  bool ok;  QString gisdbase = 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.length() == 0 || location.length() == 0 ||    mapset.length() == 0 )  {        // Mapset not specified    return;  }  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;  }  QString err = QgsGrass::closeMapset ();  if ( !err.isNull() )  {    QMessageBox::warning( 0, tr("Warning"),       tr("Cannot close current mapset. ") + err );    return;  }  mapsetChanged();  err = QgsGrass::openMapset ( gisdbase, location, mapset );  if ( !err.isNull() )  {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot open GRASS mapset. ") + err );    return;  }  mapsetChanged();}void QgsGrassPlugin::newProject(){#ifdef QGISDEBUG  std::cout << "QgsGrassPlugin::newProject" << std::endl;#endif}// Unload the plugin by cleaning up the GUIvoid QgsGrassPlugin::unload(){  // Close mapset  QString err = QgsGrass::closeMapset();  // remove the GUI  qGisInterface->removePluginMenu(tr("&GRASS"), mOpenMapsetAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mNewMapsetAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mCloseMapsetAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mAddVectorAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mAddRasterAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mOpenToolsAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mRegionAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mEditRegionAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mEditAction);  qGisInterface->removePluginMenu(tr("&GRASS"), mNewVectorAction);  delete mOpenMapsetAction;  delete mNewMapsetAction;  delete mCloseMapsetAction;  delete mAddVectorAction;  delete mAddRasterAction;  delete mOpenToolsAction;  delete mRegionAction;  delete mEditRegionAction;  delete mEditAction;  delete mNewVectorAction;  if ( toolBarPointer )    delete toolBarPointer;  // 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->getMainWindow();  disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead()));  disconnect( qgis, SIGNAL( newProject() ), this, SLOT(newProject()));}/**  * 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 classQGISEXTERN 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 QObject::tr("GRASS");}// Return the descriptionQGISEXTERN QString description(){  return QObject::tr("GRASS layer");}// Return the type (either UI or MapLayer plugin)QGISEXTERN int type(){  return QgisPlugin::UI;}// Return the version number for the pluginQGISEXTERN QString version(){  return pluginVersion;}// Delete ourselfQGISEXTERN void unload(QgisPlugin * thePluginPointer){  delete thePluginPointer;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -