Skip to content

Commit 5c50e2a

Browse files
committedJun 9, 2013
Check qgsMaximumVersion also when loading plugin to QgsPluginRegistry
1 parent 094245e commit 5c50e2a

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed
 

‎python/pyplugin_installer/version_compare.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ def compareVersions(a,b):
124124
# convert the strings to the lists
125125
v1 = chopString(a)
126126
v2 = chopString(b)
127+
128+
# !! ensure the version contains at least 3 segments. Fill to "x.y.z with "999" segments if needed.
129+
# 999 must me unicode because of isnumeric method used.
130+
if len(v1) == 2:
131+
v1 += [u"999"]
132+
elif len(v1) == 1:
133+
v1 += [u"999",u"999"]
134+
if len(v2) == 2:
135+
v2 += [u"999"]
136+
elif len(v2) == 1:
137+
v2 += [u"999",u"999"]
138+
127139
# set the shorter string as a base
128140
l = len(v1)
129141
if l > len(v2):

‎src/app/qgspluginregistry.cpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ void QgsPluginRegistry::unloadAll()
184184
}
185185

186186

187-
bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
187+
bool QgsPluginRegistry::checkQgisVersion( QString minVersion, QString maxVersion )
188188
{
189+
// Parse qgisMinVersion. Must be in form x.y.z or just x.y
189190
QStringList minVersionParts = minVersion.split( '.' );
190-
// qgis version must be in form x.y.z or just x.y
191191
if ( minVersionParts.count() != 2 && minVersionParts.count() != 3 )
192192
return false;
193193

@@ -206,6 +206,35 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
206206
return false;
207207
}
208208

209+
// Parse qgisMaxVersion. Must be in form x.y.z or just x.y
210+
int maxVerMajor, maxVerMinor, maxVerBugfix = 0;
211+
if ( maxVersion.isEmpty() || maxVersion == "__error__" )
212+
{
213+
maxVerMajor = minVerMajor;
214+
maxVerMinor = 999;
215+
maxVerBugfix = 999;
216+
}
217+
else
218+
{
219+
QStringList maxVersionParts = maxVersion.split( '.' );
220+
if ( maxVersionParts.count() != 2 && maxVersionParts.count() != 3 )
221+
return false;
222+
223+
bool ok;
224+
maxVerMajor = maxVersionParts.at( 0 ).toInt( &ok );
225+
if ( !ok )
226+
return false;
227+
maxVerMinor = maxVersionParts.at( 1 ).toInt( &ok );
228+
if ( !ok )
229+
return false;
230+
if ( maxVersionParts.count() == 3 )
231+
{
232+
maxVerBugfix = maxVersionParts.at( 2 ).toInt( &ok );
233+
if ( !ok )
234+
return false;
235+
}
236+
}
237+
209238
// our qgis version - cut release name after version number
210239
QString qgisVersion = QString( QGis::QGIS_VERSION ).section( '-', 0, 0 );
211240
QStringList qgisVersionParts = qgisVersion.split( "." );
@@ -215,21 +244,21 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
215244
int qgisBugfix = qgisVersionParts.at( 2 ).toInt();
216245

217246
// first check major version
218-
if ( minVerMajor > qgisMajor )
247+
if ( minVerMajor > qgisMajor || maxVerMajor < qgisMajor )
219248
return false;
220-
if ( minVerMajor < qgisMajor )
249+
if ( minVerMajor < qgisMajor || maxVerMajor > qgisMajor )
221250
return true;
222251
// if same, check minor version
223-
if ( minVerMinor > qgisMinor )
252+
if ( minVerMinor > qgisMinor || maxVerMinor < qgisMinor )
224253
return false;
225-
if ( minVerMinor < qgisMinor )
254+
if ( minVerMinor < qgisMinor || maxVerMinor > qgisMinor )
226255
return true;
227256

228-
// if still same, check bugfix version
257+
// if still same, check bugfix version (lower range only)
229258
if ( minVerBugfix > qgisBugfix )
230259
return false;
231260

232-
// looks like min version is the same as our version - that's fine
261+
// looks like min or max version is the same as our version - that's fine
233262
return true;
234263
}
235264

@@ -562,7 +591,9 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
562591
bool QgsPluginRegistry::isPythonPluginCompatible( QString packageName )
563592
{
564593
QString minVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMinimumVersion" );
565-
return minVersion != "__error__" && checkQgisVersion( minVersion );
594+
// try to read qgisMaximumVersion. Note checkQgisVersion can cope with "__error__" value.
595+
QString maxVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMaximumVersion" );
596+
return minVersion != "__error__" && checkQgisVersion( minVersion, maxVersion );
566597
}
567598

568599
QList<QgsPluginMetadata*> QgsPluginRegistry::pluginData()

‎src/app/qgspluginregistry.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class QgsPluginRegistry
102102
//! Try to load and get metadata from Python plugin, return true on success
103103
bool checkPythonPlugin( QString packageName );
104104

105-
//! Check current QGIS version against plugin's minimal requested QGIS version
106-
bool checkQgisVersion( QString minVersion );
105+
//! Check current QGIS version against requested minimal and optionally maximal QGIS version
106+
//! if maxVersion not specified, the default value is assumed: floor(minVersion) + 0.999.999
107+
bool checkQgisVersion( QString minVersion, QString maxVersion = "" );
107108

108109
private:
109110
static QgsPluginRegistry* _instance;

0 commit comments

Comments
 (0)
Please sign in to comment.