Skip to content
Permalink
Browse files

[composer] Change to pos() for item position, free up transform for f…

…uture use
  • Loading branch information
nyalldawson committed Nov 19, 2013
1 parent 584aba7 commit 1a88acbb30a5c8c998e1114c216ed49921a0536f
@@ -244,64 +244,64 @@ void QgsComposerItemWidget::setValuesForGuiPositionElements()
if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperLeft )
{
mUpperLeftCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() ) );
mXLineEdit->setText( QString::number( mItem->pos().x() ) );
mYLineEdit->setText( QString::number( mItem->pos().y() ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperMiddle )
{
mUpperMiddleCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() ) );
mXLineEdit->setText( QString::number( mItem->pos().x() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( mItem->pos().y() ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperRight )
{
mUpperRightCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() ) );
mXLineEdit->setText( QString::number( mItem->pos().x() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( mItem->pos().y() ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::MiddleLeft )
{
mMiddleLeftCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() + mItem->rect().height() / 2.0 ) );
mXLineEdit->setText( QString::number( mItem->pos().x() ) );
mYLineEdit->setText( QString::number( mItem->pos().y() + mItem->rect().height() / 2.0 ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::Middle )
{
mMiddleCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() + mItem->rect().height() / 2.0 ) );
mXLineEdit->setText( QString::number( mItem->pos().x() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( mItem->pos().y() + mItem->rect().height() / 2.0 ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::MiddleRight )
{
mMiddleRightCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() + mItem->rect().height() / 2.0 ) );
mXLineEdit->setText( QString::number( mItem->pos().x() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( mItem->pos().y() + mItem->rect().height() / 2.0 ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerLeft )
{
mLowerLeftCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() + mItem->rect().height() ) );
mXLineEdit->setText( QString::number( mItem->pos().x() ) );
mYLineEdit->setText( QString::number( mItem->pos().y() + mItem->rect().height() ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerMiddle )
{
mLowerMiddleCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() + mItem->rect().height() ) );
mXLineEdit->setText( QString::number( mItem->pos().x() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( mItem->pos().y() + mItem->rect().height() ) );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerRight )
{
mLowerRightCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( mItem->transform().dx() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( mItem->transform().dy() + mItem->rect().height() ) );
mXLineEdit->setText( QString::number( mItem->pos().x() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( mItem->pos().y() + mItem->rect().height() ) );
}

mWidthLineEdit->setText( QString::number( mItem->rect().width() ) );
@@ -395,7 +395,7 @@ void QgsComposerItemWidget::on_mUpperLeftCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx(), mItem->transform().dy(), QgsComposerItem::UpperLeft );
mItem->setItemPosition( mItem->pos().x(), mItem->pos().y(), QgsComposerItem::UpperLeft );
}
setValuesForGuiPositionElements();
}
@@ -406,8 +406,8 @@ void QgsComposerItemWidget::on_mUpperMiddleCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx() + mItem->rect().width() / 2.0,
mItem->transform().dy(), QgsComposerItem::UpperMiddle );
mItem->setItemPosition( mItem->pos().x() + mItem->rect().width() / 2.0,
mItem->pos().y(), QgsComposerItem::UpperMiddle );
}
setValuesForGuiPositionElements();
}
@@ -418,8 +418,8 @@ void QgsComposerItemWidget::on_mUpperRightCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx() + mItem->rect().width(),
mItem->transform().dy(), QgsComposerItem::UpperRight );
mItem->setItemPosition( mItem->pos().x() + mItem->rect().width(),
mItem->pos().y(), QgsComposerItem::UpperRight );
}
setValuesForGuiPositionElements();
}
@@ -430,8 +430,8 @@ void QgsComposerItemWidget::on_mMiddleLeftCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx(),
mItem->transform().dy() + mItem->rect().height() / 2.0, QgsComposerItem::MiddleLeft );
mItem->setItemPosition( mItem->pos().x(),
mItem->pos().y() + mItem->rect().height() / 2.0, QgsComposerItem::MiddleLeft );
}
setValuesForGuiPositionElements();
}
@@ -442,8 +442,8 @@ void QgsComposerItemWidget::on_mMiddleCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx() + mItem->rect().width() / 2.0,
mItem->transform().dy() + mItem->rect().height() / 2.0, QgsComposerItem::Middle );
mItem->setItemPosition( mItem->pos().x() + mItem->rect().width() / 2.0,
mItem->pos().y() + mItem->rect().height() / 2.0, QgsComposerItem::Middle );
}
setValuesForGuiPositionElements();
}
@@ -454,8 +454,8 @@ void QgsComposerItemWidget::on_mMiddleRightCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx() + mItem->rect().width(),
mItem->transform().dy() + mItem->rect().height() / 2.0, QgsComposerItem::MiddleRight );
mItem->setItemPosition( mItem->pos().x() + mItem->rect().width(),
mItem->pos().y() + mItem->rect().height() / 2.0, QgsComposerItem::MiddleRight );
}
setValuesForGuiPositionElements();
}
@@ -466,8 +466,8 @@ void QgsComposerItemWidget::on_mLowerLeftCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx(),
mItem->transform().dy() + mItem->rect().height(), QgsComposerItem::LowerLeft );
mItem->setItemPosition( mItem->pos().x(),
mItem->pos().y() + mItem->rect().height(), QgsComposerItem::LowerLeft );
}
setValuesForGuiPositionElements();
}
@@ -478,8 +478,8 @@ void QgsComposerItemWidget::on_mLowerMiddleCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx() + mItem->rect().width() / 2.0,
mItem->transform().dy() + mItem->rect().height(), QgsComposerItem::LowerMiddle );
mItem->setItemPosition( mItem->pos().x() + mItem->rect().width() / 2.0,
mItem->pos().y() + mItem->rect().height(), QgsComposerItem::LowerMiddle );
}
setValuesForGuiPositionElements();
}
@@ -490,8 +490,8 @@ void QgsComposerItemWidget::on_mLowerRightCheckBox_stateChanged( int state )
return;
if ( mItem )
{
mItem->setItemPosition( mItem->transform().dx() + mItem->rect().width(),
mItem->transform().dy() + mItem->rect().height(), QgsComposerItem::LowerRight );
mItem->setItemPosition( mItem->pos().x() + mItem->rect().width(),
mItem->pos().y() + mItem->rect().height(), QgsComposerItem::LowerRight );
}
setValuesForGuiPositionElements();
}
@@ -76,7 +76,7 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
arrowPen.setColor( mArrowColor );
painter->setPen( arrowPen );
painter->setBrush( QBrush( mArrowColor ) );
painter->drawLine( QPointF( mStartPoint.x() - transform().dx(), mStartPoint.y() - transform().dy() ), QPointF( mStopPoint.x() - transform().dx(), mStopPoint.y() - transform().dy() ) );
painter->drawLine( QPointF( mStartPoint.x() - pos().x(), mStartPoint.y() - pos().y() ), QPointF( mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y() ) );

