Skip to content
Permalink
Browse files
Read composer from xml considers rulers
  • Loading branch information
mhugent committed Feb 14, 2013
1 parent 1a1dde1 commit 049fb235a71de7b2c2e20829b680f0a636efe6ca
Showing with 46 additions and 33 deletions.
  1. +31 −33 src/app/composer/qgscomposer.cpp
  2. +7 −0 src/app/composer/qgscomposer.h
  3. +6 −0 src/app/qgisapp.cpp
  4. +2 −0 src/gui/qgscomposerview.cpp
@@ -247,23 +247,20 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mViewFrame->setMouseTracking( true );

//create composer view and layout with rulers
mView = new QgsComposerView();
mView->setContentsMargins( 0, 0, 0, 0 );
QGridLayout* viewLayout = new QGridLayout();
viewLayout->setSpacing( 0 );
viewLayout->setMargin( 0 );
QgsComposerRuler* hRuler = new QgsComposerRuler( QgsComposerRuler::Horizontal );
mView->setHorizontalRuler( hRuler );
QgsComposerRuler* vRuler = new QgsComposerRuler( QgsComposerRuler::Vertical );
mView->setVerticalRuler( vRuler );
mView = 0;
mViewLayout = new QGridLayout();
mViewLayout->setSpacing( 0 );
mViewLayout->setMargin( 0 );
mHorizontalRuler = new QgsComposerRuler( QgsComposerRuler::Horizontal );
mVerticalRuler = new QgsComposerRuler( QgsComposerRuler::Vertical );
QWidget* fake = new QWidget();
fake->setBackgroundRole( QPalette::Window );
fake->setFixedSize( 20, 20 );
viewLayout->addWidget( fake, 0, 0 );
viewLayout->addWidget( hRuler, 0, 1 );
viewLayout->addWidget( vRuler, 1, 0 );
viewLayout->addWidget( mView, 1, 1 );
mViewFrame->setLayout( viewLayout );
mViewLayout->addWidget( fake, 0, 0 );
mViewLayout->addWidget( mHorizontalRuler, 0, 1 );
mViewLayout->addWidget( mVerticalRuler, 1, 0 );
createComposerView();
mViewFrame->setLayout( mViewLayout );

//init undo/redo buttons
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
@@ -328,10 +325,6 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

mGeneralDock->raise();

QGridLayout *l = new QGridLayout( mViewFrame );
l->setMargin( 0 );
l->addLayout( viewLayout, 0, 0 );

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
mSizeGrip = new QSizeGrip( this );
mSizeGrip->resize( mSizeGrip->sizeHint() );
@@ -438,6 +431,10 @@ void QgsComposer::open( void )
mFirstTime = false;
show();
zoomFull(); // zoomFull() does not work properly until we have called show()
if ( mView )
{
mView->updateRulers();
}
}

else
@@ -1605,21 +1602,11 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
}
}

//delete composer view and composition
delete mView;
mView = 0;
//delete every child of mViewFrame
QObjectList viewFrameChildren = mViewFrame->children();
QObjectList::iterator it = viewFrameChildren.begin();
for ( ; it != viewFrameChildren.end(); ++it )
{
delete( *it );
}
//delete composition widget
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralDock->widget() );
delete oldCompositionWidget;

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

//read composition settings
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
@@ -1632,10 +1619,6 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&

connectSlots();

QGridLayout *l = new QGridLayout( mViewFrame );
l->setMargin( 0 );
l->addWidget( mView, 0, 0 );

//create compositionwidget
QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
QObject::connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
@@ -1948,3 +1931,18 @@ void QgsComposer::initialiseComposerPicturePreviews()
}
mPicturePreviews.clear();
}

void QgsComposer::createComposerView()
{
if ( !mViewLayout )
{
return;
}

delete mView;
mView = new QgsComposerView();
mView->setContentsMargins( 0, 0, 0, 0 );
mView->setHorizontalRuler( mHorizontalRuler );
mView->setVerticalRuler( mVerticalRuler );
mViewLayout->addWidget( mView, 1, 1 );
}
@@ -28,6 +28,7 @@ class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerPicture;
class QgsComposerPictureWidget;
class QgsComposerRuler;
class QgsComposerScaleBar;
class QgsComposerShape;
class QgsComposerAttributeTable;
@@ -299,11 +300,17 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! To make loading from project faster, the previews are generated when the composer becomes visible.
void initialiseComposerPicturePreviews();

//! Create composer view and rulers
void createComposerView();

/**Composer title*/
QString mTitle;

//! Pointer to composer view
QgsComposerView *mView;
QGridLayout* mViewLayout;
QgsComposerRuler* mHorizontalRuler;
QgsComposerRuler* mVerticalRuler;

//! Current composition
QgsComposition *mComposition;
@@ -109,6 +109,7 @@
#include "qgsclipboard.h"
#include "qgscomposer.h"
#include "qgscomposermanager.h"
#include "qgscomposerview.h"
#include "qgsconfigureshortcutsdialog.h"
#include "qgscoordinatetransform.h"
#include "qgscredentialdialog.h"
@@ -4496,6 +4497,11 @@ bool QgisApp::loadComposersFromProject( const QDomDocument& doc )
composer->showMinimized();
#endif
composer->zoomFull();
QgsComposerView* composerView = composer->view();
if ( composerView )
{
composerView->updateRulers();
}
if ( composerNodes.at( i ).toElement().attribute( "visible", "1" ).toInt() < 1 )
{
composer->close();
@@ -46,6 +46,8 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
, mRubberBandLineItem( 0 )
, mMoveContentItem( 0 )
, mPaintingEnabled( true )
, mHorizontalRuler( 0 )
, mVerticalRuler( 0 )
{
Q_UNUSED( f );
Q_UNUSED( name );

0 comments on commit 049fb23

Please sign in to comment.