34 , mEmbeddedInParent( false )
49 return Qt::ItemIsEnabled;
68 double itemHeight = qMax((
double ) settings.
symbolSize().height(), textHeight );
79 QIcon symbolIcon =
data( Qt::DecorationRole ).value<QIcon>();
80 if ( symbolIcon.isNull() )
92 QSizeF labelSize( 0, 0 );
99 labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * settings.
lineSpacing();
101 double labelX, labelY;
106 labelX = ctx->
point.x() + qMax((
double ) symbolSize.width(), ctx->
labelXOffset );
107 labelY = ctx->
point.y();
110 if ( labelSize.height() < symbolSize.height() )
111 labelY += symbolSize.height() / 2 + textHeight / 2;
113 labelY += textHeight;
116 for ( QStringList::Iterator itemPart = lines.begin(); itemPart != lines.end(); ++itemPart )
118 labelSize.rwidth() = qMax( settings.
textWidthMillimeters( symbolLabelFont, *itemPart ), double( labelSize.width() ) );
122 settings.
drawText( ctx->
painter, labelX, labelY, *itemPart, symbolLabelFont );
123 if ( itemPart != lines.end() )
137 , mSymbolUsesMapUnits( false )
152 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
154 return Qt::ItemIsEnabled;
160 if ( role == Qt::DisplayRole )
164 else if ( role == Qt::EditRole )
168 else if ( role == Qt::DecorationRole )
170 QSize iconSize( 16, 16 );
171 const int indentSize = 20;
172 if ( mPixmap.isNull() )
182 bool validData = mupp != 0 && dpi != 0 && scale != 0;
194 pix = QPixmap( iconSize );
195 pix.fill( Qt::transparent );
203 QPixmap pix2( pix.width() + mItem.
level() * indentSize, pix.height() );
204 pix2.fill( Qt::transparent );
206 p.drawPixmap( mItem.
level() * indentSize, 0, pix );
213 else if ( role == Qt::CheckStateRole )
242 if ( role != Qt::CheckStateRole )
280 double height = settings.
symbolSize().height();
284 double widthOffset = 0;
285 double heightOffset = 0;
295 widthOffset = ( settings.
symbolSize().width() - width ) / 2.0;
297 if ( height < settings.
symbolSize().height() )
299 heightOffset = ( settings.
symbolSize().height() - height ) / 2.0;
305 double currentXPosition = ctx->
point.x();
306 double currentYCoord = ctx->
point.y() + ( itemHeight - settings.
symbolSize().height() ) / 2;
314 opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
317 p->setRenderHint( QPainter::Antialiasing );
318 p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
319 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
324 QSize tempImageSize( width * dotsPerMM, height * dotsPerMM );
325 QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
326 tempImage.fill( Qt::transparent );
327 QPainter imagePainter( &tempImage );
332 imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
333 imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
336 p->drawImage( 0, 0, tempImage );
340 s->
drawPreviewIcon( p, QSize( width * dotsPerMM, height * dotsPerMM ), &context );
345 return QSizeF( qMax( width + 2 * widthOffset, (
double ) settings.
symbolSize().width() ),
346 qMax( height + 2 * heightOffset, (
double ) settings.
symbolSize().height() ) );
359 if ( mSymbolUsesMapUnits )
367 void QgsSymbolV2LegendNode::updateLabel()
404 if ( role == Qt::DisplayRole || role == Qt::EditRole )
406 else if ( role == Qt::DecorationRole )
423 if ( role == Qt::DecorationRole )
425 return QPixmap::fromImage( mImage );
427 else if ( role == Qt::SizeHintRole )
429 return mImage.size();
436 Q_UNUSED( itemHeight );
441 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
457 if ( role == Qt::DecorationRole )
459 QSize iconSize( 16, 16 );
460 QPixmap pix( iconSize );
464 else if ( role == Qt::DisplayRole || role == Qt::EditRole )
475 QColor itemColor = mColor;
479 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
482 ctx->
painter->setBrush( itemColor );
497 const QImage& QgsWMSLegendNode::getLegendGraphic()
const
499 if ( ! mValid && ! mFetcher )
506 if ( ! mod )
return mImage;
511 Q_ASSERT( ! mFetcher );
515 connect( mFetcher.data(), SIGNAL( finish(
const QImage& ) ),
this, SLOT( getLegendGraphicFinished(
const QImage& ) ) );
516 connect( mFetcher.data(), SIGNAL( error(
const QString& ) ),
this, SLOT( getLegendGraphicErrored(
const QString& ) ) );
517 connect( mFetcher.data(), SIGNAL( progress( qint64, qint64 ) ),
this, SLOT( getLegendGraphicProgress( qint64, qint64 ) ) );
530 if ( role == Qt::DecorationRole )
532 return QPixmap::fromImage( getLegendGraphic() );
534 else if ( role == Qt::SizeHintRole )
536 return getLegendGraphic().size();
543 Q_UNUSED( itemHeight );
549 QRectF( QPointF( 0, 0 ), mImage.size() ) );
555 QImage QgsWMSLegendNode::renderMessage(
const QString& msg )
const
557 const int fontHeight = 10;
558 const int margin = fontHeight / 2;
559 const int nlines = 1;
561 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
562 QImage theImage( w, h, QImage::Format_ARGB32_Premultiplied );
564 painter.begin( &theImage );
565 painter.setPen( QColor( 255, 0, 0 ) );
566 painter.setFont( QFont(
"Chicago", fontHeight ) );
567 painter.fillRect( 0, 0, w, h, QColor( 255, 255, 255 ) );
568 painter.drawText( 0, margin + fontHeight, msg );
575 void QgsWMSLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
577 QString msg = QString(
"Downloading... %1/%2" ).arg( cur ).arg( tot );
579 mImage = renderMessage( msg );
583 void QgsWMSLegendNode::getLegendGraphicErrored(
const QString& msg )
585 if ( ! mFetcher )
return;
587 mImage = renderMessage( msg );
599 void QgsWMSLegendNode::getLegendGraphicFinished(
const QImage& theImage )
601 if ( ! mFetcher )
return;
604 if ( ! theImage.isNull() )
606 if ( theImage != mImage )