[QGIS Commit] r9352 - trunk/qgis/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Sep 19 03:37:54 EDT 2008
Author: mhugent
Date: 2008-09-19 03:37:54 -0400 (Fri, 19 Sep 2008)
New Revision: 9352
Modified:
trunk/qgis/src/app/composer/qgscomposer.cpp
trunk/qgis/src/app/composer/qgscomposer.h
Log:
Cleanup of unused code in qgscomposer class
Modified: trunk/qgis/src/app/composer/qgscomposer.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.cpp 2008-09-19 06:54:12 UTC (rev 9351)
+++ trunk/qgis/src/app/composer/qgscomposer.cpp 2008-09-19 07:37:54 UTC (rev 9352)
@@ -231,7 +231,7 @@
mSizeGrip->move( rect().bottomRight() - mSizeGrip->rect().bottomRight() );
restoreWindowState();
- selectItem(); // Set selection tool
+ setSelectionTool();
mView->setFocus();
@@ -483,378 +483,8 @@
QApplication::restoreOverrideCursor();
}
-#if 0
- /* Uff!!! It is impossible to set a custom page size for QPrinter.
- * Only the sizes hardcoded in Qt library can be used.
- * 'Fortunately', it seems that everything is written to postscript output file,
- * regardless the pages size ->
- *
- * 1) outputToFile == false: If the output page size doesn't match the user defined size
- * (in QgsComposer) the output is rescaled and centered so that
- * it fit to the select output page size.
- * a warning is displayed, that the map was rescaled.
- *
- * 2) outputToFile == true: the output postscript file is written (page size is not
- * important but bigger is better because it lefts enough space
- * in BoundingBox definition), then the file is reopened,
- * and the BoundingBox is redefined.
- */
-
- // NOTE: QT 3.2 has QPrinter::setOptionEnabled but only for three options
- if ( !mPrinter )
- {
-
- mPrinter = new QPrinter( QPrinter::PrinterResolution );
- //mPrinter = new QPrinter ( QPrinter::HighResolution );
- //mPrinter = new QPrinter ( QPrinter::ScreenResolution );
- mPrinter->setFullPage( true );
-#ifndef Q_OS_MACX
- // For Qt/Mac 3, don't set outputToFile to true before calling setup
- // because it wiil suppress the Print dialog and output to file without
- // giving the user a chance to select a printer instead.
- // The Mac Print dialog provides an option to create a pdf which is
- // intended to be invisible to the application. If an eps is desired,
- // a custom Mac Print dialog is needed.
-
- // There is a bug in Qt<=4.2.2 (dialog is not correct) if output is set to file
- // => disable until they fix it
- //mPrinter->setOutputFileName ( QDir::convertSeparators ( QDir::home().path() + "/" + "qgis.eps") );
-#endif
- mPrinter->setColorMode( QPrinter::Color );
- mPrinter->setPageSize( QPrinter::A4 ); //would be nice set this based on the composition paper size
- }
- else
- {
- // Because of bug in Qt<=4.2.2 (dialog is not correct) we have to reset always
- // to printer otherwise print to file is checked but printer combobox is in dialog
- mPrinter->setOutputFileName( NULL );
- }
-
- //set the resolution and paper orientation each time we call up the dialog, not just the first time we run it
- mPrinter->setResolution( mComposition->resolution() );
-
- if ( mComposition->paperOrientation() == QgsComposition::Portrait )
- {
- mPrinter->setOrientation( QPrinter::Portrait );
- }
- else
- {
- mPrinter->setOrientation( QPrinter::Landscape );
- }
-
-
- //if ( mPrinter->setup(this) ) {
- QPrintDialog printDialog( mPrinter, this );
- if ( printDialog.exec() == QDialog::Accepted )
- {
- // TODO: mPrinter->setup() moves the composer under Qgisapp, get it to foreground somehow
- // raise() for now, is it something better?
- raise();
-
- // TODO: Qt does not add pagesize to output file, it can cause problems if ps2pdf is used
- // or if default page on printer is different.
- // We should add somewhere in output file:
- // << /PageSize [ %d %d ] >> setpagedevice
- // %d %d is width and height in points
-
- // WARNING: If QCanvasView receives repaint signal during the printing
- // (e.g. covered by QPrinter::setup dialog) it breaks somehow drawing of QCanvas items
- // (for example not all features in the map are drawn.
- // I don't know how to stop temporarily updating, (I don't want to reimplement
- // repaint in QCanvasView, so I unset the view, print and reset.
- mView->setScene( 0 );
-
- int resolution = mPrinter->resolution();
-
- QgsDebugMsg( QString( "Resolution = %1" ).arg( resolution ) );
-
- //double scale = resolution / 25.4 / mComposition->scale();
-
- mComposition->setPlotStyle( QgsComposition::Postscript );
-
- if ( !mPrinter->outputFileName().isNull() )
- {
- try
- {
- QgsDebugMsg( "Print to file" );
-
- QPrinter::PageSize psize = QPrinter::A4; //sensible default
-
- // WARNING mPrinter->outputFormat() returns always 0 in Qt 4.2.2
- // => we have to check extension
- bool isPs = false;
- if ( mPrinter->outputFileName().right( 3 ).toLower() == ".ps" || mPrinter->outputFileName().right( 4 ).toLower() == ".eps" )
- {
- isPs = true;
- }
- //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
- if ( isPs )
- {
- // NOTE: setPageSize after setup() works, but setOrientation does not
- // -> the BoundingBox must follow the orientation
-
- psize = mPrinter->pageSize();
- // B0 ( 1000x1414mm = 2835x4008pt ) is the biggest defined in Qt, a map can be bigger
- // but probably not bigger than 9999x9999pt = 3527x3527mm
- mPrinter->setPageSize( QPrinter::B0 );
- }
-
- QPainter p( mPrinter );
- //p.scale(scale, scale);
-
- //QRectF renderArea(0, 0, (mComposition->paperWidth() * mComposition->scale()),
- //(mComposition->paperHeight() * mComposition->scale()));
-
- mComposition->canvas()->render( &p/*, renderArea*/ );
-
- p.end();
-
- QgsDebugMsg( QString( "mPrinter->outputFormat() = %1" ).arg( mPrinter->outputFormat() ) );
-
-
- //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
- if ( isPs )
- {
- // reset the page
- mPrinter->setPageSize( psize );
-
- QFile f( mPrinter->outputFileName() );
-
- // Overwrite the bounding box
- QgsDebugMsg( "Overwrite the bounding box" );
- if ( !f.open( QIODevice::ReadWrite ) )
- {
- throw QgsIOException( tr( "Couldn't open " ) + f.name() + tr( " for read/write" ) );
- }
- Q_LONG offset = 0;
- Q_LONG size;
- bool found = false;
- QString s;
- char buf[101];
- while ( !f.atEnd() )
- {
- size = f.readLine( buf, 100 );
- s = QString( buf );
- if ( s.find( "%%BoundingBox:" ) == 0 )
- {
- found = true;
- break;
- }
- offset += size;
- }
-
- if ( found )
- {
- int w, h;
-
- w = ( int )( 72 * mComposition->paperWidth() / 25.4 );
- h = ( int )( 72 * mComposition->paperHeight() / 25.4 );
- if ( mPrinter->orientation() == QPrinter::Landscape )
- {
- int tmp = w;
- w = h;
- h = tmp;
- }
- s.sprintf( "%%%%BoundingBox: 0 0 %d %d", w, h );
-
- if ( s.length() > size )
- {
- int shift = s.length() - size;
- shiftFileContent( &f, offset + size + 1, shift );
- }
- else
- {
- if ( !f.at( offset ) )
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot seek" ) );
- }
- else
- {
- // Write spaces (for case the size > s.length() )
- QString es;
- es.fill( ' ', size - 1 );
- f.flush();
- if ( f.writeBlock( es.toLocal8Bit().data(), size - 1 ) < size - 1 )
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot overwrite BoundingBox" ) );
- }
- f.flush();
- f.at( offset );
- f.flush();
- if ( f.writeBlock( s.toLocal8Bit().data(), s.length() ) < s.length() - 1 )
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot overwrite BoundingBox" ) );
- }
- f.flush();
- } //END else (!f.at(offset))
- } //END else (s.length() > size)
- } //END if(found)
- else
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot find BoundingBox" ) );
- }
- f.close();
-
- // Overwrite translate
- if ( mPrinter->orientation() == QPrinter::Portrait )
- {
- QgsDebugMsg( "Orientation portraint -> overwrite translate" );
- if ( !f.open( QIODevice::ReadWrite ) )
- {
- throw QgsIOException( tr( "Couldn't open " ) + f.name() + tr( " for read/write" ) );
- }
- offset = 0;
- found = false;
-
- //Example Qt3:
- //0 4008 translate 1 -1 scale/defM ...
- //QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
- //Example Qt4:
- //0 0 translate 0.239999 -0.239999 scale } def
- QRegExp rx( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale \\} def" );
-
- while ( !f.atEnd() )
- {
- size = f.readLine( buf, 100 );
- s = QString( buf );
- if ( rx.search( s ) != -1 )
- {
- found = true;
- break;
- }
- offset += size;
- } //END while( !f.atEnd() )
-
- if ( found )
- {
- int trans;
-
- trans = ( int )( 72 * mComposition->paperHeight() / 25.4 );
- QgsDebugMsg( QString( "trans = %1" ).arg( trans ) );
- //Qt3:
- //s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
- //Qt4:
- s.sprintf( "0 %d translate %s scale } def\n", trans, ( const char * ) rx.cap( 1 ).toLocal8Bit().data() );
-
- QgsDebugMsg( QString( "s.length() = %1 size = %2" ).arg( s.length() ).arg( size ) );
- if ( s.length() > size )
- {
- //QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
- // Move the content up
- int shift = s.length() - size;
- /*
- int last = f.size() + shift -1;
- for ( int i = last; i > offset + size; i-- )
- {
- f.at(i-shift);
- QByteArray ba = f.read(1);
- f.at(i);
- f.write(ba);
- }
- */
- shiftFileContent( &f, offset + size + 1, shift );
- } //END if( s.length() > size)
-
- // Overwrite the row
- if ( !f.at( offset ) )
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot seek" ) );
- }
- else
- {
- /* Write spaces (for case the size > s.length() ) */
- QString es;
- es.fill( ' ', size - 1 );
- f.flush();
- if ( f.writeBlock( es.toLocal8Bit().data(), size - 1 ) < size - 1 )
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot overwrite translate" ) );
- }
- f.flush();
- f.at( offset );
- f.flush();
- if ( f.writeBlock( s.toLocal8Bit().data(), s.length() ) < s.length() - 1 )
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot overwrite translate" ) );
- }
- f.flush();
- } //END else
- }
- else
- {
- QMessageBox::warning( this, tr( "Error in Print" ), tr( "Cannot find translate" ) );
- }
- f.close();
- }
- }
- }
- catch ( QgsIOException e )
- {
- QMessageBox::warning( this, tr( "File IO Error" ), e.what() );
- }
- }
- else
- { // print to printer
- bool print = true;
-
- // Check size
- QgsDebugMsg( QString( "Paper: %1 x %2" ).arg( mPrinter->widthMM() ).arg( mPrinter->heightMM() ) );
- if ( mComposition->paperWidth() != mPrinter->widthMM() || mComposition->paperHeight() != mPrinter->heightMM() )
- {
- int answer = QMessageBox::warning( 0, tr( "Paper does not match" ),
- tr( "The selected paper size does not match the composition size" ),
- QMessageBox::Ok, QMessageBox::Abort );
-
- if ( answer == QMessageBox::Abort )
- {
- print = false;
- }
- } //END if(compositionSize != paperSize)
-
- if ( print )
- {
- QgsDebugMsg( "Printing ... " );
- QPainter p( mPrinter );
- //p.scale(scale, scale);
-
- //MH: is this necessary?
- //QRectF renderArea(0, 0, (mComposition->paperWidth() * mComposition->scale()),
- //(mComposition->paperHeight() * mComposition->scale()));
-
- mComposition->canvas()->render( &p/*, renderArea*/ );
-
- p.end();
- QgsDebugMsg( "... printing finished" );
- } //END if ( print )
- }
-
- mComposition->setPlotStyle( QgsComposition::Preview );
- mView->setScene( mComposition->canvas() );
- }
- else
- {
- raise();
- }
-#endif //0
}
-
-#if 0
-bool QgsComposer::shiftFileContent( QFile *file, Q_LONG start, int shift )
-{
- int last = file->size() + shift - 1;
- for ( int i = last; i >= start + shift; i-- )
- {
- if ( !file->at( i - shift ) ) return false;
- QByteArray ba = file->read( 1 );
- if ( ba.isEmpty() ) return false;
- if ( !file->at( i ) ) return false;
- if ( file->write( ba ) != 1 ) return false;
- }
- return true;
-}
-#endif //0
-
void QgsComposer::on_mActionExportAsImage_activated( void )
{
// Image size
@@ -1056,37 +686,6 @@
#endif
}
-
-void QgsComposer::setToolActionsOff( void )
-{
-#if 0
- mActionOpenTemplate->setOn( false );
- mActionSaveTemplateAs->setOn( false );
- mActionExportAsImage->setOn( false );
- mActionExportAsSVG->setOn( false );
- mActionPrint->setOn( false );
- mActionZoomAll->setOn( false );
- mActionZoomIn->setOn( false );
- mActionZoomOut->setOn( false );
- mActionRefreshView->setOn( false );
- mActionAddNewMap->setOn( false );
- mActionAddImage->setOn( false );
- mActionAddNewLabel->setOn( false );
- mActionAddNewVectLegend->setOn( false );
- mActionAddNewScalebar->setOn( false );
- mActionSelectMoveItem->setOn( false );
-#endif //0
-}
-
-void QgsComposer::selectItem( void )
-{
-#if 0
- mComposition->setTool( QgsComposition::Select );
- setToolActionsOff();
- mActionSelectMoveItem->setOn( true );
-#endif //0
-}
-
void QgsComposer::on_mActionSelectMoveItem_activated( void )
{
if ( mView )
Modified: trunk/qgis/src/app/composer/qgscomposer.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.h 2008-09-19 06:54:12 UTC (rev 9351)
+++ trunk/qgis/src/app/composer/qgscomposer.h 2008-09-19 07:37:54 UTC (rev 9352)
@@ -68,9 +68,6 @@
//! Zoom to full extent of the paper
void zoomFull();
- //! Select item
- void selectItem();
-
//! Return pointer to map canvas
QgsMapCanvas *mapCanvas( void );
@@ -228,9 +225,6 @@
/**Establishes the signal slot connection for the class*/
void connectSlots();
- //! Set buttons up
- void setToolActionsOff( void );
-
//! returns new world matrix for canvas view after zoom with factor scaleChange
QMatrix updateMatrix( double scaleChange );
More information about the QGIS-commit
mailing list