if ( mMarkerMode == DefaultMarker )
{
@@ -98,10 +98,10 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
{
//maintain the relative position of start and stop point in the rectangle
double startPointXPos = ( mStartPoint.x() - transform().dx() ) / rect().width();
double startPointYPos = ( mStartPoint.y() - transform().dy() ) / rect().height();
double stopPointXPos = ( mStopPoint.x() - transform().dx() ) / rect().width();
double stopPointYPos = ( mStopPoint.y() - transform().dy() ) / rect().height();
double startPointXPos = ( mStartPoint.x() - pos().x() ) / rect().width();
double startPointYPos = ( mStartPoint.y() - pos().y() ) / rect().height();
double stopPointXPos = ( mStopPoint.x() - pos().x() ) / rect().width();
double stopPointYPos = ( mStopPoint.y() - pos().y() ) / rect().height();

mStartPoint.setX( rectangle.left() + startPointXPos * rectangle.width() );
mStartPoint.setY( rectangle.top() + startPointYPos * rectangle.height() );
@@ -117,7 +117,7 @@ void QgsComposerArrow::drawHardcodedMarker( QPainter *p, MarkerType type )
QBrush arrowBrush = p->brush();
arrowBrush.setColor( mArrowColor );
p->setBrush( arrowBrush );
drawArrowHead( p, mStopPoint.x() - transform().dx(), mStopPoint.y() - transform().dy(), angle( mStartPoint, mStopPoint ), mArrowHeadWidth );
drawArrowHead( p, mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y(), angle( mStartPoint, mStopPoint ), mArrowHeadWidth );
}

void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QString &markerPath )
@@ -156,12 +156,12 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
QPointF canvasPoint;
if ( type == StartMarker )
{
canvasPoint = QPointF( mStartPoint.x() - transform().dx(), mStartPoint.y() - transform().dy() );
canvasPoint = QPointF( mStartPoint.x() - pos().x(), mStartPoint.y() - pos().y() );
imageFixPoint.setY( mStartArrowHeadHeight );
}
else //end marker
{
canvasPoint = QPointF( mStopPoint.x() - transform().dx(), mStopPoint.y() - transform().dy() );
canvasPoint = QPointF( mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y() );
imageFixPoint.setY( 0 );
}

