Skip to content

Commit 885269e

Browse files
committedMar 21, 2017
Only create composer item config widgets on demand
Instead of creating them for all items when composer window is opened, instead just create and destroy them when required. None are too heavy to have a noticable delay when selecting items, but in contrast keeping them around forever is wasteful on memory. Also clean up a lot of duplicate composer/composition code and remove unnecessary signals from api (use a single itemAdded signal instead of multiple signals for every item type)
1 parent dbf0160 commit 885269e

File tree

7 files changed

+129
-356
lines changed

7 files changed

+129
-356
lines changed
 

‎doc/api_break.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ were removed. Use setSnapTolerance() and snapTolerance() instead.
728728
- dataDefinedProperty() and setDataDefinedProperty() now use the QgsProperty framework instead
729729
of QgsDataDefined objects.
730730
- mapSettings() was removed. Use QgsComposerMap::mapSettings() instead.
731+
- The composerArrowAdded, composerPolygonAdded, composerPolylineAdded, composerHtmlFrameAdded, composerItemGroupAdded,
732+
composerLabelAdded, composerMapAdded, composerScaleBarAdded, composerLegendAdded, composerPictureAdded,
733+
composerShapeAdded, and composerTableFrameAdded were removed. Use the general itemAdded signal instead to catch
734+
all these item added events.
731735

732736

733737
QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem}

‎python/core/composer/qgscomposition.sip

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -659,37 +659,10 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
659659
void paperSizeChanged();
660660
void nPagesChanged();
661661
void printResolutionChanged();
662-
663-
/** Is emitted when selected item changed. If 0, no item is selected*/
664-
void selectedItemChanged( QgsComposerItem* selected );
665-
/** Is emitted when new composer arrow has been added to the view*/
666-
void composerArrowAdded( QgsComposerArrow* arrow );
667-
/** Is emitted when new composer polygon has been added to the view*/
668-
void composerPolygonAdded( QgsComposerPolygon* polygon );
669-
/** Is emitted when new composer polyline has been added to the view*/
670-
void composerPolylineAdded( QgsComposerPolyline* polyline );
671-
/** Is emitted when a new composer html has been added to the view*/
672-
void composerHtmlFrameAdded( QgsComposerHtml* html, QgsComposerFrame* frame );
673-
/** Is emitted when a new item group has been added to the view*/
674-
void composerItemGroupAdded( QgsComposerItemGroup* group );
675-
/** Is emitted when new composer label has been added to the view*/
676-
void composerLabelAdded( QgsComposerLabel* label );
677-
/** Is emitted when new composer map has been added to the view*/
678-
void composerMapAdded( QgsComposerMap* map );
679-
/** Is emitted when new composer scale bar has been added*/
680-
void composerScaleBarAdded( QgsComposerScaleBar* scalebar );
681-
/** Is emitted when a new composer legend has been added*/
682-
void composerLegendAdded( QgsComposerLegend* legend );
683-
/** Is emitted when a new composer picture has been added*/
684-
void composerPictureAdded( QgsComposerPicture* picture );
685-
/** Is emitted when a new composer shape has been added*/
686-
void composerShapeAdded( QgsComposerShape* shape );
687-
/** Is emitted when a new composer table frame has been added to the view*/
688-
void composerTableFrameAdded( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame );
689-
/** Is emitted when a composer item has been removed from the scene*/
690-
void itemRemoved( QgsComposerItem* );
691-
692-
/** Is emitted when item in the composition must be refreshed*/
662+
void selectedItemChanged( QgsComposerItem *selected );
663+
void itemAdded( QgsComposerItem *item );
664+
void composerItemGroupAdded( QgsComposerItemGroup *group );
665+
void itemRemoved( QgsComposerItem * );
693666
void refreshItemsTriggered();
694667

695668
/** Is emitted when the composition has an updated status bar message for the composer window*/

‎src/app/composer/qgscomposer.cpp

Lines changed: 70 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ QgsComposer::QgsComposer( QgsComposition *composition )
673673

674674
QgsComposer::~QgsComposer()
675675
{
676-
deleteItemWidgets();
677676
delete mPrinter;
678677
}
679678

@@ -774,17 +773,7 @@ void QgsComposer::connectCompositionSlots()
774773

