Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A couple of print composer bug fixes related to image and symbol
scaling.



git-svn-id: http://svn.osgeo.org/qgis/trunk@7078 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
StevenB authored and StevenB committed Jul 19, 2007
1 parent 190fcc1 commit 659bda5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
28 changes: 20 additions & 8 deletions src/app/composer/qgscomposermap.cpp
Expand Up @@ -138,12 +138,14 @@ void QgsComposerMap::draw ( QPainter *painter, QgsRect &extent, QgsMapToPixel *t

double widthScale = mWidthScale;
double symbolScale = mSymbolScale;
if (plotStyle() != QgsComposition::Preview)

//TODO: attempt to scale cache lines and point symbols to be larger as we zoom in
/* if(creating cache pixmap)
{
widthScale /= mComposition->viewScale();
symbolScale /= mComposition->viewScale();
widthScale *= (cachePixmap.width / map.rect.width);
symbolScale *= (cachePixmap.width / map.rect.width);
}

*/
QgsRect r1, r2;
r1 = extent;
// TODO: revisit later and make this QgsMapRender-aware [MD]
Expand Down Expand Up @@ -235,13 +237,15 @@ void QgsComposerMap::setUserExtent ( QgsRect const & rect )

void QgsComposerMap::cache ( void )
{
std::cout << "QgsComposerMap::cache()" << std::endl;

// Create preview on some reasonable size. It was slow with cca 1500x1500 points on 2x1.5GHz
// Note: The resolution should also respect the line widths, it means that
// 1 pixel in cache should have ia similar size as 1 pixel in canvas
// but it can result in big cache -> limit

int w = (int)(QGraphicsRectItem::rect().width() * mComposition->viewScale());
w = w < 1000 ? w : 1000;
w = w < 1000 ? w : 1000; //limit the cache pixmap to 1000 pixels wide
int h = (int) ( mExtent.height() * w / mExtent.width() );
// It can happen that extent is not initialised well -> check
if ( h < 1 || h > 10000 ) h = w;
Expand All @@ -259,6 +263,14 @@ void QgsComposerMap::cache ( void )
// WARNING: ymax in QgsMapToPixel is device height!!!
QgsMapToPixel transform(scale, h, mCacheExtent.yMin(), mCacheExtent.xMin() );

//somthing about this transform isn't really what we want...
/*Ideally, the cache pixmap wouldn't behave the same as the map canvas.
* zooming in should make the lines become thicker, and symbols larger, rather than just
* redrawing them to be n pixels wide.
* We also want to make sure that changing the composition's resolution has the desired effect
* on both the cache, screen render, and print.
*/

std::cout << "transform = " << transform.showParameters().toLocal8Bit().data() << std::endl;

mCachePixmap.fill(QColor(255,255,255));
Expand Down Expand Up @@ -290,12 +302,12 @@ void QgsComposerMap::paint ( QPainter* painter, const QStyleOptionGraphicsItem*

// Scale so that the cache fills the map rectangle
double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
std::cout << "scale = " << scale << std::endl;

painter->save();

painter->translate(0, 0); //do we need this?
painter->scale(scale,scale);
std::cout << "scale = " << scale << std::endl;

// Note: drawing only a visible part of the pixmap doesn't make it much faster
painter->drawPixmap(0,0, mCachePixmap);
Expand All @@ -310,7 +322,7 @@ void QgsComposerMap::paint ( QPainter* painter, const QStyleOptionGraphicsItem*

double scale = mExtent.width() / QGraphicsRectItem::rect().width();
QgsMapToPixel transform(scale, QGraphicsRectItem::rect().height(), mExtent.yMin(), mExtent.xMin() );

painter->save();
painter->translate(0, 0); //do we need this?

Expand Down Expand Up @@ -386,7 +398,7 @@ void QgsComposerMap::on_mCalculateComboBox_activated( int )
double QgsComposerMap::scaleFromUserScale ( double us )
{
double s=0;

switch ( mComposition->mapCanvas()->mapUnits() ) {
case QGis::METERS :
s = 1000. * mComposition->scale() / us;
Expand Down
16 changes: 12 additions & 4 deletions src/app/composer/qgscomposerpicture.cpp
Expand Up @@ -205,15 +205,23 @@ void QgsComposerPicture::paint ( QPainter* painter, const QStyleOptionGraphicsIt
#endif

QRectF box = mPicture.boundingRect();
double scale = 1. * mWidth / box.width();

double scale = 1. * mWidth / box.width();

if(plotStyle() == QgsComposition::Postscript)
{
scale *= (96.0 / mComposition->resolution());
}
painter->save();

painter->translate(-mWidth/2, -mHeight/2);

painter->scale ( scale, scale );
painter->rotate ( -mAngle );

painter->drawPicture (QPointF(-box.width()/2, -box.height()/2), mPicture );

// painter->drawPicture (QPointF(-box.width()/2, -box.height()/2), mPicture ); //this doesn't work right...

painter->drawPicture (0, 0, mPicture );

painter->restore();

if ( mFrame ) {
Expand Down
8 changes: 7 additions & 1 deletion src/app/composer/qgscomposervectorlegend.cpp
Expand Up @@ -372,8 +372,13 @@ std::cout << "widthScale: " << widthScale << std::endl;
painter->setBrush ( sym->brush() );

if ( vector->vectorType() == QGis::Point ) {
double scale = map->symbolScale() * mComposition->scale();
double scale = map->symbolScale();// * mComposition->scale();

/* if (plotStyle() != QgsComposition::Preview)
{
scale /= mComposition->viewScale();
}
*/
// Get the picture of appropriate size directly from catalogue
QPixmap pic = QPixmap::fromImage(sym->getPointSymbolAsImage(widthScale,false,sym->color()));

Expand Down Expand Up @@ -461,6 +466,7 @@ void QgsComposerVectorLegend::cache ( void )
//typical boundingRect size is 15 units wide,
mCachePixmap.resize ((int)QGraphicsRectItem::rect().width(), (int)QGraphicsRectItem::rect().height() );


QPainter p(&mCachePixmap);

mCachePixmap.fill(QColor(255,255,255));
Expand Down

0 comments on commit 659bda5

Please sign in to comment.