Skip to content

Commit

Permalink
Remove composer from more code, port georeferencer reports to layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 17, 2018
1 parent 5804745 commit d8402ac
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 147 deletions.
1 change: 0 additions & 1 deletion doc/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion python/CMakeLists.txt
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/app/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -636,7 +635,6 @@ INCLUDE_DIRECTORIES(
../core
../core/annotations
../core/auth
../core/composer
../core/gps
../core/dxf
../core/geometry
Expand Down
1 change: 0 additions & 1 deletion src/app/locator/qgsinbuiltlocatorfilters.cpp
Expand Up @@ -23,7 +23,6 @@
#include "qgisapp.h"
#include "qgsstringutils.h"
#include "qgsmaplayermodel.h"
#include "qgscomposition.h"
#include "qgslayoutmanager.h"
#include "qgsmapcanvas.h"
#include <QToolButton>
Expand Down
1 change: 0 additions & 1 deletion src/core/qgslegendstyle.cpp
Expand Up @@ -16,7 +16,6 @@
***************************************************************************/

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

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/georeferencer/CMakeLists.txt
Expand Up @@ -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
Expand Down
209 changes: 104 additions & 105 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp

Large diffs are not rendered by default.

97 changes: 74 additions & 23 deletions src/plugins/georeferencer/qgsresidualplotitem.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
}
30 changes: 24 additions & 6 deletions src/plugins/georeferencer/qgsresidualplotitem.h
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
1 change: 0 additions & 1 deletion src/server/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/server/services/wcs/CMakeLists.txt
Expand Up @@ -36,7 +36,6 @@ INCLUDE_DIRECTORIES(
../../../core/metadata
../../../core/raster
../../../core/symbology
../../../core/composer
../../../core/layertree
../..
..
Expand Down
1 change: 0 additions & 1 deletion src/server/services/wfs/CMakeLists.txt
Expand Up @@ -46,7 +46,6 @@ INCLUDE_DIRECTORIES(
../../../core/metadata
../../../core/raster
../../../core/symbology
../../../core/composer
../../../core/layertree
../..
..
Expand Down
1 change: 0 additions & 1 deletion src/server/services/wms/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/src/3d/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/src/app/CMakeLists.txt
Expand Up @@ -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
Expand Down

0 comments on commit d8402ac

Please sign in to comment.