Skip to content
Permalink
Browse files

Connect signal slots for html dialog

  • Loading branch information
mhugent committed Jul 26, 2012
1 parent 590929d commit 6f14d2c089481696f217ec7be79b9c9c7933735f
@@ -109,6 +109,7 @@ SET(QGIS_APP_SRCS
composer/qgsattributeselectiondialog.cpp
composer/qgscomposer.cpp
composer/qgscomposerarrowwidget.cpp
composer/qgscomposerhtmlwidget.cpp
composer/qgscomposeritemwidget.cpp
composer/qgscomposerlabelwidget.cpp
composer/qgscomposerpicturewidget.cpp
@@ -249,6 +250,7 @@ SET (QGIS_APP_MOC_HDRS
composer/qgsattributeselectiondialog.h
composer/qgscomposer.h
composer/qgscomposerarrowwidget.h
composer/qgscomposerhtmlwidget.h
composer/qgscomposeritemwidget.h
composer/qgscomposerlabelwidget.h
composer/qgscomposerlegendwidget.h
@@ -23,6 +23,9 @@
#include "qgscompositionwidget.h"
#include "qgscomposerarrow.h"
#include "qgscomposerarrowwidget.h"
#include "qgscomposerframe.h"
#include "qgscomposerhtml.h"
#include "qgscomposerhtmlwidget.h"
#include "qgscomposerlabel.h"
#include "qgscomposerlabelwidget.h"
#include "qgscomposerlegend.h"
@@ -368,6 +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( composerLabelAdded( QgsComposerLabel* ) ), this, SLOT( addComposerLabel( QgsComposerLabel* ) ) );
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( addComposerMap( QgsComposerMap* ) ) );
connect( mComposition, SIGNAL( composerScaleBarAdded( QgsComposerScaleBar* ) ), this, SLOT( addComposerScaleBar( QgsComposerScaleBar* ) ) );
@@ -1344,7 +1348,13 @@ void QgsComposer::addComposerHtml( QgsComposerHtml* html )
return;
}

//todo: create html widget and create entry for each frame in the item/widget map
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 );
}
}

void QgsComposer::deleteItem( QgsComposerItem* item )
@@ -0,0 +1,74 @@
#include "qgscomposerhtmlwidget.h"
#include "qgscomposerhtml.h"
#include <QFileDialog>

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

QgsComposerHtmlWidget::QgsComposerHtmlWidget()
{
}

QgsComposerHtmlWidget::~QgsComposerHtmlWidget()
{
}

void QgsComposerHtmlWidget::blockSignals( bool block )
{
mUrlLineEdit->blockSignals( block );
mFileToolButton->blockSignals( block );
mResizeModeComboBox->blockSignals( block );
}

void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
{
if ( mHtml )
{
//mHtml->beginCommand( tr( "Url changed" ) );
mHtml->setUrl( QUrl( mUrlLineEdit->text() ) );
mHtml->update();
//mHtmlItem->endCommand();
}
}

void QgsComposerHtmlWidget::on_mFileToolButton_clicked()
{
QString file = QFileDialog::getOpenFileName( this, tr( "Select HTML document" ), QString(), "HTML (*.html)" );
if ( !file.isEmpty() )
{
QUrl url = QUrl::fromLocalFile( file );
//mHtmlItem->beginCommand( tr( "Url changed" ) );
mHtml->setUrl( url );
//mHtmlItem->endCommand();
mUrlLineEdit->setText( url.toString() );
}
}

void QgsComposerHtmlWidget::on_mResizeModeComboBox_currentIndexChanged( int index )
{
if ( !mHtml )
{
return;
}

mHtml->setResizeMode(( QgsComposerMultiFrame::ResizeMode )mResizeModeComboBox->itemData( index ).toInt() );
}

void QgsComposerHtmlWidget::setGuiElementValues()
{
if ( !mHtml )
{
return;
}

blockSignals( true );
mUrlLineEdit->setText( mHtml->url().toString() );
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
blockSignals( false );
}


@@ -0,0 +1,30 @@
#ifndef QGSCOMPOSERHTMLWIDGET_H
#define QGSCOMPOSERHTMLWIDGET_H

