Skip to content

Commit 77fd7e6

Browse files
authored
Merge pull request #4646 from nyalldawson/rotation
Unify UX behavior, pt 2: rotation
2 parents 8ce847f + c019314 commit 77fd7e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+460
-244
lines changed

doc/api_break.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
10241024
- The SizeType enum was removed. Use QgsUnitTypes.RenderUnit instead.
10251025
- readXml() and writeXml() do not take QgsVectorLayer as an argument anymore.
10261026
- transparency was removed. Use opacity instead.
1027+
- angleOffset was removed. Use rotationOffset instead.
10271028

10281029

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

17351737

17361738
QgsPanelWidgetStack {#qgis_api_break_3_0_QgsPanelWidgetStack}

python/core/composer/qgscomposermap.sip

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,20 +373,21 @@ In case of annotations, the bounding rectangle can be larger than the map item r
373373
reimplement setFrameStrokeWidth, so that updateBoundingRect() is called after setting the frame width */
374374
%End
375375

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

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

python/core/effects/qgstransformeffect.sip

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,14 @@ class QgsTransformEffect : QgsPaintEffect
157157

158158
void setRotation( const double rotation );
159159
%Docstring
160-
Sets the transform rotation.
161-
\param rotation degrees to rotate, clockwise
162-
.. seealso:: rotation
160+
Sets the transform ``rotation``, in degrees clockwise.
161+
.. seealso:: rotation()
163162
%End
164163

165164
double rotation() const;
166165
%Docstring
167-
Returns the transform rotation.
168-
:return: rotation in degrees clockwise
169-
.. seealso:: setRotation
166+
Returns the transform rotation, in degrees clockwise.
167+
.. seealso:: setRotation()
170168
:rtype: float
171169
%End
172170

python/core/qgsdiagramrenderer.sip

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ Opacity, from 0 (transparent) to 1.0 (opaque)
365365
%End
366366

367367
bool scaleByArea;
368-
int angleOffset;
368+
369+
double rotationOffset;
370+
%Docstring
371+
Rotation offset, in degrees clockwise from horizontal.
372+
.. versionadded:: 3.0
373+
%End
369374

370375
bool scaleBasedVisibility;
371376
double minScaleDenominator;

python/core/qgsmapsettings.sip

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ Set the size of the resulting map image
5757

5858
double rotation() const;
5959
%Docstring
60+
Returns the rotation of the resulting map image, in degrees clockwise.
6061
.. versionadded:: 2.8
62+
.. seealso:: setRotation()
6163
:rtype: float
6264
%End
63-
void setRotation( double degrees );
65+
66+
void setRotation( double rotation );
6467
%Docstring
68+
Sets the ``rotation`` of the resulting map image, in degrees clockwise.
6569
.. versionadded:: 2.8
70+
.. seealso:: rotation()
6671
%End
6772

6873
double outputDpi() const;

python/core/qgspallabeling.sip

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class QgsPalLayerSettings
239239
Hali,
240240
Vali,
241241
Rotation,
242+
LabelRotation,
242243
RepeatDistance,
243244
RepeatDistanceUnit,
244245
Priority,
@@ -346,7 +347,12 @@ Offset type for layer (only applies in certain placement modes)
346347
double yOffset; // offset from point in mm or map units
347348
bool labelOffsetInMapUnits; //true if label offset is in map units (otherwise in mm)
348349
QgsMapUnitScale labelOffsetMapUnitScale;
349-
double angleOffset; // rotation applied to offset labels
350+
351+
double angleOffset;
352+
%Docstring
353+
Label rotation, in degrees clockwise
354+
%End
355+
350356
bool preserveRotation; // preserve predefined rotation data during label pin/unpin operations
351357

352358
double maxCurvedCharAngleIn; // maximum angle between inside curved label characters (defaults to 20.0, range 20.0 to 60.0)

python/core/qgstextrenderer.sip

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,15 @@ class QgsTextBackgroundSettings
405405

406406
double rotation() const;
407407
%Docstring
408-
Returns the rotation for the background shape.
408+
Returns the rotation for the background shape, in degrees clockwise.
409409
.. seealso:: rotationType()
410410
.. seealso:: setRotation()
411411
:rtype: float
412412
%End
413413

414414
void setRotation( double rotation );
415415
%Docstring
416-
Sets the rotation for the background shape.
417-
\param rotation angle in degrees to rotate
416+
Sets the ``rotation`` for the background shape, in degrees clockwise.
418417
.. seealso:: rotation()
419418
.. seealso:: setRotationType()
420419
%End

src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget *parent, QgsComposerItem *
150150

151151
setupUi( this );
152152

153+
mItemRotationSpinBox->setClearValue( 0 );
154+
153155
//make button exclusive
154156
QButtonGroup *buttonGroup = new QButtonGroup( this );
155157
buttonGroup->addButton( mUpperLeftCheckBox );

src/app/composer/qgscomposermapwidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap *composerMap )
4747
{
4848
setupUi( this );
4949
setPanelTitle( tr( "Map properties" ) );
50+
mMapRotationSpinBox->setClearValue( 0 );
5051

5152
//add widget for general composer item properties
5253
QgsComposerItemWidget *itemPropertiesWidget = new QgsComposerItemWidget( this, composerMap );
@@ -116,7 +117,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap *composerMap )
116117
loadGridEntries();
117118
loadOverviewEntries();
118119

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

