22
22
#include < QApplication>
23
23
#include < QFileDialog>
24
24
#include < QLineEdit>
25
- #include < Q3ListView>
26
25
#include < QMessageBox>
27
26
#include < QLibrary>
28
27
#include < QSettings>
@@ -60,6 +59,7 @@ QgsPluginManager::QgsPluginManager(QWidget * parent, Qt::WFlags fl)
60
59
QString libDir = baseDir + "/lib"; */
61
60
62
61
txtPluginDir->setText (pr->libraryDirectory ().path ());
62
+ setTable ();
63
63
getPluginDescriptions ();
64
64
getPythonPluginDescriptions ();
65
65
}
@@ -69,6 +69,32 @@ QgsPluginManager::~QgsPluginManager()
69
69
{
70
70
}
71
71
72
+ void QgsPluginManager::setTable ()
73
+ {
74
+ lstPlugins->setAlternatingRowColors (true );
75
+ modelPlugins= new QStandardItemModel (0 ,4 );
76
+ modelPlugins->setHorizontalHeaderItem (0 ,new QStandardItem (tr (" Name" )));
77
+ modelPlugins->setHorizontalHeaderItem (1 ,new QStandardItem (tr (" Version" )));
78
+ modelPlugins->setHorizontalHeaderItem (2 ,new QStandardItem (tr (" Description" )));
79
+ modelPlugins->setHorizontalHeaderItem (3 ,new QStandardItem (tr (" Library name" )));
80
+ lstPlugins->setModel (modelPlugins);
81
+ // No vertical headers
82
+ lstPlugins->verticalHeader ()->hide ();
83
+ }
84
+
85
+ void QgsPluginManager::resizeColumnsToContents ()
86
+ {
87
+ // Resize columns to contents.
88
+ lstPlugins->resizeColumnsToContents ();
89
+ QgsDebugMsg (" QgsPluginManager::resizeColumnsToContents\n " );
90
+ }
91
+
92
+ void QgsPluginManager::sortModel (int column)
93
+ {
94
+ // Sort column ascending.
95
+ modelPlugins->sort (column);
96
+ QgsDebugMsg (" QgsPluginManager::sortModel\n " );
97
+ }
72
98
73
99
void QgsPluginManager::getPythonPluginDescriptions ()
74
100
{
@@ -94,16 +120,23 @@ void QgsPluginManager::getPythonPluginDescriptions()
94
120
95
121
if (pluginName == " ???" || description == " ???" || version == " ???" )
96
122
continue ;
97
-
98
- // add to the list box
99
- Q3CheckListItem *pl = new Q3CheckListItem (lstPlugins, pluginName, Q3CheckListItem::CheckBox);
100
- pl->setText (1 , version);
101
- pl->setText (2 , description);
102
- pl->setText (3 , " python:" + packageName);
103
-
123
+
124
+ // create the items
125
+ QStandardItem *myName=new QStandardItem (pluginName);
126
+ QStandardItem *myVersion=new QStandardItem (version);
127
+ QStandardItem *myDesc=new QStandardItem (description);
128
+ QStandardItem *myDir=new QStandardItem (" python:" + packageName);
129
+ // myName have a checkbox
130
+ myName->setCheckable (true );
131
+ // read only
132
+ myName->setEditable (false );
133
+ myVersion->setEditable (false );
134
+ myDesc->setEditable (false );
135
+ myDir->setEditable (false );
136
+
104
137
// check to see if the plugin is loaded and set the checkbox accordingly
105
138
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance ();
106
-
139
+
107
140
QString libName = pRegistry->library (pluginName);
108
141
if (libName.length () == 0 || !pRegistry->isPythonPlugin (pluginName))
109
142
{
@@ -115,9 +148,13 @@ void QgsPluginManager::getPythonPluginDescriptions()
115
148
if (libName == packageName)
116
149
{
117
150
// set the checkbox
118
- pl-> setOn ( true );
151
+ myName-> setCheckState (Qt::Checked );
119
152
}
120
153
}
154
+ // Add items to model
155
+ QList<QStandardItem *> myItems;
156
+ myItems << myName << myVersion << myDesc << myDir;
157
+ modelPlugins->appendRow (myItems);
121
158
}
122
159
#endif
123
160
}
@@ -223,10 +260,18 @@ sharedLibExtension = "*.so*";
223
260
continue ;
224
261
}
225
262
226
- Q3CheckListItem *pl = new Q3CheckListItem (lstPlugins, pName (), Q3CheckListItem::CheckBox); // , pDesc(), pluginDir[i])
227
- pl->setText (1 , pVersion ());
228
- pl->setText (2 , pDesc ());
229
- pl->setText (3 , pluginDir[i]);
263
+ // create the items
264
+ QStandardItem *myName=new QStandardItem (pName ());
265
+ QStandardItem *myVersion=new QStandardItem (pVersion ());
266
+ QStandardItem *myDesc=new QStandardItem (pDesc ());
267
+ QStandardItem *myDir=new QStandardItem (pluginDir[i]);
268
+ // myName have a checkbox
269
+ myName->setCheckable (true );
270
+ // read only
271
+ myName->setEditable (false );
272
+ myVersion->setEditable (false );
273
+ myDesc->setEditable (false );
274
+ myDir->setEditable (false );
230
275
231
276
QgsDebugMsg (" Getting an instance of the QgsPluginRegistry" );
232
277
@@ -245,15 +290,18 @@ sharedLibExtension = "*.so*";
245
290
if (libName == myLib->library ())
246
291
{
247
292
// set the checkbox
248
- pl-> setOn ( true );
293
+ myName-> setCheckState (Qt::Checked );
249
294
}
250
295
}
296
+ // Add items to model
297
+ QList<QStandardItem *> myItems;
298
+ myItems << myName << myVersion << myDesc << myDir;
299
+ modelPlugins->appendRow (myItems);
251
300
252
301
delete myLib;
253
302
}
254
303
}
255
304
256
-
257
305
void QgsPluginManager::on_btnOk_clicked ()
258
306
{
259
307
unload ();
@@ -266,59 +314,56 @@ void QgsPluginManager::unload()
266
314
#ifdef QGISDEBUG
267
315
std::cout << " Checking for plugins to unload" << std::endl;
268
316
#endif
269
- Q3CheckListItem *lvi = (Q3CheckListItem *) lstPlugins->firstChild ();
270
- while (lvi != 0 )
317
+ for (int row=0 ;row < modelPlugins->rowCount ();row++)
318
+ {
319
+ // FPV - I want to use index. You can do evrething with item.
320
+ QModelIndex myIndex=modelPlugins->index (row,0 );
321
+ if (modelPlugins->data (myIndex,Qt::CheckStateRole).toInt () == 0 )
271
322
{
272
- if (!lvi->isOn ())
273
- {
274
- // its off -- see if it is loaded and if so, unload it
275
- QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance ();
323
+ // its off -- see if it is loaded and if so, unload it
324
+ QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance ();
276
325
#ifdef QGISDEBUG
277
- std::cout << " Checking to see if " << lvi-> text ( 0 ).toLocal8Bit ().data () << " is loaded" << std::endl;
326
+ std::cout << " Checking to see if " << modelPlugins-> data (myIndex). toString ( ).toLocal8Bit ().data () << " is loaded" << std::endl;
278
327
#endif
279
-
280
- QString pluginName = lvi->text (0 );
281
-
282
- if (pRegistry->isPythonPlugin (pluginName))
283
- {
328
+ QString pluginName = modelPlugins->data (myIndex).toString ();
329
+ if (pRegistry->isPythonPlugin (pluginName))
330
+ {
284
331
#ifdef HAVE_PYTHON
285
- QString packageName = pRegistry->library (pluginName);
286
- QgsPythonUtils::unloadPlugin (packageName);
287
-
288
- // disable it to the qsettings file
289
- settings.writeEntry (" /PythonPlugins/" + packageName, false );
332
+ QString packageName = pRegistry->library (pluginName);
333
+ QgsPythonUtils::unloadPlugin (packageName);
334
+ // disable it to the qsettings file
335
+ settings.setValue (" /PythonPlugins/" + packageName, false );
290
336
#endif
291
- }
292
- else // C++ plugin
293
- {
294
- QgisPlugin *plugin = pRegistry->plugin (pluginName);
295
- if (plugin)
296
- {
297
- plugin->unload ();
298
- }
299
- // disable it to the qsettings file [ts]
300
- settings.writeEntry (" /Plugins/" + pluginName, false );
301
- }
302
-
303
- // remove the plugin from the registry
304
- pRegistry->removePlugin (pluginName);
337
+ }
338
+ else // C++ plugin
339
+ {
340
+ QgisPlugin *plugin = pRegistry->plugin (pluginName);
341
+ if (plugin)
342
+ {
343
+ plugin->unload ();
305
344
}
306
- lvi = (Q3CheckListItem *) lvi->nextSibling ();
345
+ // disable it to the qsettings file [ts]
346
+ settings.setValue (" /Plugins/" + pluginName, false );
347
+ }
348
+ // remove the plugin from the registry
349
+ pRegistry->removePlugin (pluginName);
307
350
}
351
+ }
308
352
}
309
353
310
354
std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins ()
311
355
{
312
356
std::vector < QgsPluginItem > pis;
313
- Q3CheckListItem *lvi = (Q3CheckListItem *) lstPlugins-> firstChild ();
314
- while (lvi != 0 )
357
+ // FPV - I want to use item here. You can do everything with index if you want.
358
+ for ( int row= 0 ;row < modelPlugins-> rowCount ();row++ )
315
359
{
316
- if (lvi->isOn ())
360
+ QStandardItem *myItem=modelPlugins->item (row,0 );
361
+ if (modelPlugins->item (row,0 )->checkState () == Qt::Checked)
317
362
{
318
- QString pluginName = lvi-> text ( 0 );
363
+ QString pluginName = modelPlugins-> item (row, 0 )-> text ( );
319
364
bool pythonic = false ;
320
-
321
- QString library = lvi-> text ( 3 );
365
+
366
+ QString library = modelPlugins-> item (row, 3 )-> text ( );
322
367
if (library.left (7 ) == " python:" )
323
368
{
324
369
library = library.mid (7 );
@@ -328,34 +373,30 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
328
373
{
329
374
library = txtPluginDir->text () + " /" + library;
330
375
}
331
-
332
- pis.push_back (QgsPluginItem (pluginName, lvi->text (2 ), library, 0 , pythonic));
376
+ pis.push_back (QgsPluginItem (pluginName, modelPlugins->item (row,2 )->text (), library, 0 , pythonic));
333
377
}
334
- lvi = (Q3CheckListItem *) lvi-> nextSibling ();
378
+
335
379
}
336
380
return pis;
337
381
}
338
382
339
383
void QgsPluginManager::on_btnSelectAll_clicked ()
340
384
{
341
385
// select all plugins
342
- Q3CheckListItem *child = dynamic_cast <Q3CheckListItem *>(lstPlugins->firstChild ());
343
- while (child)
386
+ for (int row=0 ;row < modelPlugins->rowCount ();row++)
344
387
{
345
- child-> setOn ( true );
346
- child = dynamic_cast <Q3CheckListItem *>(child-> nextSibling () );
388
+ QStandardItem *myItem=modelPlugins-> item (row, 0 );
389
+ myItem-> setCheckState (Qt::Checked );
347
390
}
348
-
349
391
}
350
392
351
393
void QgsPluginManager::on_btnClearAll_clicked ()
352
394
{
353
- // clear all selection checkboxes
354
- Q3CheckListItem *child = dynamic_cast <Q3CheckListItem *>(lstPlugins->firstChild ());
355
- while (child)
395
+ // clear all selection checkboxes
396
+ for (int row=0 ;row < modelPlugins->rowCount ();row++)
356
397
{
357
- child-> setOn ( false );
358
- child = dynamic_cast <Q3CheckListItem *>(child-> nextSibling () );
398
+ QStandardItem *myItem=modelPlugins-> item (row, 0 );
399
+ myItem-> setCheckState (Qt::Unchecked );
359
400
}
360
401
}
361
402
0 commit comments