|
18 | 18 | #include "qgscomposeritem.h" |
19 | 19 | #include "qgscomposermap.h" |
20 | 20 | #include "qgspaperitem.h" |
| 21 | +#include "qgscomposerarrow.h" |
| 22 | +#include "qgscomposerlabel.h" |
| 23 | +#include "qgscomposerlegend.h" |
| 24 | +#include "qgscomposermap.h" |
| 25 | +#include "qgscomposeritemgroup.h" |
| 26 | +#include "qgscomposerpicture.h" |
| 27 | +#include "qgscomposerscalebar.h" |
| 28 | +#include "qgscomposershape.h" |
| 29 | +#include "qgscomposerattributetable.h" |
21 | 30 | #include "qgslogger.h" |
22 | 31 | #include <QDomDocument> |
23 | 32 | #include <QDomElement> |
@@ -252,6 +261,113 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu |
252 | 261 | return true; |
253 | 262 | } |
254 | 263 |
|
| 264 | +void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, QPointF* pos ) |
| 265 | +{ |
| 266 | + QDomNodeList composerLabelList = elem.elementsByTagName( "ComposerLabel" ); |
| 267 | + for ( int i = 0; i < composerLabelList.size(); ++i ) |
| 268 | + { |
| 269 | + QDomElement currentComposerLabelElem = composerLabelList.at( i ).toElement(); |
| 270 | + QgsComposerLabel* newLabel = new QgsComposerLabel( this ); |
| 271 | + newLabel->readXML( currentComposerLabelElem, doc ); |
| 272 | + if ( pos ) |
| 273 | + { |
| 274 | + newLabel->setItemPosition( pos->x(), pos->y() ); |
| 275 | + } |
| 276 | + addComposerLabel( newLabel ); |
| 277 | + } |
| 278 | + // map |
| 279 | + QDomNodeList composerMapList = elem.elementsByTagName( "ComposerMap" ); |
| 280 | + for ( int i = 0; i < composerMapList.size(); ++i ) |
| 281 | + { |
| 282 | + QDomElement currentComposerMapElem = composerMapList.at( i ).toElement(); |
| 283 | + QgsComposerMap* newMap = new QgsComposerMap( this ); |
| 284 | + newMap->readXML( currentComposerMapElem, doc ); |
| 285 | + if ( pos ) |
| 286 | + { |
| 287 | + newMap->setItemPosition( pos->x(), pos->y() ); |
| 288 | + } |
| 289 | + addComposerMap( newMap ); |
| 290 | + } |
| 291 | + // arrow |
| 292 | + QDomNodeList composerArrowList = elem.elementsByTagName( "ComposerArrow" ); |
| 293 | + for ( int i = 0; i < composerArrowList.size(); ++i ) |
| 294 | + { |
| 295 | + QDomElement currentComposerArrowElem = composerArrowList.at( i ).toElement(); |
| 296 | + QgsComposerArrow* newArrow = new QgsComposerArrow( this ); |
| 297 | + newArrow->readXML( currentComposerArrowElem, doc ); |
| 298 | + if ( pos ) |
| 299 | + { |
| 300 | + newArrow->setItemPosition( pos->x(), pos->y() ); |
| 301 | + } |
| 302 | + addComposerArrow( newArrow ); |
| 303 | + } |
| 304 | + // scalebar |
| 305 | + QDomNodeList composerScaleBarList = elem.elementsByTagName( "ComposerScaleBar" ); |
| 306 | + for ( int i = 0; i < composerScaleBarList.size(); ++i ) |
| 307 | + { |
| 308 | + QDomElement currentComposerScaleBarElem = composerScaleBarList.at( i ).toElement(); |
| 309 | + QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar( this ); |
| 310 | + newScaleBar->readXML( currentComposerScaleBarElem, doc ); |
| 311 | + if ( pos ) |
| 312 | + { |
| 313 | + newScaleBar->setItemPosition( pos->x(), pos->y() ); |
| 314 | + } |
| 315 | + addComposerScaleBar( newScaleBar ); |
| 316 | + } |
| 317 | + // shape |
| 318 | + QDomNodeList composerShapeList = elem.elementsByTagName( "ComposerShape" ); |
| 319 | + for ( int i = 0; i < composerShapeList.size(); ++i ) |
| 320 | + { |
| 321 | + QDomElement currentComposerShapeElem = composerShapeList.at( i ).toElement(); |
| 322 | + QgsComposerShape* newShape = new QgsComposerShape( this ); |
| 323 | + newShape->readXML( currentComposerShapeElem, doc ); |
| 324 | + if ( pos ) |
| 325 | + { |
| 326 | + newShape->setItemPosition( pos->x(), pos->y() ); |
| 327 | + } |
| 328 | + addComposerShape( newShape ); |
| 329 | + } |
| 330 | + // picture |
| 331 | + QDomNodeList composerPictureList = elem.elementsByTagName( "ComposerPicture" ); |
| 332 | + for ( int i = 0; i < composerPictureList.size(); ++i ) |
| 333 | + { |
| 334 | + QDomElement currentComposerPictureElem = composerPictureList.at( i ).toElement(); |
| 335 | + QgsComposerPicture* newPicture = new QgsComposerPicture( this ); |
| 336 | + newPicture->readXML( currentComposerPictureElem, doc ); |
| 337 | + if ( pos ) |
| 338 | + { |
| 339 | + newPicture->setItemPosition( pos->x(), pos->y() ); |
| 340 | + } |
| 341 | + addComposerPicture( newPicture ); |
| 342 | + } |
| 343 | + // legend |
| 344 | + QDomNodeList composerLegendList = elem.elementsByTagName( "ComposerLegend" ); |
| 345 | + for ( int i = 0; i < composerLegendList.size(); ++i ) |
| 346 | + { |
| 347 | + QDomElement currentComposerLegendElem = composerLegendList.at( i ).toElement(); |
| 348 | + QgsComposerLegend* newLegend = new QgsComposerLegend( this ); |
| 349 | + newLegend->readXML( currentComposerLegendElem, doc ); |
| 350 | + if ( pos ) |
| 351 | + { |
| 352 | + newLegend->setItemPosition( pos->x(), pos->y() ); |
| 353 | + } |
| 354 | + addComposerLegend( newLegend ); |
| 355 | + } |
| 356 | + // table |
| 357 | + QDomNodeList composerTableList = elem.elementsByTagName( "ComposerAttributeTable" ); |
| 358 | + for ( int i = 0; i < composerTableList.size(); ++i ) |
| 359 | + { |
| 360 | + QDomElement currentComposerTableElem = composerTableList.at( i ).toElement(); |
| 361 | + QgsComposerAttributeTable* newTable = new QgsComposerAttributeTable( this ); |
| 362 | + newTable->readXML( currentComposerTableElem, doc ); |
| 363 | + if ( pos ) |
| 364 | + { |
| 365 | + newTable->setItemPosition( pos->x(), pos->y() ); |
| 366 | + } |
| 367 | + addComposerTable( newTable ); |
| 368 | + } |
| 369 | +} |
| 370 | + |
255 | 371 | void QgsComposition::addItemToZList( QgsComposerItem* item ) |
256 | 372 | { |
257 | 373 | if ( !item ) |
@@ -833,3 +949,99 @@ void QgsComposition::cancelCommand() |
833 | 949 | delete mActiveCommand; |
834 | 950 | mActiveCommand = 0; |
835 | 951 | } |
| 952 | + |
| 953 | +void QgsComposition::addComposerArrow( QgsComposerArrow* arrow ) |
| 954 | +{ |
| 955 | + addItem( arrow ); |
| 956 | + emit composerArrowAdded( arrow ); |
| 957 | + clearSelection(); |
| 958 | + arrow->setSelected( true ); |
| 959 | + emit selectedItemChanged( arrow ); |
| 960 | + //pushAddRemoveCommand( arrow, tr( "Arrow added" ) ); |
| 961 | +} |
| 962 | + |
| 963 | +void QgsComposition::addComposerLabel( QgsComposerLabel* label ) |
| 964 | +{ |
| 965 | + addItem( label ); |
| 966 | + emit composerLabelAdded( label ); |
| 967 | + clearSelection(); |
| 968 | + label->setSelected( true ); |
| 969 | + emit selectedItemChanged( label ); |
| 970 | + //pushAddRemoveCommand( label, tr( "Label added" ) ); |
| 971 | +} |
| 972 | + |
| 973 | +void QgsComposition::addComposerMap( QgsComposerMap* map ) |
| 974 | +{ |
| 975 | + addItem( map ); |
| 976 | + //set default preview mode to cache. Must be done here between adding composer map to scene and emiting signal |
| 977 | + map->setPreviewMode( QgsComposerMap::Cache ); |
| 978 | + map->cache(); |
| 979 | + emit composerMapAdded( map ); |
| 980 | + clearSelection(); |
| 981 | + map->setSelected( true ); |
| 982 | + emit selectedItemChanged( map ); |
| 983 | + //pushAddRemoveCommand( map, tr( "Map added" ) ); |
| 984 | +} |
| 985 | + |
| 986 | +void QgsComposition::addComposerScaleBar( QgsComposerScaleBar* scaleBar ) |
| 987 | +{ |
| 988 | + //take first available map |
| 989 | + QList<const QgsComposerMap*> mapItemList = composerMapItems(); |
| 990 | + if ( mapItemList.size() > 0 ) |
| 991 | + { |
| 992 | + scaleBar->setComposerMap( mapItemList.at( 0 ) ); |
| 993 | + } |
| 994 | + scaleBar->applyDefaultSize(); //4 segments, 1/5 of composer map width |
| 995 | + addItem( scaleBar ); |
| 996 | + emit composerScaleBarAdded( scaleBar ); |
| 997 | + clearSelection(); |
| 998 | + scaleBar->setSelected( true ); |
| 999 | + emit selectedItemChanged( scaleBar ); |
| 1000 | + //pushAddRemoveCommand( scaleBar, tr( "Scale bar added" ) ); |
| 1001 | +} |
| 1002 | + |
| 1003 | +void QgsComposition::addComposerLegend( QgsComposerLegend* legend ) |
| 1004 | +{ |
| 1005 | + //take first available map |
| 1006 | + QList<const QgsComposerMap*> mapItemList = composerMapItems(); |
| 1007 | + if ( mapItemList.size() > 0 ) |
| 1008 | + { |
| 1009 | + legend->setComposerMap( mapItemList.at( 0 ) ); |
| 1010 | + } |
| 1011 | + addItem( legend ); |
| 1012 | + emit composerLegendAdded( legend ); |
| 1013 | + clearSelection(); |
| 1014 | + legend->setSelected( true ); |
| 1015 | + emit selectedItemChanged( legend ); |
| 1016 | + //pushAddRemoveCommand( legend, tr( "Legend added" ) ); |
| 1017 | +} |
| 1018 | + |
| 1019 | +void QgsComposition::addComposerPicture( QgsComposerPicture* picture ) |
| 1020 | +{ |
| 1021 | + addItem( picture ); |
| 1022 | + emit composerPictureAdded( picture ); |
| 1023 | + clearSelection(); |
| 1024 | + picture->setSelected( true ); |
| 1025 | + emit selectedItemChanged( picture ); |
| 1026 | + //pushAddRemoveCommand( picture, tr( "Picture added" ) ); |
| 1027 | +} |
| 1028 | + |
| 1029 | +void QgsComposition::addComposerShape( QgsComposerShape* shape ) |
| 1030 | +{ |
| 1031 | + addItem( shape ); |
| 1032 | + emit composerShapeAdded( shape ); |
| 1033 | + clearSelection(); |
| 1034 | + shape->setSelected( true ); |
| 1035 | + emit selectedItemChanged( shape ); |
| 1036 | + //pushAddRemoveCommand( shape, tr( "Shape added" ) ); |
| 1037 | +} |
| 1038 | + |
| 1039 | +void QgsComposition::addComposerTable( QgsComposerAttributeTable* table ) |
| 1040 | +{ |
| 1041 | + addItem( table ); |
| 1042 | + emit composerTableAdded( table ); |
| 1043 | + clearSelection(); |
| 1044 | + table->setSelected( true ); |
| 1045 | + emit selectedItemChanged( table ); |
| 1046 | + //pushAddRemoveCommand( table, tr( "Table added" ) ); |
| 1047 | +} |
0 commit comments