|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgscomposerframe.cpp 00003 ------------------------------------------------------------ 00004 begin : July 2012 00005 copyright : (C) 2012 by Marco Hugentobler 00006 email : marco dot hugentobler at sourcepole dot ch 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #include "qgscomposerframe.h" 00017 #include "qgscomposermultiframe.h" 00018 #include "qgscomposition.h" 00019 00020 QgsComposerFrame::QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height ) 00021 : QgsComposerItem( x, y, width, height, c ) 00022 , mMultiFrame( mf ) 00023 { 00024 } 00025 00026 QgsComposerFrame::QgsComposerFrame() 00027 : QgsComposerItem( 0, 0, 0, 0, 0 ) 00028 , mMultiFrame( 0 ) 00029 { 00030 } 00031 00032 QgsComposerFrame::~QgsComposerFrame() 00033 { 00034 } 00035 00036 bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const 00037 { 00038 QDomElement frameElem = doc.createElement( "ComposerFrame" ); 00039 frameElem.setAttribute( "sectionX", QString::number( mSection.x() ) ); 00040 frameElem.setAttribute( "sectionY", QString::number( mSection.y() ) ); 00041 frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) ); 00042 frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) ); 00043 elem.appendChild( frameElem ); 00044 return _writeXML( frameElem, doc ); 00045 } 00046 00047 bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument& doc ) 00048 { 00049 double x = itemElem.attribute( "sectionX" ).toDouble(); 00050 double y = itemElem.attribute( "sectionY" ).toDouble(); 00051 double width = itemElem.attribute( "sectionWidth" ).toDouble(); 00052 double height = itemElem.attribute( "sectionHeight" ).toDouble(); 00053 mSection = QRectF( x, y, width, height ); 00054 QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" ); 00055 if ( composerItem.isNull() ) 00056 { 00057 return false; 00058 } 00059 return _readXML( composerItem, doc ); 00060 } 00061 00062 void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) 00063 { 00064 Q_UNUSED( itemStyle ); 00065 Q_UNUSED( pWidget ); 00066 00067 if ( !painter ) 00068 { 00069 return; 00070 } 00071 00072 drawBackground( painter ); 00073 if ( mMultiFrame ) 00074 { 00075 mMultiFrame->render( painter, mSection ); 00076 } 00077 00078 drawFrame( painter ); 00079 if ( isSelected() ) 00080 { 00081 drawSelectionBoxes( painter ); 00082 } 00083 } 00084 00085 void QgsComposerFrame::beginItemCommand( const QString& text ) 00086 { 00087 if ( mComposition ) 00088 { 00089 mComposition->beginMultiFrameCommand( multiFrame(), text ); 00090 } 00091 } 00092 00093 void QgsComposerFrame::endItemCommand() 00094 { 00095 if ( mComposition ) 00096 { 00097 mComposition->endMultiFrameCommand(); 00098 } 00099 }