Skip to content
Permalink
Browse files

Improved multiframe command handling

  • Loading branch information
mhugent committed Aug 2, 2012
1 parent ec0a02b commit 3ebef1b66db8d97a2481194b7f829daa07849e0c
@@ -38,6 +38,8 @@ class QgsComposerFrame: public QgsComposerItem

int type() const { return ComposerFrame; }

QgsComposerMultiFrame* multiFrame() { return mMultiFrame; }

private:
QgsComposerFrame(); //forbidden

@@ -16,22 +16,29 @@
#include "qgscomposerhtml.h"
#include "qgscomposerframe.h"
#include "qgscomposition.h"
#include "qgsaddremovemultiframecommand.h"
#include <QCoreApplication>
#include <QImage>
#include <QPainter>
#include <QWebFrame>
#include <QWebPage>

QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height ): QgsComposerMultiFrame( c ), mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 )
QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height, bool addCommands ): QgsComposerMultiFrame( c ), mWebPage( 0 ),
mLoaded( false ), mHtmlUnitsToMM( 1.0 )
{
mHtmlUnitsToMM = htmlUnitsToMM();
mWebPage = new QWebPage();
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );

if ( mComposition && width > 0 && height > 0 )
{
if ( addCommands )
{
QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Added, this, mComposition, tr( "HTML added" ), 0 );
mComposition->undoStack()->push( c );
}
QgsComposerFrame* frame = new QgsComposerFrame( c, this, x, y, width, height );
addFrame( frame );
addFrame( frame, addCommands );
QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
recalculateFrameSizes();
}
@@ -105,13 +112,17 @@ double QgsComposerHtml::htmlUnitsToMM()
return ( pixelPerMM / ( img.dotsPerMeterX() / 1000.0 ) );
}

void QgsComposerHtml::addFrame( QgsComposerFrame* frame )
void QgsComposerHtml::addFrame( QgsComposerFrame* frame, bool addCommand )
{
mFrameItems.push_back( frame );
QObject::connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
if ( mComposition )
{
mComposition->addComposerHtmlFrame( this, frame );
if ( addCommand )
{
mComposition->pushAddRemoveCommand( frame, tr( "Add Html frame" ) );
}
}
}

@@ -25,7 +25,7 @@ class QgsComposerHtml: public QgsComposerMultiFrame
{
Q_OBJECT
public:
QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height );
QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height, bool addCommands = false );
QgsComposerHtml();
~QgsComposerHtml();

@@ -39,7 +39,7 @@ class QgsComposerHtml: public QgsComposerMultiFrame
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

protected:
void addFrame( QgsComposerFrame* frame );
void addFrame( QgsComposerFrame* frame, bool addCommand = false );

private slots:
void frameLoaded( bool ok );
@@ -28,6 +28,7 @@ QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode(

QgsComposerMultiFrame::~QgsComposerMultiFrame()
{
//todo: remove all frames from composition and delete them
}

void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )
@@ -40,7 +41,7 @@ void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )
}
}

void QgsComposerMultiFrame::recalculateFrameSizes()
void QgsComposerMultiFrame::recalculateFrameSizes( bool addCommands )
{
if ( mFrameItems.size() < 1 )
{
@@ -67,7 +68,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes()
{
for ( int j = mFrameItems.size(); j > i; --j )
{
removeFrame( j - 1 );
removeFrame( j - 1, addCommands );
}
}
return;
@@ -100,7 +101,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes()
newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), newFrame->rect().height() ) );
currentY += newFrame->rect().height();
currentItem = newFrame;
addFrame( newFrame );
addFrame( newFrame, addCommands );
}
}
}
@@ -125,8 +126,8 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
{
//schedule this composer multi frame for deletion
mComposition->removeMultiFrame( this );
QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Removed, this, mComposition, tr( "Html removed" ), 0 );
mComposition->undoStack()->push( c );
// QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Removed, this, mComposition, tr( "Html removed" ), 0 );
// mComposition->undoStack()->push( c );
}
}
else
@@ -135,12 +136,16 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
}
}

void QgsComposerMultiFrame::removeFrame( int i )
void QgsComposerMultiFrame::removeFrame( int i, bool addCommand )
{
QgsComposerFrame* frameItem = mFrameItems[i];
if ( mComposition )
{
mComposition->removeComposerItem( frameItem );
if ( addCommand )
{
mComposition->pushAddRemoveCommand( frameItem, tr( "Frame removed" ), QgsAddRemoveItemCommand::Removed );
}
}
}

@@ -43,7 +43,7 @@ class QgsComposerMultiFrame: public QObject
virtual ~QgsComposerMultiFrame();
virtual QSizeF totalSize() const = 0;
virtual void render( QPainter* p, const QRectF& renderExtent ) = 0;
void removeFrame( int i );
void removeFrame( int i, bool addCommand = false );

void update();

@@ -61,10 +61,10 @@ class QgsComposerMultiFrame: public QObject
QList<QgsComposerFrame*> mFrameItems;
ResizeMode mResizeMode;

virtual void addFrame( QgsComposerFrame* frame ) = 0;
virtual void addFrame( QgsComposerFrame* frame, bool addCommand = false ) = 0;

protected slots:
void recalculateFrameSizes();
void recalculateFrameSizes( bool addCommands = false );
/**Called before a frame is going to be removed (update frame list)*/
void handleFrameRemoval( QgsComposerItem* item );

@@ -1260,6 +1260,19 @@ void QgsComposition::sendItemAddedSignal( QgsComposerItem* item )
emit selectedItemChanged( table );
return;
}
QgsComposerFrame* frame = dynamic_cast<QgsComposerFrame*>( item );
if ( frame )
{
//emit composerFrameAdded( multiframe, frame, );
QgsComposerMultiFrame* mf = frame->multiFrame();
QgsComposerHtml* html = dynamic_cast<QgsComposerHtml*>( mf );
if ( html )
{
emit composerHtmlFrameAdded( html, frame );
}
emit selectedItemChanged( frame );
return;
}
}

void QgsComposition::updatePaperItems()
@@ -324,14 +324,11 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
if ( composition() )
{
QgsComposerHtml* composerHtml = new QgsComposerHtml( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(),
mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
mRubberBandItem->rect().width(), mRubberBandItem->rect().height(), true );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
emit actionFinished();

QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Added, composerHtml, composition(), tr( "HTML added" ), 0 );
composition()->undoStack()->push( c );
}
default:
break;

0 comments on commit 3ebef1b

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