Skip to content
Permalink
Browse files

Merge pull request #4073 from nyalldawson/annotations

Refactor annotations, add new annotation features + some other exciting stuff
  • Loading branch information
nyalldawson committed Jan 30, 2017
2 parents 50319b1 + 1f7758a commit 61d3147261729562a8d481382b3900845c0064a2
Showing with 4,610 additions and 2,671 deletions.
  1. +1 −0 doc/CMakeLists.txt
  2. +1 −0 python/CMakeLists.txt
  3. +84 −0 python/core/annotations/qgsannotation.sip
  4. +24 −0 python/core/annotations/qgsannotationmanager.sip
  5. +28 −0 python/core/annotations/qgshtmlannotation.sip
  6. +22 −0 python/core/annotations/qgssvgannotation.sip
  7. +22 −0 python/core/annotations/qgstextannotation.sip
  8. +2 −5 python/core/composer/qgscomposermap.sip
  9. +11 −1 python/core/composer/qgscomposerutils.sip
  10. +7 −1 python/core/core.sip
  11. +0 −63 python/core/qgsannotation.sip
  12. +47 −0 python/core/qgsmargins.sip
  13. +2 −0 python/core/qgsproject.sip
  14. +7 −7 python/core/symbology-ng/qgsfillsymbollayer.sip
  15. +2 −2 python/core/symbology-ng/qgslinesymbollayer.sip
  16. +1 −1 python/core/symbology-ng/qgsmarkersymbollayer.sip
  17. +3 −0 python/core/symbology-ng/qgssymbol.sip
  18. +1 −1 python/core/symbology-ng/qgssymbollayer.sip
  19. +1 −1 python/core/symbology-ng/qgssymbollayerutils.sip
  20. +2 −5 python/gui/gui.sip
  21. +0 −132 python/gui/qgsannotationitem.sip
  22. +27 −0 python/gui/qgsformannotation.sip
  23. +0 −30 python/gui/qgsformannotationitem.sip
  24. +0 −27 python/gui/qgshtmlannotationitem.sip
  25. +46 −0 python/gui/qgsmapcanvasannotationitem.sip
  26. +0 −18 python/gui/qgssvgannotationitem.sip
  27. +0 −19 python/gui/qgstextannotationitem.sip
  28. +4 −1 scripts/parse_dash_results.py
  29. +1 −0 src/app/CMakeLists.txt
  30. +0 −1 src/app/composer/qgscomposer.cpp
  31. +2 −2 src/app/composer/qgscomposermapwidget.cpp
  32. +25 −82 src/app/qgisapp.cpp
  33. +5 −6 src/app/qgisapp.h
  34. +68 −28 src/app/qgsannotationwidget.cpp
  35. +8 −4 src/app/qgsannotationwidget.h
  36. +16 −15 src/app/qgsformannotationdialog.cpp
  37. +4 −4 src/app/qgsformannotationdialog.h
  38. +15 −20 src/app/qgshtmlannotationdialog.cpp
  39. +4 −4 src/app/qgshtmlannotationdialog.h
  40. +136 −84 src/app/qgsmaptoolannotation.cpp
  41. +17 −9 src/app/qgsmaptoolannotation.h
  42. +3 −19 src/app/qgsmaptoolformannotation.cpp
  43. +1 −1 src/app/qgsmaptoolformannotation.h
  44. +3 −19 src/app/qgsmaptoolhtmlannotation.cpp
  45. +1 −1 src/app/qgsmaptoolhtmlannotation.h
  46. +3 −8 src/app/qgsmaptoolsvgannotation.cpp
  47. +1 −1 src/app/qgsmaptoolsvgannotation.h
  48. +3 −9 src/app/qgsmaptooltextannotation.cpp
  49. +1 −1 src/app/qgsmaptooltextannotation.h
  50. +22 −16 src/app/qgssvgannotationdialog.cpp
  51. +4 −4 src/app/qgssvgannotationdialog.h
  52. +26 −27 src/app/qgstextannotationdialog.cpp
  53. +5 −6 src/app/qgstextannotationdialog.h
  54. +17 −1 src/core/CMakeLists.txt
  55. +433 −0 src/core/annotations/qgsannotation.cpp
  56. +359 −0 src/core/annotations/qgsannotation.h
  57. +150 −0 src/core/annotations/qgsannotationmanager.cpp
  58. +118 −0 src/core/annotations/qgsannotationmanager.h
  59. +129 −0 src/core/annotations/qgsannotationregistry.h
  60. +154 −0 src/core/annotations/qgshtmlannotation.cpp
  61. +86 −0 src/core/annotations/qgshtmlannotation.h
  62. +21 −34 src/{gui/qgssvgannotationitem.cpp → core/annotations/qgssvgannotation.cpp}
  63. +71 −0 src/core/annotations/qgssvgannotation.h
  64. +24 −49 src/{gui/qgstextannotationitem.cpp → core/annotations/qgstextannotation.cpp}
  65. +72 −0 src/core/annotations/qgstextannotation.h
  66. +1 −1 src/core/composer/qgscomposerarrow.cpp
  67. +36 −42 src/core/composer/qgscomposermap.cpp
  68. +14 −9 src/core/composer/qgscomposermap.h
  69. +2 −2 src/core/composer/qgscomposermapgrid.cpp
  70. +1 −1 src/core/composer/qgscomposermapoverview.cpp
  71. +2 −2 src/core/composer/qgscomposernodesitem.cpp
  72. +1 −1 src/core/composer/qgscomposerpolygon.cpp
  73. +1 −1 src/core/composer/qgscomposerpolyline.cpp
  74. +7 −3 src/core/composer/qgscomposershape.cpp
  75. +30 −8 src/core/composer/qgscomposerutils.cpp
  76. +11 −1 src/core/composer/qgscomposerutils.h
  77. +7 −3 src/core/composer/qgspaperitem.cpp
  78. +21 −21 src/core/pal/feature.cpp
  79. +0 −90 src/core/qgsannotation.h
  80. +8 −0 src/core/qgsapplication.cpp
  81. +9 −0 src/core/qgsapplication.h
  82. +4 −49 src/core/qgslabelfeature.h
  83. +37 −0 src/core/qgsmargins.cpp
  84. +323 −0 src/core/qgsmargins.h
  85. +1 −1 src/core/qgspallabeling.cpp
  86. +13 −0 src/core/qgsproject.cpp
  87. +9 −0 src/core/qgsproject.h
  88. +14 −21 src/core/symbology-ng/qgsfillsymbollayer.cpp
  89. +7 −7 src/core/symbology-ng/qgsfillsymbollayer.h
  90. +8 −6 src/core/symbology-ng/qgslinesymbollayer.cpp
  91. +2 −2 src/core/symbology-ng/qgslinesymbollayer.h
  92. +2 −2 src/core/symbology-ng/qgsmarkersymbollayer.cpp
  93. +1 −1 src/core/symbology-ng/qgsmarkersymbollayer.h
  94. +2 −0 src/core/symbology-ng/qgssymbol.cpp
  95. +18 −0 src/core/symbology-ng/qgssymbol.h
  96. +3 −2 src/core/symbology-ng/qgssymbollayer.h
  97. +2 −2 src/core/symbology-ng/qgssymbollayerutils.cpp
  98. +1 −1 src/core/symbology-ng/qgssymbollayerutils.h
  99. +5 −10 src/gui/CMakeLists.txt
  100. +0 −508 src/gui/qgsannotationitem.cpp
  101. +0 −188 src/gui/qgsannotationitem.h
  102. +185 −0 src/gui/qgsformannotation.cpp
  103. +82 −0 src/gui/qgsformannotation.h
  104. +0 −283 src/gui/qgsformannotationitem.cpp
  105. +0 −74 src/gui/qgsformannotationitem.h
  106. +0 −251 src/gui/qgshtmlannotationitem.cpp
  107. +0 −78 src/gui/qgshtmlannotationitem.h
  108. +2 −1 src/gui/qgsmapcanvas.cpp
  109. +289 −0 src/gui/qgsmapcanvasannotationitem.cpp
  110. +109 −0 src/gui/qgsmapcanvasannotationitem.h
  111. +0 −47 src/gui/qgssvgannotationitem.h
  112. +0 −47 src/gui/qgstextannotationitem.h
  113. +0 −1 src/plugins/georeferencer/qgsgeorefplugingui.cpp
  114. +197 −96 src/ui/qgsannotationwidgetbase.ui
  115. +31 −31 src/ui/qgsoptionsbase.ui
  116. +1 −0 tests/src/core/CMakeLists.txt
  117. +60 −8 tests/src/core/testqgscomposerutils.cpp
  118. +5 −0 tests/src/python/CMakeLists.txt
  119. +176 −0 tests/src/python/test_qgsannotation.py
  120. +94 −0 tests/src/python/test_qgsfillsymbollayers.py
  121. +94 −0 tests/src/python/test_qgslinesymbollayers.py
  122. +165 −0 tests/src/python/test_qgsmapcanvasannotationitem.py
  123. +123 −0 tests/src/python/test_qgsmargins.py
  124. BIN ...stdata/control_images/annotations/expected_annotation_fillstyle/expected_annotation_fillstyle.png
  125. BIN ...s/testdata/control_images/annotations/expected_annotation_margins/expected_annotation_margins.png
  126. BIN tests/testdata/control_images/annotations/expected_html_annotation/expected_html_annotation.png
  127. BIN tests/testdata/control_images/annotations/expected_html_feature/default/expected_html_feature.png
  128. BIN tests/testdata/control_images/annotations/expected_html_feature/travis/expected_html_feature.png
  129. BIN ...s/testdata/control_images/annotations/expected_html_nofeature/default/expected_html_nofeature.png
  130. BIN tests/testdata/control_images/annotations/expected_html_nofeature/travis/expected_html_nofeature.png
  131. BIN tests/testdata/control_images/annotations/expected_relative_style/expected_relative_style.png
  132. BIN tests/testdata/control_images/annotations/expected_svg_annotation/expected_svg_annotation.png
  133. BIN tests/testdata/control_images/annotations/expected_svg_annotation/expected_svg_annotation_mask.png
  134. BIN ...testdata/control_images/annotations/expected_text_annotation/default/expected_text_annotation.png
  135. BIN .../testdata/control_images/annotations/expected_text_annotation/travis/expected_text_annotation.png
  136. BIN ...a/control_images/symbol_layer/expected_fill_simpleline_offset/expected_fill_simpleline_offset.png
  137. BIN tests/testdata/control_images/symbol_layer/expected_simpleline_offset/expected_simpleline_offset.png
  138. +41 −0 tests/testdata/test_html_feature.html
