Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Clean up item rotation api, seperate item rotation (for sh…
…apes, labels) from map rotation and picture rotation.

Maintain compatibility with 2.0 api, deprecate ambiguous rotation/setRotation methods
  • Loading branch information
nyalldawson committed Dec 30, 2013
1 parent 4aeaa3f commit 719c78c
Show file tree
Hide file tree
Showing 27 changed files with 473 additions and 100 deletions.
36 changes: 34 additions & 2 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -332,6 +332,14 @@ class QgsComposerItem: QObject, QGraphicsRectItem
@note this method was added in version 1.2*/
bool positionLock() const;

/**Returns the rotation for the composer item
@note this method was added in version 2.1*/
double itemRotation() const;

/**Returns the rotation for the composer item
* @deprecated Use itemRotation()
* instead
*/
double rotation() const;

/**Updates item, with the possibility to do custom update for subclasses*/
Expand All @@ -351,7 +359,15 @@ class QgsComposerItem: QObject, QGraphicsRectItem
QString uuid() const;

public slots:
/**Sets the item rotation
* @deprecated Use setItemRotation( double rotation ) instead
*/
virtual void setRotation( double r );

/**Sets the item rotation
@note this method was added in version 2.1
*/
virtual void setItemRotation( double r );
void repaint();

protected:
Expand Down Expand Up @@ -394,11 +410,27 @@ class QgsComposerItem: QObject, QGraphicsRectItem
//some utility functions

/**Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation*/
bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
/**Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation
* @deprecated Use bool imageSizeConsideringRotation( double& width, double& height, double rotation )
* instead
*/
bool imageSizeConsideringRotation( double& width, double& height ) const;

/**Calculates corner point after rotation and scaling*/
bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
/**Calculates corner point after rotation and scaling
* @deprecated Use bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation )
* instead
*/
bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;

/**Calculates width / height of the bounding box of a rotated rectangle (mRotation)*/
/**Calculates width / height of the bounding box of a rotated rectangle*/
void sizeChangedByRotation( double& width, double& height, double rotation );
/**Calculates width / height of the bounding box of a rotated rectangle
* @deprecated Use void sizeChangedByRotation( double& width, double& height, double rotation )
* instead
*/
void sizeChangedByRotation( double& width, double& height );
/**Rotates a point / vector
@param angle rotation angle in degrees, counterclockwise
Expand All @@ -416,7 +448,7 @@ class QgsComposerItem: QObject, QGraphicsRectItem

signals:
/**Is emitted on rotation change to notify north arrow pictures*/
void rotationChanged( double newRotation );
void itemRotationChanged( double newRotation );
/**Used e.g. by the item widgets to update the gui elements*/
void itemChanged();
/**Emitted if the rectangle changes*/
Expand Down
8 changes: 5 additions & 3 deletions python/core/composer/qgscomposeritemcommand.sip
Expand Up @@ -46,7 +46,6 @@ class QgsComposerMergeCommand : QgsComposerItemCommand
//composer label
ComposerLabelSetText,
ComposerLabelSetId,
ComposerLabelRotation,
//composer map
ComposerMapRotation,
ComposerMapAnnotationDistance,
Expand All @@ -57,6 +56,8 @@ class QgsComposerMergeCommand : QgsComposerItemCommand
LegendEqualColumnWidth,
LegendSymbolWidth,
LegendSymbolHeight,
LegendWmsLegendWidth,
LegendWmsLegendHeight,
LegendTitleSpaceBottom,
LegendGroupSpace,
LegendLayerSpace,
Expand All @@ -81,14 +82,15 @@ class QgsComposerMergeCommand : QgsComposerItemCommand
TableMargin,
TableGridStrokeWidth,
//composer shape
ShapeRotation,
ShapeCornerRadius,
ShapeOutlineWidth,
//composer arrow
ArrowOutlineWidth,
ArrowHeadWidth,
//item
ItemOutlineWidth,
ItemMove
ItemMove,
ItemRotation
};

QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
Expand Down
6 changes: 6 additions & 0 deletions python/core/composer/qgscomposerlabel.sip
Expand Up @@ -79,5 +79,11 @@ class QgsComposerLabel : QgsComposerItem
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

public slots:
/* Sets rotation for the label
* @deprecated Use setItemRotation( double rotation ) instead
*/
virtual void setRotation( double r );

/* Sets rotation for the label */
virtual void setItemRotation( double r );
};
34 changes: 34 additions & 0 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -293,7 +293,22 @@ class QgsComposerMap : QgsComposerItem
void setCrossLength( double l );
double crossLength();

/**Sets rotation for the map - this does not affect the composer item shape, only the
way the map is drawn within the item
* @deprecated Use setMapRotation( double rotation ) instead
*/
void setRotation( double r );
/**Returns the rotation used for drawing the map within the composer item
* @deprecated Use mapRotation() instead
*/
double rotation() const;

