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

📄 qgsgrassedit.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  }}void QgsGrassEdit::addAttributes ( int field, int cat ){  QString *key = mProvider->key ( field );  QString lab;  lab.sprintf ( "%d:%d", field, cat );  int tab = mAttributes->addTab( lab );  mAttributes->setField ( tab, field );  QString catLabel;  if ( key->isEmpty() ) {    catLabel = "Category";  } else {    catLabel = *key;  }  mAttributes->setCat ( tab, catLabel, cat );  if ( !key->isEmpty() ) { // Database link defined     std::vector<QgsField> *cols = mProvider->columns ( field );    if ( cols->size() == 0 ) {      QString str;      str.setNum( field );      QMessageBox::warning( 0, tr("Warning"), tr("Cannot describe table for field ") + str );    } else {      QgsAttributeMap *atts = mProvider->attributes ( field, cat );      if ( atts->size() == 0 ) { // cannot select attributes        mAttributes->addTextRow ( tab, "WARNING: ATTRIBUTES MISSING" );      } else {        int size;        if ( atts->size() < (int) cols->size() )          size = atts->size();        else          size = cols->size();        for ( unsigned int j = 0; j < cols->size(); j++ ) {          QgsField col = (*cols)[j];          QVariant att = (*atts)[j];          std::cerr << " name = " << col.name().toLocal8Bit().data() <<  std::endl;          if ( col.name() != *key ) {            std::cerr << " value = " << att.toString().toLocal8Bit().data() <<  std::endl;            mAttributes->addAttribute ( tab, col.name(), att.toString(), col.typeName() );          }        }      }      delete atts;    }    delete cols;  }}void QgsGrassEdit::addCat ( int line ){  int mode = mCatModeBox->currentItem();  int field = mFieldBox->currentText().toInt();  int cat = mCatEntry->text().toInt();  int type = mProvider->readLine ( mPoints, mCats, line );  if ( mode == CAT_MODE_NEXT || mode == CAT_MODE_MANUAL ) {    Vect_cat_set ( mCats, field, cat );  }  line = mProvider->rewriteLine ( line, type, mPoints, mCats );  mSelectedLine = line;  if ( mAttributes ) mAttributes->setLine ( line );  updateSymb();  increaseMaxCat();  // 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->size() == 0 ) { // Nothing selected      QString *error = mProvider->insertAttributes ( field, cat );      if ( !error->isEmpty() ) {        QMessageBox::warning( 0, tr("Warning"), *error );      }      delete error;    }    delete atts;  }  addAttributes( field, cat );}void QgsGrassEdit::deleteCat ( int line, int field, int cat ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::deleteCat" << std::endl;#endif  int type = mProvider->readLine ( mPoints, mCats, line );  Vect_field_cat_del ( mCats, field, cat );  line = mProvider->rewriteLine ( line, type, mPoints, mCats );  mSelectedLine = line;  if ( mAttributes ) mAttributes->setLine ( line );  // Check orphan record  checkOrphan ( field, cat );  updateSymb();}void QgsGrassEdit::postRender(QPainter *){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::postRender" << std::endl;#endif  // Warning: it seems that this slot can be called even   //          after disconnect (is it a queue?)   //          -> check mValid  if ( !mValid ) return;  displayMap();  // Redisplay highlighted  if ( mSelectedLine ) {    displayElement ( mSelectedLine, mSymb[SYMB_HIGHLIGHT], mSize );  }}void QgsGrassEdit::displayMap (){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayMap" << std::endl;#endif  mTransform = mCanvas->getCoordinateTransform();  // re-create pixmap - it's transparent by default  *mPixmap = QPixmap(mCanvas->size());  mPixmap->fill(QColor(0,0,0,0));  QPainter *painter = new QPainter();  painter->begin(mPixmap);  // Display lines  int nlines = mProvider->numLines();   QPen pen;  // TODO?: 2 loops, first lines, then points  for ( int line = 1; line <= nlines; line++ ) {    displayElement ( line, mSymb[mLineSymb[line]], mSize, painter );  }  // Display nodes  int nnodes = mProvider->numNodes();   pen.setColor(QColor(255,0,0));  if ( mSymbDisplay[SYMB_NODE_1] || mSymbDisplay[SYMB_NODE_2] ) {    for ( int node = 1; node <= nnodes; node++ ) {      if ( mNodeSymb[node] == SYMB_NODE_0 ) continue; // do not display nodes with points only      displayNode ( node, mSymb[mNodeSymb[node]], mSize, painter );     }  }  painter->end();  delete painter;  // porting mCanvas->update();  mCanvasEdit->update();  mRubberBandIcon->update();  mRubberBandLine->update();}void QgsGrassEdit::displayUpdated (void){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayUpdated" << std::endl;#endif  mTransform = mCanvas->getCoordinateTransform();  mProjectionEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);  QPainter *painter = new QPainter();  painter->begin(mPixmap);  // Display lines  int nlines = mProvider->numUpdatedLines();  for ( int i = 0; i < nlines; i++ ) {    int line = mProvider->updatedLine(i);    if ( !(mProvider->lineAlive(line)) ) continue;    displayElement ( line, mSymb[mLineSymb[line]], mSize, painter );  }  // Display nodes  int nnodes = mProvider->numUpdatedNodes();   for ( int i = 0; i < nnodes; i++ ) {    int node = mProvider->updatedNode(i);    if ( !(mProvider->nodeAlive(node)) ) continue;    if ( mNodeSymb[node] == SYMB_NODE_0 ) continue; // do not display nodes with points only    displayNode ( node, mSymb[mNodeSymb[node]], mSize, painter );   }  painter->end();  delete painter;  // porting mCanvas->update();  mCanvasEdit->update();  mRubberBandIcon->update();  mRubberBandLine->update();}void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPainter *painter){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayElement() line = " << line << std::endl;#endif  // is it a valid line?  if (line == 0)    return;  if ( !mSymbDisplay[mLineSymb[line]] ) return;  int type = mProvider->readLine ( mPoints, NULL, line );  if ( type < 0 ) return;  QPainter *myPainter;  if ( !painter ) {    myPainter = new QPainter();    myPainter->begin(mPixmap);  } else {    myPainter = painter;  }  if ( type & GV_POINTS ) {    displayIcon ( mPoints->x[0], mPoints->y[0], pen, QgsVertexMarker::ICON_CROSS, size, myPainter );  } else { // line    QgsPoint point;    Q3PointArray pointArray(mPoints->n_points);    for ( int i = 0; i < mPoints->n_points; i++ ) {      point.setX(mPoints->x[i]);      point.setY(mPoints->y[i]);      point = transformLayerToCanvas ( point );      pointArray.setPoint( i, static_cast<int>(round(point.x())),         static_cast<int>(round(point.y())) );     }    myPainter->setPen ( pen );    myPainter->drawPolyline ( pointArray );  }  if ( !painter ) {    myPainter->end();    // porting mCanvas->update();    mCanvasEdit->update();    delete myPainter;  }}void QgsGrassEdit::eraseElement ( int line ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::eraseElement() line = " << line << std::endl;#endif  int type = mProvider->readLine ( NULL, NULL, line );  if ( type < 0 ) return;  // Erase line  displayElement ( line, mSymb[SYMB_BACKGROUND], mSize );  // Erase nodes  if ( type & GV_LINES ) {    int node1, node2;    mProvider->lineNodes( line, &node1, &node2 );    double x, y;    mProvider->nodeCoor( node1, &x, &y );    displayIcon ( x, y, mSymb[SYMB_BACKGROUND], QgsVertexMarker::ICON_X, mSize );    mProvider->nodeCoor( node2, &x, &y );    displayIcon ( x, y, mSymb[SYMB_BACKGROUND], QgsVertexMarker::ICON_X, mSize );  }}void QgsGrassEdit::eraseDynamic ( void ){  displayDynamic ( 0, 0.0, 0.0, QgsVertexMarker::ICON_NONE, 0 );}void QgsGrassEdit::displayDynamic ( struct line_pnts *Points ){  displayDynamic ( Points, 0.0, 0.0, QgsVertexMarker::ICON_NONE, 0 );}void QgsGrassEdit::displayDynamic ( double x, double y, int type, int size ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayDynamic icon" << std::endl;#endif  displayDynamic ( 0, x, y, type, size );}void QgsGrassEdit::displayDynamic ( struct line_pnts *Points, double x, double y, int type, int size ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayDynamic Points = " << Points << " type = " << type  << std::endl;#endif  QgsPoint point;  //mTransform = mCanvas->getCoordinateTransform();  // Dynamic points are in layer coordinate system, we have to   // reproject them to current coordinate system if necessary  mRubberBandLine->reset();  if ( Points )  {    for ( int i = 0; i < Points->n_points; i++ )     {      point.setX(Points->x[i]);      point.setY(Points->y[i]);      point = transformLayerToMap ( point );      mRubberBandLine->addPoint(point, false); // false = don't update now    }    // Now add the last point again and force update of rubberband.    // This should improve the performance as canvas is updated only once    // and not with every added point to rubberband.    mRubberBandLine->addPoint(point, true);  }  mRubberBandIcon->setIconType(type);  mRubberBandIcon->setIconSize(size);  point = transformLayerToMap (QgsPoint(x,y) );  mRubberBandIcon->setCenter(point);}void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter *painter ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayNode() node = " << node << std::endl;#endif  if ( !mSymbDisplay[mNodeSymb[node]] ) return;  double x, y;  if ( !(mProvider->nodeCoor(node,&x,&y )) ) return;  displayIcon ( x, y, pen, QgsVertexMarker::ICON_X, size, painter );}QgsPoint QgsGrassEdit::transformLayerToCanvas ( QgsPoint point){  point = mCanvas->mapRender()->layerCoordsToOutputCoords(mLayer, point);  return mTransform->transform(point);}QgsPoint QgsGrassEdit::transformLayerToMap ( QgsPoint point){  return mCanvas->mapRender()->layerCoordsToOutputCoords(mLayer, point);}void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,                                 int type, int size, QPainter *painter ){#ifdef QGISDEBUG  std::cerr << "QgsGrassEdit::displayIcon()" << std::endl;#endif  QgsPoint point;  Q3PointArray pointArray(2);  point.setX(x);  point.setY(y);  point = transformLayerToCanvas ( point );  int px = static_cast<int>(round(point.x()));  int py = static_cast<int>(round(point.y()));  int m = (size-1)/2;  QPainter *myPainter;  if ( !painter ) {    myPainter = new QPainter();    myPainter->begin(mPixmap);  } else {    myPainter = painter;  }  myPainter->setPen ( pen );  switch ( type ) {    case QgsVertexMarker::ICON_CROSS :      pointArray.setPoint( 0, px-m, py );       pointArray.setPoint( 1, px+m, py );       myPainter->drawPolyline ( pointArray );      pointArray.setPoint( 0, px, py+m );       pointArray.setPoint( 1, px, py-m );       myPainter->drawPolyline ( pointArray );      break;    case QgsVertexMarker::ICON_X :      pointArray.setPoint( 0, px-m, py+m );       pointArray.setPoint( 1, px+m, py-m );       myPainter->drawPolyline ( pointArray );      pointArray.setPoint( 0, px-m, py-m );       pointArray.setPoint( 1, px+m, py+m );       myPainter->drawPolyline ( pointArray );      break;    case QgsVertexMarker::ICON_BOX :      pointArray.resize(5);      pointArray.setPoint( 0, px-m, py-m );       pointArray.setPoint( 1, px+m, py-m );       pointArray.setPoint( 2, px+m, py+m );       pointArray.setPoint( 3, px-m, py+m );       pointArray.setPoint( 4, px-m, py-m );       myPainter->drawPolyline ( pointArray );      break;  }  if ( !painter ) {    myPainter->end();    //mCanvas->update();    mCanvasEdit->update();    delete myPainter;  }}void QgsGrassEdit::setCanvasPropmt( QString left, QString mid, QString right){  std::cerr << "QgsGrassEdit::setCanvasPropmt" << std::endl;  mCanvasPrompt = "";  if ( left.length() > 0 ) mCanvasPrompt.append ( tr("Left: ") + left + "   " );  if ( mid.length() > 0 ) mCanvasPrompt.append ( tr("Middle: ") + mid + "   " );  if ( right.length() > 0 ) mCanvasPrompt.append ( tr("Right: ") + right );}void QgsGrassEdit::attributesClosed(){    mAttributes = 0;}

⌨️ 快捷键说明

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