Skip to content
Permalink
Browse files

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 9db4f984ccfc353e5be2131f6ccf09ab13404cda
Showing with 30 additions and 43 deletions.
  1. +28 −43 src/core/composer/qgscomposeritem.cpp
  2. +2 −0 src/core/composer/qgscomposeritem.h
@@ -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 )
@@ -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 );
@@ -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;
}
}

@@ -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.
You can’t perform that action at this time.