Skip to content
Permalink
Browse files

Apply editor widget project upgrades in any case

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent aa64688 commit a332ff92f83f0ff8a4e0bcb3a341aee03fc788e9
@@ -35,7 +35,7 @@
typedef QgsProjectVersion PFV;


QgsProjectFileTransform::transform QgsProjectFileTransform::transformers[] =
QgsProjectFileTransform::TransformItem QgsProjectFileTransform::sTransformers[] =
{
{PFV( 0, 8, 0 ), PFV( 0, 8, 1 ), &QgsProjectFileTransform::transformNull},
{PFV( 0, 8, 1 ), PFV( 0, 9, 0 ), &QgsProjectFileTransform::transform081to090},
@@ -60,23 +60,27 @@ QgsProjectFileTransform::transform QgsProjectFileTransform::transformers[] =
{PFV( 2, 0, 0 ), PFV( 2, 1, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 2, 1, 0 ), PFV( 2, 2, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 2, 2, 0 ), PFV( 2, 3, 0 ), &QgsProjectFileTransform::transform2200to2300},
{PFV( 2, 18, 0 ), PFV( 2, 99, 0 ), &QgsProjectFileTransform::transform2180to2990},
// A transformer with a NULL from version means that it should be run when upgrading
// from any version and will take care that it's not going to cause trouble if it's
// run several times on the same file.
{PFV(), PFV( 2, 99, 0 ), &QgsProjectFileTransform::transform2990},
};

bool QgsProjectFileTransform::updateRevision( const QgsProjectVersion& newVersion )
{
Q_UNUSED( newVersion );
bool returnValue = false;

if ( ! mDom.isNull() )
if ( !mDom.isNull() )
{
for ( std::size_t i = 0; i < sizeof( transformers ) / sizeof( transform ); i++ )
for ( std::size_t i = 0; i < sizeof( sTransformers ) / sizeof( TransformItem ); i++ )
{
if ( transformers[i].from == mCurrentVersion )
const TransformItem& transformer = sTransformers[i];
if ( transformer.from == mCurrentVersion || transformer.from.isNull() )
{
// Run the transformer, and update the revision in every case
( this->*( transformers[i].transformFunc ) )();
mCurrentVersion = transformers[i].to;
( this->*( transformer.transformFunc ) )();
mCurrentVersion = transformer.to;
returnValue = true;
}
}
@@ -614,7 +618,7 @@ void QgsProjectFileTransform::transform2200to2300()
}
}

void QgsProjectFileTransform::transform2180to2990()
void QgsProjectFileTransform::transform2990()
{
QDomNodeList mapLayers = mDom.elementsByTagName( QStringLiteral( "maplayer" ) );

@@ -28,7 +28,6 @@

#include <QString>
#include <QDomDocument>
#include <vector>
#include "qgsprojectversion.h"

class QgsRasterLayer;
@@ -69,9 +68,9 @@ class CORE_EXPORT QgsProjectFileTransform
QgsProjectVersion from;
QgsProjectVersion to;
void ( QgsProjectFileTransform::* transformFunc )();
} transform;
} TransformItem;

static transform transformers[];
static TransformItem sTransformers[];

QDomDocument mDom;
QgsProjectVersion mCurrentVersion;
@@ -88,7 +87,7 @@ class CORE_EXPORT QgsProjectFileTransform
void transform1400to1500();
void transform1800to1900();
void transform2200to2300();
void transform2180to2990();
void transform2990();

//helper functions
static int rasterBandNumber( const QDomElement &rasterPropertiesElem, const QString &bandName, QgsRasterLayer *rlayer );
@@ -100,3 +100,8 @@ QString QgsProjectVersion::text()
return QStringLiteral( "%1.%2.%3-%4" ).arg( mMajor ).arg( mMinor ).arg( mSub ).arg( mName );
}
}

bool QgsProjectVersion::isNull() const
{
return mMajor == 0 && mMinor == 0 && mSub == 0;
}
@@ -32,6 +32,9 @@ class CORE_EXPORT QgsProjectVersion

public:

/**
* Creates a new NULL version
*/
QgsProjectVersion()
: mMajor( 0 )
, mMinor( 0 )
@@ -45,6 +48,11 @@ class CORE_EXPORT QgsProjectVersion
int subVersion() { return mSub;}
QString text();

/**
* Returns true if this is a NULL project version.
*/
bool isNull() const;

/** Boolean equal operator
*/
bool operator==( const QgsProjectVersion &other ) const;

0 comments on commit a332ff9

Please sign in to comment.
You can’t perform that action at this time.