/**Sets rotation for the map - this does not affect the composer item shape, only the
way the map is drawn within the item
@note this function was added in version 2.1*/
void setMapRotation( double r );
/**Returns the rotation used for drawing the map within the composer item*/
double mapRotation() const;

void updateItem();

Expand Down Expand Up @@ -336,9 +351,28 @@ class QgsComposerMap : QgsComposerItem
/**Sets mId to a number not yet used in the composition. mId is kept if it is not in use.
Usually, this function is called before adding the composer map to the composition*/
void assignFreeId();

/**Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation
* @deprecated Use bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height, double rotation )
* instead
*/
bool imageSizeConsideringRotation( double& width, double& height ) const;
/**Calculates corner point after rotation and scaling
* @deprecated Use QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation )
* instead
*/
bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
/**Calculates width / height of the bounding box of a rotated rectangle
* @deprecated Use QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
* instead
*/
void sizeChangedByRotation( double& width, double& height );

signals:
void extentChanged();

/**Is emitted on rotation change to notify north arrow pictures*/
void mapRotationChanged( double newRotation );

public slots:

Expand Down
39 changes: 38 additions & 1 deletion python/core/composer/qgscomposerpicture.sip
Expand Up @@ -38,14 +38,51 @@ class QgsComposerPicture: QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

/**Returns the rotation used for drawing the picture within the composer item
* @deprecated Use pictureRotation() instead
*/
double rotation() const;

/**Returns the rotation used for drawing the picture within the item
@note this function was added in version 2.1*/
double pictureRotation() const;

/**Sets the map object for rotation (by id). A value of -1 disables the map rotation*/
void setRotationMap( int composerMapId );
/**Returns the id of the rotation map*/
int rotationMap() const;
/**True if the rotation is taken from a map item*/
bool useRotationMap() const;

/**Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation
* @deprecated Use bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height, double rotation )
* instead
*/
bool imageSizeConsideringRotation( double& width, double& height ) const;
/**Calculates corner point after rotation and scaling
* @deprecated Use QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation )
* instead
*/
bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
/**Calculates width / height of the bounding box of a rotated rectangle
* @deprecated Use QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
* instead
*/
void sizeChangedByRotation( double& width, double& height );

public slots:
/**Sets the rotation and adapts the item rect*/
/**Sets the picture rotation within the item bounds. This does not affect the item rectangle,
only the way the picture is drawn within the item.
* @deprecated Use setPictureRotation( double rotation ) instead
*/
virtual void setRotation( double r );

/**Sets the picture rotation within the item bounds. This does not affect the item rectangle,
only the way the picture is drawn within the item.
@note this function was added in version 2.1*/
virtual void setPictureRotation( double r );

signals:
/**Is emitted on picture rotation change*/
void pictureRotationChanged( double newRotation );
};
2 changes: 1 addition & 1 deletion python/core/composer/qgscomposershape.sip
Expand Up @@ -50,7 +50,7 @@ class QgsComposerShape: QgsComposerItem

public slots:
/**Sets item rotation and resizes item bounds such that the shape always has the same size*/
virtual void setRotation( double r );
virtual void setItemRotation( double r );

protected:
/* reimplement drawFrame, since it's not a rect, but a custom shape */
Expand Down
6 changes: 3 additions & 3 deletions src/app/composer/qgscomposerlabelwidget.cpp
Expand Up @@ -232,8 +232,8 @@ void QgsComposerLabelWidget::on_mRotationSpinBox_valueChanged( double v )
{
if ( mComposerLabel )
{
mComposerLabel->beginCommand( tr( "Label rotation changed" ), QgsComposerMergeCommand::ComposerLabelRotation );
mComposerLabel->setRotation( v );
mComposerLabel->beginCommand( tr( "Label rotation changed" ), QgsComposerMergeCommand::ItemRotation );
mComposerLabel->setItemRotation( v );
mComposerLabel->update();
mComposerLabel->endCommand();
}
Expand All @@ -252,7 +252,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
mRotationSpinBox->setValue( mComposerLabel->rotation() );
mRotationSpinBox->setValue( mComposerLabel->itemRotation() );
blockAllSignals( false );
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -161,7 +161,7 @@ void QgsComposerMapWidget::on_mScaleLineEdit_editingFinished()
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mRotationSpinBox_valueChanged( double value )
void QgsComposerMapWidget::on_mMapRotationSpinBox_valueChanged( double value )
{
if ( !mComposerMap )
{
Expand Down Expand Up @@ -291,7 +291,7 @@ void QgsComposerMapWidget::updateGuiElements()
mYMinLineEdit->setText( QString::number( composerMapExtent.yMinimum(), 'f', 3 ) );
mYMaxLineEdit->setText( QString::number( composerMapExtent.yMaximum(), 'f', 3 ) );

mRotationSpinBox->setValue( mComposerMap->rotation() );
mMapRotationSpinBox->setValue( mComposerMap->mapRotation() );

//keep layer list check box
if ( mComposerMap->keepLayerSet() )
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermapwidget.h
Expand Up @@ -37,7 +37,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
public slots:
void on_mPreviewModeComboBox_activated( int i );
void on_mScaleLineEdit_editingFinished();
void on_mRotationSpinBox_valueChanged( double value );
void on_mMapRotationSpinBox_valueChanged( double value );
void on_mSetToMapCanvasExtentButton_clicked();
void on_mUpdatePreviewButton_clicked();
void on_mKeepLayerListCheckBox_stateChanged( int state );
Expand Down
29 changes: 18 additions & 11 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -50,7 +50,7 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
connect( mSearchDirectoriesGroupBox, SIGNAL( collapsedStateChanged( bool ) ), this, SLOT( loadPicturePreviews( bool ) ) );

connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( pictureRotationChanged( double ) ), this, SLOT( setPicRotationSpinValue( double ) ) );
}

QgsComposerPictureWidget::~QgsComposerPictureWidget()
Expand Down Expand Up @@ -121,13 +121,12 @@ void QgsComposerPictureWidget::on_mPictureLineEdit_editingFinished()
}


