@@ -52,8 +52,20 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
5252
5353 connect ( mPicture , SIGNAL ( itemChanged () ), this , SLOT ( setGuiElementValues () ) );
5454 connect ( mPicture , SIGNAL ( pictureRotationChanged ( double ) ), this , SLOT ( setPicRotationSpinValue ( double ) ) );
55- connect ( mPictureExpressionLineEdit , SIGNAL ( editingFinished () ), this , SLOT ( setPictureExpression () ) );
5655
56+ QgsAtlasComposition* atlas = atlasComposition ();
57+ if ( atlas )
58+ {
59+ // repopulate data defined buttons if atlas layer changes
60+ connect ( atlas, SIGNAL ( coverageLayerChanged ( QgsVectorLayer* ) ),
61+ this , SLOT ( populateDataDefinedButtons () ) );
62+ connect ( atlas, SIGNAL ( toggled ( bool ) ), this , SLOT ( populateDataDefinedButtons () ) );
63+ }
64+
65+ // connections for data defined buttons
66+ connect ( mSourceDDBtn , SIGNAL ( dataDefinedChanged ( const QString& ) ), this , SLOT ( updateDataDefinedProperty ( ) ) );
67+ connect ( mSourceDDBtn , SIGNAL ( dataDefinedActivated ( bool ) ), this , SLOT ( updateDataDefinedProperty ( ) ) );
68+ connect ( mSourceDDBtn , SIGNAL ( dataDefinedActivated ( bool ) ), mPictureLineEdit , SLOT ( setDisabled ( bool ) ) );
5769}
5870
5971QgsComposerPictureWidget::~QgsComposerPictureWidget ()
@@ -124,29 +136,6 @@ void QgsComposerPictureWidget::on_mPictureLineEdit_editingFinished()
124136 }
125137}
126138
127- void QgsComposerPictureWidget::on_mPictureExpressionButton_clicked ()
128- {
129- if ( !mPicture )
130- {
131- return ;
132- }
133-
134- // use the atlas coverage layer, if any
135- QgsVectorLayer* coverageLayer = atlasCoverageLayer ();
136-
137- QgsExpressionBuilderDialog exprDlg ( coverageLayer, mPictureExpressionLineEdit ->text (), this );
138- exprDlg.setWindowTitle ( tr ( " Expression based image path" ) );
139- if ( exprDlg.exec () == QDialog::Accepted )
140- {
141- QString expression = exprDlg.expressionText ();
142- if ( !expression.isEmpty () )
143- {
144- mPictureExpressionLineEdit ->setText ( expression );
145- setPictureExpression ();
146- }
147- }
148- }
149-
150139void QgsComposerPictureWidget::on_mPictureRotationSpinBox_valueChanged ( double d )
151140{
152141 if ( mPicture )
@@ -262,52 +251,6 @@ void QgsComposerPictureWidget::on_mAnchorPointComboBox_currentIndexChanged( int
262251 mPicture ->endCommand ();
263252}
264253
265- void QgsComposerPictureWidget::on_mRadioPath_clicked ()
266- {
267- if ( !mPicture )
268- {
269- return ;
270- }
271-
272- mPicture ->beginCommand ( tr ( " Picture source changed" ) );
273- mPicture ->setUsePictureExpression ( false );
274- mPicture ->endCommand ();
275-
276- mPictureLineEdit ->setEnabled ( true );
277- mPictureBrowseButton ->setEnabled ( true );
278- mPictureExpressionLineEdit ->setEnabled ( false );
279- mPictureExpressionButton ->setEnabled ( false );
280- }
281-
282- void QgsComposerPictureWidget::on_mRadioExpression_clicked ()
283- {
284- if ( !mPicture )
285- {
286- return ;
287- }
288-
289- mPicture ->beginCommand ( tr ( " Picture source changed" ) );
290- mPicture ->setUsePictureExpression ( true );
291- mPicture ->endCommand ();
292-
293- mPictureLineEdit ->setEnabled ( false );
294- mPictureBrowseButton ->setEnabled ( false );
295- mPictureExpressionLineEdit ->setEnabled ( true );
296- mPictureExpressionButton ->setEnabled ( true );
297- }
298-
299- void QgsComposerPictureWidget::setPictureExpression ()
300- {
301- if ( !mPicture )
302- {
303- return ;
304- }
305-
306- mPicture ->beginCommand ( tr ( " Picture source expression" ) );
307- mPicture ->setPictureExpression ( mPictureExpressionLineEdit ->text () );
308- mPicture ->endCommand ();
309- }
310-
311254void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged ( int state )
312255{
313256 if ( !mPicture )
@@ -438,9 +381,6 @@ void QgsComposerPictureWidget::setGuiElementValues()
438381 mRotationFromComposerMapCheckBox ->blockSignals ( true );
439382 mResizeModeComboBox ->blockSignals ( true );
440383 mAnchorPointComboBox ->blockSignals ( true );
441- mRadioPath ->blockSignals ( true );
442- mRadioExpression ->blockSignals ( true );
443- mPictureExpressionLineEdit ->blockSignals ( true );
444384
445385 mPictureLineEdit ->setText ( mPicture ->pictureFile () );
446386 mPictureRotationSpinBox ->setValue ( mPicture ->pictureRotation () );
@@ -482,24 +422,14 @@ void QgsComposerPictureWidget::setGuiElementValues()
482422 mAnchorPointComboBox ->setEnabled ( false );
483423 }
484424
485- mRadioPath ->setChecked ( !( mPicture ->usePictureExpression () ) );
486- mRadioExpression ->setChecked ( mPicture ->usePictureExpression () );
487- mPictureLineEdit ->setEnabled ( !( mPicture ->usePictureExpression () ) );
488- mPictureBrowseButton ->setEnabled ( !( mPicture ->usePictureExpression () ) );
489- mPictureExpressionLineEdit ->setEnabled ( mPicture ->usePictureExpression () );
490- mPictureExpressionButton ->setEnabled ( mPicture ->usePictureExpression () );
491-
492- mPictureExpressionLineEdit ->setText ( mPicture ->pictureExpression () );
493-
494425 mRotationFromComposerMapCheckBox ->blockSignals ( false );
495426 mPictureRotationSpinBox ->blockSignals ( false );
496427 mPictureLineEdit ->blockSignals ( false );
497428 mComposerMapComboBox ->blockSignals ( false );
498429 mResizeModeComboBox ->blockSignals ( false );
499430 mAnchorPointComboBox ->blockSignals ( false );
500- mRadioPath ->blockSignals ( false );
501- mRadioExpression ->blockSignals ( false );
502- mPictureExpressionLineEdit ->blockSignals ( false );
431+
432+ populateDataDefinedButtons ();
503433 }
504434}
505435
@@ -671,3 +601,31 @@ void QgsComposerPictureWidget::resizeEvent( QResizeEvent * event )
671601 mSearchDirectoriesComboBox ->setMinimumWidth ( mPreviewListWidget ->sizeHint ().width () );
672602}
673603
604+ QgsComposerObject::DataDefinedProperty QgsComposerPictureWidget::ddPropertyForWidget ( QgsDataDefinedButton *widget )
605+ {
606+ if ( widget == mSourceDDBtn )
607+ {
608+ return QgsComposerObject::PictureSource;
609+ }
610+
611+ return QgsComposerObject::NoProperty;
612+ }
613+
614+ void QgsComposerPictureWidget::populateDataDefinedButtons ()
615+ {
616+ QgsVectorLayer* vl = atlasCoverageLayer ();
617+
618+ // block signals from data defined buttons
619+ mSourceDDBtn ->blockSignals ( true );
620+
621+ // initialise buttons to use atlas coverage layer
622+ mSourceDDBtn ->init ( vl, mPicture ->dataDefinedProperty ( QgsComposerObject::PictureSource ),
623+ QgsDataDefinedButton::AnyType, QgsDataDefinedButton::anyStringDesc () );
624+
625+ // initial state of controls - disable related controls when dd buttons are active
626+ mPictureLineEdit ->setEnabled ( !mSourceDDBtn ->isActive () );
627+
628+ // unblock signals from data defined buttons
629+ mSourceDDBtn ->blockSignals ( false );
630+ }
631+
0 commit comments