mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Add signals for size and rotation changes
This commit is contained in:
parent
b5777adbdd
commit
7d072beee7
@ -419,6 +419,16 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
|
|||||||
.. seealso:: setLocked()
|
.. seealso:: setLocked()
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
void rotationChanged( double newRotation );
|
||||||
|
%Docstring
|
||||||
|
Emitted on item rotation change.
|
||||||
|
%End
|
||||||
|
|
||||||
|
void sizeChanged();
|
||||||
|
%Docstring
|
||||||
|
Emitted when the item's size changes.
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void drawDebugRect( QPainter *painter );
|
virtual void drawDebugRect( QPainter *painter );
|
||||||
|
@ -230,6 +230,7 @@ void QgsLayoutItem::attemptResize( const QgsLayoutSize &size )
|
|||||||
mItemSize = actualSizeTargetUnits;
|
mItemSize = actualSizeTargetUnits;
|
||||||
|
|
||||||
setRect( 0, 0, actualSizeLayoutUnits.width(), actualSizeLayoutUnits.height() );
|
setRect( 0, 0, actualSizeLayoutUnits.width(), actualSizeLayoutUnits.height() );
|
||||||
|
emit sizeChanged();
|
||||||
refreshItemPosition();
|
refreshItemPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,12 +483,10 @@ void QgsLayoutItem::rotateItem( const double angle, const QPointF &transformOrig
|
|||||||
//adjust stored position of item to match scene pos of reference point
|
//adjust stored position of item to match scene pos of reference point
|
||||||
updateStoredItemPosition();
|
updateStoredItemPosition();
|
||||||
|
|
||||||
//TODO
|
emit rotationChanged( evaluatedAngle );
|
||||||
// emit itemRotationChanged( rotation );
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
//update bounds of scene, since rotation may affect this
|
//update bounds of scene, since rotation may affect this
|
||||||
//mLayout->updateBounds();
|
mLayout->updateBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -419,6 +419,16 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
|
|||||||
*/
|
*/
|
||||||
void lockChanged();
|
void lockChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted on item rotation change.
|
||||||
|
*/
|
||||||
|
void rotationChanged( double newRotation );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the item's size changes.
|
||||||
|
*/
|
||||||
|
void sizeChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -686,6 +686,8 @@ void TestQgsLayoutItem::resize()
|
|||||||
//resize test item (no restrictions), same units as layout
|
//resize test item (no restrictions), same units as layout
|
||||||
l.setUnits( QgsUnitTypes::LayoutMillimeters );
|
l.setUnits( QgsUnitTypes::LayoutMillimeters );
|
||||||
TestItem *item = new TestItem( &l );
|
TestItem *item = new TestItem( &l );
|
||||||
|
QSignalSpy spySizeChanged( item, &QgsLayoutItem::sizeChanged );
|
||||||
|
|
||||||
item->setRect( 0, 0, 55, 45 );
|
item->setRect( 0, 0, 55, 45 );
|
||||||
item->attemptMove( QgsLayoutPoint( 27, 29 ) );
|
item->attemptMove( QgsLayoutPoint( 27, 29 ) );
|
||||||
item->attemptResize( QgsLayoutSize( 100.0, 200.0, QgsUnitTypes::LayoutMillimeters ) );
|
item->attemptResize( QgsLayoutSize( 100.0, 200.0, QgsUnitTypes::LayoutMillimeters ) );
|
||||||
@ -693,6 +695,7 @@ void TestQgsLayoutItem::resize()
|
|||||||
QCOMPARE( item->rect().height(), 200.0 );
|
QCOMPARE( item->rect().height(), 200.0 );
|
||||||
QCOMPARE( item->scenePos().x(), 27.0 ); //item should not move
|
QCOMPARE( item->scenePos().x(), 27.0 ); //item should not move
|
||||||
QCOMPARE( item->scenePos().y(), 29.0 );
|
QCOMPARE( item->scenePos().y(), 29.0 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 1 );
|
||||||
|
|
||||||
//test conversion of units
|
//test conversion of units
|
||||||
l.setUnits( QgsUnitTypes::LayoutCentimeters );
|
l.setUnits( QgsUnitTypes::LayoutCentimeters );
|
||||||
@ -700,34 +703,41 @@ void TestQgsLayoutItem::resize()
|
|||||||
item->attemptResize( QgsLayoutSize( 0.30, 0.45, QgsUnitTypes::LayoutMeters ) );
|
item->attemptResize( QgsLayoutSize( 0.30, 0.45, QgsUnitTypes::LayoutMeters ) );
|
||||||
QCOMPARE( item->rect().width(), 30.0 );
|
QCOMPARE( item->rect().width(), 30.0 );
|
||||||
QCOMPARE( item->rect().height(), 45.0 );
|
QCOMPARE( item->rect().height(), 45.0 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 2 );
|
||||||
|
|
||||||
//test pixel -> page conversion
|
//test pixel -> page conversion
|
||||||
l.setUnits( QgsUnitTypes::LayoutInches );
|
l.setUnits( QgsUnitTypes::LayoutInches );
|
||||||
l.context().setDpi( 100.0 );
|
l.context().setDpi( 100.0 );
|
||||||
item->refresh();
|
item->refresh();
|
||||||
|
QCOMPARE( spySizeChanged.count(), 3 );
|
||||||
item->setRect( 0, 0, 1, 2 );
|
item->setRect( 0, 0, 1, 2 );
|
||||||
item->attemptResize( QgsLayoutSize( 140, 280, QgsUnitTypes::LayoutPixels ) );
|
item->attemptResize( QgsLayoutSize( 140, 280, QgsUnitTypes::LayoutPixels ) );
|
||||||
QCOMPARE( item->rect().width(), 1.4 );
|
QCOMPARE( item->rect().width(), 1.4 );
|
||||||
QCOMPARE( item->rect().height(), 2.8 );
|
QCOMPARE( item->rect().height(), 2.8 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 4 );
|
||||||
//changing the dpi should resize the item
|
//changing the dpi should resize the item
|
||||||
l.context().setDpi( 200.0 );
|
l.context().setDpi( 200.0 );
|
||||||
item->refresh();
|
item->refresh();
|
||||||
QCOMPARE( item->rect().width(), 0.7 );
|
QCOMPARE( item->rect().width(), 0.7 );
|
||||||
QCOMPARE( item->rect().height(), 1.4 );
|
QCOMPARE( item->rect().height(), 1.4 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 5 );
|
||||||
|
|
||||||
//test page -> pixel conversion
|
//test page -> pixel conversion
|
||||||
l.setUnits( QgsUnitTypes::LayoutPixels );
|
l.setUnits( QgsUnitTypes::LayoutPixels );
|
||||||
l.context().setDpi( 100.0 );
|
l.context().setDpi( 100.0 );
|
||||||
item->refresh();
|
item->refresh();
|
||||||
item->setRect( 0, 0, 2, 2 );
|
item->setRect( 0, 0, 2, 2 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 6 );
|
||||||
item->attemptResize( QgsLayoutSize( 1, 3, QgsUnitTypes::LayoutInches ) );
|
item->attemptResize( QgsLayoutSize( 1, 3, QgsUnitTypes::LayoutInches ) );
|
||||||
QCOMPARE( item->rect().width(), 100.0 );
|
QCOMPARE( item->rect().width(), 100.0 );
|
||||||
QCOMPARE( item->rect().height(), 300.0 );
|
QCOMPARE( item->rect().height(), 300.0 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 7 );
|
||||||
//changing dpi results in item resize
|
//changing dpi results in item resize
|
||||||
l.context().setDpi( 200.0 );
|
l.context().setDpi( 200.0 );
|
||||||
item->refresh();
|
item->refresh();
|
||||||
QCOMPARE( item->rect().width(), 200.0 );
|
QCOMPARE( item->rect().width(), 200.0 );
|
||||||
QCOMPARE( item->rect().height(), 600.0 );
|
QCOMPARE( item->rect().height(), 600.0 );
|
||||||
|
QCOMPARE( spySizeChanged.count(), 8 );
|
||||||
|
|
||||||
l.setUnits( QgsUnitTypes::LayoutMillimeters );
|
l.setUnits( QgsUnitTypes::LayoutMillimeters );
|
||||||
}
|
}
|
||||||
@ -1133,6 +1143,9 @@ void TestQgsLayoutItem::rotation()
|
|||||||
QgsLayout l( &proj );
|
QgsLayout l( &proj );
|
||||||
|
|
||||||
TestItem *item = new TestItem( &l );
|
TestItem *item = new TestItem( &l );
|
||||||
|
|
||||||
|
QSignalSpy spyRotationChanged( item, &QgsLayoutItem::rotationChanged );
|
||||||
|
|
||||||
l.setUnits( QgsUnitTypes::LayoutMillimeters );
|
l.setUnits( QgsUnitTypes::LayoutMillimeters );
|
||||||
item->setPos( 6.0, 10.0 );
|
item->setPos( 6.0, 10.0 );
|
||||||
item->setRect( 0.0, 0.0, 10.0, 8.0 );
|
item->setRect( 0.0, 0.0, 10.0, 8.0 );
|
||||||
@ -1151,6 +1164,9 @@ void TestQgsLayoutItem::rotation()
|
|||||||
QCOMPARE( bounds.right(), 15.0 );
|
QCOMPARE( bounds.right(), 15.0 );
|
||||||
QCOMPARE( bounds.top(), 9.0 );
|
QCOMPARE( bounds.top(), 9.0 );
|
||||||
QCOMPARE( bounds.bottom(), 19.0 );
|
QCOMPARE( bounds.bottom(), 19.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 1 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 0 ).at( 0 ).toDouble(), 90.0 );
|
||||||
|
|
||||||
|
|
||||||
//check that negative angles are preserved as negative
|
//check that negative angles are preserved as negative
|
||||||
item->setItemRotation( -90.0 );
|
item->setItemRotation( -90.0 );
|
||||||
@ -1159,14 +1175,21 @@ void TestQgsLayoutItem::rotation()
|
|||||||
bounds = item->sceneBoundingRect();
|
bounds = item->sceneBoundingRect();
|
||||||
QCOMPARE( bounds.width(), 8.0 );
|
QCOMPARE( bounds.width(), 8.0 );
|
||||||
QCOMPARE( bounds.height(), 10.0 );
|
QCOMPARE( bounds.height(), 10.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 2 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 1 ).at( 0 ).toDouble(), -90.0 );
|
||||||
|
|
||||||
//check that rotating changes stored item position for reference point
|
//check that rotating changes stored item position for reference point
|
||||||
item->setItemRotation( 0.0 );
|
item->setItemRotation( 0.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 3 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 2 ).at( 0 ).toDouble(), 0.0 );
|
||||||
|
|
||||||
item->attemptMove( QgsLayoutPoint( 5.0, 8.0 ) );
|
item->attemptMove( QgsLayoutPoint( 5.0, 8.0 ) );
|
||||||
item->attemptResize( QgsLayoutSize( 10.0, 6.0 ) );
|
item->attemptResize( QgsLayoutSize( 10.0, 6.0 ) );
|
||||||
item->setItemRotation( 90.0 );
|
item->setItemRotation( 90.0 );
|
||||||
QCOMPARE( item->positionWithUnits().x(), 13.0 );
|
QCOMPARE( item->positionWithUnits().x(), 13.0 );
|
||||||
QCOMPARE( item->positionWithUnits().y(), 6.0 );
|
QCOMPARE( item->positionWithUnits().y(), 6.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 4 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 3 ).at( 0 ).toDouble(), 90.0 );
|
||||||
|
|
||||||
//setting item position (for reference point) respects rotation
|
//setting item position (for reference point) respects rotation
|
||||||
item->attemptMove( QgsLayoutPoint( 10.0, 8.0 ) );
|
item->attemptMove( QgsLayoutPoint( 10.0, 8.0 ) );
|
||||||
@ -1184,15 +1207,22 @@ void TestQgsLayoutItem::rotation()
|
|||||||
|
|
||||||
//data defined rotation
|
//data defined rotation
|
||||||
item->setItemRotation( 0.0 );
|
item->setItemRotation( 0.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 5 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 4 ).at( 0 ).toDouble(), 0.0 );
|
||||||
|
|
||||||
item->attemptMove( QgsLayoutPoint( 5.0, 8.0 ) );
|
item->attemptMove( QgsLayoutPoint( 5.0, 8.0 ) );
|
||||||
item->attemptResize( QgsLayoutSize( 10.0, 6.0 ) );
|
item->attemptResize( QgsLayoutSize( 10.0, 6.0 ) );
|
||||||
item->dataDefinedProperties().setProperty( QgsLayoutObject::ItemRotation, QgsProperty::fromExpression( QStringLiteral( "90" ) ) );
|
item->dataDefinedProperties().setProperty( QgsLayoutObject::ItemRotation, QgsProperty::fromExpression( QStringLiteral( "90" ) ) );
|
||||||
item->refreshDataDefinedProperty( QgsLayoutObject::ItemRotation );
|
item->refreshDataDefinedProperty( QgsLayoutObject::ItemRotation );
|
||||||
QCOMPARE( item->itemRotation(), 90.0 );
|
QCOMPARE( item->itemRotation(), 90.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 6 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 5 ).at( 0 ).toDouble(), 90.0 );
|
||||||
//also check when refreshing all properties
|
//also check when refreshing all properties
|
||||||
item->dataDefinedProperties().setProperty( QgsLayoutObject::ItemRotation, QgsProperty::fromExpression( QStringLiteral( "45" ) ) );
|
item->dataDefinedProperties().setProperty( QgsLayoutObject::ItemRotation, QgsProperty::fromExpression( QStringLiteral( "45" ) ) );
|
||||||
item->refreshDataDefinedProperty( QgsLayoutObject::AllProperties );
|
item->refreshDataDefinedProperty( QgsLayoutObject::AllProperties );
|
||||||
QCOMPARE( item->itemRotation(), 45.0 );
|
QCOMPARE( item->itemRotation(), 45.0 );
|
||||||
|
QCOMPARE( spyRotationChanged.count(), 7 );
|
||||||
|
QCOMPARE( spyRotationChanged.at( 6 ).at( 0 ).toDouble(), 45.0 );
|
||||||
|
|
||||||
delete item;
|
delete item;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user