Skip to content
Permalink
Browse files

Merge branch 'composeritem_xml'

  • Loading branch information
marco
marco committed Dec 7, 2011
2 parents a74d82d + f1c4d53 commit 06bda9c3aa1989c9d0d64116ff40565ba401059e
@@ -102,6 +102,13 @@ class QgsComposition: QGraphicsScene
/**Reads settings from xml file*/
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );

/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
@param elem items parent element, e.g. <Composer> or <ComposerItemClipboard>
@param doc xml document
@param addUndoCommands insert AddItem commands if true (e.g. for copy/paste)
@param pos item position. Optional, take position from xml if 0*/
void addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, bool addUndoCommands = false, QPointF* pos = 0 );

/**Adds item to z list. Usually called from constructor of QgsComposerItem*/
void addItemToZList( QgsComposerItem* item );
/**Removes item from z list. Usually called from destructor of QgsComposerItem*/
@@ -142,4 +149,27 @@ class QgsComposition: QGraphicsScene
void endCommand();
/**Deletes current command*/
void cancelCommand();

/**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. Additionally to QGraphicsScene::removeItem, this function considers undo/redo command*/
void removeComposerItem( QgsComposerItem* item );

/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state );
};
@@ -49,31 +49,13 @@ 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();

void setPaintingEnabled( bool enabled );
bool paintingEnabled() const;

/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );

protected:
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
@@ -85,23 +67,9 @@ class QgsComposerView: QGraphicsView
void wheelEvent( QWheelEvent* event );


public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
void sendItemAddedSignal( QgsComposerItem* item );

signals:
/**Is emitted when selected item changed. If 0, no item is selected*/
void selectedItemChanged( QgsComposerItem* selected );
/**Ist emittted 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 composer item has been removed from the scene*/
void itemRemoved( QgsComposerItem* );
/**Current action (e.g. adding composer map) has been finished. The purpose of this signal is that
36 src/app/composer/qgscomposer.cpp 100755 → 100644
@@ -201,10 +201,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),

//create composer view
mView = new QgsComposerView( mViewFrame );
connectSlots();

//init undo/redo buttons
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );

mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
if ( mComposition->undoStack() )
@@ -213,6 +213,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
}

connectSlots();


mComposition->setParent( mView );
mView->setComposition( mComposition );
@@ -314,16 +316,19 @@ void QgsComposer::setIconSizes( int size )
void QgsComposer::connectSlots()
{
connect( mView, SIGNAL( selectedItemChanged( QgsComposerItem* ) ), this, SLOT( showItemOptions( QgsComposerItem* ) ) );
connect( mView, SIGNAL( composerLabelAdded( QgsComposerLabel* ) ), this, SLOT( addComposerLabel( QgsComposerLabel* ) ) );
connect( mView, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( addComposerMap( QgsComposerMap* ) ) );
connect( mView, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( deleteItem( QgsComposerItem* ) ) );
connect( mView, SIGNAL( composerScaleBarAdded( QgsComposerScaleBar* ) ), this, SLOT( addComposerScaleBar( QgsComposerScaleBar* ) ) );
connect( mView, SIGNAL( composerLegendAdded( QgsComposerLegend* ) ), this, SLOT( addComposerLegend( QgsComposerLegend* ) ) );
connect( mView, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
connect( mView, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
connect( mView, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
connect( mView, SIGNAL( composerTableAdded( QgsComposerAttributeTable* ) ), this, SLOT( addComposerTable( QgsComposerAttributeTable* ) ) );
connect( mView, SIGNAL( actionFinished() ), this, SLOT( setSelectionTool() ) );

connect( mComposition, SIGNAL( selectedItemChanged( QgsComposerItem* ) ), this, SLOT( showItemOptions( QgsComposerItem* ) ) );
connect( mComposition, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
connect( mComposition, SIGNAL( composerLabelAdded( QgsComposerLabel* ) ), this, SLOT( addComposerLabel( QgsComposerLabel* ) ) );
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( addComposerMap( QgsComposerMap* ) ) );
connect( mComposition, SIGNAL( composerScaleBarAdded( QgsComposerScaleBar* ) ), this, SLOT( addComposerScaleBar( QgsComposerScaleBar* ) ) );
connect( mComposition, SIGNAL( composerLegendAdded( QgsComposerLegend* ) ), this, SLOT( addComposerLegend( QgsComposerLegend* ) ) );
connect( mComposition, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
connect( mComposition, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
connect( mComposition, SIGNAL( composerTableAdded( QgsComposerAttributeTable* ) ), this, SLOT( addComposerTable( QgsComposerAttributeTable* ) ) );
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( deleteItem( QgsComposerItem* ) ) );
}

void QgsComposer::open( void )
@@ -1306,7 +1311,6 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mCompositionOptionsLayout = 0;

mView = new QgsComposerView( mViewFrame );
connectSlots();

//read composition settings
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
@@ -1317,6 +1321,8 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mComposition->readXML( compositionElem, doc );
}

connectSlots();

QGridLayout *l = new QGridLayout( mViewFrame );
l->setMargin( 0 );
l->addWidget( mView, 0, 0 );
@@ -1331,7 +1337,12 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mCompositionOptionsLayout->addWidget( compositionWidget );

//read and restore all the items
if ( mComposition )
{
mComposition->addItemsFromXML( composerElem, doc );
}

#if 0
//composer labels
QDomNodeList composerLabelList = composerElem.elementsByTagName( "ComposerLabel" );
for ( int i = 0; i < composerLabelList.size(); ++i )
@@ -1465,6 +1476,7 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
newTable->setSelected( true );
showItemOptions( newTable );
}
#endif //0

mComposition->sortZList();
mView->setComposition( mComposition );
@@ -1553,10 +1565,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 );
}

0 comments on commit 06bda9c

Please sign in to comment.
You can’t perform that action at this time.