Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove duplicated code and coding style improvements in composer item…
… (provided as part of pull request 33 by Rokemoon)
  • Loading branch information
mhugent committed Aug 3, 2011
1 parent 4d56f98 commit 9db4f98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 43 deletions.
71 changes: 28 additions & 43 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -45,20 +45,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
{
setFlag( QGraphicsItem::ItemIsSelectable, true );
setAcceptsHoverEvents( true );

//set default pen and brush
setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
QPen defaultPen( QColor( 0, 0, 0 ) );
defaultPen.setWidthF( 0.3 );
setPen( defaultPen );

//let z-Value be managed by composition
if ( mComposition && manageZValue )
{
mComposition->addItemToZList( this );
}
init( manageZValue );
}

QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue )
Expand All @@ -71,20 +58,22 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
{
setFlag( QGraphicsItem::ItemIsSelectable, true );
setAcceptsHoverEvents( true );

init( manageZValue );
QTransform t;
t.translate( x, y );
setTransform( t );
}

void QgsComposerItem::init( bool manageZValue )
{
setFlag( QGraphicsItem::ItemIsSelectable, true );
setAcceptsHoverEvents( true );
//set default pen and brush
setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
QPen defaultPen( QColor( 0, 0, 0 ) );
defaultPen.setWidthF( 0.3 );
setPen( defaultPen );

//let z-Value be managed by composition
//let z-Value be managed by composition
if ( mComposition && manageZValue )
{
mComposition->addItemToZList( this );
Expand Down Expand Up @@ -387,30 +376,26 @@ void QgsComposerItem::mouseReleaseEvent( QGraphicsSceneMouseEvent * event )
Qt::CursorShape QgsComposerItem::cursorForPosition( const QPointF& itemCoordPos )
{
QgsComposerItem::MouseMoveAction mouseAction = mouseMoveActionForPosition( itemCoordPos );

if ( mouseAction == QgsComposerItem::NoAction )
{
return Qt::ForbiddenCursor;
}
if ( mouseAction == QgsComposerItem::MoveItem )
{
return Qt::ClosedHandCursor;
}
else if ( mouseAction == QgsComposerItem::ResizeLeftUp || mouseAction == QgsComposerItem::ResizeRightDown )
{
return Qt::SizeFDiagCursor;
}
else if ( mouseAction == QgsComposerItem::ResizeLeftDown || mouseAction == QgsComposerItem::ResizeRightUp )
{
return Qt::SizeBDiagCursor;
}
else if ( mouseAction == QgsComposerItem::ResizeUp || mouseAction == QgsComposerItem::ResizeDown )
{
return Qt::SizeVerCursor;
}
else //if(mouseAction == QgsComposerItem::ResizeLeft || mouseAction == QgsComposerItem::ResizeRight)
{
return Qt::SizeHorCursor;
switch ( mouseAction )
{
case NoAction:
return Qt::ForbiddenCursor;
case MoveItem:
return Qt::SizeAllCursor;
case ResizeUp:
case ResizeDown:
return Qt::SizeVerCursor;
case ResizeLeft:
case ResizeRight:
return Qt::SizeHorCursor;
case ResizeLeftUp:
case ResizeRightDown:
return Qt::SizeFDiagCursor;
case ResizeRightUp:
case ResizeLeftDown:
return Qt::SizeBDiagCursor;
default:
return Qt::ArrowCursor;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -333,6 +333,8 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
private:
// Label id (unique within the same composition)
QString mId;

void init( bool manageZValue );
};

#endif

0 comments on commit 9db4f98

Please sign in to comment.