Skip to content

Commit 1106f6a

Browse files
authoredApr 23, 2019
Merge pull request #9839 from wonder-sk/fix-3d-extra-terrain-updates
[3d] Fix unnecessary terrain map updates when changing 3D renderer
2 parents 74d30b9 + 60572ac commit 1106f6a

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed
 

‎python/gui/auto_generated/qgsmaplayerconfigwidget.sip.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ A panel widget that can be shown in the map style dock
3636
Keep the loading light as possible for speed in the UI.
3737
%End
3838

39+
virtual bool shouldTriggerLayerRepaint() const;
40+
%Docstring
41+
Whether this config widget changes map layer properties in a way that triggerRepaint() should
42+
be called for the layer after applying changes. This is true by default, but some config widgets
43+
(for example 3D rendering config) do not need layer repaint as they do not modify 2D map rendering.
44+
45+
.. versionadded:: 3.8
46+
%End
47+
3948
public slots:
4049

4150
virtual void apply() = 0;

‎src/app/3d/qgsvectorlayer3drendererwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class QgsVectorLayer3DRendererWidget : public QgsMapLayerConfigWidget
6666

6767
void setDockMode( bool dockMode ) override;
6868

69+
//! Only modifies 3D renderer so we do not want layer repaint (which would trigger unnecessary terrain map update)
70+
bool shouldTriggerLayerRepaint() const override { return false; }
71+
6972
public slots:
7073
void apply() override;
7174

‎src/app/qgslayerstylingwidget.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void QgsLayerStylingWidget::apply()
272272
QWidget *current = mWidgetStack->mainPanel();
273273

274274
bool styleWasChanged = false;
275+
bool triggerRepaint = false; // whether the change needs the layer to be repainted
275276
if ( QgsLabelingWidget *widget = qobject_cast<QgsLabelingWidget *>( current ) )
276277
{
277278
widget->apply();
@@ -287,31 +288,34 @@ void QgsLayerStylingWidget::apply()
287288
QgsRendererAbstractMetadata *m = QgsApplication::rendererRegistry()->rendererMetadata( layer->renderer()->type() );
288289
undoName = QStringLiteral( "Style Change - %1" ).arg( m->visibleName() );
289290
styleWasChanged = true;
291+
triggerRepaint = true;
290292
}
291293
}
292294
else if ( QgsRasterTransparencyWidget *widget = qobject_cast<QgsRasterTransparencyWidget *>( current ) )
293295
{
294296
widget->apply();
295297
styleWasChanged = true;
298+
triggerRepaint = true;
296299
}
297300
else if ( qobject_cast<QgsRasterHistogramWidget *>( current ) )
298301
{
299302
mRasterStyleWidget->apply();
300303
styleWasChanged = true;
304+
triggerRepaint = true;
301305
}
302306
else if ( QgsMapLayerConfigWidget *widget = qobject_cast<QgsMapLayerConfigWidget *>( current ) )
303307
{
304308
widget->apply();
305309
styleWasChanged = true;
310+
triggerRepaint = widget->shouldTriggerLayerRepaint();
306311
}
307312

308-
pushUndoItem( undoName );
313+
pushUndoItem( undoName, triggerRepaint );
309314

310315
if ( styleWasChanged )
311316
{
312317
emit styleChanged( mCurrentLayer );
313318
QgsProject::instance()->setDirty( true );
314-
mCurrentLayer->triggerRepaint();
315319
}
316320
connect( mCurrentLayer, &QgsMapLayer::styleChanged, this, &QgsLayerStylingWidget::updateCurrentWidgetLayer );
317321
}
@@ -609,25 +613,26 @@ void QgsLayerStylingWidget::liveApplyToggled( bool value )
609613
settings.setValue( QStringLiteral( "UI/autoApplyStyling" ), value );
610614
}
611615

612-
void QgsLayerStylingWidget::pushUndoItem( const QString &name )
616+
void QgsLayerStylingWidget::pushUndoItem( const QString &name, bool triggerRepaint )
613617
{
614618
QString errorMsg;
615619
QDomDocument doc( QStringLiteral( "style" ) );
616620
QDomElement rootNode = doc.createElement( QStringLiteral( "qgis" ) );
617621
doc.appendChild( rootNode );
618622
mCurrentLayer->writeStyle( rootNode, doc, errorMsg, QgsReadWriteContext() );
619-
mCurrentLayer->undoStackStyles()->push( new QgsMapLayerStyleCommand( mCurrentLayer, name, rootNode, mLastStyleXml ) );
623+
mCurrentLayer->undoStackStyles()->push( new QgsMapLayerStyleCommand( mCurrentLayer, name, rootNode, mLastStyleXml, triggerRepaint ) );
620624
// Override the last style on the stack
621625
mLastStyleXml = rootNode.cloneNode();
622626
}
623627