@@ -48,6 +48,7 @@ IF(WITH_APIDOC)
SET(DOXYGEN_INPUT
${CMAKE_SOURCE_DIR}/doc
${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/diagram
@@ -93,6 +93,7 @@ INCLUDE_DIRECTORIES(SYSTEM
)
INCLUDE_DIRECTORIES(
../src/core
../src/core/annotations
../src/core/auth
../src/core/pal
../src/core/composer
@@ -0,0 +1,84 @@
%ModuleHeaderCode
#include <qgshtmlannotation.h>
#include <qgssvgannotation.h>
#include <qgstextannotation.h>
%End

class QgsAnnotation : QObject
{
%TypeHeaderCode
#include <qgsannotation.h>
%End

%ConvertToSubClassCode
if ( dynamic_cast< QgsTextAnnotation* > ( sipCpp ) )
sipType = sipType_QgsTextAnnotation;
else if ( dynamic_cast< QgsSvgAnnotation* > ( sipCpp ) )
sipType = sipType_QgsSvgAnnotation;
else if ( dynamic_cast< QgsHtmlAnnotation* > ( sipCpp ) )
sipType = sipType_QgsHtmlAnnotation;
else
sipType = NULL;
%End

public:

QgsAnnotation( QObject* parent /TransferThis/ = nullptr );

bool isVisible() const;
void setVisible( bool visible );

bool hasFixedMapPosition() const;
void setHasFixedMapPosition( bool fixed );

QgsPoint mapPosition() const;
void setMapPosition( const QgsPoint& position );

QgsCoordinateReferenceSystem mapPositionCrs() const;
void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );

QPointF relativePosition() const;
void setRelativePosition( QPointF position );

void setFrameOffsetFromReferencePoint( QPointF offset );
QPointF frameOffsetFromReferencePoint() const;

void setFrameSize( QSizeF size );
QSizeF frameSize() const;

void setContentsMargin( const QgsMargins& margins );
QgsMargins contentsMargin() const;

void setFillSymbol( QgsFillSymbol* symbol /Transfer/ );
QgsFillSymbol* fillSymbol() const;

void render( QgsRenderContext& context ) const;

virtual void writeXml( QDomElement& elem, QDomDocument & doc ) const = 0;
virtual void readXml( const QDomElement& itemElem, const QDomDocument& doc ) = 0;

void setMarkerSymbol( QgsMarkerSymbol* symbol /Transfer/ );
QgsMarkerSymbol* markerSymbol() const;

QgsMapLayer* mapLayer() const;
void setMapLayer( QgsMapLayer* layer );

QgsFeature associatedFeature() const;
virtual void setAssociatedFeature( const QgsFeature& feature );

signals:

void appearanceChanged();
void moved();
void mapLayerChanged();

protected:

virtual void renderAnnotation( QgsRenderContext& context, QSizeF size ) const = 0;

virtual QSizeF minimumFrameSize() const;

void _writeXml( QDomElement& itemElem, QDomDocument& doc ) const;
void _readXml( const QDomElement& annotationElem, const QDomDocument& doc );

};
@@ -0,0 +1,24 @@
class QgsAnnotationManager : QObject
{
%TypeHeaderCode
#include <qgsannotationmanager.h>
%End
public:

explicit QgsAnnotationManager( QgsProject* project = nullptr );
~QgsAnnotationManager();

bool addAnnotation( QgsAnnotation* annotation /Transfer/ );
bool removeAnnotation( QgsAnnotation* annotation );
void clear();
QList< QgsAnnotation* > annotations() const;
bool readXml( const QDomElement& element, const QDomDocument& doc );
QDomElement writeXml( QDomDocument& doc ) const;

signals:

void annotationAdded( QgsAnnotation* annotation );
void annotationRemoved();
void annotationAboutToBeRemoved( QgsAnnotation* annotation );

};
@@ -0,0 +1,28 @@
class QgsHtmlAnnotation : QgsAnnotation
{
%TypeHeaderCode
#include <qgshtmlannotation.h>
%End
public:

QgsHtmlAnnotation( QObject* parent /TransferThis/ = nullptr );

~QgsHtmlAnnotation();

QSizeF minimumFrameSize() const;

void setSourceFile( const QString& htmlFile );
QString sourceFile() const;

virtual void writeXml( QDomElement& elem, QDomDocument & doc ) const;
virtual void readXml( const QDomElement& itemElem, const QDomDocument& doc );

virtual void setAssociatedFeature( const QgsFeature& feature );

static QgsHtmlAnnotation* create() /Factory/;

protected:

void renderAnnotation( QgsRenderContext& context, QSizeF size ) const;

};
@@ -0,0 +1,22 @@
class QgsSvgAnnotation : QgsAnnotation
{
%TypeHeaderCode
#include <qgssvgannotation.h>
%End
public:

QgsSvgAnnotation( QObject* parent /TransferThis/ = nullptr );

virtual void writeXml( QDomElement& elem, QDomDocument & doc ) const;
virtual void readXml( const QDomElement& itemElem, const QDomDocument& doc );

void setFilePath( const QString& file );
QString filePath() const;

static QgsSvgAnnotation* create() /Factory/;

protected:

void renderAnnotation( QgsRenderContext& context, QSizeF size ) const;

};
@@ -0,0 +1,22 @@
class QgsTextAnnotation : QgsAnnotation
{
%TypeHeaderCode
#include <qgstextannotation.h>
%End
public:

QgsTextAnnotation( QObject* parent /TransferThis/ = nullptr );

const QTextDocument* document() const;
void setDocument( const QTextDocument* doc );

virtual void writeXml( QDomElement& elem, QDomDocument & doc ) const;
virtual void readXml( const QDomElement& itemElem, const QDomDocument& doc );

static QgsTextAnnotation* create() /Factory/;

protected:

void renderAnnotation( QgsRenderContext& context, QSizeF size ) const;

};
@@ -255,11 +255,8 @@ class QgsComposerMap : QgsComposerItem

void updateItem();

/** Sets canvas pointer (necessary to query and draw map canvas items)*/
void setMapCanvas( QGraphicsView* canvas /Transfer/ );

void setDrawCanvasItems( bool b );
bool drawCanvasItems() const;
void setDrawAnnotations( bool draw );
bool drawAnnotations() const;

/** Returns the conversion factor map units -> mm*/
double mapUnitsToMM() const;
@@ -222,11 +222,21 @@ class QgsComposerUtils
*/
static void drawText( QPainter* painter, const QRectF& rect, const QString& text, const QFont& font, const QColor& color = QColor(), const Qt::AlignmentFlag halignment = Qt::AlignLeft, const Qt::AlignmentFlag valignment = Qt::AlignTop, const int flags = Qt::TextWordWrap );

/**
* Creates a render context suitable for the specified composer map and QPainter destination.
* This method returns a new QgsRenderContext which matches the scale and settings of the
* target map.
* @note added in QGIS 3.0
* @see createRenderContextForComposition()
*/
static QgsRenderContext createRenderContextForMap( QgsComposerMap* map, QPainter* painter );

/**
* Creates a render context suitable for the specified composition and QPainter destination.
* This method returns a new QgsRenderContext which matches the scale and settings from the composition's
* QgsComposition::referenceMap().
* @note added in QGIS 3.0
* @see createRenderContextForMap()
*/
static QgsRenderContext createRenderContext( QgsComposition* composition, QPainter* painter );
static QgsRenderContext createRenderContextForComposition( QgsComposition* composition, QPainter* painter );
};
@@ -13,7 +13,6 @@

%Include qgis.sip

%Include qgsannotation.sip
%Include qgsapplication.sip
%Include qgsaction.sip
%Include qgsactionmanager.sip
@@ -94,6 +93,7 @@
%Include qgsmapsettings.sip
%Include qgsmaptopixel.sip
%Include qgsmapunitscale.sip
%Include qgsmargins.sip
%Include qgsmessagelog.sip
%Include qgsmessageoutput.sip
%Include qgsmimedatautils.sip
@@ -174,6 +174,12 @@
%Include qgsmapthemecollection.sip
%Include qgsxmlutils.sip

%Include annotations/qgsannotation.sip
%Include annotations/qgsannotationmanager.sip
%Include annotations/qgshtmlannotation.sip
%Include annotations/qgssvgannotation.sip
%Include annotations/qgstextannotation.sip

%Include auth/qgsauthcertutils.sip
%Include auth/qgsauthconfig.sip
// %Include auth/qgsauthcrypto.sip

This file was deleted.

@@ -0,0 +1,47 @@
class QgsMargins
{
%TypeHeaderCode
#include <qgsmargins.h>
%End

public:

QgsMargins();
QgsMargins( double left, double top, double right, double bottom );

bool isNull() const;

double left() const;
double top() const;
double right() const;
double bottom() const;

void setLeft( double left );
void setTop( double top );
void setRight( double right );
void setBottom( double bottom );

QgsMargins &operator+=( const QgsMargins &margins );
QgsMargins &operator-=( const QgsMargins &margins );
QgsMargins &operator+=( double addend );
QgsMargins &operator-=( double subtrahend );
QgsMargins &operator*=( double factor );
QgsMargins &operator/=( double divisor );

QString toString() const;
static QgsMargins fromString( const QString& string );
};

bool operator==( const QgsMargins &lhs, const QgsMargins &rhs );
bool operator!=( const QgsMargins &lhs, const QgsMargins &rhs );
QgsMargins operator+( const QgsMargins &m1, const QgsMargins &m2 );
QgsMargins operator-( const QgsMargins &m1, const QgsMargins &m2 );
QgsMargins operator+( const QgsMargins &lhs, double rhs );
QgsMargins operator+( double lhs, const QgsMargins &rhs );
QgsMargins operator-( const QgsMargins &lhs, double rhs );
QgsMargins operator*( const QgsMargins &margins, double factor );
QgsMargins operator*( double factor, const QgsMargins &margins );
QgsMargins operator/( const QgsMargins &margins, double divisor );
QgsMargins operator+( const QgsMargins &margins );
QgsMargins operator-( const QgsMargins &margins );

@@ -325,6 +325,8 @@ class QgsProject : QObject, QgsExpressionContextGenerator
*/
QgsMapThemeCollection* mapThemeCollection();

QgsAnnotationManager* annotationManager();

/**
* Set a list of layers which should not be taken into account on map identification
*/

0 comments on commit 61d3147

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