Skip to content
Permalink
Browse files

[FEATURE][composer] Add expression support for picture source (sponso…

…red by City of Uster, Switzerland)
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent ca186c7 commit 021da60892e4e9ba91ac60b490c444fa597f5381
@@ -21,6 +21,7 @@
#include "qgscomposerpicture.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposition.h"
#include "qgsexpressionbuilderdialog.h"
#include <QDoubleValidator>
#include <QFileDialog>
#include <QFileInfo>
@@ -51,6 +52,8 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture

connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( pictureRotationChanged( double ) ), this, SLOT( setPicRotationSpinValue( double ) ) );
connect( mPictureExpressionLineEdit, SIGNAL( editingFinished() ), this, SLOT( setPictureExpression() ) );

}

QgsComposerPictureWidget::~QgsComposerPictureWidget()
@@ -120,6 +123,37 @@ void QgsComposerPictureWidget::on_mPictureLineEdit_editingFinished()
}
}

void QgsComposerPictureWidget::on_mPictureExpressionButton_clicked()
{
if ( !mPicture )
{
return;
}

QgsVectorLayer* vl = 0;
QgsComposition* composition = mPicture->composition();

if ( composition )
{
QgsAtlasComposition* atlasMap = &composition->atlasComposition();
if ( atlasMap )
{
vl = atlasMap->coverageLayer();
}
}

QgsExpressionBuilderDialog exprDlg( vl, mPictureExpressionLineEdit->text(), this );
exprDlg.setWindowTitle( tr( "Expression based image path" ) );
if ( exprDlg.exec() == QDialog::Accepted )
{
QString expression = exprDlg.expressionText();
if ( !expression.isEmpty() )
{
mPictureExpressionLineEdit->setText( expression );
setPictureExpression();
}
}
}

void QgsComposerPictureWidget::on_mPictureRotationSpinBox_valueChanged( double d )
{
@@ -213,6 +247,52 @@ void QgsComposerPictureWidget::on_mResizeModeComboBox_currentIndexChanged( int i
mRotationGroupBox->setEnabled( mPicture->resizeMode() == QgsComposerPicture::Zoom );
}

void QgsComposerPictureWidget::on_mRadioPath_clicked()
{
if ( !mPicture )
{
return;
}

mPicture->beginCommand( tr( "Picture source changed" ) );
mPicture->setUsePictureExpression( false );
mPicture->endCommand();

mPictureLineEdit->setEnabled( true );
mPictureBrowseButton->setEnabled( true );
mPictureExpressionLineEdit->setEnabled( false );
mPictureExpressionButton->setEnabled( false );
}

void QgsComposerPictureWidget::on_mRadioExpression_clicked()
{
if ( !mPicture )
{
return;
}

mPicture->beginCommand( tr( "Picture source changed" ) );
mPicture->setUsePictureExpression( true );
mPicture->endCommand();

mPictureLineEdit->setEnabled( false );
mPictureBrowseButton->setEnabled( false );
mPictureExpressionLineEdit->setEnabled( true );
mPictureExpressionButton->setEnabled( true );
}

void QgsComposerPictureWidget::setPictureExpression()
{
if ( !mPicture )
{
return;
}

mPicture->beginCommand( tr( "Picture source expression" ) );
mPicture->setPictureExpression( mPictureExpressionLineEdit->text() );
mPicture->endCommand();
}

void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged( int state )
{
if ( !mPicture )
@@ -342,6 +422,9 @@ void QgsComposerPictureWidget::setGuiElementValues()
mComposerMapComboBox->blockSignals( true );
mRotationFromComposerMapCheckBox->blockSignals( true );
mResizeModeComboBox->blockSignals( true );
mRadioPath->blockSignals( true );
mRadioExpression->blockSignals( true );
mPictureExpressionLineEdit->blockSignals( true );

mPictureLineEdit->setText( mPicture->pictureFile() );
// QRectF pictureRect = mPicture->rect();
@@ -372,11 +455,23 @@ void QgsComposerPictureWidget::setGuiElementValues()
//disable picture rotation for non-zoom modes
mRotationGroupBox->setEnabled( mPicture->resizeMode() == QgsComposerPicture::Zoom );

mRadioPath->setChecked( !( mPicture->usePictureExpression() ) );
mRadioExpression->setChecked( mPicture->usePictureExpression() );
mPictureLineEdit->setEnabled( !( mPicture->usePictureExpression() ) );
mPictureBrowseButton->setEnabled( !( mPicture->usePictureExpression() ) );
mPictureExpressionLineEdit->setEnabled( mPicture->usePictureExpression() );
mPictureExpressionButton->setEnabled( mPicture->usePictureExpression() );

mPictureExpressionLineEdit->setText( mPicture->pictureExpression() );

mRotationFromComposerMapCheckBox->blockSignals( false );
mPictureRotationSpinBox->blockSignals( false );
mPictureLineEdit->blockSignals( false );
mComposerMapComboBox->blockSignals( false );
mResizeModeComboBox->blockSignals( false );
mRadioPath->blockSignals( false );
mRadioExpression->blockSignals( false );
mPictureExpressionLineEdit->blockSignals( false );
}
}

@@ -39,13 +39,17 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
public slots:
void on_mPictureBrowseButton_clicked();
void on_mPictureLineEdit_editingFinished();
void on_mPictureExpressionButton_clicked();
void on_mPictureRotationSpinBox_valueChanged( double d );
void on_mPreviewListWidget_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
void on_mAddDirectoryButton_clicked();
void on_mRemoveDirectoryButton_clicked();
void on_mRotationFromComposerMapCheckBox_stateChanged( int state );
void on_mComposerMapComboBox_activated( const QString & text );
void on_mResizeModeComboBox_currentIndexChanged( int index );
void on_mRadioPath_clicked();
void on_mRadioExpression_clicked();
void setPictureExpression();

protected:
void showEvent( QShowEvent * event );

0 comments on commit 021da60

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