Skip to content
Permalink
Browse files
Remove addItem methods of composer view. Use the ones from compositio…
…n instead
  • Loading branch information
marco committed Dec 5, 2011
1 parent 8999de6 commit c9bcd60a8903c136628f6666ed33d372a0b68c89
Showing with 84 additions and 194 deletions.
  1. +0 −15 python/gui/qgscomposerview.sip
  2. +0 −4 src/app/composer/qgscomposer.cpp
  3. +84 −158 src/gui/qgscomposerview.cpp
  4. +0 −17 src/gui/qgscomposerview.h
@@ -49,21 +49,6 @@ class QgsComposerView: QGraphicsView
void setComposition( QgsComposition* c );
/**Returns the composition or 0 in case of error*/
QgsComposition* composition();

/**Adds label to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerLabel( QgsComposerLabel* label);
/**Adds map to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerMap( QgsComposerMap* map );
/**Adds scale bar to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerScaleBar( QgsComposerScaleBar* scaleBar );
/**Adds legend to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerLegend( QgsComposerLegend* legend );
/**Adds picture to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerPicture( QgsComposerPicture* picture );
/**Adds a composer shape to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerShape( QgsComposerShape* shape );
/**Adds a composer table to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerTable( QgsComposerAttributeTable* table );

/**Returns the composer main window*/
QMainWindow* composerWindow();
@@ -1572,10 +1572,6 @@ void QgsComposer::addComposerLegend( QgsComposerLegend* legend )
}

QgsComposerLegendWidget* lWidget = new QgsComposerLegendWidget( legend );
if ( sender() ) //only update if created from GUI (not after XML read)
{
lWidget->updateLegend();
}
mItemWidgetMap.insert( legend, lWidget );
}

@@ -137,50 +137,68 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
break;

case AddLabel:
{
QgsComposerLabel* newLabelItem = new QgsComposerLabel( composition() );
newLabelItem->setText( tr( "Quantum GIS" ) );
newLabelItem->adjustSizeToText();
newLabelItem->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
addComposerLabel( newLabelItem );
emit actionFinished();
}
break;
if ( composition() )
{
QgsComposerLabel* newLabelItem = new QgsComposerLabel( composition() );
newLabelItem->setText( tr( "Quantum GIS" ) );
newLabelItem->adjustSizeToText();
newLabelItem->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
composition()->addComposerLabel( newLabelItem );
emit actionFinished();
pushAddRemoveCommand( newLabelItem, tr( "Label added" ) );
}
break;

case AddScalebar:
{
QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar( composition() );
newScaleBar->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 20, 20 ) );
addComposerScaleBar( newScaleBar );
emit actionFinished();
}
break;
if ( composition() )
{
QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar( composition() );
newScaleBar->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 20, 20 ) );
composition()->addComposerScaleBar( newScaleBar );
QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
if ( mapItemList.size() > 0 )
{
newScaleBar->setComposerMap( mapItemList.at( 0 ) );
}
newScaleBar->applyDefaultSize(); //4 segments, 1/5 of composer map width
emit actionFinished();
pushAddRemoveCommand( newScaleBar, tr( "Scale bar added" ) );
}
break;

case AddLegend:
{
QgsComposerLegend* newLegend = new QgsComposerLegend( composition() );
newLegend->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
addComposerLegend( newLegend );
emit actionFinished();
if ( composition() )
{
QgsComposerLegend* newLegend = new QgsComposerLegend( composition() );
newLegend->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
composition()->addComposerLegend( newLegend );
newLegend->updateLegend();
emit actionFinished();
pushAddRemoveCommand( newLegend, tr( "Legend added" ) );
}
break;
}
case AddPicture:
{
QgsComposerPicture* newPicture = new QgsComposerPicture( composition() );
newPicture->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
addComposerPicture( newPicture );
emit actionFinished();
if ( composition() )
{
QgsComposerPicture* newPicture = new QgsComposerPicture( composition() );
newPicture->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
composition()->addComposerPicture( newPicture );
emit actionFinished();
pushAddRemoveCommand( newPicture, tr( "Picture added" ) );
}
break;
}
case AddTable:
{
QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( composition() );
newTable->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
addComposerTable( newTable );
emit actionFinished();
if ( composition() )
{
QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( composition() );
newTable->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
composition()->addComposerTable( newTable );
emit actionFinished();
pushAddRemoveCommand( newTable, tr( "Table added" ) );
}
break;
}

default:
break;
}
@@ -225,39 +243,41 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
break;
}
case AddArrow:
{
QPointF scenePoint = mapToScene( e->pos() );
QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint );
QgsComposerArrow* composerArrow = new QgsComposerArrow( mRubberBandStartPos, QPointF( snappedScenePoint.x(), snappedScenePoint.y() ), composition() );
addComposerArrow( composerArrow );
scene()->removeItem( mRubberBandLineItem );
delete mRubberBandLineItem;
mRubberBandLineItem = 0;
emit actionFinished();
if ( composition() )
{
QPointF scenePoint = mapToScene( e->pos() );
QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint );
QgsComposerArrow* composerArrow = new QgsComposerArrow( mRubberBandStartPos, QPointF( snappedScenePoint.x(), snappedScenePoint.y() ), composition() );
composition()->addComposerArrow( composerArrow );
scene()->removeItem( mRubberBandLineItem );
delete mRubberBandLineItem;
mRubberBandLineItem = 0;
emit actionFinished();
pushAddRemoveCommand( composerArrow, tr( "Arrow added" ) );
}
break;
}

