Skip to content
Permalink
Browse files

Fix for paint event problems in case of multiple composer maps

git-svn-id: http://svn.osgeo.org/qgis/trunk@14761 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 25, 2010
1 parent 72b2ed4 commit 41e47e2ad4ef967a59a03ed0b7b23fc8fe864d70
Showing with 48 additions and 18 deletions.
  1. +26 −17 src/app/composer/qgscomposer.cpp
  2. +15 −1 src/gui/qgscomposerview.cpp
  3. +7 −0 src/gui/qgscomposerview.h
@@ -38,6 +38,7 @@
#include "qgscomposerattributetable.h"
#include "qgscomposertablewidget.h"
#include "qgsexception.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
@@ -46,26 +47,29 @@
#include "qgscursors.h"

#include <QCloseEvent>
#include <QCheckBox>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QFileInfo>
#include <QIcon>
#include <QImageWriter>
#include <QMatrix>
#include <QMenuBar>
#include <QMessageBox>
#include <QPageSetupDialog>
#include <QPainter>

#include <QPixmap>
#include <QPrintDialog>
#include <QSettings>
#include <QIcon>
#include <QPixmap>
#include <QSizeGrip>
#include <QSvgGenerator>
#include <QToolBar>
#include <QToolButton>
#include <QImageWriter>
#include <QCheckBox>
#include <QSizeGrip>
#include "qgslogger.h"
//#include <QUndoView>





QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title )
{
@@ -212,6 +216,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),

mCompositionNameComboBox->insertItem( 0, tr( "Map 1" ) );

//undo widget
/*QUndoView* undoWidget = new QUndoView( mComposition->undoStack(), this );
mOptionsTabWidget->addTab( undoWidget, tr( "Command history" ) );*/

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
mSizeGrip = new QSizeGrip( this );
mSizeGrip->resize( mSizeGrip->sizeHint() );
@@ -507,7 +515,7 @@ void QgsComposer::on_mActionPrint_triggered()

void QgsComposer::print( QPrinter &printer )
{
if ( !mComposition )
if ( !mComposition || !mView )
return;

if ( containsWMSLayer() )
@@ -530,6 +538,7 @@ void QgsComposer::print( QPrinter &printer )
QApplication::setOverrideCursor( Qt::BusyCursor );

bool printAsRaster = mComposition->printAsRaster();
//mView->setScene( 0 );

if ( printAsRaster )
{
@@ -545,8 +554,9 @@ void QgsComposer::print( QPrinter &printer )
QPainter imagePainter( &image );
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
QRectF targetArea( 0, 0, width, height );
mView->setPaintingEnabled( false );
mComposition->render( &imagePainter, targetArea, sourceArea );
imagePainter.end();
mView->setPaintingEnabled( true );
p.drawImage( targetArea, image, targetArea );
}
else
@@ -574,7 +584,10 @@ void QgsComposer::print( QPrinter &printer )
//better in case of custom page size, but only possible with Qt>=4.4.0
QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );

mView->setPaintingEnabled( false );
mComposition->render( &p, paperRectPixel, paperRectMM );
mView->setPaintingEnabled( true );
}

mComposition->setPlotStyle( savedPlotStyle );
@@ -707,19 +720,18 @@ void QgsComposer::on_mActionExportAsImage_triggered()
}

mComposition->setPlotStyle( QgsComposition::Print );
mView->setScene( 0 );
image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
image.fill( 0 );
QPainter p( &image );
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
QRectF targetArea( 0, 0, width, height );
mView->setPaintingEnabled( false );
mComposition->render( &p, targetArea, sourceArea );
p.end();

mComposition->setPlotStyle( QgsComposition::Preview );
mView->setPaintingEnabled( true );
image.save( myOutputFileNameQString, myFilterMap[myFilterString].toLocal8Bit().data() );
mView->setScene( mComposition );
}


@@ -779,8 +791,6 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
}

myQSettings.setValue( "/UI/lastSaveAsSvgFile", myOutputFileNameQString );

//mView->setScene(0);//don't redraw the scene on the display while we render
mComposition->setPlotStyle( QgsComposition::Print );

QSvgGenerator generator;
@@ -799,12 +809,11 @@ void QgsComposer::on_mActionExportAsSVG_triggered()

QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
QRectF targetArea( 0, 0, width, height );
mView->setPaintingEnabled( false );
mComposition->render( &p, targetArea, sourceArea );

p.end();

mComposition->setPlotStyle( QgsComposition::Preview );
//mView->setScene(mComposition->canvas()); //now that we're done, set the view to show the scene again
mView->setPaintingEnabled( true );
}

void QgsComposer::on_mActionSelectMoveItem_triggered()
@@ -31,7 +31,7 @@
#include "qgscomposerattributetable.h"

QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f ) :
QGraphicsView( parent ), mShiftKeyPressed( false ), mRubberBandItem( 0 ), mRubberBandLineItem( 0 ), mMoveContentItem( 0 )
QGraphicsView( parent ), mShiftKeyPressed( false ), mRubberBandItem( 0 ), mRubberBandLineItem( 0 ), mMoveContentItem( 0 ), mPaintingEnabled( true )
{
setResizeAnchor( QGraphicsView::AnchorViewCenter );
setMouseTracking( true );
@@ -204,6 +204,7 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )

double moveX = scenePoint.x() - mMoveContentStartPos.x();
double moveY = scenePoint.y() - mMoveContentStartPos.y();

mMoveContentItem->moveContent( -moveX, -moveY );
mMoveContentItem = 0;
}
@@ -450,6 +451,19 @@ void QgsComposerView::wheelEvent( QWheelEvent* event )
}
}

void QgsComposerView::paintEvent( QPaintEvent* event )
{
if ( mPaintingEnabled )
{
QGraphicsView::paintEvent( event );
event->accept();
}
else
{
event->ignore();
}
}

void QgsComposerView::setComposition( QgsComposition* c )
{
setScene( c );
@@ -98,6 +98,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Returns the composer main window*/
QMainWindow* composerWindow();

void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
bool paintingEnabled() const { return mPaintingEnabled; }

protected:
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
@@ -109,6 +112,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView

void wheelEvent( QWheelEvent* event );

void paintEvent( QPaintEvent* event );

private:
/**Status of shift key (used for multiple selection)*/
bool mShiftKeyPressed;
@@ -125,6 +130,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Start of rubber band creation*/
QPointF mRubberBandStartPos;

bool mPaintingEnabled;

public slots:
/**For QgsComposerItemGroup to send its signals to QgsComposer (or other classes that keep track of input widgets)*/
void sendItemRemovedSignal( QgsComposerItem* item );

0 comments on commit 41e47e2

Please sign in to comment.
You can’t perform that action at this time.