Skip to content
Permalink
Browse files

Added GUI for data-defined size legend (single/categorized/graduated …

…renderer)
  • Loading branch information
wonder-sk committed Jun 16, 2017
1 parent 8c4d5bb commit ea8a2c2bf9b1c0af687c69c72ea5bff5175d1933
@@ -2110,6 +2110,7 @@ QgsSingleSymbolRendererWidget {#qgis_api_break_3_0_QgsSingleSymbolRendere

- sizeScaleFieldChanged() and scaleMethodChanged() were removed. These settings are no longer exposed in the widget's GUI.
- The Mode enum was removed.
- changeSingleSymbol() and showSymbolLevels() slots were made private.

QgsSlider {#qgis_api_break_3_0_QgsSlider}
---------
@@ -0,0 +1,178 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsdatadefinedsizelegend.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsDataDefinedSizeLegend
{
%Docstring
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
For example: the list of classes (size values), whether the classes should appear in separate
legend nodes or whether to collapse them into one legend node.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsdatadefinedsizelegend.h"
%End
public:
QgsDataDefinedSizeLegend();

QgsDataDefinedSizeLegend( const QgsDataDefinedSizeLegend &other );

enum LegendType
{
LegendSeparated,
LegendCollapsed,
};

enum VerticalAlignment
{
AlignCenter,
AlignBottom,
};

struct SizeClass
{
SizeClass( double size, const QString &label );

double size; //!< Marker size in units used by the symbol (usually millimeters)
QString label; //!< Label to be shown with the particular symbol size
};

void setLegendType( LegendType type );
%Docstring
Sets how the legend should be rendered
%End
LegendType legendType() const;
%Docstring
Returns how the legend should be rendered
:rtype: LegendType
%End

void setSymbol( QgsMarkerSymbol *symbol /Transfer/ );
%Docstring
Sets marker symbol that will be used to draw markers in legend
%End
QgsMarkerSymbol *symbol() const;
%Docstring
Returns marker symbol that will be used to draw markers in legend
:rtype: QgsMarkerSymbol
%End

void setClasses( const QList<QgsDataDefinedSizeLegend::SizeClass> &classes );
%Docstring
Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label
%End
QList<QgsDataDefinedSizeLegend::SizeClass> classes() const;
%Docstring
Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label
:rtype: list of QgsDataDefinedSizeLegend.SizeClass
%End

void setTitle( const QString &title );
%Docstring
Sets title label for data-defined size legend
%End
QString title() const;
%Docstring
Returns title label for data-defined size legend
:rtype: str
%End

void setVerticalAlignment( VerticalAlignment vAlign );
%Docstring
Sets vertical alignment of symbols - only valid for collapsed legend
%End
VerticalAlignment verticalAlignment() const;
%Docstring
Returns vertical alignment of symbols - only valid for collapsed legend
:rtype: VerticalAlignment
%End

void setFont( const QFont &font );
%Docstring
Sets font used for rendering of labels - only valid for collapsed legend
%End
QFont font() const;
%Docstring
Returns font used for rendering of labels - only valid for collapsed legend
:rtype: QFont
%End

void setTextColor( const QColor &color );
%Docstring
Sets text color for rendering of labels - only valid for collapsed legend
%End
QColor textColor() const;
%Docstring
Returns text color for rendering of labels - only valid for collapsed legend
:rtype: QColor
%End

void setTextAlignment( Qt::AlignmentFlag flag );
%Docstring
Sets horizontal text alignment for rendering of labels - only valid for collapsed legend
%End
Qt::AlignmentFlag textAlignment() const;
%Docstring
Returns horizontal text alignment for rendering of labels - only valid for collapsed legend
:rtype: Qt.AlignmentFlag
%End


void updateFromSymbolAndProperty( const QgsMarkerSymbol *symbol, const QgsProperty &ddSize );
%Docstring
Updates the list of classes, source symbol and title label from given symbol and property
%End

QgsLegendSymbolList legendSymbolList() const;
%Docstring
Generates legend symbol items according to the configuration
:rtype: QgsLegendSymbolList
%End

void drawCollapsedLegend( QgsRenderContext &context, QSize *outputSize /Out/ = 0, int *labelXOffset /Out/ = 0 ) const;
%Docstring
Does nothing if legend is not configured as collapsed.
%End

QImage collapsedLegendImage( QgsRenderContext &context, double paddingMM = 1 ) const;
%Docstring
Returns output image that would be shown in the legend. Returns invalid image if legend is not configured as collapsed.
:rtype: QImage
%End

static QgsDataDefinedSizeLegend *readTypeAndAlignmentFromXml( const QDomElement &elem ) /Factory/;
%Docstring
.. note::

This is a temporary method and may be removed in the future
:rtype: QgsDataDefinedSizeLegend
%End

static void writeTypeAndAlignmentToXml( const QgsDataDefinedSizeLegend &ddsLegend, QDomElement &elem );
%Docstring
.. note::

This is a temporary method and may be removed in the future
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsdatadefinedsizelegend.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -239,6 +239,7 @@
%Include symbology-ng/qgscategorizedsymbolrendererwidget.sip
%Include symbology-ng/qgscptcitycolorrampdialog.sip
%Include symbology-ng/qgsdashspacedialog.sip
%Include symbology-ng/qgsdatadefinedsizelegenddialog.sip
%Include symbology-ng/qgsellipsesymbollayerwidget.sip
%Include symbology-ng/qgsgraduatedhistogramwidget.sip
%Include symbology-ng/qgsgraduatedsymbolrendererwidget.sip
@@ -0,0 +1,57 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/symbology-ng/qgsdatadefinedsizelegenddialog.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsDataDefinedSizeLegendDialog : QDialog
{
%Docstring
Dialog for configuration of appearance of legend for marker symbols with data-defined size.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsdatadefinedsizelegenddialog.h"
%End
public:
explicit QgsDataDefinedSizeLegendDialog( const QgsDataDefinedSizeLegend *ddsLegend, QWidget *parent /TransferThis/ = 0 );
%Docstring
Creates the dialog and initializes the content to what is passed in the legend configuration (may be null)
%End
~QgsDataDefinedSizeLegendDialog();

void setSourceSymbol( QgsMarkerSymbol *symbol /Transfer/ );
%Docstring
Use given symbol for preview. Takes ownership of the symbol. It should have data-defined size enabled + size scale transformer attached.
%End

void setLegendMapViewData( double mapUnitsPerPixel, int dpi, double scale );
%Docstring
Setup map view details to make preview match the expected output
%End

QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const /Factory/;
%Docstring
Returns configuration as set up in the dialog (may be null). Ownership is passed to the caller.
:rtype: QgsDataDefinedSizeLegend
%End

signals:

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/symbology-ng/qgsdatadefinedsizelegenddialog.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -86,6 +86,12 @@ and by connecting the slot contextMenuViewCategories(const QPoint&)*
%End
virtual void refreshSymbolView();

QgsDataDefinedSizeLegend *showDataDefinedSizeLegendDialog( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend, bool *ok /Out/ ) /Factory/;
%Docstring
.. versionadded:: 3.0
:rtype: QgsDataDefinedSizeLegend
%End

protected slots:
void contextMenuViewCategories( QPoint p );
void changeSymbolColor();
@@ -35,13 +35,6 @@ class QgsSingleSymbolRendererWidget : QgsRendererWidget
\param dockMode True to enable dock mode.
%End

public slots:
void changeSingleSymbol();

void showSymbolLevels();

protected:

};


@@ -785,6 +785,11 @@ void QgsDataDefinedSizeLegendNode::cacheImage() const
if ( mImage.isNull() )
{
std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
if ( !context )
{
context.reset( new QgsRenderContext );
context->setScaleFactor( 96 / 25.4 );
}
mImage = mSettings->collapsedLegendImage( *context.get() );
}
}
@@ -28,6 +28,10 @@ QgsDataDefinedSizeLegend::QgsDataDefinedSizeLegend( const QgsDataDefinedSizeLege
, mTitleLabel( other.mTitleLabel )
, mSizeClasses( other.mSizeClasses )
, mSymbol( other.mSymbol.get() ? other.mSymbol->clone() : nullptr )
, mVAlign( other.mVAlign )
, mFont( other.mFont )
, mTextColor( other.mTextColor )
, mTextAlignment( other.mTextAlignment )
{
}

@@ -39,10 +43,24 @@ QgsDataDefinedSizeLegend &QgsDataDefinedSizeLegend::operator=( const QgsDataDefi
mTitleLabel = other.mTitleLabel;
mSizeClasses = other.mSizeClasses;
mSymbol.reset( other.mSymbol.get() ? other.mSymbol->clone() : nullptr );
mVAlign = other.mVAlign;
mFont = other.mFont;
mTextColor = other.mTextColor;
mTextAlignment = other.mTextAlignment;
}
return *this;
}

void QgsDataDefinedSizeLegend::setSymbol( QgsMarkerSymbol *symbol )
{
mSymbol.reset( symbol );
}

QgsMarkerSymbol *QgsDataDefinedSizeLegend::symbol() const
{
return mSymbol.get();
}


void QgsDataDefinedSizeLegend::updateFromSymbolAndProperty( const QgsMarkerSymbol *symbol, const QgsProperty &ddSize )
{
@@ -1,5 +1,5 @@
/***************************************************************************
qgsdatadefinedsizelegend.cpp
qgsdatadefinedsizelegend.h
--------------------------------------
Date : June 2017
Copyright : (C) 2017 by Martin Dobias
@@ -71,9 +71,9 @@ class CORE_EXPORT QgsDataDefinedSizeLegend
LegendType legendType() const { return mType; }

//! Sets marker symbol that will be used to draw markers in legend
void setSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER ) { mSymbol.reset( symbol ); }
void setSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
//! Returns marker symbol that will be used to draw markers in legend
QgsMarkerSymbol *symbol() const { return mSymbol.get(); }
QgsMarkerSymbol *symbol() const;

//! Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label
void setClasses( const QList<QgsDataDefinedSizeLegend::SizeClass> &classes ) { mSizeClasses = classes; }
@@ -471,6 +471,7 @@ QgsCategorizedSymbolRenderer *QgsCategorizedSymbolRenderer::clone() const
r->setSourceColorRamp( mSourceColorRamp->clone() );
}
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setDataDefinedSizeLegend( mDataDefinedSizeLegend ? new QgsDataDefinedSizeLegend( *mDataDefinedSizeLegend ) : nullptr );

copyRendererData( r );
return r;
@@ -504,6 +504,7 @@ QgsGraduatedSymbolRenderer *QgsGraduatedSymbolRenderer::clone() const
r->setSourceColorRamp( mSourceColorRamp->clone() );
}
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setDataDefinedSizeLegend( mDataDefinedSizeLegend ? new QgsDataDefinedSizeLegend( *mDataDefinedSizeLegend ) : nullptr );
r->setLabelFormat( labelFormat() );
r->setGraduatedMethod( graduatedMethod() );
copyRendererData( r );
@@ -100,6 +100,7 @@ QgsSingleSymbolRenderer *QgsSingleSymbolRenderer::clone() const
{
QgsSingleSymbolRenderer *r = new QgsSingleSymbolRenderer( mSymbol->clone() );
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setDataDefinedSizeLegend( mDataDefinedSizeLegend ? new QgsDataDefinedSizeLegend( *mDataDefinedSizeLegend ) : nullptr );
copyRendererData( r );
return r;
}
@@ -298,7 +299,6 @@ QDomElement QgsSingleSymbolRenderer::save( QDomDocument &doc, const QgsReadWrite

QgsLegendSymbolList QgsSingleSymbolRenderer::legendSymbolItems() const
{
QgsLegendSymbolList lst;
if ( mDataDefinedSizeLegend && mSymbol->type() == QgsSymbol::Marker )
{
const QgsMarkerSymbol *symbol = static_cast<const QgsMarkerSymbol *>( mSymbol.get() );
@@ -307,10 +307,11 @@ QgsLegendSymbolList QgsSingleSymbolRenderer::legendSymbolItems() const
{
QgsDataDefinedSizeLegend ddSizeLegend( *mDataDefinedSizeLegend );
ddSizeLegend.updateFromSymbolAndProperty( static_cast<const QgsMarkerSymbol *>( mSymbol.get() ), sizeDD );
lst += ddSizeLegend.legendSymbolList();
return ddSizeLegend.legendSymbolList();
}
}

QgsLegendSymbolList lst;
lst << QgsLegendSymbolItem( mSymbol.get(), QString(), QString() );
return lst;
}

0 comments on commit ea8a2c2

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