121122
blockAllSignals( false );
122123
}
@@ -451,15 +452,15 @@ void QgsComposerMapWidget::on_mScaleLineEdit_editingFinished()
451452
mComposerMap->endCommand();
452453
}
453454

454-
void QgsComposerMapWidget::rotationChanged()
455+
void QgsComposerMapWidget::rotationChanged( double value )
455456
{
456457
if ( !mComposerMap )
457458
{
458459
return;
459460
}
460461

461462
mComposerMap->beginCommand( tr( "Map rotation changed" ), QgsComposerMergeCommand::ComposerMapRotation );
462-
mComposerMap->setMapRotation( mMapRotationSpinBox->value() );
463+
mComposerMap->setMapRotation( value );
463464
mComposerMap->endCommand();
464465
mComposerMap->invalidateCache();
465466
}

src/app/composer/qgscomposermapwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
130130
//! Blocks / unblocks the signals of all GUI elements
131131
void blockAllSignals( bool b );
132132

133-
void rotationChanged();
133+
void rotationChanged( double value );
134134

135135
void handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode );
136136
void handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString &text );

src/app/dwg/qgsdwgimportdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, QString name, QS
396396
" WHEN alignv=3 THEN 'Top'"
397397
" END"
398398
" END" ).arg( DRW::MTEXT ) ) );
399-
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Rotation, QgsProperty::fromExpression( QStringLiteral( "angle*180.0/pi()" ) ) );
399+
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle*180.0/pi()" ) ) );
400400

401401
pls.placement = QgsPalLayerSettings::OrderedPositionsAroundPoint;
402402
l->setLabeling( new QgsVectorLayerSimpleLabeling( pls ) );

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ void QgisApp::createStatusBar()
25892589
mRotationEdit->setKeyboardTracking( false );
25902590
mRotationEdit->setMaximumWidth( 120 );
25912591
mRotationEdit->setDecimals( 1 );
2592-
mRotationEdit->setRange( -180.0, 180.0 );
2592+
mRotationEdit->setRange( -360.0, 360.0 );
25932593
mRotationEdit->setWrapping( true );
25942594
mRotationEdit->setSingleStep( 5.0 );
25952595
mRotationEdit->setFont( myFont );

src/app/qgsdiagramproperties.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
147147
mScaleDependencyComboBox->addItem( tr( "Area" ), true );
148148
mScaleDependencyComboBox->addItem( tr( "Diameter" ), false );
149149

150-
mAngleOffsetComboBox->addItem( tr( "Top" ), 90 * 16 );
150+
mAngleOffsetComboBox->addItem( tr( "Top" ), 270 );
151151
mAngleOffsetComboBox->addItem( tr( "Right" ), 0 );
152-
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 270 * 16 );
153-
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 * 16 );
152+
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 90 );
153+
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 );
154154

155155
QgsSettings settings;
156156

@@ -283,7 +283,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
283283
mLabelPlacementComboBox->setCurrentIndex( 1 );
284284
}
285285

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

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

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

784784
// Diagram orientation (histogram)
785785
ds.diagramOrientation = static_cast<QgsDiagramSettings::DiagramOrientation>( mOrientationButtonGroup->checkedButton()->property( "direction" ).toInt() );

src/app/qgslabelinggui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ void QgsLabelingGui::populateDataDefinedButtons()
545545
mCoordAlignmentHDDBtn->setUsageInfo( ddPlaceInfo );
546546
registerDataDefinedButton( mCoordAlignmentVDDBtn, QgsPalLayerSettings::Vali );
547547
mCoordAlignmentVDDBtn->setUsageInfo( ddPlaceInfo );
548-
registerDataDefinedButton( mCoordRotationDDBtn, QgsPalLayerSettings::Rotation );
548+
registerDataDefinedButton( mCoordRotationDDBtn, QgsPalLayerSettings::LabelRotation );
549549
mCoordRotationDDBtn->setUsageInfo( ddPlaceInfo );
550550

551551
// rendering

