Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[diagram] add unit type setting for outlines (fixes #14614)
  • Loading branch information
nirvn committed Apr 5, 2016
1 parent ca642e4 commit 31d7be4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsdiagramrendererv2.sip
Expand Up @@ -290,6 +290,14 @@ class QgsDiagramSettings
QList< QString > categoryLabels;
QSizeF size; //size
SizeType sizeType; //mm or map units
/** Line unit index (mm, map units, or pixels)
* @note added in 2.16
*/
QgsSymbolV2::OutputUnit lineSizeType;
/** Line unit scale
* @note added in 2.16
*/
QgsMapUnitScale lineSizeScale;
QColor backgroundColor;
QColor penColor;
double penWidth;
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -86,6 +86,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare

mDiagramUnitComboBox->insertItem( 0, tr( "mm" ), QgsDiagramSettings::MM );
mDiagramUnitComboBox->insertItem( 1, tr( "Map units" ), QgsDiagramSettings::MapUnits );
mDiagramLineUnitComboBox->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );

QGis::GeometryType layerType = layer->geometryType();
if ( layerType == QGis::UnknownGeometry || layerType == QGis::NoGeometry )
Expand Down Expand Up @@ -193,6 +194,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mDiagramFrame->setEnabled( false );
mFixedSizeRadio->setChecked( true );
mDiagramUnitComboBox->setCurrentIndex( mDiagramUnitComboBox->findText( tr( "mm" ) ) );
mDiagramLineUnitComboBox->setUnit( QgsSymbolV2::MM );
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "x-height" ) ) );
mDiagramSizeSpinBox->setEnabled( true );
mDiagramSizeSpinBox->setValue( 15 );
Expand Down Expand Up @@ -271,6 +273,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
{
mDiagramUnitComboBox->setCurrentIndex( 1 );
}
mDiagramLineUnitComboBox->setUnit( settingList.at( 0 ).lineSizeType );
mDiagramLineUnitComboBox->setMapUnitScale( settingList.at( 0 ).lineSizeScale );

