Skip to content

Commit

Permalink
Merge pull request #4646 from nyalldawson/rotation
Browse files Browse the repository at this point in the history
Unify UX behavior, pt 2: rotation
  • Loading branch information
nyalldawson committed May 31, 2017
2 parents 8ce847f + c019314 commit 77fd7e6
Show file tree
Hide file tree
Showing 57 changed files with 460 additions and 244 deletions.
2 changes: 2 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1024,6 +1024,7 @@ QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
- The SizeType enum was removed. Use QgsUnitTypes.RenderUnit instead.
- readXml() and writeXml() do not take QgsVectorLayer as an argument anymore.
- transparency was removed. Use opacity instead.
- angleOffset was removed. Use rotationOffset instead.


QgsDial {#qgis_api_break_3_0_QgsDial}
Expand Down Expand Up @@ -1731,6 +1732,7 @@ members were removed. Use the QgsProperty framework through dataDefinedPropertie
and setDataDefinedProperties() instead.
- readXml() and writeXml() now expect a reference to QgsReadWriteContext.
- fromLayer() has been reoved. Labeling is read/written in QgsAbstractVectorLayerLabeling and its subclasses.
- angleOffset is now in degrees clockwise. QGIS 2.x used degrees counterclockwise.


QgsPanelWidgetStack {#qgis_api_break_3_0_QgsPanelWidgetStack}
Expand Down
11 changes: 6 additions & 5 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -373,20 +373,21 @@ In case of annotations, the bounding rectangle can be larger than the map item r
reimplement setFrameStrokeWidth, so that updateBoundingRect() is called after setting the frame width */
%End

void setMapRotation( double r );
void setMapRotation( double rotation );
%Docstring
Sets rotation for the map - this does not affect the composer item shape, only the
way the map is drawn within the item
Sets the ``rotation`` for the map - this does not affect the composer item shape, only the
way the map is drawn within the item. Rotation is in degrees, clockwise.
.. versionadded:: 2.1
.. seealso:: mapRotation()
%End

double mapRotation( QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
%Docstring
Returns the rotation used for drawing the map within the composer item
:return: rotation for map
Returns the rotation used for drawing the map within the composer item, in degrees clockwise.
\param valueType controls whether the returned value is the user specified rotation,
or the current evaluated rotation (which may be affected by data driven rotation
settings).
.. seealso:: setMapRotation()
:rtype: float
%End

Expand Down
10 changes: 4 additions & 6 deletions python/core/effects/qgstransformeffect.sip
Expand Up @@ -157,16 +157,14 @@ class QgsTransformEffect : QgsPaintEffect

void setRotation( const double rotation );
%Docstring
Sets the transform rotation.
\param rotation degrees to rotate, clockwise
.. seealso:: rotation
Sets the transform ``rotation``, in degrees clockwise.
.. seealso:: rotation()
%End

double rotation() const;
%Docstring
Returns the transform rotation.
:return: rotation in degrees clockwise
.. seealso:: setRotation
Returns the transform rotation, in degrees clockwise.
.. seealso:: setRotation()
:rtype: float
%End

Expand Down
7 changes: 6 additions & 1 deletion python/core/qgsdiagramrenderer.sip
Expand Up @@ -365,7 +365,12 @@ Opacity, from 0 (transparent) to 1.0 (opaque)
%End

bool scaleByArea;
int angleOffset;

double rotationOffset;
%Docstring
Rotation offset, in degrees clockwise from horizontal.
.. versionadded:: 3.0
%End

bool scaleBasedVisibility;
double minScaleDenominator;
Expand Down
7 changes: 6 additions & 1 deletion python/core/qgsmapsettings.sip
Expand Up @@ -57,12 +57,17 @@ Set the size of the resulting map image

double rotation() const;
%Docstring
Returns the rotation of the resulting map image, in degrees clockwise.
.. versionadded:: 2.8
.. seealso:: setRotation()
:rtype: float
%End
void setRotation( double degrees );

void setRotation( double rotation );
%Docstring
Sets the ``rotation`` of the resulting map image, in degrees clockwise.
.. versionadded:: 2.8
.. seealso:: rotation()
%End

double outputDpi() const;
Expand Down
8 changes: 7 additions & 1 deletion python/core/qgspallabeling.sip
Expand Up @@ -239,6 +239,7 @@ class QgsPalLayerSettings
Hali,
Vali,
Rotation,
LabelRotation,
RepeatDistance,
RepeatDistanceUnit,
Priority,
Expand Down Expand Up @@ -346,7 +347,12 @@ Offset type for layer (only applies in certain placement modes)
double yOffset; // offset from point in mm or map units
bool labelOffsetInMapUnits; //true if label offset is in map units (otherwise in mm)
QgsMapUnitScale labelOffsetMapUnitScale;
double angleOffset; // rotation applied to offset labels

double angleOffset;
%Docstring
Label rotation, in degrees clockwise
%End

bool preserveRotation; // preserve predefined rotation data during label pin/unpin operations

double maxCurvedCharAngleIn; // maximum angle between inside curved label characters (defaults to 20.0, range 20.0 to 60.0)
Expand Down
5 changes: 2 additions & 3 deletions python/core/qgstextrenderer.sip
Expand Up @@ -405,16 +405,15 @@ class QgsTextBackgroundSettings

double rotation() const;
%Docstring
Returns the rotation for the background shape.
Returns the rotation for the background shape, in degrees clockwise.
.. seealso:: rotationType()
.. seealso:: setRotation()
:rtype: float
%End

void setRotation( double rotation );
%Docstring
Sets the rotation for the background shape.
\param rotation angle in degrees to rotate
Sets the ``rotation`` for the background shape, in degrees clockwise.
.. seealso:: rotation()
.. seealso:: setRotationType()
%End
Expand Down
2 changes: 2 additions & 0 deletions src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -150,6 +150,8 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget *parent, QgsComposerItem *

setupUi( this );

mItemRotationSpinBox->setClearValue( 0 );

//make button exclusive
QButtonGroup *buttonGroup = new QButtonGroup( this );
buttonGroup->addButton( mUpperLeftCheckBox );
Expand Down
7 changes: 4 additions & 3 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -47,6 +47,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap *composerMap )
{
setupUi( this );
setPanelTitle( tr( "Map properties" ) );
mMapRotationSpinBox->setClearValue( 0 );

//add widget for general composer item properties
QgsComposerItemWidget *itemPropertiesWidget = new QgsComposerItemWidget( this, composerMap );
Expand Down Expand Up @@ -116,7 +117,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap *composerMap )
loadGridEntries();
loadOverviewEntries();

connect( mMapRotationSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsComposerMapWidget::rotationChanged );
connect( mMapRotationSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsComposerMapWidget::rotationChanged );

blockAllSignals( false );
}
Expand Down Expand Up @@ -451,15 +452,15 @@ void QgsComposerMapWidget::on_mScaleLineEdit_editingFinished()
mComposerMap->endCommand();
}

