Skip to content

Commit

Permalink
[FEATURE][composer] Add expression support for picture source (sponso…
Browse files Browse the repository at this point in the history
…red by City of Uster, Switzerland)
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent ca186c7 commit 021da60
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 20 deletions.
95 changes: 95 additions & 0 deletions src/app/composer/qgscomposerpicturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgscomposerpicture.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposition.h"
#include "qgsexpressionbuilderdialog.h"
#include <QDoubleValidator>
#include <QFileDialog>
#include <QFileInfo>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/app/composer/qgscomposerpicturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading

0 comments on commit 021da60

Please sign in to comment.