Skip to content

Commit 7aa12fc

Browse files
author
timlinux
committedFeb 23, 2011
[FEATURE] Added option to load c++ plugins from user specified directories. Requires application restart to activate.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15250 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

6 files changed

+159
-29
lines changed

6 files changed

+159
-29
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,16 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
490490
QgsPluginRegistry::instance()->restoreSessionPlugins( QgsApplication::pluginPath() );
491491
}
492492

493+
// Also restore plugins from user specified plugin directories - added for 1.7
494+
QSettings settings;
495+
QString myPaths = settings.value( "plugins/searchPathsForPlugins", "" ).toString();
496+
if ( !myPaths.isEmpty() )
497+
{
498+
QStringList myPathList = myPaths.split( "|" );
499+
QgsPluginRegistry::instance()->restoreSessionPlugins( myPathList );
500+
QMessageBox::critical( this, tr( "Plugin paths" ), myPaths );
501+
}
502+
493503
mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
494504
qApp->processEvents();
495505
// now build vector file filter
@@ -541,7 +551,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
541551
mMapCanvas->mapRenderer()->setLabelingEngine( mLBL );
542552

543553
// Show a nice tip of the day
544-
QSettings settings;
545554
if ( settings.value( "/qgis/showTips", 1 ).toBool() )
546555
{
547556
mSplash->hide();

‎src/app/qgsoptions.cpp

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,23 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
7979
spinBoxIdentifyValue->setMinimum( 0.01 );
8080
spinBoxIdentifyValue->setValue( identifyValue );
8181

82+
//local directories to search when loading c++ plugins
83+
QString myPaths = settings.value( "plugins/searchPathsForPlugins", "" ).toString();
84+
if ( !myPaths.isEmpty() )
85+
{
86+
QStringList myPathList = myPaths.split( "|" );
87+
QStringList::const_iterator pathIt = myPathList.constBegin();
88+
for ( ; pathIt != myPathList.constEnd(); ++pathIt )
89+
{
90+
QListWidgetItem* newItem = new QListWidgetItem( mListPluginPaths );
91+
newItem->setText( *pathIt );
92+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
93+
mListPluginPaths->addItem( newItem );
94+
}
95+
}
8296

8397
//local directories to search when looking for an SVG with a given basename
84-
QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
98+
myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
8599
if ( !myPaths.isEmpty() )
86100
{
87101
QStringList myPathList = myPaths.split( "|" );
@@ -479,8 +493,20 @@ void QgsOptions::saveOptions()
479493
{
480494
QSettings settings;
481495

482-
//search directories for svgs
496+
//search directories for user plugins
483497
QString myPaths;
498+
for ( int i = 0; i < mListPluginPaths->count(); ++i )
499+
{
500+
if ( i != 0 )
501+
{
502+
myPaths += "|";
503+
}
504+
myPaths += mListPluginPaths->item( i )->text();
505+
}
506+
settings.setValue( "plugins/searchPathsForPlugins", myPaths );
507+
508+
//search directories for svgs
509+
myPaths;
484510
for ( int i = 0; i < mListSVGPaths->count(); ++i )
485511
{
486512
if ( i != 0 )
@@ -881,6 +907,33 @@ QStringList QgsOptions::i18nList()
881907
return myList;
882908
}
883909

910+
void QgsOptions::on_mBtnAddPluginPath_clicked()
911+
{
912+
QString myDir = QFileDialog::getExistingDirectory(
913+
this,
914+
tr( "Choose a directory" ),
915+
QDir::toNativeSeparators( QDir::homePath() ),
916+
QFileDialog::ShowDirsOnly
917+
);
918+
919+
if ( ! myDir.isEmpty() )
920+
{
921+
QListWidgetItem* newItem = new QListWidgetItem( mListPluginPaths );
922+
newItem->setText( myDir );
923+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
924+
mListPluginPaths->addItem( newItem );
925+
mListPluginPaths->setCurrentItem( newItem );
926+
}
927+
}
928+
929+
void QgsOptions::on_mBtnRemovePluginPath_clicked()
930+
{
931+
int currentRow = mListPluginPaths->currentRow();
932+
QListWidgetItem* itemToRemove = mListPluginPaths->takeItem( currentRow );
933+
delete itemToRemove;
934+
}
935+
936+
884937
void QgsOptions::on_mBtnAddSVGPath_clicked()
885938
{
886939
QString myDir = QFileDialog::getExistingDirectory(

‎src/app/qgsoptions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
9090
/**Remove an URL to exclude from Proxy*/
9191
void on_mRemoveUrlPushButton_clicked();
9292

93+
/* Let the user add a path to the list of search paths
94+
* used for finding user Plugin libs.
95+
* @note added in QGIS 1.7
96+
*/
97+
void on_mBtnAddPluginPath_clicked();
98+
99+
/* Let the user remove a path to the list of search paths
100+
* used for finding Plugin libs.
101+
* @note added in QGIS 1.7
102+
*/
103+
void on_mBtnRemovePluginPath_clicked();
104+
93105
/* Let the user add a path to the list of search paths
94106
* used for finding SVG files.
95107
* @note added in QGIS 1.4

‎src/app/qgspluginregistry.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,17 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
356356
QgsDebugMsg( "Plugin " + theFullPathName + " did not return a valid type and cannot be loaded" );
357357
break;
358358
}
359-
360359
}
361360

361+
//overloaded version of the next method that will load from multiple directories not just one
362+
void QgsPluginRegistry::restoreSessionPlugins( QStringList thePluginDirList )
363+
{
364+
QStringListIterator myIterator( thePluginDirList );
365+
while ( myIterator.hasNext() )
366+
{
367+
restoreSessionPlugins( myIterator.next() );
368+
}
369+
}
362370

363371
void QgsPluginRegistry::restoreSessionPlugins( QString thePluginDirString )
364372
{

‎src/app/qgspluginregistry.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class QString;
3030

3131
/**
3232
* \class QgsPluginRegistry
33-
* \brief This class tracks plugins that are currently loaded an provides
33+
* \brief This class tracks plugins that are currently loaded and provides
3434
* a means to fetch a pointer to a plugin and unload it
3535
*
3636
* plugin key is:
@@ -78,6 +78,8 @@ class QgsPluginRegistry
7878
//! Python plugin loader
7979
void loadPythonPlugin( QString packageName );
8080

81+
//! Overloaded version of the next method that will load from multiple directories not just one
82+
void restoreSessionPlugins( QStringList thePluginDirList );
8183
//! Load any plugins used in the last qgis session
8284
void restoreSessionPlugins( QString thePluginDirString );
8385

‎src/ui/qgsoptionsbase.ui

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
<property name="geometry">
6060
<rect>
6161
<x>0</x>
62-
<y>-155</y>
62+
<y>-369</y>
6363
<width>746</width>
64-
<height>640</height>
64+
<height>827</height>
6565
</rect>
6666
</property>
6767
<layout class="QGridLayout" name="gridLayout_12">
@@ -168,8 +168,8 @@
168168
<property name="title">
169169
<string>Application</string>
170170
</property>
171-
<layout class="QVBoxLayout" name="verticalLayout_2">
172-
<item>
171+
<layout class="QGridLayout" name="gridLayout">
172+
<item row="0" column="0">
173173
<layout class="QHBoxLayout" name="horizontalLayout_3">
174174
<item>
175175
<widget class="QLabel" name="textLabel1_4">
@@ -211,7 +211,7 @@
211211
</item>
212212
</layout>
213213
</item>
214-
<item>
214+
<item row="1" column="0">
215215
<layout class="QHBoxLayout" name="horizontalLayout_7">
216216
<item>
217217
<widget class="QLabel" name="textLabel1_5">
@@ -248,77 +248,77 @@
248248
</item>
249249
</layout>
250250
</item>
251-
<item>
251+
<item row="2" column="0">
252252
<widget class="QCheckBox" name="capitaliseCheckBox">
253253
<property name="text">
254254
<string>Capitalise layer names in legend</string>
255255
</property>
256256
</widget>
257257
</item>
258-
<item>
258+
<item row="3" column="0">
259259
<widget class="QCheckBox" name="cbxLegendClassifiers">
260260
<property name="text">
261261
<string>Display classification attribute names in legend</string>
262262
</property>
263263
</widget>
264264
</item>
265-
<item>
265+
<item row="4" column="0">
266266
<widget class="QCheckBox" name="cbxCreateRasterLegendIcons">
267267
<property name="text">
268268
<string>Create raster icons in legend</string>
269269
</property>
270270
</widget>
271271
</item>
272-
<item>
272+
<item row="5" column="0">
273273
<widget class="QCheckBox" name="cbxHideSplash">
274274
<property name="text">
275275
<string>Hide splash screen at startup</string>
276276
</property>
277277
</widget>
278278
</item>
279-
<item>
279+
<item row="6" column="0">
280280
<widget class="QCheckBox" name="cbxShowTips">
281281
<property name="text">
282282
<string>Show tips at start up</string>
283283
</property>
284284
</widget>
285285
</item>
286-
<item>
286+
<item row="7" column="0">
287287
<widget class="QCheckBox" name="cbxIdentifyResultsDocked">
288288
<property name="text">
289289
<string>Open identify results in a dock window (QGIS restart required)</string>
290290
</property>
291291
</widget>
292292
</item>
293-
<item>
293+
<item row="8" column="0">
294294
<widget class="QCheckBox" name="cbxSnappingOptionsDocked">
295295
<property name="text">
296296
<string>Open snapping options in a dock window (QGIS restart required)</string>
297297
</property>
298298
</widget>
299299
</item>
300-
<item>
300+
<item row="9" column="0">
301301
<widget class="QCheckBox" name="cbxAttributeTableDocked">
302302
<property name="text">
303303
<string>Open attribute table in a dock window (QGIS restart required)</string>
304304
</property>
305305
</widget>
306306
</item>
307-
<item>
307+
<item row="10" column="0">
308308
<widget class="QCheckBox" name="cbxAddPostgisDC">
309309
<property name="text">
310310
<string>Add PostGIS layers with double click and select in extended mode</string>
311311
</property>
312312
</widget>
313313
</item>
314-
<item>
314+
<item row="11" column="0">
315315
<widget class="QCheckBox" name="cbxAddNewLayersToCurrentGroup">
316316
<property name="text">
317317
<string>Add new layers to selected group</string>
318318
</property>
319319
</widget>
320320
</item>
321-
<item>
321+
<item row="12" column="0">
322322
<layout class="QHBoxLayout" name="horizontalLayout_5">
323323
<item>
324324
<widget class="QLabel" name="textLabel1_7">
@@ -360,7 +360,7 @@
360360
</item>
361361
</layout>
362362
</item>
363-
<item>
363+
<item row="13" column="0">
364364
<layout class="QHBoxLayout" name="horizontalLayout_6">
365365
<item>
366366
<widget class="QLabel" name="label_14">
@@ -387,6 +387,52 @@
387387
</item>
388388
</layout>
389389
</item>
390+
<item row="14" column="0">
391+
<widget class="QGroupBox" name="groupBox_4">
392+
<property name="title">
393+
<string>Plugin paths</string>
394+
</property>
395+
<layout class="QGridLayout" name="_2">
396+
<item row="0" column="0">
397+
<widget class="QLabel" name="mSVGLabel_2">
398+
<property name="text">
399+
<string>Path(s) to search for additional C++ plugins libraries</string>
400+
</property>
401+
</widget>
402+
</item>
403+
<item row="0" column="1">
404+
<spacer>
405+
<property name="orientation">
406+
<enum>Qt::Horizontal</enum>
407+
</property>
408+
<property name="sizeHint" stdset="0">
409+
<size>
410+
<width>31</width>
411+
<height>20</height>
412+
</size>
413+
</property>
414+
</spacer>
415+
</item>
416+
<item row="0" column="2">
417+
<widget class="QPushButton" name="mBtnAddPluginPath">
418+
<property name="text">
419+
<string>Add</string>
420+
</property>
421+
</widget>
422+
</item>
423+
<item row="0" column="3">
424+
<widget class="QPushButton" name="mBtnRemovePluginPath">
425+
<property name="text">
426+
<string>Remove</string>
427+
</property>
428+
</widget>
429+
</item>
430+
<item row="1" column="0" colspan="4">
431+
<widget class="QListWidget" name="mListPluginPaths"/>
432+
</item>
433+
</layout>
434+
</widget>
435+
</item>
390436
</layout>
391437
</widget>
392438
</item>
@@ -416,7 +462,7 @@
416462
<x>0</x>
417463
<y>0</y>
418464
<width>746</width>
419-
<height>466</height>
465+
<height>479</height>
420466
</rect>
421467
</property>
422468
<layout class="QGridLayout" name="gridLayout_8">
@@ -587,7 +633,7 @@
587633
<x>0</x>
588634
<y>0</y>
589635
<width>746</width>
590-
<height>480</height>
636+
<height>500</height>
591637
</rect>
592638
</property>
593639
<layout class="QGridLayout" name="gridLayout_4">
@@ -941,8 +987,8 @@
941987
<rect>
942988
<x>0</x>
943989
<y>0</y>
944-
<width>762</width>
945-
<height>458</height>
990+
<width>746</width>
991+
<height>462</height>
946992
</rect>
947993
</property>
948994
<layout class="QGridLayout" name="gridLayout_13">
@@ -1272,7 +1318,7 @@
12721318
<x>0</x>
12731319
<y>0</y>
12741320
<width>746</width>
1275-
<height>527</height>
1321+
<height>531</height>
12761322
</rect>
12771323
</property>
12781324
<layout class="QGridLayout" name="gridLayout_15">
@@ -1368,7 +1414,7 @@
13681414
<x>0</x>
13691415
<y>0</y>
13701416
<width>746</width>
1371-
<height>545</height>
1417+
<height>552</height>
13721418
</rect>
13731419
</property>
13741420
<layout class="QGridLayout" name="gridLayout_17">
@@ -1459,7 +1505,7 @@
14591505
<x>0</x>
14601506
<y>0</y>
14611507
<width>746</width>
1462-
<height>531</height>
1508+
<height>548</height>
14631509
</rect>
14641510
</property>
14651511
<layout class="QGridLayout" name="gridLayout_20">

0 commit comments

Comments
 (0)
Please sign in to comment.