@@ -100,7 +100,7 @@ QgisPlugin *QgsPluginRegistry::plugin( QString key )
100
100
{
101
101
QMap<QString, QgsPluginMetadata>::iterator it = mPlugins .find ( key );
102
102
if ( it == mPlugins .end () )
103
- return NULL ;
103
+ return 0 ;
104
104
105
105
// note: not used by python plugins
106
106
@@ -109,12 +109,7 @@ QgisPlugin *QgsPluginRegistry::plugin( QString key )
109
109
110
110
bool QgsPluginRegistry::isPythonPlugin ( QString key )
111
111
{
112
- if ( mPythonUtils && mPythonUtils ->isEnabled () )
113
- {
114
- if ( mPythonUtils ->isPluginLoaded ( key ) )
115
- return true ;
116
- }
117
- return false ;
112
+ return mPythonUtils && mPythonUtils ->isEnabled () && mPythonUtils ->isPluginLoaded ( key );
118
113
}
119
114
120
115
void QgsPluginRegistry::addPlugin ( QString key, QgsPluginMetadata metadata )
@@ -272,30 +267,20 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
272
267
273
268
void QgsPluginRegistry::loadCppPlugin ( QString theFullPathName )
274
269
{
275
- QSettings settings;
276
-
277
- QString baseName = QFileInfo ( theFullPathName ).baseName ();
278
-
279
270
// first check to see if its already loaded
271
+ QString baseName = QFileInfo ( theFullPathName ).baseName ();
280
272
if ( isLoaded ( baseName ) )
281
- {
282
- // plugin is loaded
283
- // QMessageBox::warning(this, "Already Loaded", description + " is already loaded");
284
273
return ;
285
- }
286
274
287
275
QLibrary myLib ( theFullPathName );
288
-
289
- QString myError; // we will only show detailed diagnostics if something went wrong
290
- myError += QObject::tr ( " Library name is %1\n " ).arg ( myLib.fileName () );
291
-
292
- bool loaded = myLib.load ();
293
- if ( !loaded )
276
+ if ( !myLib.load () )
294
277
{
295
278
QgsMessageLog::logMessage ( QObject::tr ( " Failed to load %1 (Reason: %2)" ).arg ( myLib.fileName () ).arg ( myLib.errorString () ), QObject::tr ( " Plugins" ) );
296
279
return ;
297
280
}
298
281
282
+ QString myError ( QObject::tr ( " Library name is %1\n " ).arg ( myLib.fileName () ) );
283
+
299
284
myError += QObject::tr ( " Attempting to resolve the classFactory function\n " );
300
285
301
286
type_t *pType = ( type_t * ) cast_to_fptr ( myLib.resolve ( " type" ) );
@@ -309,59 +294,57 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
309
294
{
310
295
// UI only -- doesn't use mapcanvas
311
296
create_ui *cf = ( create_ui * ) cast_to_fptr ( myLib.resolve ( " classFactory" ) );
312
- if ( cf )
297
+ if ( !cf )
298
+ {
299
+ QgsMessageLog::logMessage ( QObject::tr ( " Unable to find the class factory for %1." ).arg ( theFullPathName ), QObject::tr ( " Plugins" ) );
300
+ break ;
301
+ }
302
+
303
+ QSettings settings;
304
+ QgisPlugin *pl = cf ( mQgisInterface );
305
+ if ( !pl )
306
+ {
307
+ // something went wrong
308
+ QMessageBox::warning ( mQgisInterface ->mainWindow (), QObject::tr ( " Error Loading Plugin" ),
309
+ QObject::tr ( " There was an error loading a plugin."
310
+ " The following diagnostic information may help the QGIS developers resolve the issue:\n %1." )
311
+ .arg ( myError ) );
312
+ // disable it to the qsettings file [ts]
313
+ settings.setValue ( " /Plugins/" + baseName, false );
314
+ break ;
315
+ }
316
+
317
+ pl->initGui ();
318
+ // add it to the plugin registry
319
+ addPlugin ( baseName, QgsPluginMetadata ( myLib.fileName (), pName (), pl ) );
320
+ // add it to the qsettings file [ts]
321
+ settings.setValue ( " /Plugins/" + baseName, true );
322
+ QgsMessageLog::logMessage ( QObject::tr ( " Loaded %1 (Path: %2)" ).arg ( pName () ).arg ( myLib.fileName () ), QObject::tr ( " Plugins" ), QgsMessageLog::INFO );
323
+
324
+ QObject *o = dynamic_cast <QObject *>( pl );
325
+ if ( !o )
326
+ break ;
327
+
328
+ QgsDebugMsg ( QString ( " plugin object name: %1" ).arg ( o->objectName () ) );
329
+ if ( o->objectName ().isEmpty () )
313
330
{
314
- QgisPlugin *pl = cf ( mQgisInterface );
315
- if ( pl )
316
- {
317
- pl->initGui ();
318
- // add it to the plugin registry
319
- addPlugin ( baseName, QgsPluginMetadata ( myLib.fileName (), pName (), pl ) );
320
- // add it to the qsettings file [ts]
321
- settings.setValue ( " /Plugins/" + baseName, true );
322
- QgsMessageLog::logMessage ( QObject::tr ( " Loaded %1 (Path: %2)" ).arg ( pName () ).arg ( myLib.fileName () ), QObject::tr ( " Plugins" ), QgsMessageLog::INFO );
323
-
324
- QObject *o = dynamic_cast <QObject *>( pl );
325
- if ( o )
326
- {
327
- QgsDebugMsg ( QString ( " plugin object name: %1" ).arg ( o->objectName () ) );
328
- if ( o->objectName ().isEmpty () )
329
- {
330
331
#ifndef WIN32
331
- baseName = baseName.mid ( 3 );
332
+ baseName = baseName.mid ( 3 );
332
333
#endif
333
- QgsDebugMsg ( QString ( " object name to %1" ).arg ( baseName ) );
334
- o->setObjectName ( QString ( " qgis_plugin_%1" ).arg ( baseName ) );
335
- QgsDebugMsg ( QString ( " plugin object name now: %1" ).arg ( o->objectName () ) );
336
- }
337
-
338
- if ( !o->parent () )
339
- {
340
- QgsDebugMsg ( QString ( " setting plugin parent" ) );
341
- o->setParent ( QgisApp::instance () );
342
- }
343
- else
344
- {
345
- QgsDebugMsg ( QString ( " plugin parent already set" ) );
346
- }
347
- }
348
- }
349
- else
350
- {
351
- // something went wrong
352
- QMessageBox::warning ( mQgisInterface ->mainWindow (), QObject::tr ( " Error Loading Plugin" ),
353
- QObject::tr ( " There was an error loading a plugin."
354
- " The following diagnostic information may help the QGIS developers resolve the issue:\n %1." )
355
- .arg ( myError ) );
356
- // disable it to the qsettings file [ts]
357
- settings.setValue ( " /Plugins/" + baseName, false );
358
- }
334
+ QgsDebugMsg ( QString ( " object name to %1" ).arg ( baseName ) );
335
+ o->setObjectName ( QString ( " qgis_plugin_%1" ).arg ( baseName ) );
336
+ QgsDebugMsg ( QString ( " plugin object name now: %1" ).arg ( o->objectName () ) );
337
+ }
338
+
339
+ if ( !o->parent () )
340
+ {
341
+ QgsDebugMsg ( QString ( " setting plugin parent" ) );
342
+ o->setParent ( QgisApp::instance () );
359
343
}
360
344
else
361
345
{
362
- QgsMessageLog::logMessage ( QObject::tr ( " Unable to find the class factory for %1. " ). arg ( theFullPathName ), QObject::tr ( " Plugins " ) );
346
+ QgsDebugMsg ( QString ( " plugin parent already set " ) );
363
347
}
364
-
365
348
}
366
349
break ;
367
350
default :
@@ -411,73 +394,73 @@ void QgsPluginRegistry::restoreSessionPlugins( QString thePluginDirString )
411
394
}
412
395
}
413
396
414
- if ( mPythonUtils && mPythonUtils ->isEnabled () )
397
+ if ( !mPythonUtils || !mPythonUtils ->isEnabled () )
398
+ return ;
399
+
400
+ // check for python plugins system-wide
401
+ QStringList pluginList = mPythonUtils ->pluginList ();
402
+ QgsDebugMsg ( " Loading python plugins" );
403
+
404
+ QStringList corePlugins = QStringList ();
405
+ corePlugins << " plugin_installer" ;
406
+ corePlugins << " fTools" ;
407
+ corePlugins << " GdalTools" ;
408
+ corePlugins << " db_manager" ;
409
+
410
+ // make the required core plugins enabled by default:
411
+ for ( int i = 0 ; i < corePlugins.size (); i++ )
415
412
{
416
- // check for python plugins system-wide
417
- QStringList pluginList = mPythonUtils ->pluginList ();
418
- QgsDebugMsg ( " Loading python plugins" );
419
-
420
- QStringList corePlugins = QStringList ();
421
- corePlugins << " plugin_installer" ;
422
- corePlugins << " fTools" ;
423
- corePlugins << " GdalTools" ;
424
- corePlugins << " db_manager" ;
425
-
426
- // make the required core plugins enabled by default:
427
- for ( int i = 0 ; i < corePlugins.size (); i++ )
413
+ if ( !mySettings.contains ( " /PythonPlugins/" + corePlugins[i] ) )
428
414
{
429
- if ( !mySettings.contains ( " /PythonPlugins/" + corePlugins[i] ) )
430
- {
431
- mySettings.setValue ( " /PythonPlugins/" + corePlugins[i], true );
432
- }
415
+ mySettings.setValue ( " /PythonPlugins/" + corePlugins[i], true );
433
416
}
417
+ }
434
418
435
- for ( int i = 0 ; i < pluginList.size (); i++ )
436
- {
437
- QString packageName = pluginList[i];
419
+ for ( int i = 0 ; i < pluginList.size (); i++ )
420
+ {
421
+ QString packageName = pluginList[i];
438
422
439
- // TODO: apply better solution for #5879
440
- // start - temporary fix for issue #5879
441
- if ( QgsApplication::isRunningFromBuildDir () )
423
+ // TODO: apply better solution for #5879
424
+ // start - temporary fix for issue #5879
425
+ if ( QgsApplication::isRunningFromBuildDir () )
426
+ {
427
+ if ( corePlugins.contains ( packageName ) )
442
428
{
443
- if ( corePlugins.contains ( packageName ) )
444
- {
445
- QgsApplication::setPkgDataPath ( QString ( " " ) );
446
- }
447
- else
448
- {
449
- QgsApplication::setPkgDataPath ( QgsApplication::buildSourcePath () );
450
- }
429
+ QgsApplication::setPkgDataPath ( QString ( " " ) );
451
430
}
452
- // end - temporary fix for issue #5879, more below
453
-
454
- if ( checkPythonPlugin ( packageName ) )
431
+ else
455
432
{
456
- // check if the plugin was active on last session
457
-
458
- if ( mySettings.value ( " /PythonPlugins/" + packageName ).toBool () )
459
- {
460
- loadPythonPlugin ( packageName );
461
- }
433
+ QgsApplication::setPkgDataPath ( QgsApplication::buildSourcePath () );
462
434
}
463
435
}
464
- // start - temporary fix for issue #5879, more above
465
- if ( QgsApplication::isRunningFromBuildDir () )
436
+ // end - temporary fix for issue #5879, more below
437
+
438
+ if ( checkPythonPlugin ( packageName ) )
466
439
{
467
- QgsApplication::setPkgDataPath ( QgsApplication::buildSourcePath () );
440
+ // check if the plugin was active on last session
441
+
442
+ if ( mySettings.value ( " /PythonPlugins/" + packageName ).toBool () )
443
+ {
444
+ loadPythonPlugin ( packageName );
445
+ }
468
446
}
469
- // end - temporary fix for issue #5879
470
447
}
471
448
449
+ // start - temporary fix for issue #5879, more above
450
+ if ( QgsApplication::isRunningFromBuildDir () )
451
+ {
452
+ QgsApplication::setPkgDataPath ( QgsApplication::buildSourcePath () );
453
+ }
454
+ // end - temporary fix for issue #5879
455
+
472
456
QgsDebugMsg ( " Plugin loading completed" );
473
457
}
474
458
475
459
476
460
bool QgsPluginRegistry::checkCppPlugin ( QString pluginFullPath )
477
461
{
478
462
QLibrary myLib ( pluginFullPath );
479
- bool loaded = myLib.load ();
480
- if ( ! loaded )
463
+ if ( !myLib.load () )
481
464
{
482
465
QgsMessageLog::logMessage ( QObject::tr ( " Failed to load %1 (Reason: %2)" ).arg ( myLib.fileName () ).arg ( myLib.errorString () ), QObject::tr ( " Plugins" ) );
483
466
return false ;
@@ -488,7 +471,7 @@ bool QgsPluginRegistry::checkCppPlugin( QString pluginFullPath )
488
471
category_t * myCategory = ( category_t * ) cast_to_fptr ( myLib.resolve ( " category" ) );
489
472
version_t * myVersion = ( version_t * ) cast_to_fptr ( myLib.resolve ( " version" ) );
490
473
491
- if ( myName && myDescription && myVersion && myCategory )
474
+ if ( myName && myDescription && myVersion && myCategory )
492
475
return true ;
493
476
494
477
QgsDebugMsg ( " Failed to get name, description, category or type for " + myLib.fileName () );
0 commit comments