void QgsComposerPictureWidget::on_mRotationSpinBox_valueChanged( double d )
void QgsComposerPictureWidget::on_mPictureRotationSpinBox_valueChanged( double d )
{
if ( mPicture )
{
mPicture->beginCommand( tr( "Picture rotation changed" ), QgsComposerMergeCommand::ComposerPictureRotation );
mPicture->setRotation( d );
mPicture->update();
mPicture->setPictureRotation( d );
mPicture->endCommand();
}
}
Expand Down Expand Up @@ -210,8 +209,9 @@ void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged(
if ( state == Qt::Unchecked )
{
mPicture->setRotationMap( -1 );
mRotationSpinBox->setEnabled( true );
mPictureRotationSpinBox->setEnabled( true );
mComposerMapComboBox->setEnabled( false );
mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
}
else
{
Expand All @@ -223,7 +223,7 @@ void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged(
int composerId = mComposerMapComboBox->itemData( currentItemIndex, Qt::UserRole ).toInt();

mPicture->setRotationMap( composerId );
mRotationSpinBox->setEnabled( false );
mPictureRotationSpinBox->setEnabled( false );
mComposerMapComboBox->setEnabled( true );
}
mPicture->endCommand();
Expand Down Expand Up @@ -310,26 +310,33 @@ void QgsComposerPictureWidget::refreshMapComboBox()
mComposerMapComboBox->blockSignals( false );
}

void QgsComposerPictureWidget::setPicRotationSpinValue( double r )
{
mPictureRotationSpinBox->blockSignals( true );
mPictureRotationSpinBox->setValue( r );
mPictureRotationSpinBox->blockSignals( false );
}

void QgsComposerPictureWidget::setGuiElementValues()
{
//set initial gui values
if ( mPicture )
{
mRotationSpinBox->blockSignals( true );
mPictureRotationSpinBox->blockSignals( true );
mPictureLineEdit->blockSignals( true );
mComposerMapComboBox->blockSignals( true );
mRotationFromComposerMapCheckBox->blockSignals( true );

mPictureLineEdit->setText( mPicture->pictureFile() );
// QRectF pictureRect = mPicture->rect();
mRotationSpinBox->setValue( mPicture->rotation() );
mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );

refreshMapComboBox();

if ( mPicture->useRotationMap() )
{
mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
mRotationSpinBox->setEnabled( false );
mPictureRotationSpinBox->setEnabled( false );
mComposerMapComboBox->setEnabled( true );
QString mapText = tr( "Map %1" ).arg( mPicture->rotationMap() );
int itemId = mComposerMapComboBox->findText( mapText );
Expand All @@ -341,13 +348,13 @@ void QgsComposerPictureWidget::setGuiElementValues()
else
{
mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
mRotationSpinBox->setEnabled( true );
mPictureRotationSpinBox->setEnabled( true );
mComposerMapComboBox->setEnabled( false );
}


mRotationFromComposerMapCheckBox->blockSignals( false );
mRotationSpinBox->blockSignals( false );
mPictureRotationSpinBox->blockSignals( false );
mPictureLineEdit->blockSignals( false );
mComposerMapComboBox->blockSignals( false );
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/composer/qgscomposerpicturewidget.h
Expand Up @@ -39,7 +39,7 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
public slots:
void on_mPictureBrowseButton_clicked();
void on_mPictureLineEdit_editingFinished();
void on_mRotationSpinBox_valueChanged( double d );
void on_mPictureRotationSpinBox_valueChanged( double d );
void on_mPreviewListWidget_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
void on_mAddDirectoryButton_clicked();
void on_mRemoveDirectoryButton_clicked();
Expand All @@ -53,6 +53,10 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
private slots:
/**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues();

/**Sets the picture rotation GUI control value*/
void setPicRotationSpinValue( double r );

/** Load SVG and pixel-based image previews
* @param collapsed Whether the parent group box is collapsed
* @note added in 1.9
Expand Down

0 comments on commit 719c78c

Please sign in to comment.