void QgsUniqueValueDialog::apply() { QgsDebugMsg( "called." ); QgsUniqueValueRenderer *renderer = new QgsUniqueValueRenderer( mVectorLayer->geometryType() ); //go through mValues and add the entries to the renderer for ( QMap<QString, QgsSymbol*>::iterator it = mValues.begin(); it != mValues.end(); ++it ) { QgsSymbol* symbol = it.value(); QgsSymbol* newsymbol = new QgsSymbol( mVectorLayer->geometryType(), symbol->lowerValue(), symbol->upperValue(), symbol->label() ); newsymbol->setPen( symbol->pen() ); newsymbol->setCustomTexture( symbol->customTexture() ); newsymbol->setBrush( symbol->brush() ); newsymbol->setNamedPointSymbol( symbol->pointSymbolName() ); newsymbol->setPointSize( symbol->pointSize() ); newsymbol->setPointSizeUnits( symbol->pointSizeUnits() ); newsymbol->setScaleClassificationField( symbol->scaleClassificationField() ); newsymbol->setRotationClassificationField( symbol->rotationClassificationField() ); renderer->insertValue( it.key(), newsymbol ); } renderer->updateSymbolAttributes(); QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>( mVectorLayer->dataProvider() ); if ( provider ) { int fieldIndex = mClassificationComboBox->itemData( mClassificationComboBox->currentIndex() ).toInt(); if ( fieldIndex != -1 ) { renderer->setClassificationField( fieldIndex ); mVectorLayer->setRenderer( renderer ); return; } } delete renderer; //something went wrong }
QgsUniqueValueDialog::QgsUniqueValueDialog( QgsVectorLayer* vl ): QDialog(), mVectorLayer( vl ), sydialog( vl, true ) { setupUi( this ); setOrientation( Qt::Vertical ); //find out the fields of mVectorLayer if ( mVectorLayer ) { //we cannot use unique values for not-commited fields because QgsVectorLayer has no 'unique values' method... QgsVectorDataProvider* provider = mVectorLayer->dataProvider(); if ( provider ) { const QgsFieldMap & fields = provider->fields(); QString str; for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it ) { str = ( *it ).name(); str = mVectorLayer->attributeDisplayName( it.key() ); mClassificationComboBox->addItem( str, it.key() ); } } } mClassListWidget->setSelectionMode( QAbstractItemView::ExtendedSelection ); mClassListWidget->setEditTriggers( QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed ); mClassListWidget->setSortingEnabled( true ); if ( mVectorLayer ) { const QgsUniqueValueRenderer* renderer = dynamic_cast<const QgsUniqueValueRenderer *>( mVectorLayer->renderer() ); if ( renderer ) { mClassListWidget->clear(); QString field = mVectorLayer->attributeDisplayName( renderer->classificationField() ); mOldClassificationAttribute = field; mClassificationComboBox->setCurrentIndex( mClassificationComboBox->findText( field ) ); const QList<QgsSymbol*> list = renderer->symbols(); //fill the items of the renderer into mValues for ( QList<QgsSymbol*>::const_iterator iter = list.begin(); iter != list.end(); ++iter ) { QgsSymbol* symbol = *iter; QString symbolvalue = symbol->lowerValue(); QgsSymbol* sym = new QgsSymbol( mVectorLayer->geometryType(), symbol->lowerValue(), symbol->upperValue(), symbol->label() ); sym->setPen( symbol->pen() ); sym->setCustomTexture( symbol->customTexture() ); sym->setBrush( symbol->brush() ); sym->setNamedPointSymbol( symbol->pointSymbolName() ); sym->setPointSize( symbol->pointSize() ); sym->setPointSizeUnits( symbol->pointSizeUnits() ); sym->setScaleClassificationField( symbol->scaleClassificationField() ); sym->setRotationClassificationField( symbol->rotationClassificationField() ); mValues.insert( symbolvalue, sym ); QListWidgetItem *item = new QListWidgetItem( symbolvalue ); mClassListWidget->addItem( item ); updateEntryIcon( symbol, item ); item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); item->setData( Qt::UserRole, symbol->lowerValue() ); item->setToolTip( symbol->label() ); } } } mDeletePushButton->setEnabled( false ); connect( mClassifyButton, SIGNAL( clicked() ), this, SLOT( changeClassificationAttribute() ) ); connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addClass() ) ); connect( mDeletePushButton, SIGNAL( clicked() ), this, SLOT( deleteSelectedClasses() ) ); connect( mRandomizeColors, SIGNAL( clicked() ), this, SLOT( randomizeColors() ) ); connect( mResetColors, SIGNAL( clicked() ), this, SLOT( resetColors() ) ); connect( mClassListWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) ); connect( mCommonPropertyLock, SIGNAL( clicked() ), this, SLOT( selectionChanged() ) ); connect( mClassListWidget, SIGNAL( itemChanged( QListWidgetItem * ) ), this, SLOT( itemChanged( QListWidgetItem * ) ) ); connect( &sydialog, SIGNAL( settingsChanged() ), this, SLOT( applySymbologyChanges() ) ); mSymbolWidgetStack->addWidget( &sydialog ); mSymbolWidgetStack->setCurrentWidget( &sydialog ); }
void QgsQuickPrint::printMap() { if ( mOutputFileName.isEmpty() ) { return; } if ( mpMapRenderer == NULL ) { return; } //ensure the user never omitted the extension from the file name if ( !mOutputFileName.toUpper().endsWith( ".PDF" ) ) { mOutputFileName += ".pdf"; } // Initialising the printer this way lets us find out what // the screen resolution is which we store and then // reset the resolution of the printer after that... QPrinter myPrinter( QPrinter::ScreenResolution ); // Try to force the printer resolution to 300dpi // to get past platform specific defaults in printer // resolution... // int myPrintResolutionDpi = 300; myPrinter.setResolution( myPrintResolutionDpi ); myPrinter.setOutputFormat( QPrinter::PdfFormat ); QgsDebugMsg( QString( "Printing to page size %1" ).arg( pageSizeToString( mPageSize ) ) ); myPrinter.setPageSize( mPageSize ); myPrinter.setOutputFileName( mOutputFileName ); myPrinter.setOrientation( QPrinter::Landscape ); myPrinter.setDocName( "quickprint Report" ); QPainter myPrintPainter( &myPrinter ); myPrintPainter.setPen( Qt::gray ); myPrintPainter.setBrush( Qt::white ); // This is what we are aiming for: // a // +-(1)------ Acme Maps (2) --------------------------------------+ // |b 12/01/2007 (3) | // | Earthquakes (4) | // | +--(5)--------------------------------------------------------+ | // | |c | | // | | +-(6)---------------------------------------+ +~(7)~~~~~~+ | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | | | | | | | // | | +-------------------------------------------+ +~~~~~~~~~~+ | | // | | | | // | +-------------------------------------------------------------+ | // | | // | +-(8)-----+ +-(9-)----+ +-(10)----+ /|\ | // | | | |Copyright| | | / | \ | // | | | | 2008 | | | |(11) | // | +---------+ +---------+ +---------+ | // | +~(12)~~~~~~+ | // +-----------------------------------------------------------------+ // // 1) PageBorder 8) Logo1 // 2) PageTitle 9) CopyrightText // 3) MapDate 10) Logo2 // 4) MapTitle 11) NorthArrow // 5) MapFrame 12) ScaleBar // 6) MapPixmap // 7) LegendPixmap // a OriginXY // b HorizontalSpacing // c VerticalSpacing // // Note: Different operating systems will use different // page resolutions for QPrinter::HighResolution so I'm // working all coordinates out as percentages of page // size so that we can hopefully get comarable print // results on all platforms. // // // Note #2: Im defining all measurements here as my plan // is to later support templates with different page // layouts and paper sizes etc. // //set the top left origin for the print layout int myOriginX = myPrinter.pageRect().left(); int myOriginY = myPrinter.pageRect().top(); int myDrawableWidth = myPrinter.pageRect().width() - myOriginX; int myDrawableHeight = myPrinter.pageRect().height() - myOriginY; //define the spacing between layout elements int myHorizontalSpacing = myDrawableWidth / 100; // 1% int myVerticalSpacing = myDrawableHeight / 100; // 1% //define the proportions for the page layout int myMapWidthPercent = 65; int myMapHeightPercent = 71; int myLegendWidthPercent = 25; int myLegendHeightPercent = 65; int myLogoWidthPercent = 23; int myLogoHeightPercent = 17; // // Remember the size and dpi of the maprender // so we can restore it properly // int myOriginalDpi = mpMapRenderer->outputDpi(); //sensible default to prevent divide by zero if ( 0 == myOriginalDpi ) myOriginalDpi = 96; QSize myOriginalSize = mpMapRenderer->outputSize(); //define the font sizes and family int myMapTitleFontSize = 24; int myMapDateFontSize = 16; int myMapNameFontSize = 32; int myLegendFontSize = 12; #ifdef Q_OS_LINUX//this sucks... myLegendFontSize -= 2; #endif #ifdef WIN32 //this sucks too... myMapTitleFontSize /= 2; myMapDateFontSize /= 2; myMapNameFontSize /= 2; myLegendFontSize /= 2; #endif QString myFontFamily = "Arial"; // // Draw the PageBorder // myPrintPainter.drawRect( myOriginX, myOriginY, myDrawableWidth, myDrawableHeight ); // // Draw the PageTitle // QFont myTitleFont( myFontFamily, myMapTitleFontSize ); myPrintPainter.setFont( myTitleFont ); QFontMetrics myTitleMetrics( myTitleFont, &myPrinter ); int myPageTitleHeight = myTitleMetrics.height(); int myPageTitleWidth = myTitleMetrics.width( mTitleText ); myOriginX += myHorizontalSpacing; myOriginY -= ( myPageTitleHeight / 2 ); QRect myPageTitleRect( myOriginX, myOriginY, myPageTitleWidth, myPageTitleHeight ); // make sure the title goes onto a white background myPrintPainter.setPen( Qt::white ); myPrintPainter.drawRect( myPageTitleRect ); myPrintPainter.setPen( Qt::black ); myPrintPainter.drawText( myPageTitleRect, Qt::AlignCenter, mTitleText ); // // Draw the MapDate // QFont myDateFont( myFontFamily, myMapDateFontSize ); QString myDateText( QDate::currentDate().toString( Qt::LocalDate ) ); myPrintPainter.setFont( myDateFont ); QFontMetrics myDateMetrics( myDateFont, &myPrinter ); int myDateHeight = myDateMetrics.height(); //int myDateWidth = myDateMetrics.width(myDateText); myOriginX += myHorizontalSpacing; myOriginY += myPageTitleHeight + myVerticalSpacing ; QRect myDateRect( myOriginX, myOriginY, myPageTitleWidth, //use same width as page title for centering myDateHeight ); // make sure the title goes onto a white background myPrintPainter.setPen( Qt::white ); myPrintPainter.drawRect( myDateRect ); myPrintPainter.setPen( Qt::black ); myPrintPainter.drawText( myDateRect, Qt::AlignCenter, myDateText ); // // Draw the MapName // QFont myNameFont( myFontFamily, myMapNameFontSize ); myPrintPainter.setFont( myNameFont ); QFontMetrics myNameMetrics( myNameFont, &myPrinter ); int myNameHeight = myNameMetrics.height(); int myNameWidth = myNameMetrics.width( mNameText ); myOriginX = myPrinter.pageRect().left() + myDrawableWidth / 2; //page center myOriginX -= myNameWidth / 2; myOriginY = myPrinter.pageRect().top() + ( myPageTitleHeight / 2 ) + myVerticalSpacing ; QRect myNameRect( myOriginX, myOriginY, myNameWidth, myNameHeight ); // make sure the title goes onto a white background myPrintPainter.setPen( Qt::white ); myPrintPainter.drawRect( myNameRect ); myPrintPainter.setPen( Qt::black ); myPrintPainter.drawText( myNameRect, Qt::AlignCenter, mNameText ); // // Draw the MapFrame (top) // int myMapFrameWidth = myDrawableWidth ; myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; myOriginY += myNameHeight + myVerticalSpacing; QLine myMapFrameTopLine( myOriginX, myOriginY, myMapFrameWidth, myOriginY ); myPrintPainter.setPen( Qt::black ); myPrintPainter.drawLine( myMapFrameTopLine ); // Draw the map onto a pixmap // @TODO: we need to save teh extent of the screen map and // then set them again for the print map so that the map scales // properly in the print int myMapDimensionX = ( myDrawableWidth / 100 ) * myMapHeightPercent; int myMapDimensionY = ( myDrawableHeight / 100 ) * myMapWidthPercent; QImage myMapImage( QSize( myMapDimensionX, myMapDimensionY ), QImage::Format_ARGB32 ); myMapImage.setDotsPerMeterX(( double )( myPrinter.logicalDpiX() ) / 25.4 * 1000.0 ); myMapImage.setDotsPerMeterY(( double )( myPrinter.logicalDpiY() ) / 25.4 * 1000.0 ); myMapImage.fill( 0 ); QPainter myMapPainter; myMapPainter.begin( &myMapImage ); // Now resize for print mpMapRenderer->setOutputSize( QSize( myMapDimensionX, myMapDimensionY ), ( myPrinter.logicalDpiX() + myPrinter.logicalDpiY() ) / 2 ); mpMapRenderer->render( &myMapPainter ); myMapPainter.end(); //draw the map pixmap onto our pdf print device myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; myOriginY += myVerticalSpacing * 2; myPrintPainter.drawImage( myOriginX, myOriginY, myMapImage ); // // Draw the legend // QFont myLegendFont( myFontFamily, myLegendFontSize ); //myPrintPainter.setFont(myLegendFont); int myLegendDimensionX = ( myDrawableWidth / 100 ) * myLegendWidthPercent; int myLegendDimensionY = ( myDrawableHeight / 100 ) * myLegendHeightPercent; // Create a viewport to make coordinate conversions easier // The viewport has the same dimensions as the page(otherwise items // drawn into it will appear squashed), but a different origin. QRect myOriginalViewport = myPrintPainter.viewport(); //for restoring later myOriginX += myMapDimensionX + myHorizontalSpacing; myPrintPainter.setViewport( myOriginX, myOriginY, myOriginalViewport.width(), myOriginalViewport.height() ); //draw a rectangale around the legend frame //@TODO make this user settable if ( 0 == 1 ) //put some real logic here { myPrintPainter.drawRect( 0, 0, myLegendDimensionX, myLegendDimensionY ); } //get font metric and other vars needed QFontMetrics myLegendFontMetrics( myLegendFont, &myPrinter ); int myLegendFontHeight = myLegendFontMetrics.height(); int myLegendXPos = 0; int myLegendYPos = 0; int myLegendSpacer = myLegendFontHeight / 2; //for vertical and horizontal spacing int myLegendVerticalSpacer = myLegendFontHeight / 3; //for vertical between rows int myIconWidth = myLegendFontHeight; myPrintPainter.setFont( myLegendFont ); QStringList myLayerSet = mpMapRenderer->layerSet(); QStringListIterator myLayerIterator( myLayerSet ); //second clause below is to prevent legend spilling out the bottom while ( myLayerIterator.hasNext() && myLegendYPos < myLegendDimensionY ) { QString myLayerId = myLayerIterator.next(); QgsMapLayer * mypLayer = QgsMapLayerRegistry::instance()->mapLayer( myLayerId ); if ( mypLayer ) { QgsVectorLayer *mypVectorLayer = qobject_cast<QgsVectorLayer *>( mypLayer ); // TODO: add support for symbology-ng renderers if ( mypVectorLayer && mypVectorLayer->renderer() ) { QString myLayerName = mypVectorLayer->name(); QIcon myIcon; QPixmap myPixmap( QSize( myIconWidth, myIconWidth ) ); //square //based on code from qgslegendlayer.cpp - see that file for more info const QgsRenderer* mypRenderer = mypVectorLayer->renderer(); const QList<QgsSymbol*> mySymbolList = mypRenderer->symbols(); // // Single symbol // double widthScale = ( myPrinter.logicalDpiX() + myPrinter.logicalDpiY() ) / 2.0 / 25.4; if ( 1 == mySymbolList.size() ) { QgsSymbol * mypSymbol = mySymbolList.at( 0 ); myPrintPainter.setPen( mypSymbol->pen() ); myPrintPainter.setBrush( mypSymbol->brush() ); myLegendXPos = 0 ; if ( mypSymbol->type() == QGis::Point ) { QImage myImage; myImage = mypSymbol->getPointSymbolAsImage( widthScale ); myPrintPainter.drawImage( myLegendXPos, myLegendYPos, myImage ); } else if ( mypSymbol->type() == QGis::Line ) { myPrintPainter.drawLine( myLegendXPos, myLegendYPos, myLegendXPos + myIconWidth, myLegendYPos + myIconWidth ); } else //polygon { myPrintPainter.drawRect( myLegendXPos, myLegendYPos, myIconWidth, myIconWidth ); } myLegendXPos += myIconWidth + myLegendSpacer; myPrintPainter.setPen( Qt::black ); QStringList myWrappedLayerNameList = wordWrap( myLayerName, myLegendFontMetrics, myLegendDimensionX - myIconWidth ); // // Loop through wrapped legend label lines // QStringListIterator myLineWrapIterator( myWrappedLayerNameList ); while ( myLineWrapIterator.hasNext() ) { QString myLine = myLineWrapIterator.next(); QRect myLegendItemRect( myLegendXPos, myLegendYPos, myLegendDimensionX - myIconWidth, myLegendFontHeight ); myPrintPainter.drawText( myLegendItemRect, Qt::AlignLeft, myLine ); myLegendYPos += myLegendVerticalSpacer + myLegendFontHeight; } } else //class breaks { // draw in the layer name first, after we loop for the class breaks QStringList myWrappedLayerNameList = wordWrap( myLayerName, myLegendFontMetrics, myLegendDimensionX - myIconWidth ); // Check the wrapped layer name wont overrun the space we have // for the legend ... int myLabelHeight = myLegendFontHeight * myWrappedLayerNameList.count(); if ( myLegendYPos + myLabelHeight > myLegendDimensionY ) { continue; } // // Loop through wrapped legend label lines // QStringListIterator myLineWrapIterator( myWrappedLayerNameList ); while ( myLineWrapIterator.hasNext() ) { QString myLine = myLineWrapIterator.next(); myLegendXPos = myIconWidth; QRect myLegendItemRect( myLegendXPos, myLegendYPos, myLegendFontMetrics.width( myLine ), myLegendFontHeight ); myPrintPainter.setPen( Qt::black ); myPrintPainter.drawText( myLegendItemRect, Qt::AlignLeft, myLine ); myLegendYPos += myLegendVerticalSpacer + myLegendFontHeight; } // // Loop through the class breaks // QListIterator<QgsSymbol *> myIterator( mySymbolList ); while ( myIterator.hasNext() && myLegendYPos < myLegendDimensionY ) { QgsSymbol * mypSymbol = myIterator.next(); myPrintPainter.setPen( mypSymbol->pen() ); myPrintPainter.setBrush( mypSymbol->brush() ); myLegendXPos = myLegendSpacer * 3; //extra indent for class breaks if ( mypSymbol->type() == QGis::Point ) { QImage myImage; myImage = mypSymbol->getPointSymbolAsImage( widthScale ); myPrintPainter.drawImage( myLegendXPos, myLegendYPos, myImage ); } else if ( mypSymbol->type() == QGis::Line ) { myPrintPainter.drawLine( myLegendXPos, myLegendYPos, myLegendXPos + myIconWidth, myLegendYPos + myIconWidth ); } else //polygon { myPrintPainter.drawRect( myLegendXPos, myLegendYPos, myIconWidth, myIconWidth ); } // // Now work out the class break label // QString myLabel; QString myLower = mypSymbol->lowerValue(); if ( !myLower.isEmpty() ) { myLabel = myLower; } QString myUpper = mypSymbol->upperValue(); if ( !myUpper.isEmpty() ) { myLabel += " - "; myLabel += myUpper; } QString myText = mypSymbol->label(); if ( !myText.isEmpty() ) { myLabel += " "; myLabel += myText; } myLabel = myLabel.trimmed(); myLegendXPos += myIconWidth + myLegendSpacer; myPrintPainter.setPen( Qt::black ); QStringList myWrappedLayerNameList = wordWrap( myLabel, myLegendFontMetrics, myLegendDimensionX - myLegendXPos ); // // Loop through wrapped legend label lines // QStringListIterator myLineWrapIterator( myWrappedLayerNameList ); while ( myLineWrapIterator.hasNext() ) { QString myLine = myLineWrapIterator.next(); // check if the text will overflow the space we have QRect myLegendItemRect( myLegendXPos, myLegendYPos, myLegendDimensionX - myIconWidth, myLegendFontHeight ); myPrintPainter.drawText( myLegendItemRect, Qt::AlignLeft, myLine ); myLegendYPos += myLegendVerticalSpacer + myLegendFontHeight; } //wordwrap loop } //symbol loop } //class breaks } //if vectorlayer } //if maplayer } //layer iterator //reinstate the viewport myPrintPainter.setViewport( myOriginalViewport ); // // Draw the MapFrame (bottom) // myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; myOriginY += myMapDimensionY + ( myVerticalSpacing * 2 ); QLine myMapFrameBottomLine( myOriginX, myOriginY, myMapFrameWidth, myOriginY ); myPrintPainter.setPen( Qt::black ); myPrintPainter.drawLine( myMapFrameBottomLine ); // // Draw logo 1 // int myLogoXDim = ( myDrawableWidth / 100 ) * myLogoWidthPercent; int myLogoYDim = ( myDrawableHeight / 100 ) * myLogoHeightPercent; QPixmap myLogo1; QgsDebugMsg( QString( "Logo1: %1" ).arg( mLogo1File ) ); myLogo1.fill( Qt::white ); myLogo1.load( mLogo1File ); myLogo1 = myLogo1.scaled( myLogoXDim, myLogoYDim, Qt::KeepAspectRatio ); myOriginX = myPrinter.pageRect().left() + myHorizontalSpacing; myOriginY += myVerticalSpacing ; myPrintPainter.drawPixmap( myOriginX, myOriginY, myLogo1 ); // // Draw Copyright Text // myOriginX += myHorizontalSpacing + myLogoXDim; QRect myCopyrightRect( myOriginX, myOriginY, myLogoXDim, myLogoYDim ); myPrintPainter.setPen( Qt::black ); QFont myCopyrightFont( myFontFamily, myMapDateFontSize ); myPrintPainter.setFont( myCopyrightFont ); //myPrintPainter.drawRect( myCopyrightRect ); myPrintPainter.drawText( myCopyrightRect, Qt::AlignCenter | Qt::TextWordWrap, mCopyrightText ); // // Draw logo 2 // QPixmap myLogo2; myLogo2.fill( Qt::white ); myLogo2.load( mLogo2File ); myLogo2 = myLogo2.scaled( myLogoXDim, myLogoYDim, Qt::KeepAspectRatio ); myOriginX += myHorizontalSpacing + myLogoXDim; myPrintPainter.drawPixmap( myOriginX, myOriginY, myLogo2 ); // // Draw the north arrow // myOriginX += myHorizontalSpacing + myLogoXDim; // use half the available space for the n.arrow // and the rest for the scale bar (see below) QPixmap myNorthArrow( myLogoYDim / 2, myLogoYDim / 2 ); myNorthArrow.fill( Qt::white ); QPainter myNorthPainter( &myNorthArrow ); QSvgRenderer mySvgRenderer( mNorthArrowFile ); mySvgRenderer.render( &myNorthPainter ); myPrintPainter.drawPixmap( myOriginX + (( myLogoXDim / 2 ) ), myOriginY, myNorthArrow ); // // Draw the scale bar // myOriginY += myLogoYDim / 2 + myVerticalSpacing; myPrintPainter.setViewport( myOriginX, myOriginY, myOriginalViewport.width(), myOriginalViewport.height() ); renderPrintScaleBar( &myPrintPainter, mpMapRenderer, myLogoXDim ); myPrintPainter.setViewport( myOriginalViewport ); // // Finish up // myPrintPainter.end(); #if 0 mProgressDialog.setValue( 0 ); mProgressDialog.setLabelText( tr( "Please wait while your report is generated", "COMMENTED OUT" ) ); mProgressDialog.show(); mProgressDialog.setWindowModality( Qt::WindowModal ); mProgressDialog.setAutoClose( true ); #endif // // Restore the map render to its former glory // mpMapRenderer->setOutputSize( myOriginalSize, myOriginalDpi ); }
void QgsUniqueValueRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected, double opacity ) { QPainter *p = renderContext.painter(); QgsSymbol* symbol = symbolForFeature( &f ); if ( !symbol ) //no matching symbol { if ( img && mGeometryType == QGis::Point ) { img->fill( 0 ); } else if ( mGeometryType != QGis::Point ) { p->setPen( Qt::NoPen ); p->setBrush( Qt::NoBrush ); } return; } // Point if ( img && mGeometryType == QGis::Point ) { double fieldScale = 1.0; double rotation = 0.0; if ( symbol->scaleClassificationField() >= 0 ) { //first find out the value for the scale classification attribute fieldScale = sqrt( qAbs( f.attribute( symbol->scaleClassificationField() ).toDouble() ) ); } if ( symbol->rotationClassificationField() >= 0 ) { rotation = f.attribute( symbol->rotationClassificationField() ).toDouble(); } QString oldName; if ( symbol->symbolField() >= 0 ) { QString name = f.attribute( symbol->symbolField() ).toString(); oldName = symbol->pointSymbolName(); symbol->setNamedPointSymbol( name ); } double scale = renderContext.scaleFactor(); if ( symbol->pointSizeUnits() ) { scale = 1.0 / renderContext.mapToPixel().mapUnitsPerPixel(); } *img = symbol->getPointSymbolAsImage( scale, selected, mSelectionColor, fieldScale, rotation, renderContext.rasterScaleFactor(), opacity ); if ( !oldName.isNull() ) { symbol->setNamedPointSymbol( oldName ); } } // Line, polygon else if ( mGeometryType != QGis::Point ) { if ( !selected ) { QPen pen = symbol->pen(); pen.setWidthF( renderContext.scaleFactor() * pen.widthF() ); p->setPen( pen ); if ( mGeometryType == QGis::Polygon ) { QBrush brush = symbol->brush(); scaleBrush( brush, renderContext.rasterScaleFactor() ); //scale brush content for printout p->setBrush( brush ); } } else { QPen pen = symbol->pen(); pen.setWidthF( renderContext.scaleFactor() * pen.widthF() ); if ( mGeometryType == QGis::Polygon ) { QBrush brush = symbol->brush(); scaleBrush( brush, renderContext.rasterScaleFactor() ); //scale brush content for printout brush.setColor( mSelectionColor ); p->setBrush( brush ); } else //don't draw outlines of polygons in selection color otherwise they appear merged { pen.setColor( mSelectionColor ); } p->setPen( pen ); } } }
void QgsGraduatedSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QImage* img, bool selected, double widthScale, double rasterScaleFactor ) { QgsSymbol* theSymbol = symbolForFeature( &f ); if ( !theSymbol ) { if ( img && mGeometryType == QGis::Point ) { img->fill( 0 ); } else if ( mGeometryType != QGis::Point ) { p->setPen( Qt::NoPen ); p->setBrush( Qt::NoBrush ); } return; } //set the qpen and qpainter to the right values // Point if ( img && mGeometryType == QGis::Point ) { double fieldScale = 1.0; double rotation = 0.0; if ( theSymbol->scaleClassificationField() >= 0 ) { //first find out the value for the scale classification attribute const QgsAttributeMap& attrs = f.attributeMap(); fieldScale = sqrt( fabs( attrs[theSymbol->scaleClassificationField()].toDouble() ) ); QgsDebugMsg( QString( "Feature has field scale factor %1" ).arg( fieldScale ) ); } if ( theSymbol->rotationClassificationField() >= 0 ) { const QgsAttributeMap& attrs = f.attributeMap(); rotation = attrs[theSymbol->rotationClassificationField()].toDouble(); QgsDebugMsg( QString( "Feature has rotation factor %1" ).arg( rotation ) ); } *img = theSymbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor, fieldScale, rotation, rasterScaleFactor ); } // Line, polygon if ( mGeometryType != QGis::Point ) { if ( !selected ) { QPen pen = theSymbol->pen(); pen.setWidthF( widthScale * pen.widthF() ); p->setPen( pen ); if ( mGeometryType == QGis::Polygon ) { QBrush brush = theSymbol->brush(); scaleBrush( brush, rasterScaleFactor ); //scale brush content for printout p->setBrush( brush ); } } else { QPen pen = theSymbol->pen(); pen.setWidthF( widthScale * pen.widthF() ); if ( mGeometryType == QGis::Polygon ) { QBrush brush = theSymbol->brush(); scaleBrush( brush, rasterScaleFactor ); //scale brush content for printout brush.setColor( mSelectionColor ); p->setBrush( brush ); } else //dont draw outlines in selection colour for polys otherwise they appear merged { pen.setColor( mSelectionColor ); } p->setPen( pen ); } } }
void QgsGraduatedSymbolRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected, double opacity ) { QPainter *p = renderContext.painter(); QgsSymbol* theSymbol = symbolForFeature( &f ); if ( !theSymbol ) { if ( img && mGeometryType == QGis::Point ) { img->fill( 0 ); } else if ( mGeometryType != QGis::Point ) { p->setPen( Qt::NoPen ); p->setBrush( Qt::NoBrush ); } return; } //set the qpen and qpainter to the right values // Point if ( img && mGeometryType == QGis::Point ) { double fieldScale = 1.0; double rotation = 0.0; if ( theSymbol->scaleClassificationField() >= 0 ) { //first find out the value for the scale classification attribute const QgsAttributeMap& attrs = f.attributeMap(); fieldScale = sqrt( qAbs( attrs[theSymbol->scaleClassificationField()].toDouble() ) ); QgsDebugMsgLevel( QString( "Feature has field scale factor %1" ).arg( fieldScale ), 3 ); } if ( theSymbol->rotationClassificationField() >= 0 ) { const QgsAttributeMap& attrs = f.attributeMap(); rotation = attrs[theSymbol->rotationClassificationField()].toDouble(); QgsDebugMsgLevel( QString( "Feature has rotation factor %1" ).arg( rotation ), 3 ); } QString oldName; if ( theSymbol->symbolField() >= 0 ) { const QgsAttributeMap& attrs = f.attributeMap(); QString name = attrs[theSymbol->symbolField()].toString(); QgsDebugMsgLevel( QString( "Feature has name %1" ).arg( name ), 3 ); oldName = theSymbol->pointSymbolName(); theSymbol->setNamedPointSymbol( name ); } double scale = renderContext.scaleFactor(); if ( theSymbol->pointSizeUnits() ) { scale = 1.0 / renderContext.mapToPixel().mapUnitsPerPixel(); } *img = theSymbol->getPointSymbolAsImage( scale, selected, mSelectionColor, fieldScale, rotation, renderContext.rasterScaleFactor(), opacity ); if ( !oldName.isNull() ) { theSymbol->setNamedPointSymbol( oldName ); } } // Line, polygon if ( mGeometryType != QGis::Point ) { if ( !selected ) { QPen pen = theSymbol->pen(); pen.setWidthF( renderContext.scaleFactor() * pen.widthF() ); p->setPen( pen ); if ( mGeometryType == QGis::Polygon ) { QBrush brush = theSymbol->brush(); scaleBrush( brush, renderContext.rasterScaleFactor() ); //scale brush content for printout p->setBrush( brush ); } } else { QPen pen = theSymbol->pen(); pen.setWidthF( renderContext.scaleFactor() * pen.widthF() ); if ( mGeometryType == QGis::Polygon ) { QBrush brush = theSymbol->brush(); scaleBrush( brush, renderContext.rasterScaleFactor() ); //scale brush content for printout brush.setColor( mSelectionColor ); p->setBrush( brush ); } else //don't draw outlines in selection color for polys otherwise they appear merged { pen.setColor( mSelectionColor ); } p->setPen( pen ); } } }