Skip to content
Permalink
Browse files

Delete composer frames from list

  • Loading branch information
mhugent committed Jul 27, 2012
1 parent 6f14d2c commit 70fe6cf72317871ea30947287e6b3b402c00bbb1
@@ -371,7 +371,7 @@ void QgsComposer::connectSlots()

connect( mComposition, SIGNAL( selectedItemChanged( QgsComposerItem* ) ), this, SLOT( showItemOptions( QgsComposerItem* ) ) );
connect( mComposition, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
connect( mComposition, SIGNAL( composerHtmlAdded( QgsComposerHtml* ) ), this, SLOT( addComposerHtml( QgsComposerHtml* ) ) );
connect( mComposition, SIGNAL( composerHtmlFrameAdded( QgsComposerHtml*, QgsComposerFrame* ) ), this, SLOT( addComposerHtmlFrame( QgsComposerHtml*, QgsComposerFrame* ) ) );
connect( mComposition, SIGNAL( composerLabelAdded( QgsComposerLabel* ) ), this, SLOT( addComposerLabel( QgsComposerLabel* ) ) );
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( addComposerMap( QgsComposerMap* ) ) );
connect( mComposition, SIGNAL( composerScaleBarAdded( QgsComposerScaleBar* ) ), this, SLOT( addComposerScaleBar( QgsComposerScaleBar* ) ) );
@@ -1341,20 +1341,15 @@ void QgsComposer::addComposerTable( QgsComposerAttributeTable* table )
mItemWidgetMap.insert( table, tWidget );
}

void QgsComposer::addComposerHtml( QgsComposerHtml* html )
void QgsComposer::addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame )
{
if ( !html )
{
return;
}

QgsComposerHtmlWidget* hWidget = new QgsComposerHtmlWidget( html );
QList<QgsComposerFrame*> frameList = html->frameItems();
QList<QgsComposerFrame*>::iterator frameIt = frameList.begin();
for ( ; frameIt != frameList.end(); ++frameIt )
{
mItemWidgetMap.insert( *frameIt, hWidget );
}
QgsComposerHtmlWidget* hWidget = new QgsComposerHtmlWidget( html, frame );
mItemWidgetMap.insert( frame, hWidget );
}

void QgsComposer::deleteItem( QgsComposerItem* item )
@@ -247,7 +247,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
void addComposerTable( QgsComposerAttributeTable* table );

/**Adds composer html and creates a configuration widget*/
void addComposerHtml( QgsComposerHtml* html );
void addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame );

/**Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself*/
void deleteItem( QgsComposerItem* item );
@@ -1,12 +1,22 @@
#include "qgscomposerhtmlwidget.h"
#include "qgscomposerframe.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposerhtml.h"
#include <QFileDialog>

QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html ): mHtml( html )
QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): mHtml( html ), mFrame( frame )
{
setupUi( this );
mResizeModeComboBox->addItem( tr( "Use existing frames" ), QgsComposerMultiFrame::UseExistingFrames );
mResizeModeComboBox->addItem( tr( "Extend to next page" ), QgsComposerMultiFrame::ExtendToNextPage );

//embed widget for general options
if ( mFrame )
{
//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, mFrame );
mToolBox->addItem( itemPropertiesWidget, tr( "General options" ) );
}
}

QgsComposerHtmlWidget::QgsComposerHtmlWidget()
@@ -28,10 +38,8 @@ void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
{
if ( mHtml )
{
//mHtml->beginCommand( tr( "Url changed" ) );
mHtml->setUrl( QUrl( mUrlLineEdit->text() ) );
mHtml->update();
//mHtmlItem->endCommand();
}
}

@@ -41,9 +49,7 @@ void QgsComposerHtmlWidget::on_mFileToolButton_clicked()
if ( !file.isEmpty() )
{
QUrl url = QUrl::fromLocalFile( file );
//mHtmlItem->beginCommand( tr( "Url changed" ) );
mHtml->setUrl( url );
//mHtmlItem->endCommand();
mUrlLineEdit->setText( url.toString() );
}
}
@@ -4,12 +4,13 @@
#include "ui_qgscomposerhtmlwidgetbase.h"

class QgsComposerHtml;
class QgsComposerFrame;

class QgsComposerHtmlWidget: public QWidget, private Ui::QgsComposerHtmlWidgetBase
{
Q_OBJECT
public:
QgsComposerHtmlWidget( QgsComposerHtml* html );
QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame );
~QgsComposerHtmlWidget();

private slots:
@@ -25,6 +26,7 @@ class QgsComposerHtmlWidget: public QWidget, private Ui::QgsComposerHtmlWidgetBa
void blockSignals( bool block );

QgsComposerHtml* mHtml;
QgsComposerFrame* mFrame;
};

#endif // QGSCOMPOSERHTMLWIDGET_H
@@ -27,9 +27,13 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal wid
mHtmlUnitsToMM = htmlUnitsToMM();
mWebPage = new QWebPage();
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
//setUrl( QUrl( "http://www.qgis.org" ) );//test
QgsComposerFrame* frame = new QgsComposerFrame( c, this, x, y, width, height );
addFrame( frame );

if ( mComposition )
{
QgsComposerFrame* frame = new QgsComposerFrame( c, this, x, y, width, height );
addFrame( frame );
QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
}
recalculateFrameSizes();
}

@@ -64,6 +68,7 @@ void QgsComposerHtml::setUrl( const QUrl& url )

void QgsComposerHtml::frameLoaded( bool ok )
{
Q_UNUSED( ok );
mLoaded = true;
}

@@ -97,3 +102,13 @@ double QgsComposerHtml::htmlUnitsToMM()
double pixelPerMM = mComposition->printResolution() / 25.4;
return ( pixelPerMM / ( img.dotsPerMeterX() / 1000.0 ) );
}

