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)
This commit is contained in:
Nyall Dawson 2017-03-18 20:51:00 +10:00
parent dbf0160327
commit 885269ee78
7 changed files with 129 additions and 356 deletions

View File

@ -728,6 +728,10 @@ were removed. Use setSnapTolerance() and snapTolerance() instead.
- dataDefinedProperty() and setDataDefinedProperty() now use the QgsProperty framework instead
of QgsDataDefined objects.
- mapSettings() was removed. Use QgsComposerMap::mapSettings() instead.
- The composerArrowAdded, composerPolygonAdded, composerPolylineAdded, composerHtmlFrameAdded, composerItemGroupAdded,
composerLabelAdded, composerMapAdded, composerScaleBarAdded, composerLegendAdded, composerPictureAdded,
composerShapeAdded, and composerTableFrameAdded were removed. Use the general itemAdded signal instead to catch
all these item added events.
QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem}

View File

@ -659,37 +659,10 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
void paperSizeChanged();
void nPagesChanged();
void printResolutionChanged();
/** Is emitted when selected item changed. If 0, no item is selected*/
void selectedItemChanged( QgsComposerItem* selected );
/** Is emitted when new composer arrow has been added to the view*/
void composerArrowAdded( QgsComposerArrow* arrow );
/** Is emitted when new composer polygon has been added to the view*/
void composerPolygonAdded( QgsComposerPolygon* polygon );
/** Is emitted when new composer polyline has been added to the view*/
void composerPolylineAdded( QgsComposerPolyline* polyline );
/** Is emitted when a new composer html has been added to the view*/
void composerHtmlFrameAdded( QgsComposerHtml* html, QgsComposerFrame* frame );
/** Is emitted when a new item group has been added to the view*/
void composerItemGroupAdded( QgsComposerItemGroup* group );
/** Is emitted when new composer label has been added to the view*/
void composerLabelAdded( QgsComposerLabel* label );
/** Is emitted when new composer map has been added to the view*/
void composerMapAdded( QgsComposerMap* map );
/** Is emitted when new composer scale bar has been added*/
void composerScaleBarAdded( QgsComposerScaleBar* scalebar );
/** Is emitted when a new composer legend has been added*/
void composerLegendAdded( QgsComposerLegend* legend );
/** Is emitted when a new composer picture has been added*/
void composerPictureAdded( QgsComposerPicture* picture );
/** Is emitted when a new composer shape has been added*/
void composerShapeAdded( QgsComposerShape* shape );
/** Is emitted when a new composer table frame has been added to the view*/
void composerTableFrameAdded( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame );
/** Is emitted when a composer item has been removed from the scene*/
void itemRemoved( QgsComposerItem* );
/** Is emitted when item in the composition must be refreshed*/
void selectedItemChanged( QgsComposerItem *selected );
void itemAdded( QgsComposerItem *item );
void composerItemGroupAdded( QgsComposerItemGroup *group );
void itemRemoved( QgsComposerItem * );
void refreshItemsTriggered();
/** Is emitted when the composition has an updated status bar message for the composer window*/

View File