775774
connect( mComposition, &QgsComposition::nameChanged, this, &QgsComposer::setWindowTitle );
776775
connect( mComposition, &QgsComposition::selectedItemChanged, this, &QgsComposer::showItemOptions );
777-
connect( mComposition, &QgsComposition::composerArrowAdded, this, &QgsComposer::addComposerArrow );
778-
connect( mComposition, &QgsComposition::composerPolygonAdded, this, &QgsComposer::addComposerPolygon );
779-
connect( mComposition, &QgsComposition::composerPolylineAdded, this, &QgsComposer::addComposerPolyline );
780-
connect( mComposition, &QgsComposition::composerHtmlFrameAdded, this, &QgsComposer::addComposerHtmlFrame );
781-
connect( mComposition, &QgsComposition::composerLabelAdded, this, &QgsComposer::addComposerLabel );
782-
connect( mComposition, &QgsComposition::composerMapAdded, this, &QgsComposer::addComposerMap );
783-
connect( mComposition, &QgsComposition::composerScaleBarAdded, this, &QgsComposer::addComposerScaleBar );
784-
connect( mComposition, &QgsComposition::composerLegendAdded, this, &QgsComposer::addComposerLegend );
785-
connect( mComposition, &QgsComposition::composerPictureAdded, this, &QgsComposer::addComposerPicture );
786-
connect( mComposition, &QgsComposition::composerShapeAdded, this, &QgsComposer::addComposerShape );
787-
connect( mComposition, &QgsComposition::composerTableFrameAdded, this, &QgsComposer::addComposerTableV2 );
776+
connect( mComposition, &QgsComposition::itemAdded, this, &QgsComposer::compositionItemAdded );
788777
connect( mComposition, &QgsComposition::itemRemoved, this, &QgsComposer::deleteItem );
789778
connect( mComposition, &QgsComposition::paperSizeChanged, this, [ = ]
790779
{
@@ -847,6 +836,7 @@ bool QgsComposer::loadFromTemplate( const QDomDocument &templateDoc, bool clearE
847836

848837
setUpdatesEnabled( false );
849838
bool result = mComposition->loadFromTemplate( templateDoc, nullptr, false, clearExisting );
839+
cleanupAfterTemplateRead();
850840
setUpdatesEnabled( true );
851841

852842
dlg->close();
@@ -947,25 +937,19 @@ void QgsComposer::showItemOptions( QgsComposerItem *item )
947937
{
948938
if ( !item )
949939
{
950-
mItemPropertiesStack->takeMainPanel();
940+
delete mItemPropertiesStack->takeMainPanel();
951941
return;
952942
}
953943

954-
QMap<QgsComposerItem *, QgsPanelWidget *>::const_iterator it = mItemWidgetMap.constFind( item );
955-
if ( it == mItemWidgetMap.constEnd() )
944+
std::unique_ptr< QgsPanelWidget > widget( createItemWidget( item ) );
945+
if ( ! widget )
956946
{
957947
return;
958948
}
959949

960-
QgsPanelWidget *newWidget = it.value();
961-
if ( !newWidget || newWidget == mItemPropertiesStack->mainPanel() ) //bail out if new widget does not exist or is already there
962-
{
963-
return;
964-
}
965-
966-
( void ) mItemPropertiesStack->takeMainPanel();
967-
newWidget->setDockMode( true );
968-
mItemPropertiesStack->setMainPanel( newWidget );
950+
delete mItemPropertiesStack->takeMainPanel();
951+
widget->setDockMode( true );
952+
mItemPropertiesStack->setMainPanel( widget.release() );
969953
}
970954

971955
void QgsComposer::on_mActionOptions_triggered()
@@ -1039,6 +1023,63 @@ void QgsComposer::atlasFeatureChanged( QgsFeature *feature )
10391023
mapCanvas()->expressionContextScope().addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( atlasFeature.geometry() ), true ) );
10401024
}
10411025

