patch.diff

composer patch - Jürgen Fischer, 2010-07-02 12:51 PM

Download (5.1 KB)

View differences:

src/app/composer/qgscomposer.cpp (working copy)
541 541

  
542 542
  QApplication::setOverrideCursor( Qt::BusyCursor );
543 543

  
544
  if ( mComposition->printAsRaster() )
544
  bool printAsRaster = mComposition->printAsRaster();
545

  
546
  if ( printAsRaster )
545 547
  {
546 548
    //print out via QImage, code copied from on_mActionExportAsImage_activated
547 549
    int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
548 550
    int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
549 551
    QImage image( QSize( width, height ), QImage::Format_ARGB32 );
550
    image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
551
    image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
552
    image.fill( 0 );
553
    QPainter imagePainter( &image );
554
    QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
555
    QRectF targetArea( 0, 0, width, height );
556
    mComposition->render( &imagePainter, targetArea, sourceArea );
557
    imagePainter.end();
558
    p.drawImage( targetArea, image, targetArea );
552
    if ( !image.isNull() )
553
    {
554
      image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
555
      image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
556
      image.fill( 0 );
557
      QPainter imagePainter( &image );
558
      QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
559
      QRectF targetArea( 0, 0, width, height );
560
      mComposition->render( &imagePainter, targetArea, sourceArea );
561
      imagePainter.end();
562
      p.drawImage( targetArea, image, targetArea );
563
    }
564
    else
565
    {
566
      QApplication::restoreOverrideCursor();
567
      int answer = QMessageBox::warning( 0,
568
                                         tr( "Image too large" ),
569
                                         tr( "Creation of image with %1x%2 pixels failed.  Retry without 'Print As Raster'?" )
570
                                         .arg( width ).arg( height ),
571
                                         QMessageBox::Ok | QMessageBox::Cancel,
572
                                         QMessageBox::Ok );
573
      if ( answer == QMessageBox::Cancel )
574
      {
575
        mComposition->setPlotStyle( savedPlotStyle );
576
        return;
577
      }
578

  
579
      QApplication::setOverrideCursor( Qt::BusyCursor );
580
      printAsRaster = false;
581
    }
559 582
  }
560
  else
583

  
584
  if ( !printAsRaster )
561 585
  {
562 586
    //better in case of custom page size, but only possible with Qt>=4.4.0
563 587
    QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
564 588
    QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );
565 589
    mComposition->render( &p, paperRectPixel, paperRectMM );
566 590
  }
591

  
567 592
  mComposition->setPlotStyle( savedPlotStyle );
568 593
  QApplication::restoreOverrideCursor();
569 594
}
......
580 605
  int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
581 606

  
582 607
  int memuse = width * height * 3 / 1000000;  // pixmap + image
583
  QgsDebugMsg( QString( "Image %1 x %2" ).arg( width ).arg( height ) );
608
  QgsDebugMsg( QString( "Image %1x%2" ).arg( width ).arg( height ) );
584 609
  QgsDebugMsg( QString( "memuse = %1" ).arg( memuse ) );
585 610

  
586
  if ( memuse > 200 )   // cca 4500 x 4500
611
  if ( memuse > 200 )   // about 4500x4500
587 612
  {
588 613
    int answer = QMessageBox::warning( 0, tr( "Big image" ),
589
                                       tr( "To create image %1 x %2 requires circa %3 MB of memory" )
614
                                       tr( "To create image %1x%2 requires about %3 MB of memory. Proceed?" )
590 615
                                       .arg( width ).arg( height ).arg( memuse ),
591
                                       QMessageBox::Ok,  QMessageBox::Abort );
616
                                       QMessageBox::Ok | QMessageBox::Cancel,  QMessageBox::Ok );
592 617

  
593 618
    raise();
594
    if ( answer == QMessageBox::Abort ) return;
619
    if ( answer == QMessageBox::Cancel )
620
      return;
595 621
  }
596 622

  
597 623
  // Get file and format (stolen from qgisapp.cpp but modified significantely)
......
678 704
  myQSettings.setValue( "/UI/lastSaveAsImageFormat", myFilterMap[myFilterString] );
679 705
  myQSettings.setValue( "/UI/lastSaveAsImageFile", myOutputFileNameQString );
680 706

  
681
  if ( myOutputFileNameQString == "" ) return;
707
  if ( myOutputFileNameQString == "" )
708
    return;
682 709

  
710
  QImage image( QSize( width, height ), QImage::Format_ARGB32 );
711
  if ( image.isNull() )
712
  {
713
    QMessageBox::warning( 0,
714
                          tr( "Image too big" ),
715
                          tr( "Creation of image with %1x%2 pixels failed.  Export aborted." )
716
                          .arg( width ).arg( height ),
717
                          QMessageBox::Ok );
718
    return;
719
  }
720

  
683 721
  mComposition->setPlotStyle( QgsComposition::Print );
684 722
  mView->setScene( 0 );
685

  
686
  QImage image( QSize( width, height ), QImage::Format_ARGB32 );
687 723
  image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
688 724
  image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
689 725
  image.fill( 0 );