Skip to content

Commit a67c84b

Browse files
committedJan 23, 2017
Avoid slowdown when changing composer data defined properties
1 parent 934c7c9 commit a67c84b

7 files changed

+97
-46
lines changed
 

‎src/app/composer/qgscomposerhtmlwidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposer
6565
}
6666

6767
//connections for data defined buttons
68-
connect( mUrlDDBtn, SIGNAL( dataDefinedActivated( bool ) ), mUrlLineEdit, SLOT( setDisabled( bool ) ) );
68+
connect( mUrlDDBtn, &QgsDataDefinedButtonV2::activated, mUrlLineEdit, &QLineEdit::setDisabled );
69+
registerDataDefinedButton( mUrlDDBtn, QgsComposerObject::SourceUrl,
70+
QgsDataDefinedButtonV2::AnyType, tr( "url string" ) );
6971
}
7072

7173
QgsComposerHtmlWidget::QgsComposerHtmlWidget()
@@ -465,8 +467,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()
465467

466468
void QgsComposerHtmlWidget::populateDataDefinedButtons()
467469
{
468-
registerDataDefinedButton( mUrlDDBtn, QgsComposerObject::SourceUrl,
469-
QgsDataDefinedButtonV2::AnyType, tr( "url string" ) );
470+
updateDataDefinedButton( mUrlDDBtn );
470471

471472
//initial state of controls - disable related controls when dd buttons are active
472473
mUrlLineEdit->setEnabled( !mUrlDDBtn->isActive() );

‎src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void QgsComposerConfigObject::updateDataDefinedButtons()
7474
}
7575
}
7676