void QgsComposerHtml::addFrame( QgsComposerFrame* frame )
{
mFrameItems.push_back( frame );
QObject::connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
if ( mComposition )
{
mComposition->addComposerHtmlFrame( this, frame );
}
}
@@ -35,6 +35,9 @@ class QgsComposerHtml: public QgsComposerMultiFrame
QSizeF totalSize() const;
void render( QPainter* p, const QRectF& renderExtent );

protected:
void addFrame( QgsComposerFrame* frame );

private slots:
void frameLoaded( bool ok );

@@ -18,8 +18,6 @@

QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
{
//debug
//mResizeMode = ExtendToNextPage;
}

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
@@ -98,15 +96,20 @@ void QgsComposerMultiFrame::recalculateFrameSizes()
}
}

void QgsComposerMultiFrame::addFrame( QgsComposerFrame* frame )
void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
{
mFrameItems.push_back( frame );
QObject::connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
// QObject::connect( frame, SIGNAL( destroyed( QObject* ) ), this, SLOT( removeFrame( QObject* ) ) );
/* if ( mComposition )
{
mComposition->addItem( frame );
}*/
QgsComposerFrame* frame = dynamic_cast<QgsComposerFrame*>( item );
if ( !frame )
{
return;
}
int index = mFrameItems.indexOf( frame );
if ( index == -1 )
{
return;
}
mFrameItems.removeAt( index );
recalculateFrameSizes();
}

void QgsComposerMultiFrame::removeFrame( int i )
@@ -116,21 +119,8 @@ void QgsComposerMultiFrame::removeFrame( int i )
{
mComposition->removeComposerItem( frameItem );
}
mFrameItems.removeAt( i );
}

/*
void QgsComposerMultiFrame::removeFrame( QObject* frame )
{
QgsComposerFrame* composerFrame = dynamic_cast<QgsComposerFrame*>( frame );
if( composerFrame )
{
removeFrame( mFrameItems.indexOf( composerFrame ) );
recalculateFrameSizes();
}
}*/


void QgsComposerMultiFrame::update()
{
QList<QgsComposerFrame*>::iterator frameIt = mFrameItems.begin();
@@ -20,6 +20,7 @@
#include <QSizeF>

class QgsComposerFrame;
class QgsComposerItem;
class QgsComposition;
class QRectF;
class QPainter;
@@ -40,25 +41,24 @@ class QgsComposerMultiFrame: public QObject
virtual ~QgsComposerMultiFrame();
virtual QSizeF totalSize() const = 0;
virtual void render( QPainter* p, const QRectF& renderExtent ) = 0;

void addFrame( QgsComposerFrame* frame );
void removeFrame( int i );

void update();

void setResizeMode( ResizeMode mode );
ResizeMode resizeMode() const { return mResizeMode; }

QList<QgsComposerFrame*> frameItems() { return mFrameItems; }

protected:
QgsComposition* mComposition;
QList<QgsComposerFrame*> mFrameItems;
ResizeMode mResizeMode;

virtual void addFrame( QgsComposerFrame* frame ) = 0;

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

private:
QgsComposerMultiFrame(); //forbidden
@@ -1098,28 +1098,13 @@ void QgsComposition::addComposerTable( QgsComposerAttributeTable* table )
emit selectedItemChanged( table );
}

void QgsComposition::addComposerHtml( QgsComposerHtml* html )
void QgsComposition::addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame )
{
QList<QgsComposerFrame*> htmlFrames = html->frameItems();
if ( htmlFrames.size() < 1 )
{
return;
}

QList<QgsComposerFrame*>::iterator frameIt = htmlFrames.begin();
for ( ; frameIt != htmlFrames.end(); ++frameIt )
{
addItem( *frameIt );
}
emit composerHtmlAdded( html );
addItem( frame );
emit composerHtmlFrameAdded( html, frame );
clearSelection();

QgsComposerFrame* firstItem = htmlFrames[0];
if ( firstItem )
{
firstItem->setSelected( true );
emit selectedItemChanged( firstItem );
}
frame->setSelected( true );
emit selectedItemChanged( frame );
}

void QgsComposition::removeComposerItem( QgsComposerItem* item )
@@ -24,6 +24,7 @@
#include "qgscomposeritemcommand.h"
#include "qgsaddremoveitemcommand.h"

class QgsComposerFrame;
class QgsComposerItem;
class QgsComposerMap;
class QgsPaperItem;
@@ -215,8 +216,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
void addComposerShape( QgsComposerShape* shape );
/**Adds a composer table to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerTable( QgsComposerAttributeTable* table );
/**Adds composer html and advices composer to create a widget for it (through signal)*/
void addComposerHtml( QgsComposerHtml* html );
/**Adds composer html frame and advices composer to create a widget for it (through signal)*/
void addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame );

/**Remove item from the graphics scene. Additionally to QGraphicsScene::removeItem, this function considers undo/redo command*/
void removeComposerItem( QgsComposerItem* item );
@@ -302,7 +303,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Is emitted when new composer arrow has been added to the view*/
void composerArrowAdded( QgsComposerArrow* arrow );
/**Is emitted when a new composer html has been added to the view*/
void composerHtmlAdded( QgsComposerHtml* html );
void composerHtmlFrameAdded( QgsComposerHtml* html, QgsComposerFrame* frame );
/**Is emitted when new composer label has been added to the view*/
void composerLabelAdded( QgsComposerLabel* label );
/**Is emitted when new composer map has been added to the view*/
@@ -324,7 +324,7 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
{
QgsComposerHtml* composerHtml = new QgsComposerHtml( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(),
mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
composition()->addComposerHtml( composerHtml );
//composition()->addComposerHtml( composerHtml );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;

0 comments on commit 70fe6cf

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