mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Check qgsMaximumVersion also when loading plugin to QgsPluginRegistry
This commit is contained in:
parent
094245ef83
commit
5c50e2a6c0
@ -124,6 +124,18 @@ def compareVersions(a,b):
|
|||||||
# convert the strings to the lists
|
# convert the strings to the lists
|
||||||
v1 = chopString(a)
|
v1 = chopString(a)
|
||||||
v2 = chopString(b)
|
v2 = chopString(b)
|
||||||
|
|
||||||
|
# !! ensure the version contains at least 3 segments. Fill to "x.y.z with "999" segments if needed.
|
||||||
|
# 999 must me unicode because of isnumeric method used.
|
||||||
|
if len(v1) == 2:
|
||||||
|
v1 += [u"999"]
|
||||||
|
elif len(v1) == 1:
|
||||||
|
v1 += [u"999",u"999"]
|
||||||
|
if len(v2) == 2:
|
||||||
|
v2 += [u"999"]
|
||||||
|
elif len(v2) == 1:
|
||||||
|
v2 += [u"999",u"999"]
|
||||||
|
|
||||||
# set the shorter string as a base
|
# set the shorter string as a base
|
||||||
l = len(v1)
|
l = len(v1)
|
||||||
if l > len(v2):
|
if l > len(v2):
|
||||||
|
@ -184,10 +184,10 @@ void QgsPluginRegistry::unloadAll()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
|
bool QgsPluginRegistry::checkQgisVersion( QString minVersion, QString maxVersion )
|
||||||
{
|
{
|
||||||
|
// Parse qgisMinVersion. Must be in form x.y.z or just x.y
|
||||||
QStringList minVersionParts = minVersion.split( '.' );
|
QStringList minVersionParts = minVersion.split( '.' );
|
||||||
// qgis version must be in form x.y.z or just x.y
|
|
||||||
if ( minVersionParts.count() != 2 && minVersionParts.count() != 3 )
|
if ( minVersionParts.count() != 2 && minVersionParts.count() != 3 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -206,6 +206,35 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse qgisMaxVersion. Must be in form x.y.z or just x.y
|
||||||
|
int maxVerMajor, maxVerMinor, maxVerBugfix = 0;
|
||||||
|
if ( maxVersion.isEmpty() || maxVersion == "__error__" )
|
||||||
|
{
|
||||||
|
maxVerMajor = minVerMajor;
|
||||||
|
maxVerMinor = 999;
|
||||||
|
maxVerBugfix = 999;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QStringList maxVersionParts = maxVersion.split( '.' );
|
||||||
|
if ( maxVersionParts.count() != 2 && maxVersionParts.count() != 3 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
maxVerMajor = maxVersionParts.at( 0 ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
return false;
|
||||||
|
maxVerMinor = maxVersionParts.at( 1 ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
return false;
|
||||||
|
if ( maxVersionParts.count() == 3 )
|
||||||
|
{
|
||||||
|
maxVerBugfix = maxVersionParts.at( 2 ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// our qgis version - cut release name after version number
|
// our qgis version - cut release name after version number
|
||||||
QString qgisVersion = QString( QGis::QGIS_VERSION ).section( '-', 0, 0 );
|
QString qgisVersion = QString( QGis::QGIS_VERSION ).section( '-', 0, 0 );
|
||||||
QStringList qgisVersionParts = qgisVersion.split( "." );
|
QStringList qgisVersionParts = qgisVersion.split( "." );
|
||||||
@ -215,21 +244,21 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
|
|||||||
int qgisBugfix = qgisVersionParts.at( 2 ).toInt();
|
int qgisBugfix = qgisVersionParts.at( 2 ).toInt();
|
||||||
|
|
||||||
// first check major version
|
// first check major version
|
||||||
if ( minVerMajor > qgisMajor )
|
if ( minVerMajor > qgisMajor || maxVerMajor < qgisMajor )
|
||||||
return false;
|
return false;
|
||||||
if ( minVerMajor < qgisMajor )
|
if ( minVerMajor < qgisMajor || maxVerMajor > qgisMajor )
|
||||||
return true;
|
return true;
|
||||||
// if same, check minor version
|
// if same, check minor version
|
||||||
if ( minVerMinor > qgisMinor )
|
if ( minVerMinor > qgisMinor || maxVerMinor < qgisMinor )
|
||||||
return false;
|
return false;
|
||||||
if ( minVerMinor < qgisMinor )
|
if ( minVerMinor < qgisMinor || maxVerMinor > qgisMinor )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// if still same, check bugfix version
|
// if still same, check bugfix version (lower range only)
|
||||||
if ( minVerBugfix > qgisBugfix )
|
if ( minVerBugfix > qgisBugfix )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// looks like min version is the same as our version - that's fine
|
// looks like min or max version is the same as our version - that's fine
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,7 +591,9 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
|
|||||||
bool QgsPluginRegistry::isPythonPluginCompatible( QString packageName )
|
bool QgsPluginRegistry::isPythonPluginCompatible( QString packageName )
|
||||||
{
|
{
|
||||||
QString minVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMinimumVersion" );
|
QString minVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMinimumVersion" );
|
||||||
return minVersion != "__error__" && checkQgisVersion( minVersion );
|
// try to read qgisMaximumVersion. Note checkQgisVersion can cope with "__error__" value.
|
||||||
|
QString maxVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMaximumVersion" );
|
||||||
|
return minVersion != "__error__" && checkQgisVersion( minVersion, maxVersion );
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QgsPluginMetadata*> QgsPluginRegistry::pluginData()
|
QList<QgsPluginMetadata*> QgsPluginRegistry::pluginData()
|
||||||
|
@ -102,8 +102,9 @@ class QgsPluginRegistry
|
|||||||
//! Try to load and get metadata from Python plugin, return true on success
|
//! Try to load and get metadata from Python plugin, return true on success
|
||||||
bool checkPythonPlugin( QString packageName );
|
bool checkPythonPlugin( QString packageName );
|
||||||
|
|
||||||
//! Check current QGIS version against plugin's minimal requested QGIS version
|
//! Check current QGIS version against requested minimal and optionally maximal QGIS version
|
||||||
bool checkQgisVersion( QString minVersion );
|
//! if maxVersion not specified, the default value is assumed: floor(minVersion) + 0.999.999
|
||||||
|
bool checkQgisVersion( QString minVersion, QString maxVersion = "" );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QgsPluginRegistry* _instance;
|
static QgsPluginRegistry* _instance;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user