void Renderer_Classified::createLegend() { int x = 0, y = 0, yIncrement = 18, width = 24, height = 12, textX = 32, textY = 11; QImage legend(170, (yIncrement*nClasses), QImage::Format_ARGB32); QPainter legendPainter(&legend); legendPainter.setPen(Qt::black); legendPainter.setCompositionMode(QPainter::CompositionMode_Source); legendPainter.fillRect(legend.rect(), Qt::transparent); int colorIndex; GDALColorEntry colorEntry; QString text, text1, text2; for (int i=0; i<nClasses; i++) { text1 = "", text2 = ""; if (classBreaks[i] >= 0.0) { text1 = " "; } if (classBreaks[i+1] >= 0.0) { text2 = " "; } text = text1 + QString::number(classBreaks[i], 'f', precision) + " to " + text2 + QString::number(classBreaks[i+1], 'f', precision); colorIndex = floor(((i*1.0) / ((nClasses-1)*1.0)) *254) + 1; colorTable->GetColorEntryAsRGB(colorIndex, &colorEntry); QColor swatchColor(colorEntry.c1, colorEntry.c2, colorEntry.c3); QRectF swatchRect(x, y, width, height); legendPainter.setBrush(swatchColor); legendPainter.drawRect(swatchRect); legendPainter.drawText(textX, textY, text); y += yIncrement; textY += yIncrement; } legend.save(legendPath); }
//---------------------------------------------------------------------------------------- // AddAllSwatches //---------------------------------------------------------------------------------------- void CZExpXMLExport_Colors::AddAllSwatches( //Color names IXMLOutStream * ioStream, const IDocument * inDoc) { LogFunctionEnterExit; if( !inDoc || !ioStream ) return; InterfacePtr<const IWorkspace> docWorkSpace( const_cast<IDocument*>(inDoc)->GetDocWorkSpace(), UseDefaultIID() ); ASSERT( docWorkSpace ); InterfacePtr<const ISwatchList> docSwatchList( docWorkSpace, UseDefaultIID() ); ASSERT( docSwatchList ); WideString elementStr( STRXMLTag_Colors ); ioStream->IndentLevel(kTrue); ioStream->Push( elementStr, kTrue ); StXMLPopper autoPopParaStyles( ioStream ); int32 colorCount = docSwatchList->GetNumSwatches(); IZPLog_Str( thisFileLA, enLT_DebugInfo, "Color Swatch Count: %d", colorCount ); Utils<IUIColorUtils> colorUtils; for( int i = 0; i < colorCount ; ++i ) { UIDRef swatchRef = docSwatchList->GetNthSwatch(i); InterfacePtr<const IColorData> swatchColor( swatchRef, UseDefaultIID() ); if( !swatchColor ) continue; ClassID theClassID = ::GetClass( swatchColor ); AddColorInfo( ioStream, swatchColor, colorUtils); } }