@@ -86,9 +86,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mUuid( QUuid::createUuid().toString() )
{
init( manageZValue );
QTransform t;
t.translate( x, y );
setTransform( t );
setPos( x, y );
}

void QgsComposerItem::init( bool manageZValue )
@@ -165,8 +163,8 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
}

//scene rect
composerItemElem.setAttribute( "x", QString::number( transform().dx() ) );
composerItemElem.setAttribute( "y", QString::number( transform().dy() ) );
composerItemElem.setAttribute( "x", QString::number( pos().x() ) );
composerItemElem.setAttribute( "y", QString::number( pos().y() ) );
composerItemElem.setAttribute( "width", QString::number( rect().width() ) );
composerItemElem.setAttribute( "height", QString::number( rect().height() ) );
composerItemElem.setAttribute( "positionMode", QString::number(( int ) mLastUsedPositionMode ) );
@@ -416,8 +414,7 @@ void QgsComposerItem::setPositionLock( bool lock )

void QgsComposerItem::move( double dx, double dy )
{
QTransform t = transform();
QRectF newSceneRect( t.dx() + dx, t.dy() + dy, rect().width(), rect().height() );
QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
setSceneRect( newSceneRect );
}

@@ -482,11 +479,7 @@ void QgsComposerItem::setSceneRect( const QRectF& rectangle )

QRectF newRect( 0, 0, newWidth, newHeight );
QGraphicsRectItem::setRect( newRect );

//set up transformation matrix for item coordinates
QTransform t;
t.translate( xTranslation, yTranslation );
setTransform( t );
setPos( xTranslation, yTranslation );

emit sizeChanged();
}
@@ -60,8 +60,8 @@ void QgsComposerItemGroup::addItem( QgsComposerItem* item )
item->setFlag( QGraphicsItem::ItemIsSelectable, false ); //item in groups cannot be selected

//update extent (which is in scene coordinates)
double minXItem = item->transform().dx();
double minYItem = item->transform().dy();
double minXItem = item->pos().x();
double minYItem = item->pos().y();
double maxXItem = minXItem + item->rect().width();
double maxYItem = minYItem + item->rect().height();