#include "ui_qgscomposerhtmlwidgetbase.h"

class QgsComposerHtml;

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

private slots:
void on_mUrlLineEdit_editingFinished();
void on_mFileToolButton_clicked();
void on_mResizeModeComboBox_currentIndexChanged( int index );

/**Sets the GUI elements to the values of mHtmlItem*/
void setGuiElementValues();

private:
QgsComposerHtmlWidget();
void blockSignals( bool block );

QgsComposerHtml* mHtml;
};

#endif // QGSCOMPOSERHTMLWIDGET_H
@@ -27,7 +27,7 @@ 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
//setUrl( QUrl( "http://www.qgis.org" ) );//test
QgsComposerFrame* frame = new QgsComposerFrame( c, this, x, y, width, height );
addFrame( frame );
recalculateFrameSizes();
@@ -94,7 +94,6 @@ double QgsComposerHtml::htmlUnitsToMM()
}

QImage img( 1, 1, QImage::Format_ARGB32_Premultiplied );
double debug = img.dotsPerMeterX();
double pixelPerMM = mComposition->printResolution() / 25.4;
return ( pixelPerMM / ( img.dotsPerMeterX() / 1000.0 ) );
}
@@ -19,7 +19,7 @@
QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
{
//debug
mResizeMode = ExtendToNextPage;
//mResizeMode = ExtendToNextPage;
}

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
@@ -30,6 +30,15 @@ QgsComposerMultiFrame::~QgsComposerMultiFrame()
{
}

void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )
{
if ( mode != mResizeMode )
{
mResizeMode = mode;
recalculateFrameSizes();
}
}

void QgsComposerMultiFrame::recalculateFrameSizes()
{
if ( mFrameItems.size() < 1 )
@@ -94,10 +103,10 @@ void QgsComposerMultiFrame::addFrame( QgsComposerFrame* frame )
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 );
}
/* if ( mComposition )
{
mComposition->addItem( frame );
}*/
}

void QgsComposerMultiFrame::removeFrame( int i )
@@ -120,3 +129,13 @@ void QgsComposerMultiFrame::removeFrame( QObject* frame )
recalculateFrameSizes();
}
}*/


void QgsComposerMultiFrame::update()
{
QList<QgsComposerFrame*>::iterator frameIt = mFrameItems.begin();
for ( ; frameIt != mFrameItems.end(); ++frameIt )
{
( *frameIt )->update();
}
}
@@ -44,9 +44,13 @@ class QgsComposerMultiFrame: public QObject
void addFrame( QgsComposerFrame* frame );
void removeFrame( int i );

void setResizeMode( ResizeMode mode ) { mResizeMode = mode; }
void update();

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

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

protected:
QgsComposition* mComposition;
QList<QgsComposerFrame*> mFrameItems;
@@ -17,6 +17,8 @@
#include "qgscomposition.h"
#include "qgscomposeritem.h"
#include "qgscomposerarrow.h"
#include "qgscomposerframe.h"
#include "qgscomposerhtml.h"
#include "qgscomposerlabel.h"
#include "qgscomposerlegend.h"
#include "qgscomposermap.h"
@@ -1098,8 +1100,26 @@ void QgsComposition::addComposerTable( QgsComposerAttributeTable* table )

void QgsComposition::addComposerHtml( QgsComposerHtml* html )
{
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 );
clearSelection();

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

void QgsComposition::removeComposerItem( QgsComposerItem* item )
@@ -324,6 +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 );
scene()->removeItem( mRubberBandItem );
delete mRubberBandItem;
mRubberBandItem = 0;
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsComposerHtmlWidgetBase</class>
<widget class="QWidget" name="QgsComposerHtmlWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>243</width>
<height>116</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QToolBox" name="mToolBox">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>225</width>
<height>72</height>
</rect>
</property>
<attribute name="label">
<string>HTML</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QToolButton" name="mFileToolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mUrlLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mUrlLabel">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mResizeModeLabel">
<property name="text">
<string>Resize mode</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mResizeModeComboBox"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 6f14d2c

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