Skip to content
Permalink
Browse files

Avoid undo commands from multiframe classes

  • Loading branch information
mhugent committed Aug 7, 2012
1 parent 02d05d1 commit b2782c06ef665e9d16c4e672bdc99972bf53665d
@@ -22,7 +22,7 @@
#include <QWebFrame>
#include <QWebPage>

QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height, bool addCommands ): QgsComposerMultiFrame( c ), mWebPage( 0 ),
QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height ): QgsComposerMultiFrame( c ), mWebPage( 0 ),
mLoaded( false ), mHtmlUnitsToMM( 1.0 )
{
mHtmlUnitsToMM = htmlUnitsToMM();
@@ -31,13 +31,8 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal wid

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, addCommands );
addFrame( frame );
QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
recalculateFrameSizes();
}
@@ -110,17 +105,13 @@ double QgsComposerHtml::htmlUnitsToMM()
return ( mComposition->printResolution() / 96.0 ); //webkit seems to assume a standard dpi of 96
}

void QgsComposerHtml::addFrame( QgsComposerFrame* frame, bool addCommand )
void QgsComposerHtml::addFrame( QgsComposerFrame* frame )
{
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, bool addCommands = false );
QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal width, qreal height );
QgsComposerHtml();
~QgsComposerHtml();

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

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

private slots:
void frameLoaded( bool ok );
@@ -42,12 +42,12 @@ void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )
if ( mode != mResizeMode )
{
mResizeMode = mode;
recalculateFrameSizes( false );
recalculateFrameSizes();
emit changed();
}
}

void QgsComposerMultiFrame::recalculateFrameSizes( bool addCommands )
void QgsComposerMultiFrame::recalculateFrameSizes()
{
if ( mFrameItems.size() < 1 )
{
@@ -74,7 +74,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes( bool addCommands )
{
for ( int j = mFrameItems.size(); j > i; --j )
{
removeFrame( j - 1, addCommands );
removeFrame( j - 1 );
}
}
return;
@@ -107,7 +107,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes( bool addCommands )
newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), newFrame->rect().height() ) );
currentY += newFrame->rect().height();
currentItem = newFrame;
addFrame( newFrame, addCommands );
addFrame( newFrame );
}
}
}
@@ -140,16 +140,12 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
}
}

void QgsComposerMultiFrame::removeFrame( int i, bool addCommand )
void QgsComposerMultiFrame::removeFrame( int i )
{
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, bool addCommand = false );
void removeFrame( int i );

void update();

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

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

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

@@ -63,7 +63,7 @@ void QgsComposerMultiFrameCommand::saveState( QDomDocument& stateDoc )
{
stateDoc.clear();
QDomElement documentElement = stateDoc.createElement( "ComposerMultiFrameState" );
mMultiFrame->writeXML( documentElement, stateDoc, true );
mMultiFrame->writeXML( documentElement, stateDoc );
stateDoc.appendChild( documentElement );
}
}
@@ -72,7 +72,7 @@ void QgsComposerMultiFrameCommand::restoreState( QDomDocument& stateDoc )
{
if ( mMultiFrame )
{
mMultiFrame->readXML( stateDoc.documentElement().firstChild().toElement(), stateDoc, true );
mMultiFrame->readXML( stateDoc.documentElement().firstChild().toElement(), stateDoc );
}
}

@@ -324,7 +324,7 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
if ( composition() )
{
QgsComposerHtml* composerHtml = new QgsComposerHtml( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(),
mRubberBandItem->rect().width(), mRubberBandItem->rect().height(), true );
mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
@@ -58,7 +58,7 @@ void TestQgsComposerHtml::cleanup()

void TestQgsComposerHtml::table()
{
QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, 0, 0, 100, 200, false );
QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, 0, 0, 100, 200 );
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "html_table.html" ) ) );
QgsCompositionChecker checker( "Composer html table", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composerhtml" + QDir::separator() + "composerhtml_table.png" ) );
@@ -70,7 +70,7 @@ void TestQgsComposerHtml::table()

void TestQgsComposerHtml::tableMultiFrame()
{
QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, 10, 10, 100, 50, false );
QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, 10, 10, 100, 50 );
htmlItem->setResizeMode( QgsComposerMultiFrame::ExtendToNextPage );
bool result = true;
//page1

0 comments on commit b2782c0

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