mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Add the option to print maps as rasters
git-svn-id: http://svn.osgeo.org/qgis/trunk@10162 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
1f046b8152
commit
537a9fafc5
@ -460,7 +460,6 @@ void QgsComposer::on_mActionPrint_activated( void )
|
||||
printer.setColorMode( QPrinter::Color );
|
||||
|
||||
QPrintDialog printDialog( &printer );
|
||||
|
||||
if ( printDialog.exec() == QDialog::Accepted )
|
||||
{
|
||||
//set user-defined resolution
|
||||
@ -475,6 +474,24 @@ void QgsComposer::on_mActionPrint_activated( void )
|
||||
|
||||
QApplication::setOverrideCursor( Qt::BusyCursor );
|
||||
|
||||
if(mComposition->printAsRaster())
|
||||
{
|
||||
//print out via QImage, code copied from on_mActionExportAsImage_activated
|
||||
int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
|
||||
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
|
||||
QImage image( QSize( width, height ), QImage::Format_ARGB32 );
|
||||
image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
|
||||
image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
|
||||
image.fill( 0 );
|
||||
QPainter imagePainter( &image );
|
||||
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
|
||||
QRectF targetArea( 0, 0, width, height );
|
||||
mComposition->render( &imagePainter, targetArea, sourceArea );
|
||||
imagePainter.end();
|
||||
p.drawImage(targetArea, image, targetArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if QT_VERSION < 0x040400
|
||||
QRectF paperRect( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
|
||||
QRect pageRect = printer.pageRect();
|
||||
@ -485,8 +502,8 @@ void QgsComposer::on_mActionPrint_activated( void )
|
||||
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );
|
||||
mComposition->render( &p, paperRectPixel, paperRectMM );
|
||||
#endif
|
||||
}
|
||||
mComposition->setPlotStyle( savedPlotStyle );
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,16 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
|
||||
//read printout resolution from composition
|
||||
mResolutionLineEdit->setText( QString::number( mComposition->printResolution() ) );
|
||||
|
||||
//print as raster
|
||||
if(mComposition->printAsRaster())
|
||||
{
|
||||
mPrintAsRasterCheckBox->setCheckState(Qt::Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
mPrintAsRasterCheckBox->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
|
||||
//snap grid
|
||||
if ( mComposition->snapToGridEnabled() )
|
||||
{
|
||||
@ -367,6 +377,23 @@ void QgsCompositionWidget::on_mResolutionLineEdit_textChanged( const QString& te
|
||||
}
|
||||
}
|
||||
|
||||
void QgsCompositionWidget::on_mPrintAsRasterCheckBox_stateChanged(int state)
|
||||
{
|
||||
if(!mComposition)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(state == Qt::Checked)
|
||||
{
|
||||
mComposition->setPrintAsRaster(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
mComposition->setPrintAsRaster(false);
|
||||
}
|
||||
}
|
||||
|
||||
void QgsCompositionWidget::on_mSnapToGridCheckBox_stateChanged( int state )
|
||||
{
|
||||
if ( mComposition )
|
||||
|
@ -45,6 +45,7 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
|
||||
void on_mPaperWidthLineEdit_editingFinished();
|
||||
void on_mPaperHeightLineEdit_editingFinished();
|
||||
void on_mResolutionLineEdit_textChanged( const QString& text );
|
||||
void on_mPrintAsRasterCheckBox_stateChanged(int state);
|
||||
|
||||
void on_mSnapToGridCheckBox_stateChanged( int state );
|
||||
void on_mResolutionSpinBox_valueChanged( double d );
|
||||
|
@ -34,11 +34,18 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ): QGraphicsScene( 0
|
||||
mPaperItem->setZValue( 0 );
|
||||
mPrintResolution = 300; //hardcoded default
|
||||
loadGridAppearanceSettings();
|
||||
|
||||
//mPrintAsRaster
|
||||
QSettings s;
|
||||
mPrintAsRaster = s.value("/qgis/composerPrintAsRaster", false).toBool();
|
||||
}
|
||||
|
||||
QgsComposition::QgsComposition(): QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 )
|
||||
QgsComposition::QgsComposition(): QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster(false), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 )
|
||||
{
|
||||
saveGridAppearanceSettings();
|
||||
loadGridAppearanceSettings();
|
||||
//mPrintAsRaster
|
||||
QSettings s;
|
||||
mPrintAsRaster = s.value("/qgis/composerPrintAsRaster", false).toBool();
|
||||
}
|
||||
|
||||
QgsComposition::~QgsComposition()
|
||||
@ -697,6 +704,13 @@ void QgsComposition::setGridStyle( GridStyle s )
|
||||
saveGridAppearanceSettings();
|
||||
}
|
||||
|
||||
void QgsComposition::setPrintAsRaster(bool enabled)
|
||||
{
|
||||
mPrintAsRaster = enabled;
|
||||
QSettings s;
|
||||
s.setValue("/qgis/composerPrintAsRaster", QVariant(mPrintAsRaster));
|
||||
}
|
||||
|
||||
void QgsComposition::loadGridAppearanceSettings()
|
||||
{
|
||||
//read grid style, grid color and pen width from settings
|
||||
|
@ -99,6 +99,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
int printResolution() const {return mPrintResolution;}
|
||||
void setPrintResolution( int dpi ) {mPrintResolution = dpi;}
|
||||
|
||||
bool printAsRaster() const {return mPrintAsRaster;}
|
||||
void setPrintAsRaster(bool enabled);
|
||||
|
||||
/**Returns pointer to map renderer of qgis map canvas*/
|
||||
QgsMapRenderer* mapRenderer() {return mMapRenderer;}
|
||||
|
||||
@ -162,6 +165,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
/**Dpi for printout*/
|
||||
int mPrintResolution;
|
||||
|
||||
/**Flag if map should be printed as a raster (via QImage). False by default*/
|
||||
bool mPrintAsRaster;
|
||||
|
||||
/**Parameters for snap to grid function*/
|
||||
bool mSnapToGrid;
|
||||
double mSnapGridResolution;
|
||||
|
@ -6,7 +6,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>301</width>
|
||||
<height>735</height>
|
||||
<height>761</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
@ -276,6 +276,13 @@
|
||||
<item row="2" column="1" >
|
||||
<widget class="QLineEdit" name="mResolutionLineEdit" />
|
||||
</item>
|
||||
<item row="3" column="0" >
|
||||
<widget class="QCheckBox" name="mPrintAsRasterCheckBox" >
|
||||
<property name="text" >
|
||||
<string>Print as raster</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user