Example #1
0
void QgsMapToolLabel::currentAlignment( QString& hali, QString& vali )
{
  hali = "Left";
  vali = "Bottom";

  QgsVectorLayer* vlayer = currentLayer();
  if ( !vlayer )
  {
    return;
  }

  QgsFeature f;
  if ( !currentFeature( f ) )
  {
    return;
  }

  int haliIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Hali, vlayer );
  if ( haliIndx != -1 )
  {
    hali = f.attribute( haliIndx ).toString();
  }

  int valiIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Vali, vlayer );
  if ( valiIndx != -1 )
  {
    vali = f.attribute( valiIndx ).toString();
  }
}
Example #2
0
void QgsMapToolLabel::currentAlignment( QString& hali, QString& vali )
{
    hali = "Left";
    vali = "Bottom";

    QgsFeature f;
    if ( !currentFeature( f ) )
    {
        return;
    }
    const QgsAttributeMap& featureAttributes = f.attributeMap();

    bool settingsOk;
    QgsPalLayerSettings& labelSettings = currentLabelSettings( &settingsOk );
    if ( settingsOk )
    {
        QMap< QgsPalLayerSettings::DataDefinedProperties, int > ddProperties = labelSettings.dataDefinedProperties;

        QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator haliIter = ddProperties.find( QgsPalLayerSettings::Hali );
        if ( haliIter != ddProperties.constEnd() )
        {
            hali = featureAttributes[*haliIter].toString();
        }

        QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator valiIter = ddProperties.find( QgsPalLayerSettings::Vali );
        if ( valiIter != ddProperties.constEnd() )
        {
            vali = featureAttributes[*valiIter].toString();
        }
    }
}
Example #3
0
void QgsMapToolLabel::createRubberBands()
{
  delete mLabelRubberBand;
  delete mFeatureRubberBand;

  //label rubber band
  QgsRectangle rect = mCurrentLabel.pos.labelRect;
  mLabelRubberBand = new QgsRubberBand( mCanvas, QgsWkbTypes::LineGeometry );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
  mLabelRubberBand->setColor( QColor( 0, 255, 0, 65 ) );
  mLabelRubberBand->setWidth( 3 );
  mLabelRubberBand->show();

  //feature rubber band
  QgsVectorLayer* vlayer = mCurrentLabel.layer;
  if ( vlayer )
  {
    QgsFeature f;
    if ( currentFeature( f, true ) )
    {
      QgsGeometry geom = f.geometry();
      if ( !geom.isEmpty() )
      {
        QSettings settings;
        int r = settings.value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt();
        int g = settings.value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt();
        int b = settings.value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt();
        int a = settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt();
        mFeatureRubberBand = new QgsRubberBand( mCanvas, geom.type() );
        mFeatureRubberBand->setColor( QColor( r, g, b, a ) );
        mFeatureRubberBand->setToGeometry( geom, vlayer );
        mFeatureRubberBand->show();
      }
    }

    //fixpoint rubber band
    QgsPoint fixPoint;
    if ( currentLabelRotationPoint( fixPoint, false, false ) )
    {
      if ( mCanvas )
      {
        const QgsMapSettings& s = mCanvas->mapSettings();
        if ( s.hasCrsTransformEnabled() )
        {
          fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint );
        }
      }

      QgsGeometry pointGeom = QgsGeometry::fromPoint( fixPoint );
      mFixPointRubberBand = new QgsRubberBand( mCanvas, QgsWkbTypes::LineGeometry );
      mFixPointRubberBand->setColor( QColor( 0, 0, 255, 65 ) );
      mFixPointRubberBand->setToGeometry( pointGeom, vlayer );
      mFixPointRubberBand->show();
    }
  }
}
Example #4
0
void QgsMapToolLabel::createRubberBands( )
{
  delete mLabelRubberBand;
  delete mFeatureRubberBand;

  //label rubber band
  QgsRectangle rect = mCurrentLabelPos.labelRect;
  mLabelRubberBand = new QgsRubberBand( mCanvas, QGis::Line );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) );
  mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
  mLabelRubberBand->setColor( QColor( 0, 255, 0, 65 ) );
  mLabelRubberBand->setWidth( 3 );
  mLabelRubberBand->show();

  //feature rubber band
  QgsVectorLayer* vlayer = currentLayer();
  if ( vlayer )
  {
    QgsFeature f;
    if ( currentFeature( f, true ) )
    {
      QgsGeometry* geom = f.geometry();
      if ( geom )
      {
        mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() );
        mFeatureRubberBand->setColor( QColor( 255, 0, 0, 65 ) );
        mFeatureRubberBand->setToGeometry( geom, vlayer );
        mFeatureRubberBand->show();
      }
    }

    //fixpoint rubber band
    QgsPoint fixPoint;
    if ( rotationPoint( fixPoint, false, false ) )
    {
      if ( mCanvas )
      {
        const QgsMapSettings& s = mCanvas->mapSettings();
        if ( s.hasCrsTransformEnabled() )
        {
          fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint );
        }
      }

      QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint );
      mFixPointRubberBand = new QgsRubberBand( mCanvas, QGis::Line );
      mFixPointRubberBand->setColor( QColor( 0, 0, 255, 65 ) );
      mFixPointRubberBand->setToGeometry( pointGeom, vlayer );
      mFixPointRubberBand->show();
      delete pointGeom;
    }
  }
}
Example #5
0
void QgsMapToolLabel::createRubberBands( )
{
    delete mLabelRubberBand;
    delete mFeatureRubberBand;

    //label rubber band
    QgsRectangle rect = mCurrentLabelPos.labelRect;
    mLabelRubberBand = new QgsRubberBand( mCanvas, false );
    mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
    mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) );
    mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) );
    mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) );
    mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
    mLabelRubberBand->setColor( Qt::green );
    mLabelRubberBand->setWidth( 3 );
    mLabelRubberBand->show();

    //feature rubber band
    QgsVectorLayer* vlayer = currentLayer();
    if ( vlayer )
    {
        QgsFeature f;
        if ( currentFeature( f, true ) )
        {
            QgsGeometry* geom = f.geometry();
            if ( geom )
            {
                mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() == QGis::Polygon );
                mFeatureRubberBand->setColor( Qt::red );
                mFeatureRubberBand->setToGeometry( geom, vlayer );
                mFeatureRubberBand->show();
            }
        }

        //fixpoint rubber band
        QgsPoint fixPoint;
        if ( rotationPoint( fixPoint ) )
        {
            if ( mCanvas )
            {
                QgsMapRenderer* r = mCanvas->mapRenderer();
                if ( r && r->hasCrsTransformEnabled() )
                {
                    fixPoint = r->mapToLayerCoordinates( vlayer, fixPoint );
                }
            }

            QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint );
            mFixPointRubberBand = new QgsRubberBand( mCanvas, false );
            mFixPointRubberBand->setColor( Qt::blue );
            mFixPointRubberBand->setToGeometry( pointGeom, vlayer );
            mFixPointRubberBand->show();
            delete pointGeom;
        }
    }
}