mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Only save effect element if it is non-default
(decreases file size of qgs project files)
This commit is contained in:
parent
29ac48e4f6
commit
0587a59b39
@ -106,9 +106,18 @@ class QgsPaintEffectRegistry
|
||||
* effects. All effects except the standard draw source effect are disabled,
|
||||
* but are included so that they can be easily drawn just by enabling the effect.
|
||||
* @returns default effects stack
|
||||
* @see isDefaultStack()
|
||||
*/
|
||||
static QgsPaintEffect* defaultStack() /Factory/;
|
||||
|
||||
/** Tests whether a paint effect matches the default effects stack.
|
||||
* @param effect paint effect to test
|
||||
* @returns true if effect is default stack
|
||||
* @note added in QGIS 2.12
|
||||
* @see defaultStack()
|
||||
*/
|
||||
static bool isDefaultStack( QgsPaintEffect* effect );
|
||||
|
||||
protected:
|
||||
QgsPaintEffectRegistry();
|
||||
~QgsPaintEffectRegistry();
|
||||
|
@ -122,6 +122,7 @@ QStringList QgsPaintEffectRegistry::effects() const
|
||||
|
||||
QgsPaintEffect* QgsPaintEffectRegistry::defaultStack()
|
||||
{
|
||||
//NOTE - also remember to update isDefaultStack below if making changes to this list
|
||||
QgsEffectStack* stack = new QgsEffectStack();
|
||||
QgsDropShadowEffect* dropShadow = new QgsDropShadowEffect();
|
||||
dropShadow->setEnabled( false );
|
||||
@ -138,3 +139,34 @@ QgsPaintEffect* QgsPaintEffectRegistry::defaultStack()
|
||||
stack->appendEffect( innerGlow );
|
||||
return stack;
|
||||
}
|
||||
|
||||
bool QgsPaintEffectRegistry::isDefaultStack( QgsPaintEffect* effect )
|
||||
{
|
||||
QgsEffectStack* effectStack = dynamic_cast< QgsEffectStack* >( effect );
|
||||
if ( !effectStack )
|
||||
return false;
|
||||
|
||||
if ( effectStack->count() != 5 )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < 5; ++i )
|
||||
{
|
||||
//only the third effect should be enabled
|
||||
if ( effectStack->effect( i )->enabled() != ( i == 2 ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !dynamic_cast< QgsDropShadowEffect* >( effectStack->effect( 0 ) ) )
|
||||
return false;
|
||||
if ( !dynamic_cast< QgsOuterGlowEffect* >( effectStack->effect( 1 ) ) )
|
||||
return false;
|
||||
if ( !dynamic_cast< QgsDrawSourceEffect* >( effectStack->effect( 2 ) ) )
|
||||
return false;
|
||||
if ( !dynamic_cast< QgsInnerShadowEffect* >( effectStack->effect( 3 ) ) )
|
||||
return false;
|
||||
if ( !dynamic_cast< QgsInnerGlowEffect* >( effectStack->effect( 4 ) ) )
|
||||
return false;
|
||||
|
||||
//we don't go as far as to check the individual effect's properties
|
||||
return true;
|
||||
}
|
||||
|
@ -193,9 +193,18 @@ class CORE_EXPORT QgsPaintEffectRegistry
|
||||
* effects. All effects except the standard draw source effect are disabled,
|
||||
* but are included so that they can be easily drawn just by enabling the effect.
|
||||
* @returns default effects stack
|
||||
* @see isDefaultStack()
|
||||
*/
|
||||
static QgsPaintEffect* defaultStack();
|
||||
|
||||
/** Tests whether a paint effect matches the default effects stack.
|
||||
* @param effect paint effect to test
|
||||
* @returns true if effect is default stack
|
||||
* @note added in QGIS 2.12
|
||||
* @see defaultStack()
|
||||
*/
|
||||
static bool isDefaultStack( QgsPaintEffect* effect );
|
||||
|
||||
protected:
|
||||
QgsPaintEffectRegistry();
|
||||
~QgsPaintEffectRegistry();
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "qgspointdisplacementrenderer.h"
|
||||
#include "qgsinvertedpolygonrenderer.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
#include "qgsscaleexpression.h"
|
||||
#include "qgsdatadefined.h"
|
||||
|
||||
@ -686,7 +687,7 @@ QDomElement QgsCategorizedSymbolRendererV2::save( QDomDocument& doc )
|
||||
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod ) );
|
||||
rendererElem.appendChild( sizeScaleElem );
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qgspointdisplacementrenderer.h"
|
||||
#include "qgsinvertedpolygonrenderer.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
#include "qgsscaleexpression.h"
|
||||
#include "qgsdatadefined.h"
|
||||
|
||||
@ -1156,7 +1157,7 @@ QDomElement QgsGraduatedSymbolRendererV2::save( QDomDocument& doc )
|
||||
mLabelFormat.saveToDomElement( labelFormatElem );
|
||||
rendererElem.appendChild( labelFormatElem );
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "qgsvectorcolorrampv2.h"
|
||||
#include "qgsrendercontext.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
@ -361,7 +362,7 @@ QDomElement QgsHeatmapRenderer::save( QDomDocument& doc )
|
||||
}
|
||||
rendererElem.setAttribute( "invert_ramp", QString::number( mInvertRamp ) );
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "qgssymbollayerv2.h"
|
||||
#include "qgsogcutils.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
@ -375,7 +376,7 @@ QDomElement QgsInvertedPolygonRenderer::save( QDomDocument& doc )
|
||||
rendererElem.appendChild( embeddedRendererElem );
|
||||
}
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgssinglesymbolrendererv2.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
#include "qgsfontutils.h"
|
||||
#include "qgsmultipointv2.h"
|
||||
#include "qgspointv2.h"
|
||||
@ -412,7 +413,7 @@ QDomElement QgsPointDisplacementRenderer::save( QDomDocument& doc )
|
||||
rendererElement.appendChild( centerSymbolElem );
|
||||
}
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElement );
|
||||
|
||||
return rendererElement;
|
||||
|
@ -523,7 +523,7 @@ QDomElement QgsFeatureRendererV2::save( QDomDocument& doc )
|
||||
QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
|
||||
rendererElem.setAttribute( "forceraster", ( mForceRaster ? "1" : "0" ) );
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "qgspointdisplacementrenderer.h"
|
||||
#include "qgsinvertedpolygonrenderer.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
#include "qgsdatadefined.h"
|
||||
|
||||
#include <QSet>
|
||||
@ -947,7 +948,7 @@ QDomElement QgsRuleBasedRendererV2::save( QDomDocument& doc )
|
||||
QDomElement symbolsElem = QgsSymbolLayerV2Utils::saveSymbols( symbols, "symbols", doc );
|
||||
rendererElem.appendChild( symbolsElem );
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "qgspointdisplacementrenderer.h"
|
||||
#include "qgsinvertedpolygonrenderer.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainteffectregistry.h"
|
||||
#include "qgsscaleexpression.h"
|
||||
#include "qgsdatadefined.h"
|
||||
|
||||
@ -377,7 +378,7 @@ QDomElement QgsSingleSymbolRendererV2::save( QDomDocument& doc )
|
||||
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod ) );
|
||||
rendererElem.appendChild( sizeScaleElem );
|
||||
|
||||
if ( mPaintEffect )
|
||||
if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
|
||||
mPaintEffect->saveProperties( doc, rendererElem );
|
||||
|
||||
return rendererElem;
|
||||
|
@ -1019,7 +1019,8 @@ QDomElement QgsSymbolLayerV2Utils::saveSymbol( QString name, QgsSymbolV2* symbol
|
||||
layerEl.setAttribute( "locked", layer->isLocked() );
|
||||
layerEl.setAttribute( "pass", layer->renderingPass() );
|
||||
saveProperties( layer->properties(), doc, layerEl );
|
||||
layer->paintEffect()->saveProperties( doc, layerEl );
|
||||
if ( !QgsPaintEffectRegistry::isDefaultStack( layer->paintEffect() ) )
|
||||
layer->paintEffect()->saveProperties( doc, layerEl );
|
||||
|
||||
if ( layer->subSymbol() != NULL )
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "qgspainteffectregistry.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgseffectstack.h"
|
||||
#include <QObject>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
@ -50,6 +51,7 @@ class TestQgsPaintEffectRegistry : public QObject
|
||||
void addEffect(); // check adding an effect to an empty registry
|
||||
void fetchEffects(); //check fetching effects
|
||||
void createEffect(); //check creating effect
|
||||
void defaultStack(); //check creating/testing default stack
|
||||
|
||||
private:
|
||||
|
||||
@ -152,5 +154,24 @@ void TestQgsPaintEffectRegistry::createEffect()
|
||||
QVERIFY( !effect );
|
||||
}
|
||||
|
||||
void TestQgsPaintEffectRegistry::defaultStack()
|
||||
{
|
||||
QgsPaintEffectRegistry* registry = QgsPaintEffectRegistry::instance();
|
||||
QgsEffectStack* effect = static_cast<QgsEffectStack*>( registry->defaultStack() );
|
||||
QVERIFY( registry->isDefaultStack( effect ) );
|
||||
effect->effect( 1 )->setEnabled( true );
|
||||
QVERIFY( !registry->isDefaultStack( effect ) );
|
||||
effect->effect( 1 )->setEnabled( false );
|
||||
effect->effect( 2 )->setEnabled( false ); //third effect should be enabled by default
|
||||
QVERIFY( !registry->isDefaultStack( effect ) );
|
||||
effect->effect( 2 )->setEnabled( true );
|
||||
effect->appendEffect( new QgsEffectStack() );
|
||||
QVERIFY( !registry->isDefaultStack( effect ) );
|
||||
delete effect;
|
||||
QgsPaintEffect* effect2 = new DummyPaintEffect();
|
||||
QVERIFY( !registry->isDefaultStack( effect2 ) );
|
||||
delete effect2;
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsPaintEffectRegistry )
|
||||
#include "testqgspainteffectregistry.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user