1026+
void QgsComposer::compositionItemAdded( QgsComposerItem *item )
1027+
{
1028+
if ( item && item->type() == QgsComposerItem::ComposerMap )
1029+
{
1030+
connect( this, &QgsComposer::zoomLevelChanged, static_cast< QgsComposerMap *>( item ), &QgsComposerMap::renderModeUpdateCachedImage );
1031+
}
1032+
}
1033+
1034+
QgsPanelWidget *QgsComposer::createItemWidget( QgsComposerItem *item )
1035+
{
1036+
if ( !item )
1037+
return nullptr;
1038+
1039+
switch ( item->type() )
1040+
{
1041+
case QgsComposerItem::ComposerArrow:
1042+
return new QgsComposerArrowWidget( static_cast< QgsComposerArrow * >( item ) );
1043+
1044+
case QgsComposerItem::ComposerPolygon:
1045+
return new QgsComposerPolygonWidget( static_cast< QgsComposerPolygon * >( item ) );
1046+
1047+
case QgsComposerItem::ComposerPolyline:
1048+
return new QgsComposerPolylineWidget( static_cast< QgsComposerPolyline * >( item ) );
1049+
1050+
case QgsComposerItem::ComposerLabel:
1051+
return new QgsComposerLabelWidget( static_cast< QgsComposerLabel * >( item ) );
1052+
1053+
case QgsComposerItem::ComposerMap:
1054+
return new QgsComposerMapWidget( static_cast< QgsComposerMap * >( item ) );
1055+
1056+
case QgsComposerItem::ComposerScaleBar:
1057+
return new QgsComposerScaleBarWidget( static_cast< QgsComposerScaleBar * >( item ) );
1058+
1059+
case QgsComposerItem::ComposerLegend:
1060+
return new QgsComposerLegendWidget( static_cast< QgsComposerLegend * >( item ) );
1061+
1062+
case QgsComposerItem::ComposerPicture:
1063+
return new QgsComposerPictureWidget( static_cast< QgsComposerPicture * >( item ) );
1064+
1065+
case QgsComposerItem::ComposerFrame:
1066+
{
1067+
QgsComposerFrame *frame = static_cast< QgsComposerFrame * >( item );
1068+
if ( QgsComposerHtml *html = dynamic_cast< QgsComposerHtml * >( frame->multiFrame() ) )
1069+
{
1070+
return new QgsComposerHtmlWidget( html, frame );
1071+
}
1072+
else if ( QgsComposerAttributeTableV2 *table = dynamic_cast< QgsComposerAttributeTableV2 * >( frame->multiFrame() ) )
1073+
{
1074+
return new QgsComposerAttributeTableWidget( table, frame );
1075+
}
1076+
break;
1077+
}
1078+
1079+
}
1080+
return nullptr; // no warnings!
1081+
}
1082+
10421083
void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
10431084
{
10441085
QgsAtlasComposition *atlasMap = &mComposition->atlasComposition();
@@ -3376,145 +3417,9 @@ void QgsComposer::restoreGridSettings()
33763417
mActionShowBoxes->setChecked( mComposition->boundingBoxesVisible() );
33773418
}
33783419