@@ -126,9 +126,9 @@ void QgsComposerItemGroup::setSceneRect( const QRectF& rectangle )
{
//calculate values between 0 and 1 for boundaries of all contained items, depending on their positions in the item group rectangle.
//then position the item boundaries in the new item group rect such that these values are the same
double xLeftCurrent = transform().dx();
double xLeftCurrent = pos().x();
double xRightCurrent = xLeftCurrent + rect().width();
double yTopCurrent = transform().dy();
double yTopCurrent = pos().y();
double yBottomCurrent = yTopCurrent + rect().height();

double xItemLeft, xItemRight, yItemTop, yItemBottom;
@@ -139,9 +139,9 @@ void QgsComposerItemGroup::setSceneRect( const QRectF& rectangle )
QSet<QgsComposerItem*>::iterator item_it = mItems.begin();
for ( ; item_it != mItems.end(); ++item_it )
{
xItemLeft = ( *item_it )->transform().dx();
xItemLeft = ( *item_it )->pos().x();
xItemRight = xItemLeft + ( *item_it )->rect().width();
yItemTop = ( *item_it )->transform().dy();
yItemTop = ( *item_it )->pos().y();
yItemBottom = yItemTop + ( *item_it )->rect().height();

xParamLeft = ( xItemLeft - xLeftCurrent ) / ( xRightCurrent - xLeftCurrent );
@@ -237,7 +237,7 @@ void QgsComposerLabel::adjustSizeToText()
double yShift = 0;
itemShiftAdjustSize( width, height, xShift, yShift );

QgsComposerItem::setSceneRect( QRectF( transform().dx() + xShift, transform().dy() + yShift, width, height ) );
QgsComposerItem::setSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
}

QFont QgsComposerLabel::font() const
@@ -252,8 +252,8 @@ void QgsComposerLabel::setRotation( double r )
QgsComposerItem::setRotation( r );
sizeChangedByRotation( width, height );

double x = transform().dx() + rect().width() / 2.0 - width / 2.0;
double y = transform().dy() + rect().height() / 2.0 - height / 2.0;
double x = pos().x() + rect().width() / 2.0 - width / 2.0;
double y = pos().y() + rect().height() / 2.0 - height / 2.0;
QgsComposerItem::setSceneRect( QRectF( x, y, width, height ) );
}

@@ -175,11 +175,11 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
//adjust box if width or height is to small
if ( painter && size.height() > rect().height() )
{
setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), size.height() ) );
setSceneRect( QRectF( pos().x(), pos().y(), rect().width(), size.height() ) );
}
if ( painter && size.width() > rect().width() )
{
setSceneRect( QRectF( transform().dx(), transform().dy(), size.width(), rect().height() ) );
setSceneRect( QRectF( pos().x(), pos().y(), size.width(), rect().height() ) );
}

if ( painter )
@@ -294,7 +294,7 @@ void QgsComposerLegend::adjustBoxSize()
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
if ( size.isValid() )
{
setSceneRect( QRectF( transform().dx(), transform().dy(), size.width(), size.height() ) );
setSceneRect( QRectF( pos().x(), pos().y(), size.width(), size.height() ) );
}
}

@@ -470,7 +470,7 @@ void QgsComposerMap::resize( double dx, double dy )
{
//setRect
QRectF currentRect = rect();
QRectF newSceneRect = QRectF( transform().dx(), transform().dy(), currentRect.width() + dx, currentRect.height() + dy );
QRectF newSceneRect = QRectF( pos().x(), pos().y(), currentRect.width() + dx, currentRect.height() + dy );
setSceneRect( newSceneRect );
updateItem();
}
@@ -591,7 +591,7 @@ void QgsComposerMap::setNewExtent( const QgsRectangle& extent )

double newHeight = currentRect.width() * extent.height() / extent.width();

setSceneRect( QRectF( transform().dx(), transform().dy(), currentRect.width(), newHeight ) );
setSceneRect( QRectF( pos().x(), pos().y(), currentRect.width(), newHeight ) );
updateItem();
}

@@ -1026,12 +1026,12 @@ void QgsComposerMouseHandles::collectAlignCoordinates( QMap< double, const QgsCo
{
continue;
}
alignCoordsX.insert( currentItem->transform().dx(), currentItem );
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().width(), currentItem );
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().center().x(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().top(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().center().y(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().bottom(), currentItem );
alignCoordsX.insert( currentItem->pos().x(), currentItem );
alignCoordsX.insert( currentItem->pos().x() + currentItem->rect().width(), currentItem );
alignCoordsX.insert( currentItem->pos().x() + currentItem->rect().center().x(), currentItem );
alignCoordsY.insert( currentItem->pos().y() + currentItem->rect().top(), currentItem );
alignCoordsY.insert( currentItem->pos().y() + currentItem->rect().center().y(), currentItem );
alignCoordsY.insert( currentItem->pos().y() + currentItem->rect().bottom(), currentItem );
}
}

0 comments on commit 1a88acb

Please sign in to comment.
You can’t perform that action at this time.