if ( settingList.at( 0 ).labelPlacementMethod == QgsDiagramSettings::Height )
{
Expand Down Expand Up @@ -701,6 +705,8 @@ void QgsDiagramProperties::apply()
ds.categoryLabels = categoryLabels;
ds.size = QSizeF( mDiagramSizeSpinBox->value(), mDiagramSizeSpinBox->value() );
ds.sizeType = static_cast<QgsDiagramSettings::SizeType>( mDiagramUnitComboBox->itemData( mDiagramUnitComboBox->currentIndex() ).toInt() );
ds.lineSizeType = mDiagramLineUnitComboBox->unit();
ds.lineSizeScale = mDiagramLineUnitComboBox->getMapUnitScale();
ds.labelPlacementMethod = static_cast<QgsDiagramSettings::LabelPlacementMethod>( mLabelPlacementComboBox->itemData( mLabelPlacementComboBox->currentIndex() ).toInt() );
ds.scaleByArea = mScaleDependencyComboBox->itemData( mScaleDependencyComboBox->currentIndex() ).toBool();

Expand Down
9 changes: 1 addition & 8 deletions src/core/diagram/qgsdiagram.cpp
Expand Up @@ -70,14 +70,7 @@ QgsExpression *QgsDiagram::getExpression( const QString &expression, const QgsEx

void QgsDiagram::setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsRenderContext& c )
{
if ( s.sizeType == QgsDiagramSettings::MM )
{
pen.setWidthF( s.penWidth * c.scaleFactor() );
}
else
{
pen.setWidthF( s.penWidth / c.mapToPixel().mapUnitsPerPixel() );
}
pen.setWidthF( QgsSymbolLayerV2Utils::convertToPainterUnits( c, s.penWidth, s.lineSizeType, s.lineSizeScale ) );
}


Expand Down
12 changes: 10 additions & 2 deletions src/core/qgsdiagramrendererv2.cpp
Expand Up @@ -181,7 +181,7 @@ void QgsDiagramSettings::readXML( const QDomElement& elem, const QgsVectorLayer*
scaleBasedVisibility = minScaleDenominator >= 0 && maxScaleDenominator >= 0;
}

//mm vs map units
//mm vs map units for diagram
if ( elem.attribute( "sizeType" ) == "MM" )
{
sizeType = MM;
Expand All @@ -191,6 +191,10 @@ void QgsDiagramSettings::readXML( const QDomElement& elem, const QgsVectorLayer*
sizeType = MapUnits;
}

//mm vs map units for line
lineSizeType = QgsSymbolLayerV2Utils::decodeOutputUnit( elem.attribute( "lineSizeType" ) );
lineSizeScale = QgsSymbolLayerV2Utils::decodeMapUnitScale( elem.attribute( "lineSizeScale" ) );

//label placement method
if ( elem.attribute( "labelPlacementMethod" ) == "Height" )
{
Expand Down Expand Up @@ -299,7 +303,7 @@ void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc,
categoryElem.setAttribute( "maxScaleDenominator", QString::number( maxScaleDenominator ) );
categoryElem.setAttribute( "transparency", QString::number( transparency ) );

// site type (mm vs. map units)
// site type (mm vs. map units) for diagram
if ( sizeType == MM )
{
categoryElem.setAttribute( "sizeType", "MM" );
Expand All @@ -309,6 +313,10 @@ void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc,
categoryElem.setAttribute( "sizeType", "MapUnits" );
}

// site type (mm vs. map units) for line
categoryElem.setAttribute( "lineSizeType", QgsSymbolLayerV2Utils::encodeOutputUnit( lineSizeType ) );
categoryElem.setAttribute( "lineSizeScale", QgsSymbolLayerV2Utils::encodeMapUnitScale( lineSizeScale ) );

// label placement method (text diagram)
if ( labelPlacementMethod == Height )
{
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsdiagramrendererv2.h
Expand Up @@ -24,6 +24,7 @@

#include "qgsfeature.h"
#include "qgsexpressioncontext.h"
#include "qgssymbollayerv2.h"

class QgsDiagram;
class QgsDiagramRendererV2;
Expand Down Expand Up @@ -321,6 +322,7 @@ class CORE_EXPORT QgsDiagramSettings
QgsDiagramSettings()
: enabled( true )
, sizeType( MM )
, lineSizeType( QgsSymbolV2::MM )
, penWidth( 0.0 )
, labelPlacementMethod( QgsDiagramSettings::Height )
, diagramOrientation( QgsDiagramSettings::Up )
Expand All @@ -341,6 +343,14 @@ class CORE_EXPORT QgsDiagramSettings
QList< QString > categoryLabels;
QSizeF size; //size
SizeType sizeType; //mm or map units
/** Line unit index (mm, map units, or pixels)
* @note added in 2.16
*/
QgsSymbolV2::OutputUnit lineSizeType;
/** Line unit scale
* @note added in 2.16
*/
QgsMapUnitScale lineSizeScale;
QColor backgroundColor;
QColor penColor;
double penWidth;
Expand Down
29 changes: 28 additions & 1 deletion src/ui/qgsdiagrampropertiesbase.ui
Expand Up @@ -763,13 +763,33 @@
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mPenWidthLabel">
<property name="text">
<string>Line Unit</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QgsUnitSelectionWidget" name="mDiagramLineUnitComboBox" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mAngleOffsetLabel">
<property name="text">
<string>Start angle</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QComboBox" name="mAngleOffsetComboBox"/>
</item>
<item row="3" column="1">
Expand Down Expand Up @@ -1839,6 +1859,12 @@
<extends>QWidget</extends>
<header>qgsscalerangewidget.h</header>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsunitselectionwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mEnableDiagramsCheckBox</tabstop>
Expand All @@ -1858,6 +1884,7 @@
<tabstop>mBackgroundColorButton</tabstop>
<tabstop>mDiagramPenColorButton</tabstop>
<tabstop>mPenWidthSpinBox</tabstop>
<tabstop>mDiagramLineUnitComboBox</tabstop>
<tabstop>mAngleOffsetComboBox</tabstop>
<tabstop>mDiagramFontButton</tabstop>
<tabstop>mShowAllCheckBox</tabstop>
Expand Down

0 comments on commit 31d7be4

Please sign in to comment.