3379-
void QgsComposer::deleteItemWidgets()
3380-
{
3381-
//delete all the items
3382-
qDeleteAll( mItemWidgetMap );
3383-
mItemWidgetMap.clear();
3384-
}
3385-
3386-
void QgsComposer::addComposerArrow( QgsComposerArrow *arrow )
3420+
void QgsComposer::deleteItem( QgsComposerItem * )
33873421
{
3388-
if ( !arrow )
3389-
{
3390-
return;
3391-
}
3392-
3393-
QgsComposerArrowWidget *arrowWidget = new QgsComposerArrowWidget( arrow );
3394-
mItemWidgetMap.insert( arrow, arrowWidget );
3395-
}
3396-
3397-
void QgsComposer::addComposerPolygon( QgsComposerPolygon *polygon )
3398-
{
3399-
if ( !polygon )
3400-
{
3401-
return;
3402-
}
3403-
3404-
QgsComposerPolygonWidget *polygonWidget = new QgsComposerPolygonWidget( polygon );
3405-
mItemWidgetMap.insert( polygon, polygonWidget );
3406-
}
3407-
3408-
void QgsComposer::addComposerPolyline( QgsComposerPolyline *polyline )
3409-
{
3410-
if ( !polyline )
3411-
{
3412-
return;
3413-
}
3414-
3415-
QgsComposerPolylineWidget *polylineWidget = new QgsComposerPolylineWidget( polyline );
3416-
mItemWidgetMap.insert( polyline, polylineWidget );
3417-
}
3418-
3419-
void QgsComposer::addComposerMap( QgsComposerMap *map )
3420-
{
3421-
if ( !map )
3422-
{
3423-
return;
3424-
}
3425-
3426-
QgsComposerMapWidget *mapWidget = new QgsComposerMapWidget( map );
3427-
connect( this, &QgsComposer::zoomLevelChanged, map, &QgsComposerMap::renderModeUpdateCachedImage );
3428-
mItemWidgetMap.insert( map, mapWidget );
3429-
}
3430-
3431-
void QgsComposer::addComposerLabel( QgsComposerLabel *label )
3432-
{
3433-
if ( !label )
3434-
{
3435-
return;
3436-
}
3437-
3438-
QgsComposerLabelWidget *labelWidget = new QgsComposerLabelWidget( label );
3439-
mItemWidgetMap.insert( label, labelWidget );
3440-
}
3441-
3442-
void QgsComposer::addComposerScaleBar( QgsComposerScaleBar *scalebar )
3443-
{
3444-
if ( !scalebar )
3445-
{
3446-
return;
3447-
}
3448-
3449-
QgsComposerScaleBarWidget *sbWidget = new QgsComposerScaleBarWidget( scalebar );
3450-
mItemWidgetMap.insert( scalebar, sbWidget );
3451-
}
3452-
3453-
void QgsComposer::addComposerLegend( QgsComposerLegend *legend )
3454-
{
3455-
if ( !legend )
3456-
{
3457-
return;
3458-
}
3459-
3460-
QgsComposerLegendWidget *lWidget = new QgsComposerLegendWidget( legend );
3461-
mItemWidgetMap.insert( legend, lWidget );
3462-
}
3463-
3464-
void QgsComposer::addComposerPicture( QgsComposerPicture *picture )
3465-
{
3466-
if ( !picture )
3467-
{
3468-
return;
3469-
}
3470-
3471-
QgsComposerPictureWidget *pWidget = new QgsComposerPictureWidget( picture );
3472-
mItemWidgetMap.insert( picture, pWidget );
3473-
}
3474-
3475-
void QgsComposer::addComposerShape( QgsComposerShape *shape )
3476-
{
3477-
if ( !shape )
3478-
{
3479-
return;
3480-
}
3481-
QgsComposerShapeWidget *sWidget = new QgsComposerShapeWidget( shape );
3482-
mItemWidgetMap.insert( shape, sWidget );
3483-
}
3484-
3485-
void QgsComposer::addComposerTableV2( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame )
3486-
{
3487-
if ( !table )
3488-
{
3489-
return;
3490-
}
3491-
QgsComposerAttributeTableWidget *tWidget = new QgsComposerAttributeTableWidget( table, frame );
3492-
mItemWidgetMap.insert( frame, tWidget );
3493-
}
3494-
3495-
void QgsComposer::addComposerHtmlFrame( QgsComposerHtml *html, QgsComposerFrame *frame )
3496-
{
3497-
if ( !html )
3498-
{
3499-
return;
3500-
}
3501-
3502-
QgsComposerHtmlWidget *hWidget = new QgsComposerHtmlWidget( html, frame );
3503-
mItemWidgetMap.insert( frame, hWidget );
3504-
}
3505-
3506-
void QgsComposer::deleteItem( QgsComposerItem *item )
3507-
{
3508-
QMap<QgsComposerItem *, QgsPanelWidget *>::const_iterator it = mItemWidgetMap.constFind( item );
3509-
3510-
if ( it == mItemWidgetMap.constEnd() )
3511-
{
3512-
return;
3513-
}
3514-
3515-
//the item itself is not deleted here (usually, this is done in the destructor of QgsAddRemoveItemCommand)
3516-
it.value()->deleteLater();
3517-
mItemWidgetMap.remove( it.key() );
3422+
showItemOptions( nullptr );
35183423
}
35193424

35203425
void QgsComposer::setSelectionTool()
@@ -3608,19 +3513,18 @@ void QgsComposer::showAdvancedEffectsWarning()
36083513

