Skip to content

Commit

Permalink
Fix layout problems in georef pdf output by making size of left and r…
Browse files Browse the repository at this point in the history
…ight margins a user option

git-svn-id: http://svn.osgeo.org/qgis/trunk@13765 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 21, 2010
1 parent 350fcc4 commit 05f1876
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 30 deletions.
5 changes: 5 additions & 0 deletions src/plugins/georeferencer/qgsgeorefconfigdialog.cpp
Expand Up @@ -88,6 +88,9 @@ void QgsGeorefConfigDialog::readSettings()
{
mPixelsButton->setChecked( true );
}

mLeftMarginSpinBox->setValue( s.value( "/Plugin-GeoReferencer/Config/LeftMarginPDF", "2.0" ).toDouble() );
mRightMarginSpinBox->setValue( s.value( "/Plugin-GeoReferencer/Config/RightMarginPDF", "2.0" ).toDouble() );
}

void QgsGeorefConfigDialog::writeSettings()
Expand All @@ -104,4 +107,6 @@ void QgsGeorefConfigDialog::writeSettings()
{
s.setValue( "/Plugin-GeoReferencer/Config/ResidualUnits", "mapUnits" );
}
s.setValue( "/Plugin-GeoReferencer/Config/LeftMarginPDF", mLeftMarginSpinBox->value() );
s.setValue( "/Plugin-GeoReferencer/Config/RightMarginPDF", mRightMarginSpinBox->value() );
}
86 changes: 67 additions & 19 deletions src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui
Expand Up @@ -7,13 +7,13 @@
<x>0</x>
<y>0</y>
<width>249</width>
<height>249</height>
<height>344</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Georeferencer</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QGroupBox" name="mPointTipGroupBox">
<property name="title">
Expand All @@ -37,23 +37,6 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mShowDockedCheckBox">
<property name="text">
<string>Show Georeferencer window docked</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="mResidualUnitsGroupBox">
<property name="title">
Expand All @@ -77,6 +60,71 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="mPdfReportGroupBox">
<property name="title">
<string>PDF report</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Left margin</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="mLeftMarginSpinBox">
<property name="prefix">
<string/>
</property>
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Right margin</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="mRightMarginSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mShowDockedCheckBox">
<property name="text">
<string>Show Georeferencer window docked</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
26 changes: 15 additions & 11 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -1300,34 +1300,39 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
QFont tableContentFont;
tableContentFont.setPointSize( 9 );

QSettings s;
double leftMargin = s.value( "/Plugin-GeoReferencer/Config/LeftMarginPDF", "2.0" ).toDouble();
double rightMargin = s.value( "/Plugin-GeoReferencer/Config/RightMarginPDF", "2.0" ).toDouble();
double contentWidth = 210 - ( leftMargin + rightMargin );

//title
QFileInfo rasterFi( mRasterFileName );
QgsComposerLabel* titleLabel = new QgsComposerLabel( composition );
titleLabel->setFont( titleFont );
titleLabel->setText( rasterFi.fileName() );
composition->addItem( titleLabel );
titleLabel->setSceneRect( QRectF( 2, 5, composition->paperWidth(), 8 ) );
titleLabel->setSceneRect( QRectF( leftMargin, 5, contentWidth, 8 ) );
titleLabel->setFrame( false );

//composer map
QgsRectangle canvasExtent = mCanvas->extent();
//calculate width and height considering extent aspect ratio and max Width 206, maxHeight 70
double widthExtentRatio = 206 / canvasExtent.width();
double widthExtentRatio = contentWidth / canvasExtent.width();
double heightExtentRatio = 70 / canvasExtent.height();
double mapWidthMM = 0;
double mapHeightMM = 0;
if ( widthExtentRatio < heightExtentRatio )
{
mapWidthMM = 206;
mapHeightMM = 206 / canvasExtent.width() * canvasExtent.height();
mapWidthMM = contentWidth;
mapHeightMM = contentWidth / canvasExtent.width() * canvasExtent.height();
}
else
{
mapHeightMM = 70;
mapWidthMM = 70 / canvasExtent.height() * canvasExtent.width();
}

