Skip to content
Permalink
Browse files

[diagram] add unit type setting for outlines (fixes #14614)

  • Loading branch information
nirvn committed Apr 5, 2016
1 parent ca642e4 commit 31d7be4034d738300aad372ab6d4039998773a2b
@@ -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;
@@ -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 )
@@ -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 );
@@ -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 )
{
@@ -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();

@@ -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 ) );
}


@@ -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;
@@ -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" )
{
@@ -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" );
@@ -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 )
{
@@ -24,6 +24,7 @@

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

class QgsDiagram;
class QgsDiagramRendererV2;
@@ -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 )
@@ -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;
@@ -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">
@@ -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>
@@ -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>

0 comments on commit 31d7be4

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