36093514
void QgsComposer::cleanupAfterTemplateRead()
36103515
{
3611-
QMap<QgsComposerItem *, QgsPanelWidget *>::const_iterator itemIt = mItemWidgetMap.constBegin();
3612-
for ( ; itemIt != mItemWidgetMap.constEnd(); ++itemIt )
3516+
Q_FOREACH ( QGraphicsItem *item, mComposition->items() )
36133517
{
36143518
//update all legends completely
3615-
QgsComposerLegend *legendItem = dynamic_cast<QgsComposerLegend *>( itemIt.key() );
3519+
QgsComposerLegend *legendItem = dynamic_cast<QgsComposerLegend *>( item );
36163520
if ( legendItem )
36173521
{
36183522
legendItem->updateLegend();
36193523
continue;
36203524
}
36213525

36223526
//update composer map extent if it does not intersect the full extent of all layers
3623-
QgsComposerMap *mapItem = dynamic_cast<QgsComposerMap *>( itemIt.key() );
3527+
QgsComposerMap *mapItem = dynamic_cast<QgsComposerMap *>( item );
36243528
if ( mapItem )
36253529
{
36263530
//test if composer map extent intersects extent of all layers

‎src/app/composer/qgscomposer.h

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -414,39 +414,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
414414
//! Save window state
415415
void saveWindowState();
416416

417-
//! Add a composer arrow to the item/widget map and creates a configuration widget for it
418-
void addComposerArrow( QgsComposerArrow *arrow );
419-
420-
//! Add a composer polygon to the item/widget map and creates a configuration widget for it
421-
void addComposerPolygon( QgsComposerPolygon *polygon );
422-
423-
//! Add a composer polyline to the item/widget map and creates a configuration widget for it
424-
void addComposerPolyline( QgsComposerPolyline *polyline );
425-
426-
//! Add a composer map to the item/widget map and creates a configuration widget for it
427-
void addComposerMap( QgsComposerMap *map );
428-
429-
//! Adds a composer label to the item/widget map and creates a configuration widget for it
430-
void addComposerLabel( QgsComposerLabel *label );
431-
432-
//! Adds a composer scale bar to the item/widget map and creates a configuration widget for it
433-
void addComposerScaleBar( QgsComposerScaleBar *scalebar );
434-
435-
//! Adds a composer legend to the item/widget map and creates a configuration widget for it
436-
void addComposerLegend( QgsComposerLegend *legend );
437-
438-
//! Adds a composer picture to the item/widget map and creates a configuration widget
439-
void addComposerPicture( QgsComposerPicture *picture );
440-
441-
//! Adds a composer shape to the item/widget map and creates a configuration widget
442-
void addComposerShape( QgsComposerShape *shape );
443-
444-
//! Adds a composer table v2 to the item/widget map and creates a configuration widget
445-
void addComposerTableV2( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame );
446-
447-
//! Adds composer html and creates a configuration widget
448-
void addComposerHtmlFrame( QgsComposerHtml *html, QgsComposerFrame *frame );
449-
450417
//! Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself
451418
void deleteItem( QgsComposerItem *item );
452419

@@ -503,9 +470,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
503470
//! Changes elements that are not suitable for this project
504471
void cleanupAfterTemplateRead();
505472

506-
//! Removes all the item from the graphics scene and deletes them
507-
void deleteItemWidgets();
508-
509473
//! Create composer view and rulers
510474
void createComposerView();
511475

@@ -532,6 +496,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
532496

533497
QPrinter *printer();
534498

499+
QgsPanelWidget *createItemWidget( QgsComposerItem *item );
500+
535501
QgsAppComposerInterface *mInterface = nullptr;
536502

537503
//! Labels in status bar which shows current mouse position
@@ -565,9 +531,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
565531
//! Size grip
566532
QSizeGrip *mSizeGrip = nullptr;
567533

568-
//! To know which item to show if selection changes
569-
QMap<QgsComposerItem *, QgsPanelWidget *> mItemWidgetMap;
570-
571534
//! Copy/cut/paste actions
572535
QAction *mActionCut = nullptr;
573536
QAction *mActionCopy = nullptr;
@@ -664,6 +627,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
664627
void updateAtlasPageComboBox( int pageCount );
665628

666629
void atlasFeatureChanged( QgsFeature *feature );
630+
631+
void compositionItemAdded( QgsComposerItem *item );
632+
633+
634+
667635
};
668636

669637
#endif

‎src/core/composer/qgscomposition.cpp

Lines changed: 30 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ void QgsComposition::setAllDeselected()
226226
composerItem->setSelected( false );
227227
}
228228
}
229+
emit selectedItemChanged( nullptr );
229230
}
230231

231232
void QgsComposition::refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QgsExpressionContext *context )
@@ -2452,7 +2453,7 @@ void QgsComposition::addComposerArrow( QgsComposerArrow *arrow )
24522453
updateBounds();
24532454
connect( arrow, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
24542455

2455-
emit composerArrowAdded( arrow );
2456+
emit itemAdded( arrow );
24562457
}
24572458