QgsComposerMap* composerMap = new QgsComposerMap( composition, 2, titleLabel->rect().bottom() + titleLabel->transform().dy(), mapWidthMM, mapHeightMM );
QgsComposerMap* composerMap = new QgsComposerMap( composition, leftMargin, titleLabel->rect().bottom() + titleLabel->transform().dy(), mapWidthMM, mapHeightMM );
composerMap->setLayerSet( canvasRenderer->layerSet() );
composerMap->setNewExtent( mCanvas->extent() );
composerMap->setMapCanvas( mCanvas );
Expand All @@ -1344,7 +1349,6 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
bool wldTransform = transform.getOriginScaleRotation( origin, scaleX, scaleY, rotation );

QString residualUnits;
QSettings s;
if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ) == "mapUnits" && mGeorefTransform.providesAccurateInverseTransformation() )
{
residualUnits = tr( "map units" );
Expand All @@ -1362,7 +1366,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
parameterLabel->setText( parameterTitle );
parameterLabel->adjustSizeToText();
composition->addItem( parameterLabel );
parameterLabel->setSceneRect( QRectF( 2, composerMap->rect().bottom() + composerMap->transform().dy() + 5, composition->paperWidth(), 8 ) );
parameterLabel->setSceneRect( QRectF( leftMargin, composerMap->rect().bottom() + composerMap->transform().dy() + 5, contentWidth, 8 ) );
parameterLabel->setFrame( false );

//calculate mean error
Expand All @@ -1379,7 +1383,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
row << QString::number( origin.x(), 'f', 3 ) << QString::number( origin.y(), 'f', 3 ) << QString::number( scaleX ) << QString::number( scaleY ) << QString::number( rotation * 180 / M_PI ) << QString::number( meanError );
parameterTable->addRow( row );
composition->addItem( parameterTable );
parameterTable->setSceneRect( QRectF( 2, parameterLabel->rect().bottom() + parameterLabel->transform().dy() + 5, 50, 20 ) );
parameterTable->setSceneRect( QRectF( leftMargin, parameterLabel->rect().bottom() + parameterLabel->transform().dy() + 5, contentWidth, 20 ) );
parameterTable->setGridStrokeWidth( 0.1 );
parameterTable->adjustFrameToSize();
}
Expand All @@ -1394,13 +1398,13 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
residualLabel->setFont( titleFont );
residualLabel->setText( tr( "Residuals" ) );
composition->addItem( residualLabel );
residualLabel->setSceneRect( QRectF( 2, previousItem->rect().bottom() + previousItem->transform().dy() + 5, composition->paperWidth(), 6 ) );
residualLabel->setSceneRect( QRectF( leftMargin, previousItem->rect().bottom() + previousItem->transform().dy() + 5, contentWidth, 6 ) );
residualLabel->setFrame( false );

//residual plot
QgsResidualPlotItem* resPlotItem = new QgsResidualPlotItem( composition );
composition->addItem( resPlotItem );
resPlotItem->setSceneRect( QRectF( 2, residualLabel->rect().bottom() + residualLabel->transform().dy() + 5, composerMap->rect().width(), composerMap->rect().height() ) );
resPlotItem->setSceneRect( QRectF( leftMargin, residualLabel->rect().bottom() + residualLabel->transform().dy() + 5, contentWidth, composerMap->rect().height() ) );
resPlotItem->setExtent( composerMap->extent() );
resPlotItem->setGCPList( mPoints );

Expand Down Expand Up @@ -1437,7 +1441,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG

composition->addItem( gcpTable );

gcpTable->setSceneRect( QRectF( 2, resPlotItem->rect().bottom() + resPlotItem->transform().dy() + 5, 170, 100 ) );
gcpTable->setSceneRect( QRectF( leftMargin, resPlotItem->rect().bottom() + resPlotItem->transform().dy() + 5, contentWidth, 100 ) );
gcpTable->setGridStrokeWidth( 0.1 );

printer.setResolution( composition->printResolution() );
Expand Down

0 comments on commit 05f1876

Please sign in to comment.