void QgsComposerMapWidget::rotationChanged()
void QgsComposerMapWidget::rotationChanged( double value )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Map rotation changed" ), QgsComposerMergeCommand::ComposerMapRotation );
mComposerMap->setMapRotation( mMapRotationSpinBox->value() );
mComposerMap->setMapRotation( value );
mComposerMap->endCommand();
mComposerMap->invalidateCache();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermapwidget.h
Expand Up @@ -130,7 +130,7 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
//! Blocks / unblocks the signals of all GUI elements
void blockAllSignals( bool b );

void rotationChanged();
void rotationChanged( double value );

void handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode );
void handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString &text );
Expand Down
2 changes: 1 addition & 1 deletion src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -396,7 +396,7 @@ void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, QString name, QS
" WHEN alignv=3 THEN 'Top'"
" END"
" END" ).arg( DRW::MTEXT ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Rotation, QgsProperty::fromExpression( QStringLiteral( "angle*180.0/pi()" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle*180.0/pi()" ) ) );

pls.placement = QgsPalLayerSettings::OrderedPositionsAroundPoint;
l->setLabeling( new QgsVectorLayerSimpleLabeling( pls ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -2589,7 +2589,7 @@ void QgisApp::createStatusBar()
mRotationEdit->setKeyboardTracking( false );
mRotationEdit->setMaximumWidth( 120 );
mRotationEdit->setDecimals( 1 );
mRotationEdit->setRange( -180.0, 180.0 );
mRotationEdit->setRange( -360.0, 360.0 );
mRotationEdit->setWrapping( true );
mRotationEdit->setSingleStep( 5.0 );
mRotationEdit->setFont( myFont );
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -147,10 +147,10 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mScaleDependencyComboBox->addItem( tr( "Area" ), true );
mScaleDependencyComboBox->addItem( tr( "Diameter" ), false );

mAngleOffsetComboBox->addItem( tr( "Top" ), 90 * 16 );
mAngleOffsetComboBox->addItem( tr( "Top" ), 270 );
mAngleOffsetComboBox->addItem( tr( "Right" ), 0 );
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 270 * 16 );
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 * 16 );
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 90 );
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 );

QgsSettings settings;

Expand Down Expand Up @@ -283,7 +283,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mLabelPlacementComboBox->setCurrentIndex( 1 );
}

mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).angleOffset ) );
mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).rotationOffset ) );

mOrientationLeftButton->setProperty( "direction", QgsDiagramSettings::Left );
mOrientationRightButton->setProperty( "direction", QgsDiagramSettings::Right );
Expand Down Expand Up @@ -779,7 +779,7 @@ void QgsDiagramProperties::apply()
ds.scaleBasedVisibility = mScaleVisibilityGroupBox->isChecked();

// Diagram angle offset (pie)
ds.angleOffset = mAngleOffsetComboBox->currentData().toInt();
ds.rotationOffset = mAngleOffsetComboBox->currentData().toInt();

// Diagram orientation (histogram)
ds.diagramOrientation = static_cast<QgsDiagramSettings::DiagramOrientation>( mOrientationButtonGroup->checkedButton()->property( "direction" ).toInt() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabelinggui.cpp
Expand Up @@ -545,7 +545,7 @@ void QgsLabelingGui::populateDataDefinedButtons()
mCoordAlignmentHDDBtn->setUsageInfo( ddPlaceInfo );
registerDataDefinedButton( mCoordAlignmentVDDBtn, QgsPalLayerSettings::Vali );
mCoordAlignmentVDDBtn->setUsageInfo( ddPlaceInfo );
registerDataDefinedButton( mCoordRotationDDBtn, QgsPalLayerSettings::Rotation );
registerDataDefinedButton( mCoordRotationDDBtn, QgsPalLayerSettings::LabelRotation );
mCoordRotationDDBtn->setUsageInfo( ddPlaceInfo );

// rendering
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -36,6 +36,7 @@ QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString &layerId, const QS
QDialog( parent, f ), mLabelFont( labelFont ), mCurLabelField( -1 )
{
setupUi( this );
mRotationSpinBox->setClearValue( 0 );
fillHaliComboBox();
fillValiComboBox();

Expand Down Expand Up @@ -314,7 +315,7 @@ void QgsLabelPropertyDialog::setDataDefinedValues( QgsVectorLayer *vlayer )
case QgsPalLayerSettings::Color:
mFontColorButton->setColor( QColor( result.toString() ) );
break;
case QgsPalLayerSettings::Rotation:
case QgsPalLayerSettings::LabelRotation:
{
double rot = result.toDouble( &ok );
if ( ok )
Expand Down Expand Up @@ -407,7 +408,7 @@ void QgsLabelPropertyDialog::enableDataDefinedWidgets( QgsVectorLayer *vlayer )
case QgsPalLayerSettings::Color:
mFontColorButton->setEnabled( true );
break;
case QgsPalLayerSettings::Rotation:
case QgsPalLayerSettings::LabelRotation:
mRotationSpinBox->setEnabled( true );
break;
//font related properties
Expand Down Expand Up @@ -618,7 +619,7 @@ void QgsLabelPropertyDialog::on_mRotationSpinBox_valueChanged( double d )
//null value so that size is reset to default
rotation.clear();
}
insertChangedValue( QgsPalLayerSettings::Rotation, rotation );
insertChangedValue( QgsPalLayerSettings::LabelRotation, rotation );
}

void QgsLabelPropertyDialog::on_mFontColorButton_colorChanged( const QColor &color )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoollabel.cpp
Expand Up @@ -485,7 +485,7 @@ bool QgsMapToolLabel::layerIsRotatable( QgsVectorLayer *vlayer, int &rotationCol

bool QgsMapToolLabel::labelIsRotatable( QgsVectorLayer *layer, const QgsPalLayerSettings &settings, int &rotationCol ) const
{
QString rColName = dataDefinedColumnName( QgsPalLayerSettings::Rotation, settings );
QString rColName = dataDefinedColumnName( QgsPalLayerSettings::LabelRotation, settings );
rotationCol = layer->fields().lookupField( rColName );
return rotationCol != -1;
}
Expand Down
9 changes: 3 additions & 6 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -1009,13 +1009,10 @@ double QgsComposerItem::rectHandlerBorderTolerance() const

void QgsComposerItem::setItemRotation( const double r, const bool adjustPosition )
{
if ( r >= 360 )
mItemRotation = r;
if ( mItemRotation >= 360.0 || mItemRotation <= -360.0 )
{
mItemRotation = ( static_cast< int >( r ) ) % 360;
}
else
{
mItemRotation = r;
mItemRotation = fmod( mItemRotation, 360.0 );
}

QgsExpressionContext context = createExpressionContext();
Expand Down
13 changes: 7 additions & 6 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -427,13 +427,13 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/
bool positionLock() const { return mItemPositionLocked; }

/** Returns the current rotation for the composer item.
* \returns rotation for composer item
/**
* Returns the current rotation for the composer item, in degrees clockwise.
* \param valueType controls whether the returned value is the user specified rotation,
* or the current evaluated rotation (which may be affected by data driven rotation
* settings).
* \since QGIS 2.1
* \see setItemRotation
* \see setItemRotation()
*/
double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;

Expand Down Expand Up @@ -555,14 +555,15 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec

public slots:

/** Sets the item rotation
* \param r item rotation in degrees
/**
* Sets the item \a rotation, in degrees clockwise.
* \param rotation item rotation in degrees
* \param adjustPosition set to true if item should be shifted so that rotation occurs
* around item center. If false, rotation occurs around item origin
* \since QGIS 2.1
* \see itemRotation
*/
virtual void setItemRotation( const double r, const bool adjustPosition = false );
virtual void setItemRotation( const double rotation, const bool adjustPosition = false );

void repaint() override;

Expand Down
6 changes: 3 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -901,12 +901,12 @@ void QgsComposerMap::setOffset( double xOffset, double yOffset )
mYOffset = yOffset;
}

void QgsComposerMap::setMapRotation( double r )
void QgsComposerMap::setMapRotation( double rotation )
{
mMapRotation = r;
mMapRotation = rotation;
mEvaluatedMapRotation = mMapRotation;
invalidateCache();
emit mapRotationChanged( r );
emit mapRotationChanged( rotation );
emit itemChanged();
}

Expand Down
13 changes: 8 additions & 5 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -329,17 +329,20 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/* reimplement setFrameStrokeWidth, so that updateBoundingRect() is called after setting the frame width */
virtual void setFrameStrokeWidth( const double strokeWidth ) override;

/** Sets rotation for the map - this does not affect the composer item shape, only the
* way the map is drawn within the item
/**
* Sets the \a rotation for the map - this does not affect the composer item shape, only the
* way the map is drawn within the item. Rotation is in degrees, clockwise.
* \since QGIS 2.1
* \see mapRotation()
*/
void setMapRotation( double r );
void setMapRotation( double rotation );

/** Returns the rotation used for drawing the map within the composer item
* \returns rotation for map
/**
* Returns the rotation used for drawing the map within the composer item, in degrees clockwise.
* \param valueType controls whether the returned value is the user specified rotation,
* or the current evaluated rotation (which may be affected by data driven rotation
* settings).
* \see setMapRotation()
*/
double mapRotation( QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;

Expand Down

0 comments on commit 77fd7e6

Please sign in to comment.