Skip to content
Permalink
Browse files
[FEATURE] Add inches as a measurement choice for symbology/labeling
"Make imperial great again!"
  • Loading branch information
nyalldawson committed Jan 22, 2017
1 parent b7d89a7 commit 46f2ea13eeca912c980e55b1e0b805fb9c1cb96e
@@ -69,6 +69,7 @@ class QgsUnitTypes
RenderPixels, //!< pixels
RenderPercentage, //!< percentage of another measurement (e.g., canvas size, feature size)
RenderPoints, //! points (e.g., for font sizes)
RenderInches,
RenderUnknownUnit, //!< mixed or unknown units
};

@@ -104,9 +104,9 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
connect( mAttributeBasedScalingRadio, SIGNAL( toggled( bool ) ), this, SLOT( scalingTypeChanged() ) );

mDiagramUnitComboBox->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mDiagramLineUnitComboBox->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

QgsWkbTypes::GeometryType layerType = layer->geometryType();
if ( layerType == QgsWkbTypes::UnknownGeometry || layerType == QgsWkbTypes::NullGeometry )
@@ -240,6 +240,10 @@ QPointF QgsMapToolOffsetPointSymbol::calculateOffset( const QgsPoint& startPoint
factor = 2.83464567 * 25.4 / mCanvas->mapSettings().outputDpi() / mCanvas->mapSettings().mapUnitsPerPixel() ;
break;

case QgsUnitTypes::RenderInches:
factor = 1.0 / mCanvas->mapSettings().outputDpi() / mCanvas->mapSettings().mapUnitsPerPixel() ;
break;

case QgsUnitTypes::RenderPixels:
factor = 1.0 / mCanvas->mapSettings().mapUnitsPerPixel();
break;
@@ -24,6 +24,7 @@
#include "qgsfeaturefilterprovider.h"

#define POINTS_TO_MM 2.83464567
#define INCH_TO_MM 25.4

QgsRenderContext::QgsRenderContext()
: mFlags( DrawEditingInfo | UseAdvancedEffects | DrawSelection | UseRenderingOptimization )
@@ -224,6 +225,10 @@ double QgsRenderContext::convertToPainterUnits( double size, QgsUnitTypes::Rende
conversionFactor = mScaleFactor / POINTS_TO_MM;
break;

case QgsUnitTypes::RenderInches:
conversionFactor = mScaleFactor * INCH_TO_MM;
break;

case QgsUnitTypes::RenderMapUnits:
{
double mup = scale.computeMapUnitsPerPixel( *this );
@@ -303,6 +308,10 @@ double QgsRenderContext::convertToMapUnits( double size, QgsUnitTypes::RenderUni
{
return size * mScaleFactor * mup / POINTS_TO_MM;
}
case QgsUnitTypes::RenderInches:
{
return size * mScaleFactor * mup * INCH_TO_MM;
}
case QgsUnitTypes::RenderPixels:
{
return size * mup;
@@ -334,6 +343,10 @@ double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, QgsUnitType
{
return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM );
}
case QgsUnitTypes::RenderInches:
{
return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM );
}
case QgsUnitTypes::RenderPixels:
{
return sizeInMapUnits / mup;
@@ -1081,9 +1081,12 @@ QString QgsUnitTypes::encodeUnit( RenderUnit unit )
return QStringLiteral( "Percentage" );
case RenderPoints:
return QStringLiteral( "Point" );
default:
return QStringLiteral( "MM" );
case RenderInches:
return QStringLiteral( "Inch" );
case RenderUnknownUnit:
return QString();
}
return QString();
}

QgsUnitTypes::RenderUnit QgsUnitTypes::decodeRenderUnit( const QString& string, bool* ok )
@@ -1109,6 +1112,8 @@ QgsUnitTypes::RenderUnit QgsUnitTypes::decodeRenderUnit( const QString& string,
return RenderPoints;
if ( normalized == QLatin1String( "points" ) )
return RenderPoints;
if ( normalized == encodeUnit( RenderInches ).toLower() )
return RenderInches;

if ( ok )
*ok = false;
@@ -96,6 +96,7 @@ class CORE_EXPORT QgsUnitTypes
RenderPixels, //!< Pixels
RenderPercentage, //!< Percentage of another measurement (e.g., canvas size, feature size)
RenderPoints, //! points (e.g., for font sizes)
RenderInches, //! Inches
RenderUnknownUnit, //!< Mixed or unknown units
};

@@ -256,7 +256,7 @@ QgsShadowEffectWidget::QgsShadowEffectWidget( QWidget *parent )
mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );

mOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

initGui();
}
@@ -422,7 +422,7 @@ QgsGlowWidget::QgsGlowWidget( QWidget *parent )
mColorBtn->setContext( QStringLiteral( "symbology" ) );

mSpreadUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

btnColorRamp->setShowGradientOnly( true );

@@ -612,7 +612,7 @@ QgsTransformWidget::QgsTransformWidget( QWidget *parent )
setupUi( this );

mTranslateUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mSpinTranslateX->setClearValue( 0 );
mSpinTranslateY->setClearValue( 0 );
mSpinShearX->setClearValue( 0 );
@@ -75,28 +75,28 @@ void QgsTextFormatWidget::initWidget()
unitWidget->setMapCanvas( mMapCanvas );
}
mFontSizeUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels );
<< QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderInches );
mBufferUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mShapeSizeUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mShapeOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mShapeRadiusUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderPercentage
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mShapeBorderWidthUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mShadowOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mShadowRadiusUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mPointOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mLineDistanceUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mRepeatDistanceUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

mFontLineHeightSpinBox->setClearValue( 1.0 );
mShapeRotationDblSpnBx->setClearValue( 0.0 );
@@ -28,24 +28,24 @@ QgsMapUnitScaleWidget::QgsMapUnitScaleWidget( QWidget* parent )
mComboBoxMaxScale->setScale( 1 );
mSpinBoxMinSize->setShowClearButton( false );
mSpinBoxMaxSize->setShowClearButton( false );
connect( mCheckBoxMinScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMinComboBox() ) );
connect( mCheckBoxMaxScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMaxComboBox() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), this, SLOT( configureMaxComboBox() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), mComboBoxMaxScale, SLOT( setMinScale( double ) ) );
connect( mComboBoxMaxScale, SIGNAL( scaleChanged( double ) ), this, SLOT( configureMinComboBox() ) );
connect( mCheckBoxMinScale, &QCheckBox::toggled, this, &QgsMapUnitScaleWidget::configureMinComboBox );
connect( mCheckBoxMaxScale, &QCheckBox::toggled, this, &QgsMapUnitScaleWidget::configureMaxComboBox );
connect( mComboBoxMinScale, &QgsScaleWidget::scaleChanged, this, &QgsMapUnitScaleWidget::configureMaxComboBox );
connect( mComboBoxMinScale, &QgsScaleWidget::scaleChanged, mComboBoxMaxScale, &QgsScaleWidget::setMinScale );
connect( mComboBoxMaxScale, &QgsScaleWidget::scaleChanged, this, &QgsMapUnitScaleWidget::configureMinComboBox );

connect( mCheckBoxMinSize, SIGNAL( toggled( bool ) ), mSpinBoxMinSize, SLOT( setEnabled( bool ) ) );
connect( mCheckBoxMaxSize, SIGNAL( toggled( bool ) ), mSpinBoxMaxSize, SLOT( setEnabled( bool ) ) );
connect( mCheckBoxMinSize, &QCheckBox::toggled, mSpinBoxMinSize, &QgsDoubleSpinBox::setEnabled );
connect( mCheckBoxMaxSize, &QCheckBox::toggled, mSpinBoxMaxSize, &QgsDoubleSpinBox::setEnabled );