src/app/qgslabelpropertydialog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString &layerId, const QS
3636
QDialog( parent, f ), mLabelFont( labelFont ), mCurLabelField( -1 )
3737
{
3838
setupUi( this );
39+
mRotationSpinBox->setClearValue( 0 );
3940
fillHaliComboBox();
4041
fillValiComboBox();
4142

@@ -314,7 +315,7 @@ void QgsLabelPropertyDialog::setDataDefinedValues( QgsVectorLayer *vlayer )
314315
case QgsPalLayerSettings::Color:
315316
mFontColorButton->setColor( QColor( result.toString() ) );
316317
break;
317-
case QgsPalLayerSettings::Rotation:
318+
case QgsPalLayerSettings::LabelRotation:
318319
{
319320
double rot = result.toDouble( &ok );
320321
if ( ok )
@@ -407,7 +408,7 @@ void QgsLabelPropertyDialog::enableDataDefinedWidgets( QgsVectorLayer *vlayer )
407408
case QgsPalLayerSettings::Color:
408409
mFontColorButton->setEnabled( true );
409410
break;
410-
case QgsPalLayerSettings::Rotation:
411+
case QgsPalLayerSettings::LabelRotation:
411412
mRotationSpinBox->setEnabled( true );
412413
break;
413414
//font related properties
@@ -618,7 +619,7 @@ void QgsLabelPropertyDialog::on_mRotationSpinBox_valueChanged( double d )
618619
//null value so that size is reset to default
619620
rotation.clear();
620621
}
621-
insertChangedValue( QgsPalLayerSettings::Rotation, rotation );
622+
insertChangedValue( QgsPalLayerSettings::LabelRotation, rotation );
622623
}
623624

624625
void QgsLabelPropertyDialog::on_mFontColorButton_colorChanged( const QColor &color )

src/app/qgsmaptoollabel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ bool QgsMapToolLabel::layerIsRotatable( QgsVectorLayer *vlayer, int &rotationCol
485485

486486
bool QgsMapToolLabel::labelIsRotatable( QgsVectorLayer *layer, const QgsPalLayerSettings &settings, int &rotationCol ) const
487487
{
488-
QString rColName = dataDefinedColumnName( QgsPalLayerSettings::Rotation, settings );
488+
QString rColName = dataDefinedColumnName( QgsPalLayerSettings::LabelRotation, settings );
489489
rotationCol = layer->fields().lookupField( rColName );
490490
return rotationCol != -1;
491491
}

src/core/composer/qgscomposeritem.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,13 +1009,10 @@ double QgsComposerItem::rectHandlerBorderTolerance() const
10091009

10101010
void QgsComposerItem::setItemRotation( const double r, const bool adjustPosition )
10111011
{
1012-
if ( r >= 360 )
1012+
mItemRotation = r;
1013+
if ( mItemRotation >= 360.0 || mItemRotation <= -360.0 )
10131014
{
1014-
mItemRotation = ( static_cast< int >( r ) ) % 360;
1015-
}
1016-
else
1017-
{
1018-
mItemRotation = r;
1015+
mItemRotation = fmod( mItemRotation, 360.0 );
10191016
}
10201017

10211018
QgsExpressionContext context = createExpressionContext();

src/core/composer/qgscomposeritem.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,13 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
427427
*/
428428
bool positionLock() const { return mItemPositionLocked; }
429429

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

@@ -555,14 +555,15 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
555555

556556
public slots:
557557

558-
/** Sets the item rotation
559-
* \param r item rotation in degrees
558+
/**
559+
* Sets the item \a rotation, in degrees clockwise.
560+
* \param rotation item rotation in degrees
560561
* \param adjustPosition set to true if item should be shifted so that rotation occurs
561562
* around item center. If false, rotation occurs around item origin
562563
* \since QGIS 2.1
563564
* \see itemRotation
564565
*/
565-
virtual void setItemRotation( const double r, const bool adjustPosition = false );
566+
virtual void setItemRotation( const double rotation, const bool adjustPosition = false );
566567

567568
void repaint() override;
568569

src/core/composer/qgscomposermap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,12 @@ void QgsComposerMap::setOffset( double xOffset, double yOffset )
901901
mYOffset = yOffset;
902902
}
903903

904-
void QgsComposerMap::setMapRotation( double r )
904+
void QgsComposerMap::setMapRotation( double rotation )
905905
{
906-
mMapRotation = r;
906+
mMapRotation = rotation;
907907
mEvaluatedMapRotation = mMapRotation;
908908
invalidateCache();
909-
emit mapRotationChanged( r );
909+
emit mapRotationChanged( rotation );
910910
emit itemChanged();
911911
}
912912

src/core/composer/qgscomposermap.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,20 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
329329
/* reimplement setFrameStrokeWidth, so that updateBoundingRect() is called after setting the frame width */
330330
virtual void setFrameStrokeWidth( const double strokeWidth ) override;
331331

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

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

0 commit comments

Comments
 (0)