Skip to content

Commit

Permalink
[composer] Fix item selection after pasting items
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 7, 2014
1 parent d0719b0 commit a9be559
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
52 changes: 25 additions & 27 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
Expand All @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down
45 changes: 45 additions & 0 deletions src/gui/qgscomposerview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
}
Expand All @@ -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" ) );
}
Expand All @@ -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" ) );
}
Expand All @@ -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" ) );
}
Expand All @@ -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" ) );
}
Expand Down Expand Up @@ -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" ) );
}
Expand Down Expand Up @@ -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;
Expand All @@ -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" ) );
Expand All @@ -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();
}
Expand Down

0 comments on commit a9be559

Please sign in to comment.