Skip to content
Permalink
Browse files
[composer] Create base item widget class for composer items, clean up…
… and remove duplicate code
  • Loading branch information
nyalldawson committed Jul 4, 2014
1 parent 57980ab commit 6af7dbddfd5b597697ea8ffe54b12d6cebe80ced
@@ -22,7 +22,7 @@
#include <QFileDialog>
#include <QFileInfo>

QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QWidget( 0 ), mArrow( arrow )
QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QgsComposerItemBaseWidget( 0, arrow ), mArrow( arrow )
{
setupUi( this );
mRadioButtonGroup = new QButtonGroup( this );
@@ -19,10 +19,11 @@
#define QGSCOMPOSERARROWWIDGET_H

#include "ui_qgscomposerarrowwidgetbase.h"
#include "qgscomposeritemwidget.h"

class QgsComposerArrow;

class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidgetBase
class QgsComposerArrowWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerArrowWidgetBase
{
Q_OBJECT
public:
@@ -21,7 +21,7 @@
#include <QFileDialog>
#include <QSettings>

QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): QWidget(), mHtml( html ), mFrame( frame )
QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): QgsComposerItemBaseWidget( 0, frame ), mHtml( html ), mFrame( frame )
{
setupUi( this );

@@ -47,7 +47,7 @@ QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposer
}
}

QgsComposerHtmlWidget::QgsComposerHtmlWidget()
QgsComposerHtmlWidget::QgsComposerHtmlWidget(): QgsComposerItemBaseWidget( 0, 0 )
{
}

@@ -16,11 +16,12 @@
#define QGSCOMPOSERHTMLWIDGET_H

#include "ui_qgscomposerhtmlwidgetbase.h"
#include "qgscomposeritemwidget.h"

class QgsComposerHtml;
class QgsComposerFrame;

class QgsComposerHtmlWidget: public QWidget, private Ui::QgsComposerHtmlWidgetBase
class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerHtmlWidgetBase
{
Q_OBJECT
public:
@@ -23,7 +23,52 @@
#include <QColorDialog>
#include <QPen>

QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem* item ): QWidget( parent ), mItem( item )

//QgsComposerItemBaseWidget

QgsComposerItemBaseWidget::QgsComposerItemBaseWidget( QWidget* parent, QgsComposerItem* item ): QWidget( parent ), mItem( item )
{

}

QgsComposerItemBaseWidget::~QgsComposerItemBaseWidget()
{

}

QgsAtlasComposition* QgsComposerItemBaseWidget::atlasComposition() const
{
if ( !mItem )
{
return 0;
}

QgsComposition* composition = mItem->composition();

if ( !composition )
{
return 0;
}

return &composition->atlasComposition();
}

QgsVectorLayer* QgsComposerItemBaseWidget::atlasCoverageLayer() const
{
QgsAtlasComposition* atlasMap = atlasComposition();

if ( atlasMap && atlasMap->enabled() )
{
return atlasMap->coverageLayer();
}

return 0;
}


//QgsComposerItemWidget

QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem* item ): QgsComposerItemBaseWidget( parent, item )
{

setupUi( this );
@@ -55,7 +100,7 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
connect( mTransparencySpnBx, SIGNAL( valueChanged( int ) ), mTransparencySlider, SLOT( setValue( int ) ) );
}

QgsComposerItemWidget::QgsComposerItemWidget(): QWidget( 0 ), mItem( 0 )
QgsComposerItemWidget::QgsComposerItemWidget(): QgsComposerItemBaseWidget( 0, 0 )
{

}
@@ -22,10 +22,31 @@
#include "qgscomposeritem.h"

class QgsComposerItem;
class QgsAtlasComposition;

/**A base class for property widgets for composer items. All composer item widgets should inherit from
* this base class.
*/
class QgsComposerItemBaseWidget: public QWidget
{
Q_OBJECT
public:
QgsComposerItemBaseWidget( QWidget* parent, QgsComposerItem* item );
~QgsComposerItemBaseWidget();

protected:
/**Returns the current atlas coverage layer (if set)*/
QgsVectorLayer* atlasCoverageLayer() const;

/**Returns the atlas for the composition*/
QgsAtlasComposition *atlasComposition() const;

QgsComposerItem* mItem;
};

/**A class to enter generic properties for composer items (e.g. background, outline, frame).
This widget can be embedded into other item widgets*/
class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBase
class QgsComposerItemWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerItemWidgetBase
{
Q_OBJECT
public:
@@ -92,7 +113,6 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
// void changeItemTransparency( int value );
void changeItemPosition();

QgsComposerItem* mItem;
};

#endif //QGSCOMPOSERITEMWIDGET_H
@@ -25,7 +25,7 @@
#include <QFontDialog>
#include <QWidget>

QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel* label ): QWidget(), mComposerLabel( label )
QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel* label ): QgsComposerItemBaseWidget( 0, label ), mComposerLabel( label )
{
setupUi( this );

@@ -138,12 +138,8 @@ void QgsComposerLabelWidget::on_mInsertExpressionButton_clicked()
if ( selText.startsWith( "[%" ) && selText.endsWith( "%]" ) )
selText = selText.mid( 2, selText.size() - 4 );

QgsVectorLayer* coverageLayer = 0;
// use the atlas coverage layer, if any
if ( mComposerLabel->composition()->atlasComposition().enabled() )
{
coverageLayer = mComposerLabel->composition()->atlasComposition().coverageLayer();
}
QgsVectorLayer* coverageLayer = atlasCoverageLayer();
QgsExpressionBuilderDialog exprDlg( coverageLayer, selText, this );
exprDlg.setWindowTitle( tr( "Insert expression" ) );
if ( exprDlg.exec() == QDialog::Accepted )
@@ -19,13 +19,14 @@
#define QGSCOMPOSERLABELWIDGET

#include "ui_qgscomposerlabelwidgetbase.h"
#include "qgscomposeritemwidget.h"

class QgsComposerLabel;

/** \ingroup MapComposer
* A widget to enter text, font size, box yes/no for composer labels
*/
class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidgetBase
class QgsComposerLabelWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerLabelWidgetBase
{
Q_OBJECT
public:
@@ -105,7 +105,7 @@ void QgsComposerLegendWidgetStyleDelegate::updateEditorGeometry( QWidget *editor
}


QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): mLegend( legend )
QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): QgsComposerItemBaseWidget( 0, legend ), mLegend( legend )
{
setupUi( this );

@@ -145,7 +145,7 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
this, SLOT( selectedChanged( const QModelIndex &, const QModelIndex & ) ) );
}

QgsComposerLegendWidget::QgsComposerLegendWidget(): mLegend( 0 )
QgsComposerLegendWidget::QgsComposerLegendWidget(): QgsComposerItemBaseWidget( 0, 0 ), mLegend( 0 )
{
setupUi( this );
}
@@ -19,6 +19,7 @@
#define QGSCOMPOSERLEGENDWIDGET_H

#include "ui_qgscomposerlegendwidgetbase.h"
#include "qgscomposeritemwidget.h"
#include <QWidget>
#include <QItemDelegate>

@@ -39,7 +40,7 @@ class QgsComposerLegendWidgetStyleDelegate : public QItemDelegate
/** \ingroup MapComposer
* A widget for setting properties relating to a composer legend.
*/
class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidgetBase
class QgsComposerLegendWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerLegendWidgetBase
{
Q_OBJECT

0 comments on commit 6af7dbd

Please sign in to comment.