case AddShape:
{
if ( !mRubberBandItem || mRubberBandItem->rect().width() < 0.1 || mRubberBandItem->rect().width() < 0.1 )
{
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
return;
}

QgsComposerShape* composerShape = new QgsComposerShape( mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height(), composition() );
addComposerShape( composerShape );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
emit actionFinished();
if ( composition() )
{
QgsComposerShape* composerShape = new QgsComposerShape( mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height(), composition() );
composition()->addComposerShape( composerShape );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
emit actionFinished();
pushAddRemoveCommand( composerShape, tr( "Shape added" ) );
}
break;
}

case AddMap:
{
if ( !mRubberBandItem || mRubberBandItem->rect().width() < 0.1 || mRubberBandItem->rect().width() < 0.1 )
{
if ( mRubberBandItem )
@@ -268,15 +288,17 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
}
return;
}

QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
addComposerMap( composerMap );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
emit actionFinished();
}
break;
if ( composition() )
{
QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
composition()->addComposerMap( composerMap );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
emit actionFinished();
pushAddRemoveCommand( composerMap, tr( "Map added" ) );
}
break;

default:
break;
@@ -553,102 +575,6 @@ QgsComposition* QgsComposerView::composition()
return 0;
}

void QgsComposerView::addComposerArrow( QgsComposerArrow* arrow )
{
composition()->addItem( arrow );
emit composerArrowAdded( arrow );
scene()->clearSelection();
arrow->setSelected( true );
emit selectedItemChanged( arrow );
pushAddRemoveCommand( arrow, tr( "Arrow added" ) );
}

void QgsComposerView::addComposerLabel( QgsComposerLabel* label )
{
composition()->addItem( label );
emit composerLabelAdded( label );
scene()->clearSelection();
label->setSelected( true );
emit selectedItemChanged( label );
pushAddRemoveCommand( label, tr( "Label added" ) );
}

void QgsComposerView::addComposerMap( QgsComposerMap* map )
{
scene()->addItem( map );
//set default preview mode to cache. Must be done here between adding composer map to scene and emiting signal
map->setPreviewMode( QgsComposerMap::Cache );
map->cache();
emit composerMapAdded( map );
scene()->clearSelection();
map->setSelected( true );
emit selectedItemChanged( map );
pushAddRemoveCommand( map, tr( "Map added" ) );
}

void QgsComposerView::addComposerScaleBar( QgsComposerScaleBar* scaleBar )
{
//take first available map
QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
if ( mapItemList.size() > 0 )
{
scaleBar->setComposerMap( mapItemList.at( 0 ) );
}
scaleBar->applyDefaultSize(); //4 segments, 1/5 of composer map width
scene()->addItem( scaleBar );
emit composerScaleBarAdded( scaleBar );
scene()->clearSelection();
scaleBar->setSelected( true );
emit selectedItemChanged( scaleBar );
pushAddRemoveCommand( scaleBar, tr( "Scale bar added" ) );
}

void QgsComposerView::addComposerLegend( QgsComposerLegend* legend )
{
//take first available map
QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
if ( mapItemList.size() > 0 )
{
legend->setComposerMap( mapItemList.at( 0 ) );
}
scene()->addItem( legend );
emit composerLegendAdded( legend );
scene()->clearSelection();
legend->setSelected( true );
emit selectedItemChanged( legend );
pushAddRemoveCommand( legend, tr( "Legend added" ) );
}

void QgsComposerView::addComposerPicture( QgsComposerPicture* picture )
{
scene()->addItem( picture );
emit composerPictureAdded( picture );
scene()->clearSelection();
picture->setSelected( true );
emit selectedItemChanged( picture );
pushAddRemoveCommand( picture, tr( "Picture added" ) );
}

void QgsComposerView::addComposerShape( QgsComposerShape* shape )
{
scene()->addItem( shape );
emit composerShapeAdded( shape );
scene()->clearSelection();
shape->setSelected( true );
emit selectedItemChanged( shape );
pushAddRemoveCommand( shape, tr( "Shape added" ) );
}

void QgsComposerView::addComposerTable( QgsComposerAttributeTable* table )
{
scene()->addItem( table );
emit composerTableAdded( table );
scene()->clearSelection();
table->setSelected( true );
emit selectedItemChanged( table );
pushAddRemoveCommand( table, tr( "Table added" ) );
}

void QgsComposerView::removeItem( QgsComposerItem* item )
{
QgsComposerMap* map = dynamic_cast<QgsComposerMap *>( item );
@@ -80,23 +80,6 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Returns the composition or 0 in case of error*/
QgsComposition* composition();

/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerArrow( QgsComposerArrow* arrow );
/**Adds label to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerLabel( QgsComposerLabel* label );
/**Adds map to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerMap( QgsComposerMap* map );
/**Adds scale bar to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerScaleBar( QgsComposerScaleBar* scaleBar );
/**Adds legend to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerLegend( QgsComposerLegend* legend );
/**Adds picture to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerPicture( QgsComposerPicture* picture );
/**Adds a composer shape to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerShape( QgsComposerShape* shape );
/**Adds a composer table to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerTable( QgsComposerAttributeTable* table );

/**Remove item from the graphics scene*/
void removeItem( QgsComposerItem* item );

0 comments on commit c9bcd60

Please sign in to comment.