@ -673,7 +673,6 @@ QgsComposer::QgsComposer( QgsComposition *composition )
QgsComposer::~QgsComposer()
{
deleteItemWidgets();
delete mPrinter;
}
@ -774,17 +773,7 @@ void QgsComposer::connectCompositionSlots()
connect( mComposition, &QgsComposition::nameChanged, this, &QgsComposer::setWindowTitle );
connect( mComposition, &QgsComposition::selectedItemChanged, this, &QgsComposer::showItemOptions );
connect( mComposition, &QgsComposition::composerArrowAdded, this, &QgsComposer::addComposerArrow );
connect( mComposition, &QgsComposition::composerPolygonAdded, this, &QgsComposer::addComposerPolygon );
connect( mComposition, &QgsComposition::composerPolylineAdded, this, &QgsComposer::addComposerPolyline );
connect( mComposition, &QgsComposition::composerHtmlFrameAdded, this, &QgsComposer::addComposerHtmlFrame );
connect( mComposition, &QgsComposition::composerLabelAdded, this, &QgsComposer::addComposerLabel );
connect( mComposition, &QgsComposition::composerMapAdded, this, &QgsComposer::addComposerMap );
connect( mComposition, &QgsComposition::composerScaleBarAdded, this, &QgsComposer::addComposerScaleBar );
connect( mComposition, &QgsComposition::composerLegendAdded, this, &QgsComposer::addComposerLegend );
connect( mComposition, &QgsComposition::composerPictureAdded, this, &QgsComposer::addComposerPicture );
connect( mComposition, &QgsComposition::composerShapeAdded, this, &QgsComposer::addComposerShape );
connect( mComposition, &QgsComposition::composerTableFrameAdded, this, &QgsComposer::addComposerTableV2 );
connect( mComposition, &QgsComposition::itemAdded, this, &QgsComposer::compositionItemAdded );
connect( mComposition, &QgsComposition::itemRemoved, this, &QgsComposer::deleteItem );
connect( mComposition, &QgsComposition::paperSizeChanged, this, [ = ]
{
@ -847,6 +836,7 @@ bool QgsComposer::loadFromTemplate( const QDomDocument &templateDoc, bool clearE
setUpdatesEnabled( false );
bool result = mComposition->loadFromTemplate( templateDoc, nullptr, false, clearExisting );
cleanupAfterTemplateRead();
setUpdatesEnabled( true );
dlg->close();
@ -947,25 +937,19 @@ void QgsComposer::showItemOptions( QgsComposerItem *item )
{
if ( !item )
{
mItemPropertiesStack->takeMainPanel();
delete mItemPropertiesStack->takeMainPanel();
return;
}
QMap<QgsComposerItem *, QgsPanelWidget *>::const_iterator it = mItemWidgetMap.constFind( item );
if ( it == mItemWidgetMap.constEnd() )
std::unique_ptr< QgsPanelWidget > widget( createItemWidget( item ) );
if ( ! widget )
{
return;
}
QgsPanelWidget *newWidget = it.value();
if ( !newWidget || newWidget == mItemPropertiesStack->mainPanel() ) //bail out if new widget does not exist or is already there
{
return;
}
( void ) mItemPropertiesStack->takeMainPanel();
newWidget->setDockMode( true );
mItemPropertiesStack->setMainPanel( newWidget );
delete mItemPropertiesStack->takeMainPanel();
widget->setDockMode( true );
mItemPropertiesStack->setMainPanel( widget.release() );
}
void QgsComposer::on_mActionOptions_triggered()
@ -1039,6 +1023,63 @@ void QgsComposer::atlasFeatureChanged( QgsFeature *feature )
mapCanvas()->expressionContextScope().addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( atlasFeature.geometry() ), true ) );
}
void QgsComposer::compositionItemAdded( QgsComposerItem *item )
{
if ( item && item->type() == QgsComposerItem::ComposerMap )
{
connect( this, &QgsComposer::zoomLevelChanged, static_cast< QgsComposerMap *>( item ), &QgsComposerMap::renderModeUpdateCachedImage );
}
}
QgsPanelWidget *QgsComposer::createItemWidget( QgsComposerItem *item )
{
if ( !item )
return nullptr;
switch ( item->type() )
{
case QgsComposerItem::ComposerArrow:
return new QgsComposerArrowWidget( static_cast< QgsComposerArrow * >( item ) );
case QgsComposerItem::ComposerPolygon:
return new QgsComposerPolygonWidget( static_cast< QgsComposerPolygon * >( item ) );
case QgsComposerItem::ComposerPolyline:
return new QgsComposerPolylineWidget( static_cast< QgsComposerPolyline * >( item ) );
case QgsComposerItem::ComposerLabel:
return new QgsComposerLabelWidget( static_cast< QgsComposerLabel * >( item ) );
case QgsComposerItem::ComposerMap:
return new QgsComposerMapWidget( static_cast< QgsComposerMap * >( item ) );
case QgsComposerItem::ComposerScaleBar:
return new QgsComposerScaleBarWidget( static_cast< QgsComposerScaleBar * >( item ) );
case QgsComposerItem::ComposerLegend:
return new QgsComposerLegendWidget( static_cast< QgsComposerLegend * >( item ) );
case QgsComposerItem::ComposerPicture:
return new QgsComposerPictureWidget( static_cast< QgsComposerPicture * >( item ) );
case QgsComposerItem::ComposerFrame:
{
QgsComposerFrame *frame = static_cast< QgsComposerFrame * >( item );
if ( QgsComposerHtml *html = dynamic_cast< QgsComposerHtml * >( frame->multiFrame() ) )
{
return new QgsComposerHtmlWidget( html, frame );
}
else if ( QgsComposerAttributeTableV2 *table = dynamic_cast< QgsComposerAttributeTableV2 * >( frame->multiFrame() ) )
{
return new QgsComposerAttributeTableWidget( table, frame );
}
break;
}
}
return nullptr; // no warnings!
}
void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
{
QgsAtlasComposition *atlasMap = &mComposition->atlasComposition();
@ -3376,145 +3417,9 @@ void QgsComposer::restoreGridSettings()
mActionShowBoxes->setChecked( mComposition->boundingBoxesVisible() );
}
void QgsComposer::deleteItemWidgets()
void QgsComposer::deleteItem( QgsComposerItem * )
{
//delete all the items
qDeleteAll( mItemWidgetMap );
mItemWidgetMap.clear();
}
void QgsComposer::addComposerArrow( QgsComposerArrow *arrow )
{
if ( !arrow )
{
return;
}
QgsComposerArrowWidget *arrowWidget = new QgsComposerArrowWidget( arrow );
mItemWidgetMap.insert( arrow, arrowWidget );
}
void QgsComposer::addComposerPolygon( QgsComposerPolygon *polygon )
{
if ( !polygon )
{
return;
}
QgsComposerPolygonWidget *polygonWidget = new QgsComposerPolygonWidget( polygon );
mItemWidgetMap.insert( polygon, polygonWidget );
}
void QgsComposer::addComposerPolyline( QgsComposerPolyline *polyline )
{
if ( !polyline )
{
return;
}
QgsComposerPolylineWidget *polylineWidget = new QgsComposerPolylineWidget( polyline );
mItemWidgetMap.insert( polyline, polylineWidget );
}
void QgsComposer::addComposerMap( QgsComposerMap *map )
{
if ( !map )
{
return;
}
QgsComposerMapWidget *mapWidget = new QgsComposerMapWidget( map );
connect( this, &QgsComposer::zoomLevelChanged, map, &QgsComposerMap::renderModeUpdateCachedImage );
mItemWidgetMap.insert( map, mapWidget );
}
void QgsComposer::addComposerLabel( QgsComposerLabel *label )
{
if ( !label )
{
return;
}
QgsComposerLabelWidget *labelWidget = new QgsComposerLabelWidget( label );
mItemWidgetMap.insert( label, labelWidget );
}
void QgsComposer::addComposerScaleBar( QgsComposerScaleBar *scalebar )
{
if ( !scalebar )
{
return;
}
QgsComposerScaleBarWidget *sbWidget = new QgsComposerScaleBarWidget( scalebar );
mItemWidgetMap.insert( scalebar, sbWidget );
}
void QgsComposer::addComposerLegend( QgsComposerLegend *legend )
{
if ( !legend )
{
return;
}
QgsComposerLegendWidget *lWidget = new QgsComposerLegendWidget( legend );
mItemWidgetMap.insert( legend, lWidget );
}
void QgsComposer::addComposerPicture( QgsComposerPicture *picture )
{
if ( !picture )
{
return;
}
QgsComposerPictureWidget *pWidget = new QgsComposerPictureWidget( picture );
mItemWidgetMap.insert( picture, pWidget );
}
void QgsComposer::addComposerShape( QgsComposerShape *shape )
{
if ( !shape )
{
return;
}
QgsComposerShapeWidget *sWidget = new QgsComposerShapeWidget( shape );
mItemWidgetMap.insert( shape, sWidget );
}
void QgsComposer::addComposerTableV2( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame )
{
if ( !table )
{
return;
}
QgsComposerAttributeTableWidget *tWidget = new QgsComposerAttributeTableWidget( table, frame );
mItemWidgetMap.insert( frame, tWidget );
}
void QgsComposer::addComposerHtmlFrame( QgsComposerHtml *html, QgsComposerFrame *frame )
{
if ( !html )
{
return;
}
QgsComposerHtmlWidget *hWidget = new QgsComposerHtmlWidget( html, frame );
mItemWidgetMap.insert( frame, hWidget );
}
void QgsComposer::deleteItem( QgsComposerItem *item )
{
QMap<QgsComposerItem *, QgsPanelWidget *>::const_iterator it = mItemWidgetMap.constFind( item );
if ( it == mItemWidgetMap.constEnd() )
{
return;
}
//the item itself is not deleted here (usually, this is done in the destructor of QgsAddRemoveItemCommand)
it.value()->deleteLater();
mItemWidgetMap.remove( it.key() );
showItemOptions( nullptr );
}
void QgsComposer::setSelectionTool()
@ -3608,11 +3513,10 @@ void QgsComposer::showAdvancedEffectsWarning()
void QgsComposer::cleanupAfterTemplateRead()
{
QMap<QgsComposerItem *, QgsPanelWidget *>::const_iterator itemIt = mItemWidgetMap.constBegin();
for ( ; itemIt != mItemWidgetMap.constEnd(); ++itemIt )
Q_FOREACH ( QGraphicsItem *item, mComposition->items() )
{
//update all legends completely
QgsComposerLegend *legendItem = dynamic_cast<QgsComposerLegend *>( itemIt.key() );
QgsComposerLegend *legendItem = dynamic_cast<QgsComposerLegend *>( item );
if ( legendItem )
{
legendItem->updateLegend();
@ -3620,7 +3524,7 @@ void QgsComposer::cleanupAfterTemplateRead()
}
//update composer map extent if it does not intersect the full extent of all layers
QgsComposerMap *mapItem = dynamic_cast<QgsComposerMap *>( itemIt.key() );
QgsComposerMap *mapItem = dynamic_cast<QgsComposerMap *>( item );
if ( mapItem )
{
//test if composer map extent intersects extent of all layers

View File

@ -414,39 +414,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Save window state
void saveWindowState();
//! Add a composer arrow to the item/widget map and creates a configuration widget for it
void addComposerArrow( QgsComposerArrow *arrow );
//! Add a composer polygon to the item/widget map and creates a configuration widget for it
void addComposerPolygon( QgsComposerPolygon *polygon );
//! Add a composer polyline to the item/widget map and creates a configuration widget for it
void addComposerPolyline( QgsComposerPolyline *polyline );
//! Add a composer map to the item/widget map and creates a configuration widget for it
void addComposerMap( QgsComposerMap *map );
//! Adds a composer label to the item/widget map and creates a configuration widget for it
void addComposerLabel( QgsComposerLabel *label );
//! Adds a composer scale bar to the item/widget map and creates a configuration widget for it
void addComposerScaleBar( QgsComposerScaleBar *scalebar );
//! Adds a composer legend to the item/widget map and creates a configuration widget for it
void addComposerLegend( QgsComposerLegend *legend );
//! Adds a composer picture to the item/widget map and creates a configuration widget
void addComposerPicture( QgsComposerPicture *picture );
//! Adds a composer shape to the item/widget map and creates a configuration widget
void addComposerShape( QgsComposerShape *shape );
//! Adds a composer table v2 to the item/widget map and creates a configuration widget
void addComposerTableV2( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame );
//! Adds composer html and creates a configuration widget
void addComposerHtmlFrame( QgsComposerHtml *html, QgsComposerFrame *frame );
//! Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself
void deleteItem( QgsComposerItem *item );
@ -503,9 +470,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Changes elements that are not suitable for this project
void cleanupAfterTemplateRead();
//! Removes all the item from the graphics scene and deletes them
void deleteItemWidgets();
//! Create composer view and rulers
void createComposerView();
@ -532,6 +496,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QPrinter *printer();
QgsPanelWidget *createItemWidget( QgsComposerItem *item );
QgsAppComposerInterface *mInterface = nullptr;
//! Labels in status bar which shows current mouse position
@ -565,9 +531,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Size grip
QSizeGrip *mSizeGrip = nullptr;
//! To know which item to show if selection changes
QMap<QgsComposerItem *, QgsPanelWidget *> mItemWidgetMap;
//! Copy/cut/paste actions
QAction *mActionCut = nullptr;
QAction *mActionCopy = nullptr;
@ -664,6 +627,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
void updateAtlasPageComboBox( int pageCount );
void atlasFeatureChanged( QgsFeature *feature );
void compositionItemAdded( QgsComposerItem *item );
};
#endif

View File

@ -226,6 +226,7 @@ void QgsComposition::setAllDeselected()
composerItem->setSelected( false );
}
}
emit selectedItemChanged( nullptr );
}
void QgsComposition::refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QgsExpressionContext *context )
@ -2452,7 +2453,7 @@ void QgsComposition::addComposerArrow( QgsComposerArrow *arrow )
updateBounds();
connect( arrow, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerArrowAdded( arrow );
emit itemAdded( arrow );
}
void QgsComposition::addComposerPolygon( QgsComposerPolygon *polygon )
@ -2462,7 +2463,7 @@ void QgsComposition::addComposerPolygon( QgsComposerPolygon *polygon )
updateBounds();
connect( polygon, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerPolygonAdded( polygon );
emit itemAdded( polygon );
}
void QgsComposition::addComposerPolyline( QgsComposerPolyline *polyline )
@ -2472,7 +2473,7 @@ void QgsComposition::addComposerPolyline( QgsComposerPolyline *polyline )
updateBounds();
connect( polyline, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerPolylineAdded( polyline );
emit itemAdded( polyline );
}
void QgsComposition::addComposerLabel( QgsComposerLabel *label )
@ -2482,7 +2483,7 @@ void QgsComposition::addComposerLabel( QgsComposerLabel *label )
updateBounds();
connect( label, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerLabelAdded( label );
emit itemAdded( label );
}
void QgsComposition::addComposerMap( QgsComposerMap *map, const bool setDefaultPreviewStyle )
@ -2502,7 +2503,7 @@ void QgsComposition::addComposerMap( QgsComposerMap *map, const bool setDefaultP
updateBounds();
connect( map, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerMapAdded( map );
emit itemAdded( map );
}
void QgsComposition::addComposerScaleBar( QgsComposerScaleBar *scaleBar )
@ -2512,7 +2513,7 @@ void QgsComposition::addComposerScaleBar( QgsComposerScaleBar *scaleBar )
updateBounds();
connect( scaleBar, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerScaleBarAdded( scaleBar );
emit itemAdded( scaleBar );
}
void QgsComposition::addComposerLegend( QgsComposerLegend *legend )
@ -2522,7 +2523,7 @@ void QgsComposition::addComposerLegend( QgsComposerLegend *legend )
updateBounds();
connect( legend, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerLegendAdded( legend );
emit itemAdded( legend );
}
void QgsComposition::addComposerPicture( QgsComposerPicture *picture )
@ -2532,7 +2533,7 @@ void QgsComposition::addComposerPicture( QgsComposerPicture *picture )
updateBounds();
connect( picture, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerPictureAdded( picture );
emit itemAdded( picture );
}
void QgsComposition::addComposerShape( QgsComposerShape *shape )
@ -2542,27 +2543,27 @@ void QgsComposition::addComposerShape( QgsComposerShape *shape )
updateBounds();
connect( shape, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerShapeAdded( shape );
emit itemAdded( shape );
}
void QgsComposition::addComposerHtmlFrame( QgsComposerHtml *html, QgsComposerFrame *frame )
void QgsComposition::addComposerHtmlFrame( QgsComposerHtml *, QgsComposerFrame *frame )
{
addItem( frame );
updateBounds();
connect( frame, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerHtmlFrameAdded( html, frame );
emit itemAdded( frame );
}
void QgsComposition::addComposerTableFrame( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame )
void QgsComposition::addComposerTableFrame( QgsComposerAttributeTableV2 *, QgsComposerFrame *frame )
{
addItem( frame );
updateBounds();
connect( frame, SIGNAL( sizeChanged() ), this, SLOT( updateBounds() ) );
emit composerTableFrameAdded( table, frame );
emit itemAdded( frame );
}
/* public */
@ -2670,88 +2671,25 @@ void QgsComposition::sendItemAddedSignal( QgsComposerItem *item )
{
//cast and send proper signal
item->setSelected( true );
QgsComposerArrow *arrow = dynamic_cast<QgsComposerArrow *>( item );
if ( arrow )
switch ( item->type() )
{
emit composerArrowAdded( arrow );
emit selectedItemChanged( arrow );
return;
}
QgsComposerLabel *label = dynamic_cast<QgsComposerLabel *>( item );
if ( label )
{
emit composerLabelAdded( label );
emit selectedItemChanged( label );
return;
}
QgsComposerMap *map = dynamic_cast<QgsComposerMap *>( item );
if ( map )
{
emit composerMapAdded( map );
emit selectedItemChanged( map );
return;
}
QgsComposerScaleBar *scalebar = dynamic_cast<QgsComposerScaleBar *>( item );
if ( scalebar )
{
emit composerScaleBarAdded( scalebar );
emit selectedItemChanged( scalebar );
return;
}
QgsComposerLegend *legend = dynamic_cast<QgsComposerLegend *>( item );
if ( legend )
{
emit composerLegendAdded( legend );
emit selectedItemChanged( legend );
return;
}
QgsComposerPicture *picture = dynamic_cast<QgsComposerPicture *>( item );
if ( picture )
{
emit composerPictureAdded( picture );
emit selectedItemChanged( picture );
return;
}
QgsComposerShape *shape = dynamic_cast<QgsComposerShape *>( item );
if ( shape )
{
emit composerShapeAdded( shape );
emit selectedItemChanged( shape );
return;
}
QgsComposerPolygon *polygon = dynamic_cast<QgsComposerPolygon *>( item );
if ( polygon )
{
emit composerPolygonAdded( polygon );
emit selectedItemChanged( polygon );
return;
}
QgsComposerPolyline *polyline = dynamic_cast<QgsComposerPolyline *>( item );
if ( polyline )
{
emit composerPolylineAdded( polyline );
emit selectedItemChanged( polyline );
return;
case QgsComposerItem::ComposerArrow:
case QgsComposerItem::ComposerLabel:
case QgsComposerItem::ComposerMap:
case QgsComposerItem::ComposerPolygon:
case QgsComposerItem::ComposerPolyline:
case QgsComposerItem::ComposerScaleBar:
case QgsComposerItem::ComposerLegend:
case QgsComposerItem::ComposerPicture:
case QgsComposerItem::ComposerShape:
case QgsComposerItem::ComposerFrame:
emit itemAdded( item );
emit selectedItemChanged( item );
return;
}
QgsComposerFrame *frame = dynamic_cast<QgsComposerFrame *>( item );
if ( frame )
{
//emit composerFrameAdded( multiframe, frame, );
QgsComposerMultiFrame *mf = frame->multiFrame();
QgsComposerHtml *html = dynamic_cast<QgsComposerHtml *>( mf );
if ( html )
{
emit composerHtmlFrameAdded( html, frame );
}
QgsComposerAttributeTableV2 *table = dynamic_cast<QgsComposerAttributeTableV2 *>( mf );
if ( table )
{
emit composerTableFrameAdded( table, frame );
}
emit selectedItemChanged( frame );
return;
}
QgsComposerItemGroup *group = dynamic_cast<QgsComposerItemGroup *>( item );
if ( group )
{

View File

@ -1028,30 +1028,16 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
//! Is emitted when selected item changed. If 0, no item is selected
void selectedItemChanged( QgsComposerItem *selected );
//! Is emitted when new composer arrow has been added to the view
void composerArrowAdded( QgsComposerArrow *arrow );
//! Is emitted when new composer polygon has been added to the view
void composerPolygonAdded( QgsComposerPolygon *polygon );
//! Is emitted when new composer polyline has been added to the view
void composerPolylineAdded( QgsComposerPolyline *polyline );
//! Is emitted when a new composer html has been added to the view
void composerHtmlFrameAdded( QgsComposerHtml *html, QgsComposerFrame *frame );
/**
* Is emitted when a new composer item has been added to the composition.
* @note added in QGIS 3.0
*/
void itemAdded( QgsComposerItem *item );
//! Is emitted when a new item group has been added to the view
void composerItemGroupAdded( QgsComposerItemGroup *group );
//! Is emitted when new composer label has been added to the view
void composerLabelAdded( QgsComposerLabel *label );
//! Is emitted when new composer map has been added to the view
void composerMapAdded( QgsComposerMap *map );
//! Is emitted when new composer scale bar has been added
void composerScaleBarAdded( QgsComposerScaleBar *scalebar );
//! Is emitted when a new composer legend has been added
void composerLegendAdded( QgsComposerLegend *legend );
//! Is emitted when a new composer picture has been added
void composerPictureAdded( QgsComposerPicture *picture );
//! Is emitted when a new composer shape has been added
void composerShapeAdded( QgsComposerShape *shape );
//! Is emitted when a new composer table frame has been added to the view
void composerTableFrameAdded( QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame );
//! Is emitted when a composer item has been removed from the scene
void itemRemoved( QgsComposerItem * );

View File

@ -183,9 +183,9 @@ void TestQgsComposerGroup::deleteGroup()
QVERIFY( mGroup->isRemoved() );
}
Q_DECLARE_METATYPE( QgsComposerItemGroup * );
Q_DECLARE_METATYPE( QgsComposerPolygon * );
Q_DECLARE_METATYPE( QgsComposerItem * );
Q_DECLARE_METATYPE( QgsComposerItemGroup * )
Q_DECLARE_METATYPE( QgsComposerPolygon * )
Q_DECLARE_METATYPE( QgsComposerItem * )
void TestQgsComposerGroup::undoRedo()
{
@ -195,15 +195,15 @@ void TestQgsComposerGroup::undoRedo()
int itemsRemoved = 0;
qRegisterMetaType<QgsComposerPolygon *>();
QSignalSpy spyPolygonAdded( mComposition, SIGNAL( composerPolygonAdded( QgsComposerPolygon * ) ) );
QSignalSpy spyPolygonAdded( mComposition, &QgsComposition::itemAdded );
QCOMPARE( spyPolygonAdded.count(), 0 );
qRegisterMetaType<QgsComposerItemGroup *>();
QSignalSpy spyGroupAdded( mComposition, SIGNAL( composerItemGroupAdded( QgsComposerItemGroup * ) ) );
QSignalSpy spyGroupAdded( mComposition, &QgsComposition::composerItemGroupAdded );
QCOMPARE( spyGroupAdded.count(), 0 );
qRegisterMetaType<QgsComposerItem *>();
QSignalSpy spyItemRemoved( mComposition, SIGNAL( itemRemoved( QgsComposerItem * ) ) );
QSignalSpy spyItemRemoved( mComposition, &QgsComposition::itemRemoved );
QCOMPARE( spyItemRemoved.count(), 0 );
//test for crash when undo/redoing with groups