QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerframe.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerframe.cpp
3  ------------------------------------------------------------
4  begin : July 2012
5  copyright : (C) 2012 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgscomposerframe.h"
17 #include "qgscomposermultiframe.h"
18 #include "qgscomposition.h"
19 
20 QgsComposerFrame::QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height )
21  : QgsComposerItem( x, y, width, height, c )
22  , mMultiFrame( mf )
23 {
24  //repaint frame when multiframe content changes
25  connect( mf, SIGNAL( contentsChanged() ), this, SLOT( repaint() ) );
26 }
27 
29  : QgsComposerItem( 0, 0, 0, 0, 0 )
30  , mMultiFrame( 0 )
31 {
32 }
33 
35 {
36 }
37 
38 bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const
39 {
40  QDomElement frameElem = doc.createElement( "ComposerFrame" );
41  frameElem.setAttribute( "sectionX", QString::number( mSection.x() ) );
42  frameElem.setAttribute( "sectionY", QString::number( mSection.y() ) );
43  frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) );
44  frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) );
45  elem.appendChild( frameElem );
46 
47  return _writeXML( frameElem, doc );
48 }
49 
50 bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument& doc )
51 {
52  double x = itemElem.attribute( "sectionX" ).toDouble();
53  double y = itemElem.attribute( "sectionY" ).toDouble();
54  double width = itemElem.attribute( "sectionWidth" ).toDouble();
55  double height = itemElem.attribute( "sectionHeight" ).toDouble();
56  mSection = QRectF( x, y, width, height );
57  QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" );
58  if ( composerItem.isNull() )
59  {
60  return false;
61  }
62  return _readXML( composerItem, doc );
63 }
64 
65 void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
66 {
67  Q_UNUSED( itemStyle );
68  Q_UNUSED( pWidget );
69 
70  if ( !painter )
71  {
72  return;
73  }
74 
75  drawBackground( painter );
76  if ( mMultiFrame )
77  {
78  mMultiFrame->render( painter, mSection );
79  }
80 
81  drawFrame( painter );
82  if ( isSelected() )
83  {
84  drawSelectionBoxes( painter );
85  }
86 }
87 
88 void QgsComposerFrame::beginItemCommand( const QString& text )
89 {
90  if ( mComposition )
91  {
93  }
94 }
95 
97 {
98  if ( mComposition )
99  {
101  }
102 }
virtual void render(QPainter *p, const QRectF &renderExtent)=0
A item that forms part of a map composition.
QgsComposerMultiFrame * mMultiFrame
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void beginMultiFrameCommand(QgsComposerMultiFrame *multiFrame, const QString &text)
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
Abstract base class for composer entries with the ability to distribute the content to several frames...
Graphics scene for map printing.
QgsComposition * mComposition
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
virtual void drawBackground(QPainter *p)
Draw background.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
void beginItemCommand(const QString &text)
QgsComposerMultiFrame * multiFrame() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)