Skip to content
Permalink
Browse files

Remove composer from more code, port georeferencer reports to layouts

  • Loading branch information
nyalldawson committed Jan 17, 2018
1 parent 5804745 commit d8402acee86556916c4ee29d75073844d0cfab61
@@ -56,7 +56,6 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/core/3d
${CMAKE_SOURCE_DIR}/src/core/annotations
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/diagram
${CMAKE_SOURCE_DIR}/src/core/dxf
${CMAKE_SOURCE_DIR}/src/core/effects
@@ -107,7 +107,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/pal
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/diagram
${CMAKE_SOURCE_DIR}/src/core/effects
${CMAKE_SOURCE_DIR}/src/core/fieldformatter
@@ -576,7 +576,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/annotations
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/gps
${CMAKE_SOURCE_DIR}/src/core/dxf
@@ -636,7 +635,6 @@ INCLUDE_DIRECTORIES(
../core
../core/annotations
../core/auth
../core/composer
../core/gps
../core/dxf
../core/geometry
@@ -23,7 +23,6 @@
#include "qgisapp.h"
#include "qgsstringutils.h"
#include "qgsmaplayermodel.h"
#include "qgscomposition.h"
#include "qgslayoutmanager.h"
#include "qgsmapcanvas.h"
#include <QToolButton>
@@ -16,7 +16,6 @@
***************************************************************************/

#include "qgslegendstyle.h"
#include "qgscomposition.h"
#include "qgsfontutils.h"
#include "qgssettings.h"

@@ -79,7 +79,8 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
${CMAKE_SOURCE_DIR}/src/gui/layertree

Large diffs are not rendered by default.

@@ -15,16 +15,16 @@

#include "qgsresidualplotitem.h"
#include "qgsgeorefdatapoint.h"
#include "qgscomposerutils.h"
#include "qgslayoututils.h"
#include <QPainter>
#include <cfloat>
#include <cmath>

QgsResidualPlotItem::QgsResidualPlotItem( QgsComposition *c )
: QgsComposerItem( c )
QgsResidualPlotItem::QgsResidualPlotItem( QgsLayout *layout )
: QgsLayoutItem( layout )
, mConvertScaleToMapUnits( false )
{

setBackgroundEnabled( false );
}

void QgsResidualPlotItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
@@ -68,7 +68,7 @@ void QgsResidualPlotItem::paint( QPainter *painter, const QStyleOptionGraphicsIt
painter->setBrush( disabledBrush );
}
painter->drawRect( QRectF( gcpItemMMX - 0.5, gcpItemMMY - 0.5, 1, 1 ) );
QgsComposerUtils::drawText( painter, QPointF( gcpItemMMX + 2, gcpItemMMY + 2 ), QString::number( ( *gcpIt )->id() ), QFont() );
QgsLayoutUtils::drawText( painter, QPointF( gcpItemMMX + 2, gcpItemMMY + 2 ), QString::number( ( *gcpIt )->id() ), QFont() );

mmPixelRatio = maxMMToPixelRatioForGCP( *gcpIt, gcpItemMMX, gcpItemMMY );
if ( mmPixelRatio < minMMPixelRatio )
@@ -97,7 +97,7 @@ void QgsResidualPlotItem::paint( QPainter *painter, const QStyleOptionGraphicsIt
QPointF p2( gcpItemMMX + ( *gcpIt )->residual().x() * minMMPixelRatio, gcpItemMMY + ( *gcpIt )->residual().y() * minMMPixelRatio );
painter->drawLine( p1, p2 );
painter->setBrush( QBrush( painter->pen().color() ) );
QgsComposerUtils::drawArrowHead( painter, p2.x(), p2.y(), QgsComposerUtils::angle( p1, p2 ), 1 );
drawArrowHead( painter, p2.x(), p2.y(), angle( p1, p2 ), 1 );
}

//draw scale bar
@@ -132,20 +132,29 @@ void QgsResidualPlotItem::paint( QPainter *painter, const QStyleOptionGraphicsIt
scaleBarFont.setPointSize( 9 );
if ( mConvertScaleToMapUnits )
{
QgsComposerUtils::drawText( painter, QPointF( 5, rect().height() - 4 + QgsComposerUtils::fontAscentMM( scaleBarFont ) ), QStringLiteral( "%1 map units" ).arg( scaleBarWidthUnits ), QFont() );
QgsLayoutUtils::drawText( painter, QPointF( 5, rect().height() - 4 + QgsLayoutUtils::fontAscentMM( scaleBarFont ) ), QStringLiteral( "%1 map units" ).arg( scaleBarWidthUnits ), QFont() );
}
else
{
QgsComposerUtils::drawText( painter, QPointF( 5, rect().height() - 4 + QgsComposerUtils::fontAscentMM( scaleBarFont ) ), QStringLiteral( "%1 pixels" ).arg( scaleBarWidthUnits ), QFont() );
QgsLayoutUtils::drawText( painter, QPointF( 5, rect().height() - 4 + QgsLayoutUtils::fontAscentMM( scaleBarFont ) ), QStringLiteral( "%1 pixels" ).arg( scaleBarWidthUnits ), QFont() );
}

drawFrame( painter );
if ( isSelected() )
if ( frameEnabled() )
{
drawSelectionBoxes( painter );
painter->save();
painter->setPen( pen() );
painter->setBrush( Qt::NoBrush );
painter->setRenderHint( QPainter::Antialiasing, true );
painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
painter->restore();
}
}

void QgsResidualPlotItem::draw( QgsRenderContext &, const QStyleOptionGraphicsItem * )
{

}

double QgsResidualPlotItem::maxMMToPixelRatioForGCP( const QgsGeorefDataPoint *p, double pixelXMM, double pixelYMM )
{
if ( !p )
@@ -207,23 +216,65 @@ double QgsResidualPlotItem::maxMMToPixelRatioForGCP( const QgsGeorefDataPoint *p
}
}

bool QgsResidualPlotItem::writeXml( QDomElement &elem, QDomDocument &doc ) const
double QgsResidualPlotItem::dist( QPointF p1, QPointF p2 ) const
{
Q_UNUSED( elem );
Q_UNUSED( doc );
return false;
double dx = p2.x() - p1.x();
double dy = p2.y() - p1.y();
return std::sqrt( dx * dx + dy * dy );
}

bool QgsResidualPlotItem::readXml( const QDomElement &itemElem, const QDomDocument &doc )
void QgsResidualPlotItem::drawArrowHead( QPainter *p, const double x, const double y, const double angle, const double arrowHeadWidth )
{
Q_UNUSED( itemElem );
Q_UNUSED( doc );
return false;
if ( !p )
{
return;
}

double angleRad = angle / 180.0 * M_PI;
QPointF middlePoint( x, y );
//rotate both arrow points
QPointF p1 = QPointF( -arrowHeadWidth / 2.0, arrowHeadWidth );
QPointF p2 = QPointF( arrowHeadWidth / 2.0, arrowHeadWidth );

QPointF p1Rotated, p2Rotated;
p1Rotated.setX( p1.x() * std::cos( angleRad ) + p1.y() * -std::sin( angleRad ) );
p1Rotated.setY( p1.x() * std::sin( angleRad ) + p1.y() * std::cos( angleRad ) );
p2Rotated.setX( p2.x() * std::cos( angleRad ) + p2.y() * -std::sin( angleRad ) );
p2Rotated.setY( p2.x() * std::sin( angleRad ) + p2.y() * std::cos( angleRad ) );

QPolygonF arrowHeadPoly;
arrowHeadPoly << middlePoint;
arrowHeadPoly << QPointF( middlePoint.x() + p1Rotated.x(), middlePoint.y() + p1Rotated.y() );
arrowHeadPoly << QPointF( middlePoint.x() + p2Rotated.x(), middlePoint.y() + p2Rotated.y() );

p->save();

QPen arrowPen = p->pen();
arrowPen.setJoinStyle( Qt::RoundJoin );
QBrush arrowBrush = p->brush();
arrowBrush.setStyle( Qt::SolidPattern );
p->setPen( arrowPen );
p->setBrush( arrowBrush );
arrowBrush.setStyle( Qt::SolidPattern );
p->drawPolygon( arrowHeadPoly );

p->restore();
}

double QgsResidualPlotItem::dist( QPointF p1, QPointF p2 ) const
double QgsResidualPlotItem::angle( QPointF p1, QPointF p2 )
{
double dx = p2.x() - p1.x();
double dy = p2.y() - p1.y();
return std::sqrt( dx * dx + dy * dy );
double xDiff = p2.x() - p1.x();
double yDiff = p2.y() - p1.y();
double length = std::sqrt( xDiff * xDiff + yDiff * yDiff );
if ( length <= 0 )
{
return 0;
}

double angle = std::acos( ( -yDiff * length ) / ( length * length ) ) * 180 / M_PI;
if ( xDiff < 0 )
{
return ( 360 - angle );
}
return angle;
}
@@ -16,19 +16,19 @@
#ifndef QGSRESIDUALPLOTITEM_H
#define QGSRESIDUALPLOTITEM_H

#include "qgscomposeritem.h"
#include "qgslayoutitem.h"
#include "qgsgcplist.h"
#include "qgsrectangle.h"

/**
* A composer item to visualise the distribution of georeference residuals. For the visualisation,
the length of the residual arrows are scaled*/
class QgsResidualPlotItem: public QgsComposerItem
class QgsResidualPlotItem: public QgsLayoutItem
{
Q_OBJECT

public:
explicit QgsResidualPlotItem( QgsComposition *c );
explicit QgsResidualPlotItem( QgsLayout *layout );

//! \brief Reimplementation of QCanvasItem::paint
void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
@@ -42,9 +42,7 @@ class QgsResidualPlotItem: public QgsComposerItem
void setConvertScaleToMapUnits( bool convert ) { mConvertScaleToMapUnits = convert; }
bool convertScaleToMapUnits() const { return mConvertScaleToMapUnits; }

bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;

void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) override;
private:
//gcp list
QgsGCPList mGCPList;
@@ -58,6 +56,26 @@ class QgsResidualPlotItem: public QgsComposerItem

//! Returns distance between two points
double dist( QPointF p1, QPointF p2 ) const;

/**
* Draws an arrow head on to a QPainter.
* \param p destination painter
* \param x x-coordinate of arrow center
* \param y y-coordinate of arrow center
* \param angle angle in degrees which arrow should point toward, measured
* clockwise from pointing vertical upward
* \param arrowHeadWidth size of arrow head
*/
static void drawArrowHead( QPainter *p, const double x, const double y, const double angle, const double arrowHeadWidth );

/**
* Calculates the angle of the line from p1 to p2 (counter clockwise,
* starting from a line from north to south)
* \param p1 start point of line
* \param p2 end point of line
* \returns angle in degrees, clockwise from south
*/
static double angle( QPointF p1, QPointF p2 );
};

#endif // QGSRESIDUALPLOTITEM_H
@@ -110,7 +110,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/layertree
${CMAKE_SOURCE_DIR}/src/analysis/interpolation
@@ -36,7 +36,6 @@ INCLUDE_DIRECTORIES(
../../../core/metadata
../../../core/raster
../../../core/symbology
../../../core/composer
../../../core/layertree
../..
..
@@ -46,7 +46,6 @@ INCLUDE_DIRECTORIES(
../../../core/metadata
../../../core/raster
../../../core/symbology
../../../core/composer
../../../core/layertree
../..
..
@@ -51,7 +51,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/layertree
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/gui
@@ -13,7 +13,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/metadata
@@ -5,7 +5,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/layout

0 comments on commit d8402ac

Please sign in to comment.
You can’t perform that action at this time.