77-
void QgsComposerConfigObject::registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
77+
void QgsComposerConfigObject::initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
7878
QgsDataDefinedButtonV2::DataType type, const QString& description )
7979
{
8080
button->blockSignals( true );
@@ -85,6 +85,18 @@ void QgsComposerConfigObject::registerDataDefinedButton( QgsDataDefinedButtonV2*
8585
button->blockSignals( false );
8686
}
8787

88+
void QgsComposerConfigObject::updateDataDefinedButton( QgsDataDefinedButtonV2* button )
89+
{
90+
if ( !button )
91+
return;
92+
93+
if ( !button->property( "propertyKey" ).isValid() )
94+
return;
95+
96+
QgsComposerObject::DataDefinedProperty key = static_cast< QgsComposerObject::DataDefinedProperty >( button->property( "propertyKey" ).toInt() );
97+
whileBlocking( button )->setToProperty( mComposerObject->dataDefinedProperties().property( key ) );
98+
}
99+
88100
QgsAtlasComposition* QgsComposerConfigObject::atlasComposition() const
89101
{
90102
if ( !mComposerObject )
@@ -152,6 +164,8 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
152164
buttonGroup->addButton( mLowerRightCheckBox );
153165
buttonGroup->setExclusive( true );
154166

167+
initializeDataDefinedButtons();
168+
155169
setValuesForGuiElements();
156170
connect( mItem->composition(), SIGNAL( paperSizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
157171
connect( mItem, SIGNAL( sizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
@@ -523,30 +537,38 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
523537
mExcludeFromPrintsCheckBox->blockSignals( false );
524538
}
525539

526-
void QgsComposerItemWidget::populateDataDefinedButtons()
540+
void QgsComposerItemWidget::initializeDataDefinedButtons()
527541
{
528-
mConfigObject->registerDataDefinedButton( mXPositionDDBtn, QgsComposerObject::PositionX,
542+
mConfigObject->initializeDataDefinedButton( mXPositionDDBtn, QgsComposerObject::PositionX,
529543
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
530-
mConfigObject->registerDataDefinedButton( mYPositionDDBtn, QgsComposerObject::PositionY,
544+
mConfigObject->initializeDataDefinedButton( mYPositionDDBtn, QgsComposerObject::PositionY,
531545
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
532-
mConfigObject->registerDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth,
546+
mConfigObject->initializeDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth,
533547
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
534-
mConfigObject->registerDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight,
548+
mConfigObject->initializeDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight,
535549
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
536-
mConfigObject->registerDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation,
550+
mConfigObject->initializeDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation,
537551
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::double180RotDesc() );
538-
mConfigObject->registerDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency,
552+
mConfigObject->initializeDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency,
539553
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::intTranspDesc() );
540-
mConfigObject->registerDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode,
554+
mConfigObject->initializeDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode,
541555
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::blendModesDesc() );
542-
mConfigObject->registerDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports,
556+
mConfigObject->initializeDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports,
543557
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::boolDesc() );
544-
mConfigObject->registerDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor,
558+
mConfigObject->initializeDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor,
545559
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
546-
mConfigObject->registerDataDefinedButton( mItemBackgroundColorDDBtn, QgsComposerObject::BackgroundColor,
560+
mConfigObject->initializeDataDefinedButton( mItemBackgroundColorDDBtn, QgsComposerObject::BackgroundColor,
547561
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
548562
}
549563

564+
void QgsComposerItemWidget::populateDataDefinedButtons()
565+
{
566+
Q_FOREACH ( QgsDataDefinedButtonV2* button, findChildren< QgsDataDefinedButtonV2* >() )
567+
{
568+
mConfigObject->updateDataDefinedButton( button );
569+
}
570+
}
571+
550572
void QgsComposerItemWidget::setValuesForGuiElements()
551573
{
552574
if ( !mItem )
@@ -773,7 +795,12 @@ QgsComposerItemBaseWidget::QgsComposerItemBaseWidget( QWidget* parent, QgsCompos
773795

774796
void QgsComposerItemBaseWidget::registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property, QgsDataDefinedButtonV2::DataType type, const QString& description )
775797
{
776-
mConfigObject->registerDataDefinedButton( button, property, type, description );
798+
mConfigObject->initializeDataDefinedButton( button, property, type, description );
799+
}
800+
801+
void QgsComposerItemBaseWidget::updateDataDefinedButton( QgsDataDefinedButtonV2* button )
802+
{
803+
mConfigObject->updateDataDefinedButton( button );
777804
}
778805

779806
QgsVectorLayer* QgsComposerItemBaseWidget::atlasCoverageLayer() const

‎src/app/composer/qgscomposeritemwidget.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ class QgsComposerConfigObject: public QObject
6262
* @param type valid data types for button
6363
* @param description user visible description for data defined property
6464
*/
65-
void registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
66-
QgsDataDefinedButtonV2::DataType type, const QString& description );
65+
void initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
66+
QgsDataDefinedButtonV2::DataType type, const QString& description );
67+
68+
/**
69+
* Updates a data defined button to reflect the item's current properties.
70+
*/
71+
void updateDataDefinedButton( QgsDataDefinedButtonV2* button );
6772

6873
//! Returns the current atlas coverage layer (if set)
6974
QgsVectorLayer* atlasCoverageLayer() const;
@@ -105,6 +110,11 @@ class QgsComposerItemBaseWidget: public QgsPanelWidget
105110
void registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property,
106111
QgsDataDefinedButtonV2::DataType type, const QString& description );
107112

113+
/**
114+
* Updates a previously registered data defined button to reflect the item's current properties.
115+
*/
116+
void updateDataDefinedButton( QgsDataDefinedButtonV2* button );
117+
108118
//! Returns the current atlas coverage layer (if set)
109119
QgsVectorLayer* atlasCoverageLayer() const;
110120

@@ -182,6 +192,8 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
182192

183193
protected slots:
184194
//! Initializes data defined buttons to current atlas coverage layer
195+
void initializeDataDefinedButtons();
196+
//! Sets data defined button state to match item
185197
void populateDataDefinedButtons();
186198

187199
private:

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap )
105105

106106
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsComposerMapWidget::mapCrsChanged );
107107

108-
updateGuiElements();
109-
loadGridEntries();
110-
loadOverviewEntries();
111-
populateDataDefinedButtons();
112-
blockAllSignals( false );
113-
}
114-
115-
QgsComposerMapWidget::~QgsComposerMapWidget()
116-
{
117-
}
118-
119-
void QgsComposerMapWidget::populateDataDefinedButtons()
120-
{
121108
registerDataDefinedButton( mScaleDDBtn, QgsComposerObject::MapScale,
122109
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
123110
registerDataDefinedButton( mMapRotationDDBtn, QgsComposerObject::MapRotation,
@@ -136,6 +123,29 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
136123
QgsDataDefinedButtonV2::String, tr( "string matching a style preset name" ) );
137124
registerDataDefinedButton( mLayersDDBtn, QgsComposerObject::MapLayers,
138125
QgsDataDefinedButtonV2::String, tr( "list of map layer names separated by | characters" ) );
126+
127+
updateGuiElements();
128+
loadGridEntries();
129+
loadOverviewEntries();
130+
131+
blockAllSignals( false );
132+
}
133+
134+
QgsComposerMapWidget::~QgsComposerMapWidget()
135+
{
136+
}
137+
138+
void QgsComposerMapWidget::populateDataDefinedButtons()
139+
{
140+
updateDataDefinedButton( mScaleDDBtn );
141+
updateDataDefinedButton( mMapRotationDDBtn );
142+
updateDataDefinedButton( mXMinDDBtn );
143+
updateDataDefinedButton( mYMinDDBtn );
144+
updateDataDefinedButton( mXMaxDDBtn );
145+
updateDataDefinedButton( mYMaxDDBtn );
146+
updateDataDefinedButton( mAtlasMarginDDBtn );
147+
updateDataDefinedButton( mStylePresetsDDBtn );
148+
updateDataDefinedButton( mLayersDDBtn );
139149
}
140150

141151
void QgsComposerMapWidget::compositionAtlasToggled( bool atlasEnabled )

‎src/app/composer/qgscomposerpicturewidget.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
7878

7979
//connections for data defined buttons
8080
connect( mSourceDDBtn, &QgsDataDefinedButtonV2::activated, mPictureLineEdit, &QLineEdit::setDisabled );
81+
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
82+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
83+
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor,
84+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
85+
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor,
86+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
87+
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth,
88+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
8189
}
8290

8391
QgsComposerPictureWidget::~QgsComposerPictureWidget()
@@ -700,20 +708,10 @@ void QgsComposerPictureWidget::resizeEvent( QResizeEvent * event )
700708

701709
void QgsComposerPictureWidget::populateDataDefinedButtons()
702710
{
703-
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
704-
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
705-
mFillColorDDBtn->blockSignals( true );
706-
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor,
707-
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
708-
mFillColorDDBtn->blockSignals( false );
709-
mOutlineColorDDBtn->blockSignals( true );
710-
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor,
711-
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
712-
mOutlineColorDDBtn->blockSignals( false );
713-
mOutlineWidthDDBtn->blockSignals( true );
714-
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth,
715-
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
716-
mOutlineWidthDDBtn->blockSignals( false );
711+
updateDataDefinedButton( mSourceDDBtn );
712+
updateDataDefinedButton( mFillColorDDBtn );
713+
updateDataDefinedButton( mOutlineColorDDBtn );
714+
updateDataDefinedButton( mOutlineWidthDDBtn );
717715

718716
//initial state of controls - disable related controls when dd buttons are active
719717
mPictureLineEdit->setEnabled( !mSourceDDBtn->isActive() );

‎src/gui/qgsdatadefinedbuttonv2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void QgsDataDefinedButtonV2::setToProperty( const QgsAbstractProperty *property
242242
mExpressionString.clear();
243243
}
244244
setActive( property && property->isActive() );
245+
updateGui();
245246
}
246247

247248
void QgsDataDefinedButtonV2::aboutToShowMenu()

‎src/gui/qgsdatadefinedbuttonv2.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class GUI_EXPORT QgsDataDefinedButtonV2: public QToolButton
8484

8585
QgsAbstractProperty* toProperty();
8686

87+
void setToProperty( const QgsAbstractProperty* property );
88+
8789
/**
8890
* Returns true if the button has an active property.
8991
*/
@@ -220,7 +222,7 @@ class GUI_EXPORT QgsDataDefinedButtonV2: public QToolButton
220222
private:
221223

222224
void updateFieldLists();
223-
void setToProperty( const QgsAbstractProperty* property );
225+
224226
void showDescriptionDialog();
225227
void showExpressionDialog();
226228
void updateGui();

0 commit comments

Comments
 (0)
Please sign in to comment.