Skip to content
Permalink
Browse files
[composer] Fix item selection after pasting items
  • Loading branch information
nyalldawson committed Feb 7, 2014
1 parent d0719b0 commit a9be559e7239b757a7c85bc489ae4032a4bee5e8
Showing with 70 additions and 27 deletions.
  1. +25 −27 src/core/composer/qgscomposition.cpp
  2. +45 −0 src/gui/qgscomposerview.cpp
@@ -758,6 +758,7 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
int zOrderOffset = mItemZList.size();

QPointF pasteShiftPos;
QgsComposerItem* lastPastedItem = 0;
if ( pos )
{
//If we are placing items relative to a certain point, then calculate how much we need
@@ -767,6 +768,9 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
//next, calculate how much each item needs to be shifted from its original position
//so that it's placed at the correct relative position
pasteShiftPos = *pos - minItemPos;

//since we are pasting items, clear the existing selection
clearSelection();
}

if ( pasteInPlace )
@@ -790,6 +794,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newLabel->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newLabel->setSelected( true );
lastPastedItem = newLabel;
}
addComposerLabel( newLabel );
newLabel->setZValue( newLabel->zValue() + zOrderOffset );
@@ -825,6 +831,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newMap->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newMap->setSelected( true );
lastPastedItem = newMap;
}

if ( addUndoCommands )
@@ -865,6 +873,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newArrow->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newArrow->setSelected( true );
lastPastedItem = newArrow;
}
addComposerArrow( newArrow );
newArrow->setZValue( newArrow->zValue() + zOrderOffset );
@@ -891,6 +901,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newScaleBar->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newScaleBar->setSelected( true );
lastPastedItem = newScaleBar;
}
addComposerScaleBar( newScaleBar );
newScaleBar->setZValue( newScaleBar->zValue() + zOrderOffset );
@@ -919,6 +931,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newShape->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newShape->setSelected( true );
lastPastedItem = newShape;
}
addComposerShape( newShape );
newShape->setZValue( newShape->zValue() + zOrderOffset );
@@ -945,6 +959,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newPicture->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newPicture->setSelected( true );
lastPastedItem = newPicture;
}
addComposerPicture( newPicture );
newPicture->setZValue( newPicture->zValue() + zOrderOffset );
@@ -971,6 +987,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newLegend->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newLegend->setSelected( true );
lastPastedItem = newLegend;
}
addComposerLegend( newLegend );
newLegend->setZValue( newLegend->zValue() + zOrderOffset );
@@ -997,6 +1015,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
newTable->move( pasteShiftPos.x(), pasteShiftPos.y() );
}
newTable->setSelected( true );
lastPastedItem = newTable;
}
addComposerTable( newTable );
newTable->setZValue( newTable->zValue() + zOrderOffset );
@@ -1042,6 +1062,11 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
//Make sure z order list matches the actual order of items in the scene.
refreshZList();

if ( lastPastedItem )
{
emit selectedItemChanged( lastPastedItem );
}

delete pasteInPlacePt;
pasteInPlacePt = 0;

@@ -1934,18 +1959,12 @@ void QgsComposition::addComposerArrow( QgsComposerArrow* arrow )
{
addItem( arrow );
emit composerArrowAdded( arrow );
clearSelection();
arrow->setSelected( true );
emit selectedItemChanged( arrow );
}

void QgsComposition::addComposerLabel( QgsComposerLabel* label )
{
addItem( label );
emit composerLabelAdded( label );
clearSelection();
label->setSelected( true );
emit selectedItemChanged( label );
}

void QgsComposition::addComposerMap( QgsComposerMap* map, bool setDefaultPreviewStyle )
@@ -1963,63 +1982,42 @@ void QgsComposition::addComposerMap( QgsComposerMap* map, bool setDefaultPreview
}

emit composerMapAdded( map );
clearSelection();
map->setSelected( true );
emit selectedItemChanged( map );
}

void QgsComposition::addComposerScaleBar( QgsComposerScaleBar* scaleBar )
{
addItem( scaleBar );
emit composerScaleBarAdded( scaleBar );
clearSelection();
scaleBar->setSelected( true );
emit selectedItemChanged( scaleBar );
}

void QgsComposition::addComposerLegend( QgsComposerLegend* legend )
{
addItem( legend );
emit composerLegendAdded( legend );
clearSelection();
legend->setSelected( true );
emit selectedItemChanged( legend );
}

