Skip to content

Commit

Permalink
Avoid slowdown when changing composer data defined properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 934c7c9 commit a67c84b
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 46 deletions.
7 changes: 4 additions & 3 deletions src/app/composer/qgscomposerhtmlwidget.cpp
Expand Up @@ -65,7 +65,9 @@ QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposer
}

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

QgsComposerHtmlWidget::QgsComposerHtmlWidget()
Expand Down Expand Up @@ -465,8 +467,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()

void QgsComposerHtmlWidget::populateDataDefinedButtons()
{
registerDataDefinedButton( mUrlDDBtn, QgsComposerObject::SourceUrl,
QgsDataDefinedButtonV2::AnyType, tr( "url string" ) );
updateDataDefinedButton( mUrlDDBtn );

//initial state of controls - disable related controls when dd buttons are active
mUrlLineEdit->setEnabled( !mUrlDDBtn->isActive() );
Expand Down
53 changes: 40 additions & 13 deletions src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -74,7 +74,7 @@ void QgsComposerConfigObject::updateDataDefinedButtons()
}
}

void QgsComposerConfigObject::registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
void QgsComposerConfigObject::initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
QgsDataDefinedButtonV2::DataType type, const QString& description )
{
button->blockSignals( true );
Expand All @@ -85,6 +85,18 @@ void QgsComposerConfigObject::registerDataDefinedButton( QgsDataDefinedButtonV2*
button->blockSignals( false );
}

void QgsComposerConfigObject::updateDataDefinedButton( QgsDataDefinedButtonV2* button )
{
if ( !button )
return;

if ( !button->property( "propertyKey" ).isValid() )
return;

QgsComposerObject::DataDefinedProperty key = static_cast< QgsComposerObject::DataDefinedProperty >( button->property( "propertyKey" ).toInt() );
whileBlocking( button )->setToProperty( mComposerObject->dataDefinedProperties().property( key ) );
}

QgsAtlasComposition* QgsComposerConfigObject::atlasComposition() const
{
if ( !mComposerObject )
Expand Down Expand Up @@ -152,6 +164,8 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
buttonGroup->addButton( mLowerRightCheckBox );
buttonGroup->setExclusive( true );

initializeDataDefinedButtons();

setValuesForGuiElements();
connect( mItem->composition(), SIGNAL( paperSizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
connect( mItem, SIGNAL( sizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
Expand Down Expand Up @@ -523,30 +537,38 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mExcludeFromPrintsCheckBox->blockSignals( false );
}

void QgsComposerItemWidget::populateDataDefinedButtons()
void QgsComposerItemWidget::initializeDataDefinedButtons()
{
mConfigObject->registerDataDefinedButton( mXPositionDDBtn, QgsComposerObject::PositionX,
mConfigObject->initializeDataDefinedButton( mXPositionDDBtn, QgsComposerObject::PositionX,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->registerDataDefinedButton( mYPositionDDBtn, QgsComposerObject::PositionY,
mConfigObject->initializeDataDefinedButton( mYPositionDDBtn, QgsComposerObject::PositionY,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->registerDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth,
mConfigObject->initializeDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->registerDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight,
mConfigObject->initializeDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->registerDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation,
mConfigObject->initializeDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::double180RotDesc() );
mConfigObject->registerDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency,
mConfigObject->initializeDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::intTranspDesc() );
mConfigObject->registerDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode,
mConfigObject->initializeDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::blendModesDesc() );
mConfigObject->registerDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports,
mConfigObject->initializeDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::boolDesc() );
mConfigObject->registerDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor,
mConfigObject->initializeDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
mConfigObject->registerDataDefinedButton( mItemBackgroundColorDDBtn, QgsComposerObject::BackgroundColor,
mConfigObject->initializeDataDefinedButton( mItemBackgroundColorDDBtn, QgsComposerObject::BackgroundColor,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
}

void QgsComposerItemWidget::populateDataDefinedButtons()
{
Q_FOREACH ( QgsDataDefinedButtonV2* button, findChildren< QgsDataDefinedButtonV2* >() )
{
mConfigObject->updateDataDefinedButton( button );
}
}

void QgsComposerItemWidget::setValuesForGuiElements()
{
if ( !mItem )
Expand Down Expand Up @@ -773,7 +795,12 @@ QgsComposerItemBaseWidget::QgsComposerItemBaseWidget( QWidget* parent, QgsCompos

void QgsComposerItemBaseWidget::registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property, QgsDataDefinedButtonV2::DataType type, const QString& description )
{
mConfigObject->registerDataDefinedButton( button, property, type, description );
mConfigObject->initializeDataDefinedButton( button, property, type, description );
}

void QgsComposerItemBaseWidget::updateDataDefinedButton( QgsDataDefinedButtonV2* button )
{
mConfigObject->updateDataDefinedButton( button );
}

QgsVectorLayer* QgsComposerItemBaseWidget::atlasCoverageLayer() const
Expand Down
16 changes: 14 additions & 2 deletions src/app/composer/qgscomposeritemwidget.h
Expand Up @@ -62,8 +62,13 @@ class QgsComposerConfigObject: public QObject
* @param type valid data types for button
* @param description user visible description for data defined property
*/
void registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
QgsDataDefinedButtonV2::DataType type, const QString& description );
void initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
QgsDataDefinedButtonV2::DataType type, const QString& description );

/**
* Updates a data defined button to reflect the item's current properties.
*/
void updateDataDefinedButton( QgsDataDefinedButtonV2* button );

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

/**
* Updates a previously registered data defined button to reflect the item's current properties.
*/
void updateDataDefinedButton( QgsDataDefinedButtonV2* button );

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

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

protected slots:
//! Initializes data defined buttons to current atlas coverage layer
void initializeDataDefinedButtons();
//! Sets data defined button state to match item
void populateDataDefinedButtons();

private:
Expand Down
36 changes: 23 additions & 13 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -105,19 +105,6 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap )

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

updateGuiElements();
loadGridEntries();
loadOverviewEntries();
populateDataDefinedButtons();
blockAllSignals( false );
}

QgsComposerMapWidget::~QgsComposerMapWidget()
{
}

void QgsComposerMapWidget::populateDataDefinedButtons()
{
registerDataDefinedButton( mScaleDDBtn, QgsComposerObject::MapScale,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mMapRotationDDBtn, QgsComposerObject::MapRotation,
Expand All @@ -136,6 +123,29 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
QgsDataDefinedButtonV2::String, tr( "string matching a style preset name" ) );
registerDataDefinedButton( mLayersDDBtn, QgsComposerObject::MapLayers,
QgsDataDefinedButtonV2::String, tr( "list of map layer names separated by | characters" ) );

updateGuiElements();
loadGridEntries();
loadOverviewEntries();

blockAllSignals( false );
}

QgsComposerMapWidget::~QgsComposerMapWidget()
{
}

void QgsComposerMapWidget::populateDataDefinedButtons()
{
updateDataDefinedButton( mScaleDDBtn );
updateDataDefinedButton( mMapRotationDDBtn );
updateDataDefinedButton( mXMinDDBtn );
updateDataDefinedButton( mYMinDDBtn );
updateDataDefinedButton( mXMaxDDBtn );
updateDataDefinedButton( mYMaxDDBtn );
updateDataDefinedButton( mAtlasMarginDDBtn );
updateDataDefinedButton( mStylePresetsDDBtn );
updateDataDefinedButton( mLayersDDBtn );
}

void QgsComposerMapWidget::compositionAtlasToggled( bool atlasEnabled )
Expand Down
26 changes: 12 additions & 14 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -78,6 +78,14 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture

//connections for data defined buttons
connect( mSourceDDBtn, &QgsDataDefinedButtonV2::activated, mPictureLineEdit, &QLineEdit::setDisabled );
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
}

QgsComposerPictureWidget::~QgsComposerPictureWidget()
Expand Down Expand Up @@ -700,20 +708,10 @@ void QgsComposerPictureWidget::resizeEvent( QResizeEvent * event )

void QgsComposerPictureWidget::populateDataDefinedButtons()
{
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
mFillColorDDBtn->blockSignals( true );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
mFillColorDDBtn->blockSignals( false );
mOutlineColorDDBtn->blockSignals( true );
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
mOutlineColorDDBtn->blockSignals( false );
mOutlineWidthDDBtn->blockSignals( true );
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
mOutlineWidthDDBtn->blockSignals( false );
updateDataDefinedButton( mSourceDDBtn );
updateDataDefinedButton( mFillColorDDBtn );
updateDataDefinedButton( mOutlineColorDDBtn );
updateDataDefinedButton( mOutlineWidthDDBtn );

//initial state of controls - disable related controls when dd buttons are active
mPictureLineEdit->setEnabled( !mSourceDDBtn->isActive() );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsdatadefinedbuttonv2.cpp
Expand Up @@ -242,6 +242,7 @@ void QgsDataDefinedButtonV2::setToProperty( const QgsAbstractProperty *property
mExpressionString.clear();
}
setActive( property && property->isActive() );
updateGui();
}

void QgsDataDefinedButtonV2::aboutToShowMenu()
Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgsdatadefinedbuttonv2.h
Expand Up @@ -84,6 +84,8 @@ class GUI_EXPORT QgsDataDefinedButtonV2: public QToolButton

QgsAbstractProperty* toProperty();

void setToProperty( const QgsAbstractProperty* property );

/**
* Returns true if the button has an active property.
*/
Expand Down Expand Up @@ -220,7 +222,7 @@ class GUI_EXPORT QgsDataDefinedButtonV2: public QToolButton
private:

void updateFieldLists();
void setToProperty( const QgsAbstractProperty* property );

void showDescriptionDialog();
void showExpressionDialog();
void updateGui();
Expand Down

0 comments on commit a67c84b

Please sign in to comment.