5555
5656const int PLUGIN_DATA_ROLE = Qt::UserRole;
5757const int PLUGIN_LIBRARY_ROLE = Qt::UserRole + 1 ;
58- const int PLUGIN_LIBRARY_NAME_ROLE = Qt::UserRole + 2 ;
58+ const int PLUGIN_BASE_NAME_ROLE = Qt::UserRole + 2 ;
5959
6060QgsPluginManager::QgsPluginManager ( QgsPythonUtils* pythonUtils, QWidget * parent, Qt::WFlags fl )
6161 : QDialog( parent, fl )
@@ -151,9 +151,9 @@ void QgsPluginManager::getPythonPluginDescriptions()
151151 // filtering will be done on the display role so give it name and desription
152152 // user wont see this text since we are using a custome delegate
153153 QStandardItem * mypDetailItem = new QStandardItem ( pluginName + " - " + description );
154- QString myLibraryName = " python:" + packageName;;
154+ QString myLibraryName = " python:" + packageName;
155155 mypDetailItem->setData ( myLibraryName, PLUGIN_LIBRARY_ROLE ); // for loading libs later
156- mypDetailItem->setData ( pluginName, PLUGIN_LIBRARY_NAME_ROLE ); // for matching in registry later
156+ mypDetailItem->setData ( packageName, PLUGIN_BASE_NAME_ROLE ); // for matching in registry later
157157 mypDetailItem->setCheckable ( false );
158158 mypDetailItem->setEditable ( false );
159159 // setData in the delegate with a variantised QgsDetailedItemData
@@ -167,19 +167,15 @@ void QgsPluginManager::getPythonPluginDescriptions()
167167
168168 // check to see if the plugin is loaded and set the checkbox accordingly
169169 QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance ();
170- QString libName = pRegistry->library ( pluginName );
171- if ( libName.length () == 0 || !pRegistry->isPythonPlugin ( pluginName ) )
170+ if ( pRegistry->isLoaded (packageName) && pRegistry->isPythonPlugin (packageName) )
172171 {
173- QgsDebugMsg ( " Couldn't find library name in the registry" );
172+ QgsDebugMsg ( " Found plugin in the registry" );
173+ // set the checkbox
174+ myData.setChecked ( true );
174175 }
175176 else
176177 {
177- QgsDebugMsg ( " Found library name in the registry" );
178- if ( libName == packageName )
179- {
180- // set the checkbox
181- myData.setChecked ( true );
182- }
178+ QgsDebugMsg ( " Couldn't find plugin in the registry: " + packageName );
183179 }
184180 QVariant myVariant = qVariantFromValue ( myData );
185181 mypDetailItem->setData ( myVariant, PLUGIN_DATA_ROLE );
@@ -297,40 +293,40 @@ void QgsPluginManager::getPluginDescriptions()
297293 delete myLib;
298294 continue ;
299295 }
296+
297+ QString pluginName = pName ();
298+ QString pluginDesc = pDesc ();
299+ QString pluginVersion = pVersion ();
300+ QString baseName = QFileInfo (lib).baseName ();
300301
301302 QString myLibraryName = pluginDir[i];
302303 // filtering will be done on the display role so give it name and desription
303304 // user wont see this text since we are using a custome delegate
304- QStandardItem * mypDetailItem = new QStandardItem ( pName () + " - " + pDesc () );
305+ QStandardItem * mypDetailItem = new QStandardItem ( pluginName + " - " + pluginDesc );
305306 mypDetailItem->setData ( myLibraryName, PLUGIN_LIBRARY_ROLE );
306- mypDetailItem->setData ( pName (), PLUGIN_LIBRARY_NAME_ROLE ); // for matching in registry later
307+ mypDetailItem->setData ( baseName, PLUGIN_BASE_NAME_ROLE ); // for matching in registry later
307308 QgsDetailedItemData myData;
308- myData.setTitle ( pName () );
309- myData.setDetail ( pDesc () );
309+ myData.setTitle ( pluginName );
310+ myData.setDetail ( pluginDesc );
310311 myData.setRenderAsWidget ( false );
311312 myData.setCheckable ( true );
312313 myData.setChecked ( false ); // start unchecked - we will check it later if needed
313314
314- // round trip test - delete this...no need to uncomment
315- // QgsDetailedItemData myData2 = qVariantValue<QgsDetailedItemData>(myVariant);
316- // Q_ASSERT(myData.title() == myData2.title());
317- // round trip test ends
318-
319315 QgsDebugMsg ( " Getting an instance of the QgsPluginRegistry" );
320316
321317 // check to see if the plugin is loaded and set the checkbox accordingly
322318 QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance ();
323- QString libName = pRegistry->library ( pName () );
324319
325320 // get the library using the plugin description
326- if ( libName. length () == 0 )
321+ if ( !pRegistry-> isLoaded (baseName) )
327322 {
328- QgsDebugMsg ( " Couldn't find library name in the registry" );
323+ QgsDebugMsg ( " Couldn't find plugin in the registry" );
329324 }
330325 else
331326 {
332- QgsDebugMsg ( " Found library name in the registry" );
333- if ( libName == myLib->fileName () )
327+ QgsDebugMsg ( " Found plugin in the registry" );
328+ // TODO: this check shouldn't be necessary, plugin base names must be unique
329+ if ( pRegistry->library (baseName) == myLib->fileName () )
334330 {
335331 // set the checkbox
336332 myData.setChecked ( true );
@@ -367,32 +363,36 @@ void QgsPluginManager::unload()
367363 myIndex = mModelPlugins ->index ( row, 0 );
368364 // its off -- see if it is loaded and if so, unload it
369365 QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance ();
370- QgsDebugMsg ( QString ( " Checking to see if %1 is loaded" ).arg ( mModelPlugins ->data ( myIndex, PLUGIN_LIBRARY_NAME_ROLE ).toString () ) );
371- QString pluginName = mModelPlugins ->data ( myIndex, PLUGIN_LIBRARY_NAME_ROLE ).toString ();
372- if ( pRegistry->isPythonPlugin ( pluginName ) )
366+
367+ // is loaded?
368+ QString baseName = mModelPlugins ->data ( myIndex, PLUGIN_BASE_NAME_ROLE ).toString ();
369+ if ( ! pRegistry->isLoaded ( baseName ) )
370+ continue ;
371+
372+ if ( pRegistry->isPythonPlugin ( baseName ) )
373373 {
374374 if ( mPythonUtils && mPythonUtils ->isEnabled () )
375375 {
376- QString packageName = pRegistry->library ( pluginName );
377- mPythonUtils ->unloadPlugin ( packageName );
376+ mPythonUtils ->unloadPlugin ( baseName );
378377 // disable it to the qsettings file
379- settings.setValue ( " /PythonPlugins/" + packageName , false );
378+ settings.setValue ( " /PythonPlugins/" + baseName , false );
380379 }
381380 }
382381 else // C++ plugin
383382 {
384- QgisPlugin *plugin = pRegistry->plugin ( pluginName );
383+ QgisPlugin *plugin = pRegistry->plugin ( baseName );
385384 if ( plugin )
386385 {
387386 plugin->unload ();
388387 }
389388 // disable it to the qsettings file [ts]
390- settings.setValue ( " /Plugins/" + pluginName , false );
389+ settings.setValue ( " /Plugins/" + baseName , false );
391390 }
392391 // remove the plugin from the registry
393- pRegistry->removePlugin ( pluginName );
392+ pRegistry->removePlugin ( baseName );
394393 }
395394 }
395+ QgsPluginRegistry::instance ()->dump ();
396396}
397397
398398std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins ()
@@ -406,7 +406,8 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
406406
407407 if ( myData.isChecked () )
408408 {
409- QString pluginName = mModelPlugins ->item ( row, 0 )->data ( PLUGIN_LIBRARY_NAME_ROLE ).toString ();
409+ // QString baseName = mModelPlugins->item( row, 0 )->data( PLUGIN_BASE_NAME_ROLE ).toString();
410+ QString pluginName = mModelPlugins ->item ( row, 0 )->data ( Qt::DisplayRole ).toString ();
410411 bool pythonic = false ;
411412
412413 QString library = mModelPlugins ->item ( row, 0 )->data ( PLUGIN_LIBRARY_ROLE ).toString ();
@@ -425,9 +426,7 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
425426 // QString fullPath=0,
426427 // QString type=0,
427428 // bool python=false);
428- pis.push_back ( QgsPluginItem ( pluginName,
429- mModelPlugins ->item ( row, 0 )->data ( Qt::DisplayRole ).toString (), // display role
430- library, 0 , pythonic ) );
429+ pis.push_back ( QgsPluginItem ( pluginName, library, 0 , pythonic ) );
431430 }
432431
433432 }
@@ -472,9 +471,10 @@ void QgsPluginManager::on_vwPlugins_clicked( const QModelIndex &theIndex )
472471 // the index row in the underlying model so we need to jump through this
473472 // little hoop to get the correct item
474473 //
475- QStandardItem * mypItem =
476- mModelPlugins ->findItems ( theIndex.data ( Qt ::DisplayRole ).toString () ).first ();
477- QgsDetailedItemData myData =
474+
475+ QModelIndex realIndex = mModelProxy ->mapToSource (theIndex);
476+ QStandardItem* mypItem = mModelPlugins ->itemFromIndex (realIndex);
477+ QgsDetailedItemData myData =
478478 qVariantValue<QgsDetailedItemData>( mypItem->data ( PLUGIN_DATA_ROLE ) );
479479 if ( myData.isChecked () )
480480 {
0 commit comments