コード例 #1
0
ファイル: qgsrendererv2.cpp プロジェクト: Zakui/QGIS
QgsLegendSymbolListV2 QgsFeatureRendererV2::legendSymbolItemsV2() const
{
  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
  QgsLegendSymbolListV2 lst2;
  int i = 0;
  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
  {
    lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
  }
  return lst2;
}
コード例 #2
0
void QgsSizeScaleWidget::updatePreview()
{
  if ( !mSymbol || !mLayer )
    return;

  QScopedPointer<QgsScaleExpression> expr( createExpression() );
  QList<double> breaks = QgsSymbolLayerV2Utils::prettyBreaks( expr->minValue(), expr->maxValue(), 4 );

  treeView->setIconSize( QSize( 512, 512 ) );
  mPreviewList.clear();
  int widthMax = 0;
  for ( int i = 0; i < breaks.length(); i++ )
  {
    QScopedPointer< QgsMarkerSymbolV2 > symbol( dynamic_cast<QgsMarkerSymbolV2*>( mSymbol->clone() ) );
    symbol->setDataDefinedSize( QgsDataDefined() );
    symbol->setDataDefinedAngle( QgsDataDefined() ); // to avoid symbol not beeing drawn
    symbol->setSize( expr->size( breaks[i] ) );
    QgsSymbolV2LegendNode node( mLayerTreeLayer, QgsLegendSymbolItemV2( symbol.data(), QString::number( i ), 0 ) );
    const QSize sz( node.minimumIconSize() );
    node.setIconSize( sz );
    QScopedPointer< QStandardItem > item( new QStandardItem( node.data( Qt::DecorationRole ).value<QPixmap>(), QString::number( breaks[i] ) ) );
    widthMax = qMax( sz.width(), widthMax );
    mPreviewList.appendRow( item.take() );
  }

  // center icon and align text left by giving icons the same width
  // @todo maybe add some space so that icons don't touch
  for ( int i = 0; i < breaks.length(); i++ )
  {
    QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
    QPixmap enlarged( widthMax, img.height() );
    // fill transparent and add original image
    enlarged.fill( Qt::transparent );
    QPainter p( &enlarged );
    p.drawPixmap( QPoint(( widthMax - img.width() ) / 2, 0 ), img );
    p.end();
    mPreviewList.item( i )->setIcon( enlarged );
  }
}
コード例 #3
0
QgsLegendSymbolListV2 QgsSingleSymbolRendererV2::legendSymbolItemsV2() const
{
  QgsLegendSymbolListV2 lst;
  lst << QgsLegendSymbolItemV2( mSymbol.data(), QString(), 0 );
  return lst;
}