void QgsComposition::addComposerPicture( QgsComposerPicture* picture )
{
addItem( picture );
emit composerPictureAdded( picture );
clearSelection();
picture->setSelected( true );
emit selectedItemChanged( picture );
}

void QgsComposition::addComposerShape( QgsComposerShape* shape )
{
addItem( shape );
emit composerShapeAdded( shape );
clearSelection();
shape->setSelected( true );
emit selectedItemChanged( shape );
}

void QgsComposition::addComposerTable( QgsComposerAttributeTable* table )
{
addItem( table );
emit composerTableAdded( table );
clearSelection();
table->setSelected( true );
emit selectedItemChanged( table );
}

void QgsComposition::addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame )
{
addItem( frame );
emit composerHtmlFrameAdded( html, frame );
clearSelection();
frame->setSelected( true );
emit selectedItemChanged( frame );
}

void QgsComposition::removeComposerItem( QgsComposerItem* item, bool createCommand )
@@ -346,6 +346,11 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
newLabelItem->adjustSizeToText();
newLabelItem->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
composition()->addComposerLabel( newLabelItem );

composition()->clearSelection();
newLabelItem->setSelected( true );
emit selectedItemChanged( newLabelItem );

emit actionFinished();
composition()->pushAddRemoveCommand( newLabelItem, tr( "Label added" ) );
}
@@ -363,6 +368,11 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
newScaleBar->setComposerMap( mapItemList.at( 0 ) );
}
newScaleBar->applyDefaultSize(); //4 segments, 1/5 of composer map width

composition()->clearSelection();
newScaleBar->setSelected( true );
emit selectedItemChanged( newScaleBar );

emit actionFinished();
composition()->pushAddRemoveCommand( newScaleBar, tr( "Scale bar added" ) );
}
@@ -376,6 +386,11 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
newLegend->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
composition()->addComposerLegend( newLegend );
newLegend->updateLegend();

composition()->clearSelection();
newLegend->setSelected( true );
emit selectedItemChanged( newLegend );

emit actionFinished();
composition()->pushAddRemoveCommand( newLegend, tr( "Legend added" ) );
}
@@ -387,6 +402,11 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
QgsComposerPicture* newPicture = new QgsComposerPicture( composition() );
newPicture->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
composition()->addComposerPicture( newPicture );

composition()->clearSelection();
newPicture->setSelected( true );
emit selectedItemChanged( newPicture );

emit actionFinished();
composition()->pushAddRemoveCommand( newPicture, tr( "Picture added" ) );
}
@@ -397,6 +417,11 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( composition() );
newTable->setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
composition()->addComposerTable( newTable );

composition()->clearSelection();
newTable->setSelected( true );
emit selectedItemChanged( newTable );

emit actionFinished();
composition()->pushAddRemoveCommand( newTable, tr( "Table added" ) );
}
@@ -428,6 +453,11 @@ void QgsComposerView::addShape( Tool currentTool )
composerShape->setUseSymbolV2( true );
composition()->addComposerShape( composerShape );
removeRubberBand();

composition()->clearSelection();
composerShape->setSelected( true );
emit selectedItemChanged( composerShape );

emit actionFinished();
composition()->pushAddRemoveCommand( composerShape, tr( "Shape added" ) );
}
@@ -703,6 +733,11 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint );
QgsComposerArrow* composerArrow = new QgsComposerArrow( mRubberBandStartPos, QPointF( snappedScenePoint.x(), snappedScenePoint.y() ), composition() );
composition()->addComposerArrow( composerArrow );

composition()->clearSelection();
composerArrow->setSelected( true );
emit selectedItemChanged( composerArrow );

scene()->removeItem( mRubberBandLineItem );
delete mRubberBandLineItem;
mRubberBandLineItem = 0;
@@ -727,6 +762,11 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
{
QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
composition()->addComposerMap( composerMap );

composition()->clearSelection();
composerMap->setSelected( true );
emit selectedItemChanged( composerMap );

removeRubberBand();
emit actionFinished();
composition()->pushAddRemoveCommand( composerMap, tr( "Map added" ) );
@@ -746,6 +786,11 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
composition()->beginMultiFrameCommand( composerHtml, tr( "Html frame added" ) );
composerHtml->addFrame( frame );
composition()->endMultiFrameCommand();

composition()->clearSelection();
frame->setSelected( true );
emit selectedItemChanged( frame );

removeRubberBand();
emit actionFinished();
}

0 comments on commit a9be559

Please sign in to comment.