38
38
#include " qgscomposerlabel.h"
39
39
#include " qgscomposermap.h"
40
40
#include " qgscomposertexttable.h"
41
+ #include " qgscomposertablecolumn.h"
42
+ #include " qgscomposerframe.h"
41
43
#include " qgsmapcanvas.h"
42
44
#include " qgsmapcoordsdialog.h"
43
45
#include " qgsmaplayerregistry.h"
@@ -1585,15 +1587,11 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1585
1587
return false ;
1586
1588
}
1587
1589
1588
- QPrinter printer;
1589
- printer.setOutputFormat ( QPrinter::PdfFormat );
1590
- printer.setOutputFileName ( fileName );
1591
-
1592
1590
// create composition A4 with 300 dpi
1593
1591
QgsComposition* composition = new QgsComposition ( mCanvas ->mapSettings () );
1594
1592
composition->setPaperSize ( 210 , 297 ); // A4
1595
1593
composition->setPrintResolution ( 300 );
1596
- printer. setPaperSize ( QSizeF ( composition->paperWidth (), composition-> paperHeight () ), QPrinter::Millimeter );
1594
+ composition->setNumPages ( 2 );
1597
1595
1598
1596
QFont titleFont;
1599
1597
titleFont.setPointSize ( 9 );
@@ -1646,10 +1644,8 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1646
1644
composerMap->zoomToExtent ( layerExtent );
1647
1645
composerMap->setMapCanvas ( mCanvas );
1648
1646
composition->addItem ( composerMap );
1649
- printer.setFullPage ( true );
1650
- printer.setColorMode ( QPrinter::Color );
1651
1647
1652
- QgsComposerTextTable * parameterTable = 0 ;
1648
+ QgsComposerTextTableV2 * parameterTable = 0 ;
1653
1649
double scaleX, scaleY, rotation;
1654
1650
QgsPoint origin;
1655
1651
@@ -1667,6 +1663,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1667
1663
residualUnits = tr ( " pixels" );
1668
1664
}
1669
1665
1666
+ QGraphicsRectItem* previousItem = composerMap;
1670
1667
if ( wldTransform )
1671
1668
{
1672
1669
QString parameterTitle = tr ( " Transformation parameters" ) + QString ( " (" ) + convertTransformEnumToString ( transform.transformParametrisation () ) + QString ( " )" );
@@ -1682,25 +1679,30 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1682
1679
double meanError = 0 ;
1683
1680
calculateMeanError ( meanError );
1684
1681
1685
- parameterTable = new QgsComposerTextTable ( composition );
1682
+ parameterTable = new QgsComposerTextTableV2 ( composition, false );
1686
1683
parameterTable->setHeaderFont ( tableHeaderFont );
1687
1684
parameterTable->setContentFont ( tableContentFont );
1688
- QStringList headers;
1689
- headers << tr ( " Translation x" ) << tr ( " Translation y" ) << tr ( " Scale x" ) << tr ( " Scale y" ) << tr ( " Rotation [degrees]" ) << tr ( " Mean error [%1]" ).arg ( residualUnits );
1690
- parameterTable->setHeaderLabels ( headers );
1685
+
1686
+ QgsComposerTableColumns columns;
1687
+ columns << new QgsComposerTableColumn ( tr ( " Translation x" ) )
1688
+ << new QgsComposerTableColumn ( tr ( " Translation y" ) )
1689
+ << new QgsComposerTableColumn ( tr ( " Scale x" ) )
1690
+ << new QgsComposerTableColumn ( tr ( " Scale y" ) )
1691
+ << new QgsComposerTableColumn ( tr ( " Rotation [degrees]" ) )
1692
+ << new QgsComposerTableColumn ( tr ( " Mean error [%1]" ).arg ( residualUnits ) );
1693
+
1694
+ parameterTable->setColumns ( columns );
1691
1695
QStringList row;
1692
1696
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 );
1693
1697
parameterTable->addRow ( row );
1694
- composition->addItem ( parameterTable );
1695
- parameterTable->setSceneRect ( QRectF ( leftMargin, parameterLabel->rect ().bottom () + parameterLabel->pos ().y () + 5 , contentWidth, 20 ) );
1698
+
1699
+ QgsComposerFrame* tableFrame = new QgsComposerFrame ( composition, parameterTable, leftMargin, parameterLabel->rect ().bottom () + parameterLabel->pos ().y () + 5 , contentWidth, 12 );
1700
+ parameterTable->addFrame ( tableFrame );
1701
+
1702
+ composition->addItem ( tableFrame );
1696
1703
parameterTable->setGridStrokeWidth ( 0.1 );
1697
- parameterTable->adjustFrameToSize ();
1698
- }
1699
1704
1700
- QGraphicsRectItem* previousItem = composerMap;
1701
- if ( parameterTable )
1702
- {
1703
- previousItem = parameterTable;
1705
+ previousItem = tableFrame;
1704
1706
}
1705
1707
1706
1708
QgsComposerLabel* residualLabel = new QgsComposerLabel ( composition );
@@ -1720,14 +1722,25 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1720
1722
// necessary for the correct scale bar unit label
1721
1723
resPlotItem->setConvertScaleToMapUnits ( residualUnits == tr ( " map units" ) );
1722
1724
1723
- QgsComposerTextTable * gcpTable = new QgsComposerTextTable ( composition );
1725
+ QgsComposerTextTableV2 * gcpTable = new QgsComposerTextTableV2 ( composition, false );
1724
1726
gcpTable->setHeaderFont ( tableHeaderFont );
1725
1727
gcpTable->setContentFont ( tableContentFont );
1726
- QStringList gcpHeader;
1727
- gcpHeader << " id" << " enabled" << " pixelX" << " pixelY" << " mapX" << " mapY" << " resX [" + residualUnits + " ]" << " resY [" + residualUnits + " ]" << " resTot [" + residualUnits + " ]" ;
1728
- gcpTable->setHeaderLabels ( gcpHeader );
1728
+ gcpTable->setHeaderMode ( QgsComposerTableV2::AllFrames );
1729
+ QgsComposerTableColumns columns;
1730
+ columns << new QgsComposerTableColumn ( tr ( " ID" ) )
1731
+ << new QgsComposerTableColumn ( tr ( " Enabled" ) )
1732
+ << new QgsComposerTableColumn ( tr ( " Pixel X" ) )
1733
+ << new QgsComposerTableColumn ( tr ( " Pixel Y" ) )
1734
+ << new QgsComposerTableColumn ( tr ( " Map X" ) )
1735
+ << new QgsComposerTableColumn ( tr ( " Map Y" ) )
1736
+ << new QgsComposerTableColumn ( tr ( " Res X (%1)" ).arg ( residualUnits ) )
1737
+ << new QgsComposerTableColumn ( tr ( " Res Y (%1)" ).arg ( residualUnits ) )
1738
+ << new QgsComposerTableColumn ( tr ( " Res Total (%1)" ).arg ( residualUnits ) );
1739
+
1740
+ gcpTable->setColumns ( columns );
1729
1741
1730
1742
QgsGCPList::const_iterator gcpIt = mPoints .constBegin ();
1743
+ QList< QStringList > gcpTableContents;
1731
1744
for ( ; gcpIt != mPoints .constEnd (); ++gcpIt )
1732
1745
{
1733
1746
QStringList currentGCPStrings;
@@ -1745,27 +1758,32 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1745
1758
}
1746
1759
currentGCPStrings << QString::number (( *gcpIt )->pixelCoords ().x (), ' f' , 0 ) << QString::number (( *gcpIt )->pixelCoords ().y (), ' f' , 0 ) << QString::number (( *gcpIt )->mapCoords ().x (), ' f' , 3 )
1747
1760
<< QString::number (( *gcpIt )->mapCoords ().y (), ' f' , 3 ) << QString::number ( residual.x () ) << QString::number ( residual.y () ) << QString::number ( residualTot );
1748
- gcpTable-> addRow ( currentGCPStrings ) ;
1761
+ gcpTableContents << currentGCPStrings ;
1749
1762
}
1750
1763
1751
- composition->addItem ( gcpTable );
1764
+ gcpTable->setContents ( gcpTableContents );
1765
+
1766
+ double firstFrameY = resPlotItem->rect ().bottom () + resPlotItem->pos ().y () + 5 ;
1767
+ double firstFrameHeight = 287 - firstFrameY;
1768
+ QgsComposerFrame* gcpFirstFrame = new QgsComposerFrame ( composition, gcpTable, leftMargin, firstFrameY, contentWidth, firstFrameHeight );
1769
+ gcpTable->addFrame ( gcpFirstFrame );
1770
+ composition->addItem ( gcpFirstFrame );
1771
+
1772
+ QgsComposerFrame* gcpSecondFrame = new QgsComposerFrame ( composition, gcpTable, leftMargin, 10 , contentWidth, 277.0 );
1773
+ gcpSecondFrame->setItemPosition ( leftMargin, 10 , QgsComposerItem::UpperLeft, 2 );
1774
+ gcpSecondFrame->setHidePageIfEmpty ( true );
1775
+ gcpTable->addFrame ( gcpSecondFrame );
1776
+ composition->addItem ( gcpSecondFrame );
1752
1777
1753
- gcpTable->setSceneRect ( QRectF ( leftMargin, resPlotItem->rect ().bottom () + resPlotItem->pos ().y () + 5 , contentWidth, 100 ) );
1754
1778
gcpTable->setGridStrokeWidth ( 0.1 );
1779
+ gcpTable->setResizeMode ( QgsComposerMultiFrame::RepeatUntilFinished );
1755
1780
1756
- printer.setResolution ( composition->printResolution () );
1757
- QPainter p ( &printer );
1758
- composition->setPlotStyle ( QgsComposition::Print );
1759
- QRectF paperRectMM = printer.pageRect ( QPrinter::Millimeter );
1760
- QRectF paperRectPixel = printer.pageRect ( QPrinter::DevicePixel );
1761
- composition->render ( &p, paperRectPixel, paperRectMM );
1781
+ composition->exportAsPDF ( fileName );
1762
1782
1763
1783
delete titleLabel;
1764
1784
delete parameterLabel;
1765
1785
delete residualLabel;
1766
1786
delete resPlotItem;
1767
- delete parameterTable;
1768
- delete gcpTable;
1769
1787
delete composerMap;
1770
1788
delete composition;
1771
1789
return true ;
0 commit comments