624628

625-
QgsMapLayerStyleCommand::QgsMapLayerStyleCommand( QgsMapLayer *layer, const QString &text, const QDomNode &current, const QDomNode &last )
629+
QgsMapLayerStyleCommand::QgsMapLayerStyleCommand( QgsMapLayer *layer, const QString &text, const QDomNode &current, const QDomNode &last, bool triggerRepaint )
626630
: QUndoCommand( text )
627631
, mLayer( layer )
628632
, mXml( current )
629633
, mLastState( last )
630634
, mTime( QTime::currentTime() )
635+
, mTriggerRepaint( triggerRepaint )
631636
{
632637
}
633638

@@ -636,15 +641,17 @@ void QgsMapLayerStyleCommand::undo()
636641
QString error;
637642
QgsReadWriteContext context = QgsReadWriteContext();
638643
mLayer->readStyle( mLastState, error, context );
639-
mLayer->triggerRepaint();
644+
if ( mTriggerRepaint )
645+
mLayer->triggerRepaint();
640646
}
641647

642648
void QgsMapLayerStyleCommand::redo()
643649
{
644650
QString error;
645651
QgsReadWriteContext context = QgsReadWriteContext();
646652
mLayer->readStyle( mXml, error, context );
647-
mLayer->triggerRepaint();
653+
if ( mTriggerRepaint )
654+
mLayer->triggerRepaint();
648655
}
649656

650657
bool QgsMapLayerStyleCommand::mergeWith( const QUndoCommand *other )
@@ -665,6 +672,7 @@ bool QgsMapLayerStyleCommand::mergeWith( const QUndoCommand *other )
665672

666673
mXml = otherCmd->mXml;
667674
mTime = otherCmd->mTime;
675+
mTriggerRepaint |= otherCmd->mTriggerRepaint;
668676
return true;
669677
}
670678

‎src/app/qgslayerstylingwidget.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class APP_EXPORT QgsLayerStyleManagerWidgetFactory : public QgsMapLayerConfigWid
5656
class APP_EXPORT QgsMapLayerStyleCommand : public QUndoCommand
5757
{
5858
public:
59-
QgsMapLayerStyleCommand( QgsMapLayer *layer, const QString &text, const QDomNode &current, const QDomNode &last );
59+
QgsMapLayerStyleCommand( QgsMapLayer *layer, const QString &text, const QDomNode &current, const QDomNode &last, bool triggerRepaint = true );
6060

6161
/**
6262
* Returns unique ID for this kind of undo command.
@@ -75,6 +75,7 @@ class APP_EXPORT QgsMapLayerStyleCommand : public QUndoCommand
7575
QDomNode mXml;
7676
QDomNode mLastState;
7777
QTime mTime;
78+
bool mTriggerRepaint = true;
7879
};
7980

8081
class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerStylingWidgetBase
@@ -129,7 +130,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
129130
void liveApplyToggled( bool value );
130131

131132
private:
132-
void pushUndoItem( const QString &name );
133+
void pushUndoItem( const QString &name, bool triggerRepaint = true );
133134
int mNotSupportedPage;
134135
int mLayerPage;
135136
QTimer *mAutoApplyTimer = nullptr;

‎src/gui/qgsmaplayerconfigwidget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class GUI_EXPORT QgsMapLayerConfigWidget : public QgsPanelWidget
4545
*/
4646
QgsMapLayerConfigWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
4747

48+
/**
49+
* Whether this config widget changes map layer properties in a way that triggerRepaint() should
50+
* be called for the layer after applying changes. This is true by default, but some config widgets
51+
* (for example 3D rendering config) do not need layer repaint as they do not modify 2D map rendering.
52+
* \since QGIS 3.8
53+
*/
54+
virtual bool shouldTriggerLayerRepaint() const { return true; }
55+
4856
public slots:
4957

5058
/**

0 commit comments

Comments
 (0)
Please sign in to comment.