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

📄 qgsgrassedit.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
void QgsGrassEdit::closeEdit(void){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::close()" << std::endl;#endif  // Disconnect signals  // Warning: it seems that slots (postRender) can be called even   //          after disconnect (is it a queue?)   disconnect( this, SLOT(postRender(QPainter *)));  mValid = false; // important for postRender  if ( mAttributes ) {    delete mAttributes;  }  mProvider->closeEdit(mNewMap);  hide();  // Add new layers  if ( mNewMap )  {    QString uri = QDir::cleanDirPath ( mProvider->dataSourceUri() );    std::cerr << "uri = " << uri.ascii() << std::endl;    // Note: QDir::cleanPath is using '/' also on Windows    //QChar sep = QDir::separator();    QChar sep = '/';    QStringList split = QStringList::split ( sep, uri );    split.pop_back(); // layer    QString map = split.last();    split.pop_back(); // map    QString mapset = split.last();    QgsGrassUtils::addVectorLayers ( mIface, QgsGrass::getDefaultGisdbase(),       QgsGrass::getDefaultLocation(),      mapset, map );  }  emit finished();  delete this; }void QgsGrassEdit::closeEvent(QCloseEvent *e){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::closeEvent()" << std::endl;#endif  e->accept();  closeEdit();}void QgsGrassEdit::catModeChanged ( void ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::catModeChanged()" << std::endl;#endif  int mode = mCatModeBox->currentItem();  int field = mFieldBox->currentText().toInt();  if ( mode == CAT_MODE_NEXT ) { // Find next not used    QString c = "1"; // Default for new field    for (unsigned int i = 0; i < mMaxCats.size(); i++ ) {      if ( mMaxCats[i].field == field ) {        c.sprintf("%d", mMaxCats[i].maxCat+1);        break;      }    }    mCatEntry->setText ( c );    mCatEntry->setEnabled(false);    mFieldBox->setDisabled(false);  } else if ( mode == CAT_MODE_MANUAL ) {    mCatEntry->setEnabled(true);    mFieldBox->setDisabled(false);  } else { // CAT_MODE_NOCAT    mCatEntry->clear ();    mCatEntry->setEnabled(false);    mFieldBox->setDisabled(true);  }}void QgsGrassEdit::fieldChanged ( void ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::fieldChanged()" << std::endl;#endif  int mode = mCatModeBox->currentItem();  int field = mFieldBox->currentText().toInt();  if ( mode == CAT_MODE_NEXT ) { // Find next not used    QString c = "1"; // Default for new field    for (unsigned int i = 0; i < mMaxCats.size(); i++ ) {      if ( mMaxCats[i].field == field ) {        c.sprintf("%d", mMaxCats[i].maxCat+1);        break;      }    }    mCatEntry->setText ( c );  }}int QgsGrassEdit::writeLine ( int type, struct line_pnts *Points ){  int mode = mCatModeBox->currentItem();  int field = mFieldBox->currentText().toInt();  int cat = mCatEntry->text().toInt();  Vect_reset_cats ( mCats );  if ( mode == CAT_MODE_NEXT || mode == CAT_MODE_MANUAL ) {    Vect_cat_set ( mCats, field, cat );    // Insert new DB record if link is defined and the record for this cat does not exist    QString *key = mProvider->key ( field );    if ( !key->isEmpty() ) { // Database link defined       QgsAttributeMap *atts = mProvider->attributes ( field, cat );      if ( atts->count() == 0 ) { // Nothing selected        QString *error = mProvider->insertAttributes ( field, cat );        if ( !error->isEmpty() ) {          QMessageBox::warning( 0, tr("Warning"), *error );        }        delete error;      }      delete atts;    }  }  Vect_line_prune ( Points );  int line = mProvider->writeLine ( type, Points, mCats );  increaseMaxCat();  return line;}void QgsGrassEdit::increaseMaxCat ( void ){  int mode = mCatModeBox->currentItem();  int field = mFieldBox->currentText().toInt();  int cat = mCatEntry->text().toInt();  if ( mode == CAT_MODE_NEXT || mode == CAT_MODE_MANUAL ) {    int found = 0;    for (unsigned int i = 0; i < mMaxCats.size(); i++ ) {      if ( mMaxCats[i].field == field ) {        if ( cat > mMaxCats[i].maxCat ) {          mMaxCats[i].maxCat = cat;        }        found = 1;        break;      }    }    if ( !found ) {       MaxCat mc;      mc.field = field;      mc.maxCat = cat;      mMaxCats.push_back(mc);    }    if ( mode == CAT_MODE_NEXT ) {       QString c;       c.sprintf("%d", cat+1);      mCatEntry->setText ( c );    }  }}double QgsGrassEdit::threshold ( void ){  int snapPixels = mSnapPixels->text().toInt();  // Convert to map units (not nice)  QgsPoint p1, p2;  p1 = mTransform->toMapCoordinates(0, 0 );   p2 = mTransform->toMapCoordinates(snapPixels, 0);   if ( mProjectionEnabled )   {    try    {      p1 = mCanvas->mapRender()->outputCoordsToLayerCoords(mLayer, p1);      p2 = mCanvas->mapRender()->outputCoordsToLayerCoords(mLayer, p2);    }    catch(QgsCsException& cse)    {      UNUSED(cse);      //error    }  }  double dx = p2.x() - p1.x();  double dy = p2.y() - p1.y();  double thresh = sqrt ( dx*dx + dy*dy );  return thresh;}void QgsGrassEdit::snap (  double *x, double *y ){  double thresh = threshold();  int node = mProvider->findNode ( *x, *y, thresh );  if ( node > 0 ) {    mProvider->nodeCoor ( node, x, y );  }}void QgsGrassEdit::snap (  QgsPoint & point ){  double x = point.x();  double y = point.y();  snap ( &x, &y );  point.setX(x);  point.setY(y);}void QgsGrassEdit::snap (  QgsPoint & point, double startX, double startY ){  double x = point.x();  double y = point.y();  double thresh = threshold();  // Start  double startDist = hypot ( x-startX, y-startY);  bool startIn = false;  if ( startDist <= thresh ) startIn = true;  // Nearest node  double nodeX = 0;  double  nodeY = 0;       double nodeDist = 0;  bool nodeIn = false;  int node = mProvider->findNode ( x, y, thresh );  if ( node > 0 )   {    mProvider->nodeCoor ( node, &nodeX, &nodeY );    nodeDist = hypot ( x-nodeX, y-nodeY);    nodeIn = true;  }  // Choose  if ( (startIn && !nodeIn) || (startIn && nodeIn && startDist < nodeDist)  )   {    x = startX; y = startY;  }  else if ( (!startIn && nodeIn) || (startIn && nodeIn && startDist > nodeDist) )   {    x = nodeX; y = nodeY;  }   point.setX(x);  point.setY(y);}void QgsGrassEdit::newPoint(void){  startTool(QgsGrassEdit::NEW_POINT);}void QgsGrassEdit::newLine(void){   std::cerr << "QgsGrassEdit::newLine" << std::endl;  startTool(QgsGrassEdit::NEW_LINE); }void QgsGrassEdit::newBoundary(void){   std::cerr << "QgsGrassEdit::newBoundary" << std::endl;  startTool(QgsGrassEdit::NEW_BOUNDARY); }void QgsGrassEdit::newCentroid(void){  startTool(QgsGrassEdit::NEW_CENTROID);}void QgsGrassEdit::moveVertex(void){  startTool(QgsGrassEdit::MOVE_VERTEX);}void QgsGrassEdit::addVertex(void){  startTool(QgsGrassEdit::ADD_VERTEX);}void QgsGrassEdit::deleteVertex(void){  startTool(QgsGrassEdit::DELETE_VERTEX);}void QgsGrassEdit::splitLine(void){  startTool(QgsGrassEdit::SPLIT_LINE);}void QgsGrassEdit::moveLine(void){  startTool(QgsGrassEdit::MOVE_LINE);}void QgsGrassEdit::deleteLine(void){  startTool(QgsGrassEdit::DELETE_LINE);}void QgsGrassEdit::editCats(void){  startTool(QgsGrassEdit::EDIT_CATS);}void QgsGrassEdit::editAttributes(void){  startTool(QgsGrassEdit::EDIT_ATTRIBUTES);}void QgsGrassEdit::startTool(int tool){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::startTool() tool = " << tool << std::endl;#endif  // Delete last dynamic drawing from canvas  eraseDynamic();  if ( mSelectedLine > 0 )    displayElement ( mSelectedLine, mSymb[mLineSymb[mSelectedLine]], mSize );  // close old tool  if (mMapTool)  {    delete mMapTool;    mMapTool = NULL;  }  // All necessary data were written -> reset mEditPoints etc.  Vect_reset_line ( mEditPoints );  mSelectedLine = 0;  // TODO: mTool != NEW_LINE is a hack for lines until more buttons can be recieved  if ( mAttributes && mTool != QgsGrassEdit::NEW_LINE && mTool != QgsGrassEdit::NEW_BOUNDARY ) {    delete mAttributes;    mAttributes = 0;  }  // Start new tool  mTool = tool;  switch (mTool)  {  case NEW_POINT:    mMapTool = new QgsGrassEditNewPoint(this, false);    mMapTool->setAction(mNewPointAction);    break;  case NEW_CENTROID:    mMapTool = new QgsGrassEditNewPoint(this, true);    mMapTool->setAction(mNewCentroidAction);    break;  case NEW_LINE:    mMapTool = new QgsGrassEditNewLine(this, false);    mMapTool->setAction(mNewLineAction);    break;  case NEW_BOUNDARY:    mMapTool = new QgsGrassEditNewLine(this, true);    mMapTool->setAction(mNewBoundaryAction);    break;  case MOVE_VERTEX:    mMapTool = new QgsGrassEditMoveVertex(this);    mMapTool->setAction(mMoveVertexAction);    break;  case ADD_VERTEX:    mMapTool = new QgsGrassEditAddVertex(this);    mMapTool->setAction(mAddVertexAction);    break;  case DELETE_VERTEX:    mMapTool = new QgsGrassEditDeleteVertex(this);    mMapTool->setAction(mDeleteVertexAction);    break;  case MOVE_LINE:    mMapTool = new QgsGrassEditMoveLine(this);    mMapTool->setAction(mMoveLineAction);    break;  case DELETE_LINE:    mMapTool = new QgsGrassEditDeleteLine(this);    mMapTool->setAction(mDeleteLineAction);    break;  case SPLIT_LINE:    mMapTool = new QgsGrassEditSplitLine(this);    mMapTool->setAction(mSplitLineAction);    break;  case EDIT_ATTRIBUTES:    mMapTool = new QgsGrassEditAttributes(this);    mMapTool->setAction(mEditAttributesAction);    break;  case EDIT_CATS:    mTool = NONE;    QMessageBox::warning( 0, tr("Warning"), tr("Tool not yet implemented.") );    break;  default:    std::cerr << "Unknown tool" << std::endl;    break;  }  // assign newly created tool to map canvas  mCanvas->setMapTool(mMapTool);}void QgsGrassEdit::checkOrphan ( int field, int cat ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::checkOrphan field = " << field    << " cat = " << cat << std::endl;#endif  int orphan;  QString *error = mProvider->isOrphan ( field, cat, &orphan );  if ( !error->isEmpty() ) {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot check orphan record: ")      + *error );    return;  }  if ( !orphan ) return;  QMessageBox::StandardButton ret = QMessageBox::question ( 0, tr("Warning"),     tr("Orphan record was left in attribute table. "    "<br>Delete the record?"),      QMessageBox::Ok | QMessageBox::Cancel );  if ( ret == QMessageBox::Cancel ) return;  // Delete record  error = mProvider->deleteAttributes ( field, cat );  if ( !error->isEmpty() ) {    QMessageBox::warning( 0, tr("Warning"), tr("Cannot delete orphan record: ")      + *error );    return;

⌨️ 快捷键说明

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