// notification of setting changes
connect( mCheckBoxMinScale, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMaxScale, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mComboBoxMaxScale, SIGNAL( scaleChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMinSize, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMaxSize, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mSpinBoxMinSize, SIGNAL( valueChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mSpinBoxMaxSize, SIGNAL( valueChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMinScale, &QCheckBox::toggled, this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mCheckBoxMaxScale, &QCheckBox::toggled, this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mComboBoxMinScale, &QgsScaleWidget::scaleChanged, this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mComboBoxMaxScale, &QgsScaleWidget::scaleChanged, this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mCheckBoxMinSize, &QCheckBox::toggled, this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mCheckBoxMaxSize, &QCheckBox::toggled, this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mSpinBoxMinSize, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsMapUnitScaleWidget::settingsChanged );
connect( mSpinBoxMaxSize, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsMapUnitScaleWidget::settingsChanged );
mBlockSignals = false;
}

@@ -136,9 +136,9 @@ QgsUnitSelectionWidget::QgsUnitSelectionWidget( QWidget *parent )
setFocusPolicy( Qt::StrongFocus );
setFocusProxy( mUnitCombo );

connect( mUnitCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( toggleUnitRangeButton() ) );
connect( mMapScaleButton, SIGNAL( clicked() ), this, SLOT( showDialog() ) );
connect( mUnitCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( changed() ) );
connect( mUnitCombo, static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::currentIndexChanged ), this, &QgsUnitSelectionWidget::toggleUnitRangeButton );
connect( mMapScaleButton, &QPushButton::clicked, this, &QgsUnitSelectionWidget::showDialog );
connect( mUnitCombo, static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::currentIndexChanged ), this, &QgsUnitSelectionWidget::changed );
}

void QgsUnitSelectionWidget::setUnits( const QStringList &units, int mapUnitIdx )
@@ -178,6 +178,10 @@ void QgsUnitSelectionWidget::setUnits( const QgsUnitTypes::RenderUnitList &units
{
mUnitCombo->addItem( tr( "Percentage" ), QgsUnitTypes::RenderPercentage );
}
if ( units.contains( QgsUnitTypes::RenderInches ) )
{
mUnitCombo->addItem( tr( "Inches" ), QgsUnitTypes::RenderInches );
}
blockSignals( false );
}

@@ -222,7 +226,7 @@ void QgsUnitSelectionWidget::showDialog()
widget->setPanelTitle( tr( "Adjust scaling range" ) );
widget->setMapCanvas( mCanvas );
widget->setMapUnitScale( mMapUnitScale );
connect( widget, SIGNAL( mapUnitScaleChanged( QgsMapUnitScale ) ), this, SLOT( widgetChanged( QgsMapUnitScale ) ) );
connect( widget, &QgsMapUnitScaleWidget::mapUnitScaleChanged, this, &QgsUnitSelectionWidget::widgetChanged );
panel->openPanel( widget );
return;
}
@@ -267,8 +271,8 @@ QgsMapUnitScaleDialog::QgsMapUnitScaleDialog( QWidget* parent )
mWidget = new QgsMapUnitScaleWidget();
vLayout->addWidget( mWidget );
QDialogButtonBox* bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
connect( bbox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( bbox, SIGNAL( rejected() ), this, SLOT( reject() ) );
connect( bbox, &QDialogButtonBox::accepted, this, &QgsMapUnitScaleDialog::accept );
connect( bbox, &QDialogButtonBox::rejected, this, &QgsMapUnitScaleDialog::reject );
vLayout->addWidget( bbox );
setLayout( vLayout );
}
@@ -24,15 +24,15 @@ QgsArrowSymbolLayerWidget::QgsArrowSymbolLayerWidget( const QgsVectorLayer* vl,
setupUi( this );

mArrowWidthUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mArrowStartWidthUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mHeadLengthUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mHeadThicknessUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

mOffsetSpin->setClearValue( 0.0 );
}
@@ -24,13 +24,13 @@ QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( const QgsVectorLayer*
setupUi( this );

mSymbolWidthUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mSymbolHeightUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mOutlineWidthUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

btnChangeColorFill->setAllowAlpha( true );
btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
@@ -446,7 +446,7 @@ QgsGraduatedSymbolRendererWidget::QgsGraduatedSymbolRendererWidget( QgsVectorLay
mExpressionWidget->setLayer( mLayer );

mSizeUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

spinPrecision->setMinimum( QgsRendererRangeLabelFormat::MIN_PRECISION );
spinPrecision->setMaximum( QgsRendererRangeLabelFormat::MAX_PRECISION );
@@ -85,7 +85,7 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer* layer, QgsSt
setupUi( this );

mRadiusUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints );
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
mWeightExpressionWidget->registerExpressionContextGenerator( this );

if ( renderer )

1 comment on commit 46f2ea1

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on 46f2ea1 Jan 23, 2017

Is this a feature or a regression? ;-P

Please sign in to comment.