24582459
void QgsComposition::addComposerPolygon( QgsComposerPolygon *polygon )
@@ -2462,7 +2463,7 @@ void QgsComposition::addComposerPolygon( QgsComposerPolygon *polygon )
24622463
updateBounds();
24632464
connect( polygon, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
24642465

2465-
emit composerPolygonAdded( polygon );
2466+
emit itemAdded( polygon );
24662467
}
24672468

24682469
void QgsComposition::addComposerPolyline( QgsComposerPolyline *polyline )
@@ -2472,7 +2473,7 @@ void QgsComposition::addComposerPolyline( QgsComposerPolyline *polyline )
24722473
updateBounds();
24732474
connect( polyline, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
24742475

2475-
emit composerPolylineAdded( polyline );
2476+
emit itemAdded( polyline );
24762477
}
24772478

24782479
void QgsComposition::addComposerLabel( QgsComposerLabel *label )
@@ -2482,7 +2483,7 @@ void QgsComposition::addComposerLabel( QgsComposerLabel *label )
24822483
updateBounds();
24832484
connect( label, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
24842485

2485-
emit composerLabelAdded( label );
2486+
emit itemAdded( label );
24862487
}
24872488

24882489
void QgsComposition::addComposerMap( QgsComposerMap *map, const bool setDefaultPreviewStyle )
@@ -2502,7 +2503,7 @@ void QgsComposition::addComposerMap( QgsComposerMap *map, const bool setDefaultP
25022503
updateBounds();
25032504
connect( map, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25042505

2505-
emit composerMapAdded( map );
2506+
emit itemAdded( map );
25062507
}
25072508

25082509
void QgsComposition::addComposerScaleBar( QgsComposerScaleBar *scaleBar )
@@ -2512,7 +2513,7 @@ void QgsComposition::addComposerScaleBar( QgsComposerScaleBar *scaleBar )
25122513
updateBounds();
25132514
connect( scaleBar, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25142515

2515-
emit composerScaleBarAdded( scaleBar );
2516+
emit itemAdded( scaleBar );
25162517
}
25172518

25182519
void QgsComposition::addComposerLegend( QgsComposerLegend *legend )
@@ -2522,7 +2523,7 @@ void QgsComposition::addComposerLegend( QgsComposerLegend *legend )
25222523
updateBounds();
25232524
connect( legend, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25242525

2525-
emit composerLegendAdded( legend );
2526+
emit itemAdded( legend );
25262527
}
25272528

25282529
void QgsComposition::addComposerPicture( QgsComposerPicture *picture )
@@ -2532,7 +2533,7 @@ void QgsComposition::addComposerPicture( QgsComposerPicture *picture )
25322533
updateBounds();
25332534
connect( picture, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25342535

2535-
emit composerPictureAdded( picture );
2536+
emit itemAdded( picture );
25362537
}
25372538

25382539
void QgsComposition::addComposerShape( QgsComposerShape *shape )
@@ -2542,27 +2543,27 @@ void QgsComposition::addComposerShape( QgsComposerShape *shape )
25422543
updateBounds();
25432544
connect( shape, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25442545

2545-
emit composerShapeAdded( shape );
2546+
emit itemAdded( shape );
25462547
}
25472548

2548-
void QgsComposition::addComposerHtmlFrame( QgsComposerHtml *html, QgsComposerFrame *frame )
2549+
void QgsComposition::addComposerHtmlFrame( QgsComposerHtml *, QgsComposerFrame *frame )
25492550
{
25502551
addItem( frame );
25512552

25522553
updateBounds();
25532554
connect( frame, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25542555

2555-
emit composerHtmlFrameAdded( html, frame );
2556+
emit itemAdded( frame );
25562557
}
25572558

2558-
void QgsComposition::addComposerTableFrame( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame )
2559+
void QgsComposition::addComposerTableFrame( QgsComposerAttributeTableV2 *, QgsComposerFrame *frame )
25592560
{
25602561
addItem( frame );
25612562

25622563
updateBounds();
25632564
connect( frame, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
25642565

2565-
emit composerTableFrameAdded( table, frame );
2566+
emit itemAdded( frame );
25662567
}
25672568

25682569
/* public */
@@ -2670,88 +2671,25 @@ void QgsComposition::sendItemAddedSignal( QgsComposerItem *item )
26702671
{
26712672
//cast and send proper signal
26722673
item->setSelected( true );
2673-
QgsComposerArrow *arrow = dynamic_cast<QgsComposerArrow *>( item );
2674-
if ( arrow )
2674+
switch ( item->type() )
26752675
{
2676-
emit composerArrowAdded( arrow );
2677-
emit selectedItemChanged( arrow );
2678-
return;
2679-
}
2680-
QgsComposerLabel *label = dynamic_cast<QgsComposerLabel *>( item );
2681-
if ( label )
2682-
{
2683-
emit composerLabelAdded( label );
2684-
emit selectedItemChanged( label );
2685-
return;
2686-
}
2687-
QgsComposerMap *map = dynamic_cast<QgsComposerMap *>( item );
2688-
if ( map )
2689-
{
2690-
emit composerMapAdded( map );
2691-
emit selectedItemChanged( map );
2692-
return;
2693-
}
2694-
QgsComposerScaleBar *scalebar = dynamic_cast<QgsComposerScaleBar *>( item );
2695-
if ( scalebar )
2696-
{
2697-
emit composerScaleBarAdded( scalebar );
2698-
emit selectedItemChanged( scalebar );
2699-
return;
2700-
}
2701-
QgsComposerLegend *legend = dynamic_cast<QgsComposerLegend *>( item );
2702-
if ( legend )
2703-
{
2704-
emit composerLegendAdded( legend );
2705-
emit selectedItemChanged( legend );
2706-
return;
2707-
}
2708-
QgsComposerPicture *picture = dynamic_cast<QgsComposerPicture *>( item );
2709-
if ( picture )
2710-
{
2711-
emit composerPictureAdded( picture );
2712-
emit selectedItemChanged( picture );
2713-
return;
2714-
}
2715-
QgsComposerShape *shape = dynamic_cast<QgsComposerShape *>( item );
2716-
if ( shape )
2717-
{
2718-
emit composerShapeAdded( shape );
2719-
emit selectedItemChanged( shape );
2720-
return;
2721-
}
2722-
QgsComposerPolygon *polygon = dynamic_cast<QgsComposerPolygon *>( item );
2723-
if ( polygon )
2724-
{
2725-
emit composerPolygonAdded( polygon );
2726-
emit selectedItemChanged( polygon );
2727-
return;
2728-
}
2729-
QgsComposerPolyline *polyline = dynamic_cast<QgsComposerPolyline *>( item );
2730-
if ( polyline )
2731-
{
2732-
emit composerPolylineAdded( polyline );
2733-
emit selectedItemChanged( polyline );
2734-
return;
2735-
}
2676+
case QgsComposerItem::ComposerArrow:
2677+
case QgsComposerItem::ComposerLabel:
2678+
case QgsComposerItem::ComposerMap:
2679+
case QgsComposerItem::ComposerPolygon:
2680+
case QgsComposerItem::ComposerPolyline:
2681+
case QgsComposerItem::ComposerScaleBar:
2682+
case QgsComposerItem::ComposerLegend:
2683+
case QgsComposerItem::ComposerPicture:
2684+
case QgsComposerItem::ComposerShape:
2685+
case QgsComposerItem::ComposerFrame:
2686+
2687+
emit itemAdded( item );
2688+
emit selectedItemChanged( item );
2689+
return;
27362690

2737-
QgsComposerFrame *frame = dynamic_cast<QgsComposerFrame *>( item );
2738-
if ( frame )
2739-
{
2740-
//emit composerFrameAdded( multiframe, frame, );
2741-
QgsComposerMultiFrame *mf = frame->multiFrame();
2742-
QgsComposerHtml *html = dynamic_cast<QgsComposerHtml *>( mf );
2743-
if ( html )
2744-
{
2745-
emit composerHtmlFrameAdded( html, frame );
2746-
}
2747-
QgsComposerAttributeTableV2 *table = dynamic_cast<QgsComposerAttributeTableV2 *>( mf );
2748-
if ( table )
2749-
{
2750-
emit composerTableFrameAdded( table, frame );
2751-
}
2752-
emit selectedItemChanged( frame );
2753-
return;
27542691
}
2692+
27552693
QgsComposerItemGroup *group = dynamic_cast<QgsComposerItemGroup *>( item );
27562694
if ( group )
27572695
{

‎src/core/composer/qgscomposition.h

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,30 +1028,16 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
10281028

10291029
//! Is emitted when selected item changed. If 0, no item is selected
10301030
void selectedItemChanged( QgsComposerItem *selected );
1031-
//! Is emitted when new composer arrow has been added to the view
1032-
void composerArrowAdded( QgsComposerArrow *arrow );
1033-
//! Is emitted when new composer polygon has been added to the view
1034-
void composerPolygonAdded( QgsComposerPolygon *polygon );
1035-
//! Is emitted when new composer polyline has been added to the view
1036-
void composerPolylineAdded( QgsComposerPolyline *polyline );
1037-
//! Is emitted when a new composer html has been added to the view
1038-
void composerHtmlFrameAdded( QgsComposerHtml *html, QgsComposerFrame *frame );
1031+
1032+
/**
1033+
* Is emitted when a new composer item has been added to the composition.
1034+
* @note added in QGIS 3.0
1035+
*/
1036+
void itemAdded( QgsComposerItem *item );
1037+
10391038
//! Is emitted when a new item group has been added to the view
10401039
void composerItemGroupAdded( QgsComposerItemGroup *group );
1041-
//! Is emitted when new composer label has been added to the view
1042-
void composerLabelAdded( QgsComposerLabel *label );
1043-
//! Is emitted when new composer map has been added to the view
1044-
void composerMapAdded( QgsComposerMap *map );
1045-
//! Is emitted when new composer scale bar has been added
1046-
void composerScaleBarAdded( QgsComposerScaleBar *scalebar );
1047-
//! Is emitted when a new composer legend has been added
1048-
void composerLegendAdded( QgsComposerLegend *legend );
1049-
//! Is emitted when a new composer picture has been added
1050-
void composerPictureAdded( QgsComposerPicture *picture );
1051-
//! Is emitted when a new composer shape has been added
1052-
void composerShapeAdded( QgsComposerShape *shape );
1053-
//! Is emitted when a new composer table frame has been added to the view
1054-
void composerTableFrameAdded( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame );
1040+
10551041
//! Is emitted when a composer item has been removed from the scene
10561042
void itemRemoved( QgsComposerItem * );
10571043

‎tests/src/core/testqgscomposergroup.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ void TestQgsComposerGroup::deleteGroup()
183183
QVERIFY( mGroup->isRemoved() );
184184
}
185185

186-
Q_DECLARE_METATYPE( QgsComposerItemGroup * );
187-
Q_DECLARE_METATYPE( QgsComposerPolygon * );
188-
Q_DECLARE_METATYPE( QgsComposerItem * );
186+
Q_DECLARE_METATYPE( QgsComposerItemGroup * )
187+
Q_DECLARE_METATYPE( QgsComposerPolygon * )
188+
Q_DECLARE_METATYPE( QgsComposerItem * )
189189

190190
void TestQgsComposerGroup::undoRedo()
191191
{
@@ -195,15 +195,15 @@ void TestQgsComposerGroup::undoRedo()
195195
int itemsRemoved = 0;
196196

197197
qRegisterMetaType<QgsComposerPolygon *>();
198-
QSignalSpy spyPolygonAdded( mComposition, SIGNAL( composerPolygonAdded( QgsComposerPolygon * ) ) );
198+
QSignalSpy spyPolygonAdded( mComposition, &QgsComposition::itemAdded );
199199
QCOMPARE( spyPolygonAdded.count(), 0 );
200200

201201
qRegisterMetaType<QgsComposerItemGroup *>();
202-
QSignalSpy spyGroupAdded( mComposition, SIGNAL( composerItemGroupAdded( QgsComposerItemGroup * ) ) );
202+
QSignalSpy spyGroupAdded( mComposition, &QgsComposition::composerItemGroupAdded );
203203
QCOMPARE( spyGroupAdded.count(), 0 );
204204

205205
qRegisterMetaType<QgsComposerItem *>();
206-
QSignalSpy spyItemRemoved( mComposition, SIGNAL( itemRemoved( QgsComposerItem * ) ) );
206+
QSignalSpy spyItemRemoved( mComposition, &QgsComposition::itemRemoved );
207207
QCOMPARE( spyItemRemoved.count(), 0 );
208208

209209
//test for crash when undo/redoing with groups

0 commit comments

Comments
 (0)
Please sign in to comment.