Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Nov 25, 2010
1 parent 72b2ed4 commit 41e47e2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
43 changes: 26 additions & 17 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -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"
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -507,7 +515,7 @@ void QgsComposer::on_mActionPrint_triggered()

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

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

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

if ( printAsRaster )
{
Expand All @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}


Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand Down
16 changes: 15 additions & 1 deletion src/gui/qgscomposerview.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -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* );
Expand All @@ -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;
Expand All @@ -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 );
Expand Down

0 comments on commit 41e47e2

Please sign in to comment.