Skip to content

Commit 3eefa8e

Browse files
author
timlinux
committedJan 7, 2008
Applied patch from #892 which removes qt3 deps for plugin manager. Muito obrigado Fernando!
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7858 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

4 files changed

+173
-120
lines changed

4 files changed

+173
-120
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,6 +3717,7 @@ void QgisApp::zoomToLayerExtent()
37173717
void QgisApp::showPluginManager()
37183718
{
37193719
QgsPluginManager *pm = new QgsPluginManager(this);
3720+
pm->resizeColumnsToContents();
37203721
if (pm->exec())
37213722
{
37223723
// load selected plugins

‎src/app/qgspluginmanager.cpp

Lines changed: 108 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <QApplication>
2323
#include <QFileDialog>
2424
#include <QLineEdit>
25-
#include <Q3ListView>
2625
#include <QMessageBox>
2726
#include <QLibrary>
2827
#include <QSettings>
@@ -60,6 +59,7 @@ QgsPluginManager::QgsPluginManager(QWidget * parent, Qt::WFlags fl)
6059
QString libDir = baseDir + "/lib"; */
6160

6261
txtPluginDir->setText(pr->libraryDirectory().path());
62+
setTable();
6363
getPluginDescriptions();
6464
getPythonPluginDescriptions();
6565
}
@@ -69,6 +69,32 @@ QgsPluginManager::~QgsPluginManager()
6969
{
7070
}
7171

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+
}
7298

7399
void QgsPluginManager::getPythonPluginDescriptions()
74100
{
@@ -94,16 +120,23 @@ void QgsPluginManager::getPythonPluginDescriptions()
94120

95121
if (pluginName == "???" || description == "???" || version == "???")
96122
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+
104137
// check to see if the plugin is loaded and set the checkbox accordingly
105138
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
106-
139+
107140
QString libName = pRegistry->library(pluginName);
108141
if (libName.length() == 0 || !pRegistry->isPythonPlugin(pluginName))
109142
{
@@ -115,9 +148,13 @@ void QgsPluginManager::getPythonPluginDescriptions()
115148
if (libName == packageName)
116149
{
117150
// set the checkbox
118-
pl->setOn(true);
151+
myName->setCheckState(Qt::Checked);
119152
}
120153
}
154+
// Add items to model
155+
QList<QStandardItem *> myItems;
156+
myItems << myName << myVersion << myDesc << myDir;
157+
modelPlugins->appendRow(myItems);
121158
}
122159
#endif
123160
}
@@ -223,10 +260,18 @@ sharedLibExtension = "*.so*";
223260
continue;
224261
}
225262

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);
230275

231276
QgsDebugMsg("Getting an instance of the QgsPluginRegistry");
232277

@@ -245,15 +290,18 @@ sharedLibExtension = "*.so*";
245290
if (libName == myLib->library())
246291
{
247292
// set the checkbox
248-
pl->setOn(true);
293+
myName->setCheckState(Qt::Checked);
249294
}
250295
}
296+
// Add items to model
297+
QList<QStandardItem *> myItems;
298+
myItems << myName << myVersion << myDesc << myDir;
299+
modelPlugins->appendRow(myItems);
251300

252301
delete myLib;
253302
}
254303
}
255304

256-
257305
void QgsPluginManager::on_btnOk_clicked()
258306
{
259307
unload();
@@ -266,59 +314,56 @@ void QgsPluginManager::unload()
266314
#ifdef QGISDEBUG
267315
std::cout << "Checking for plugins to unload" << std::endl;
268316
#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)
271322
{
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();
276325
#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;
278327
#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+
{
284331
#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);
290336
#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();
305344
}
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);
307350
}
351+
}
308352
}
309353

310354
std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
311355
{
312356
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++)
315359
{
316-
if (lvi->isOn())
360+
QStandardItem *myItem=modelPlugins->item(row,0);
361+
if (modelPlugins->item(row,0)->checkState() == Qt::Checked)
317362
{
318-
QString pluginName = lvi->text(0);
363+
QString pluginName = modelPlugins->item(row,0)->text();
319364
bool pythonic = false;
320-
321-
QString library = lvi->text(3);
365+
366+
QString library = modelPlugins->item(row,3)->text();
322367
if (library.left(7) == "python:")
323368
{
324369
library = library.mid(7);
@@ -328,34 +373,30 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
328373
{
329374
library = txtPluginDir->text() + "/" + library;
330375
}
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));
333377
}
334-
lvi = (Q3CheckListItem *) lvi->nextSibling();
378+
335379
}
336380
return pis;
337381
}
338382

339383
void QgsPluginManager::on_btnSelectAll_clicked()
340384
{
341385
// select all plugins
342-
Q3CheckListItem *child = dynamic_cast<Q3CheckListItem *>(lstPlugins->firstChild());
343-
while(child)
386+
for (int row=0;row < modelPlugins->rowCount();row++)
344387
{
345-
child->setOn(true);
346-
child = dynamic_cast<Q3CheckListItem *>(child->nextSibling());
388+
QStandardItem *myItem=modelPlugins->item(row,0);
389+
myItem->setCheckState(Qt::Checked);
347390
}
348-
349391
}
350392

351393
void QgsPluginManager::on_btnClearAll_clicked()
352394
{
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++)
356397
{
357-
child->setOn(false);
358-
child = dynamic_cast<Q3CheckListItem *>(child->nextSibling());
398+
QStandardItem *myItem=modelPlugins->item(row,0);
399+
myItem->setCheckState(Qt::Unchecked);
359400
}
360401
}
361402

‎src/app/qgspluginmanager.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919
#ifndef QGSPLUGINMANAGER_H
2020
#define QGSPLUGINMANAGER_H
2121
#include <vector>
22+
#include <QTableView>
23+
#include <QStandardItemModel>
24+
#include <QStandardItem>
25+
#include <QHeaderView>
2226
#include "ui_qgspluginmanagerbase.h"
2327
#include "qgisgui.h"
2428

2529
class QgsPluginItem;
30+
class QTableView;
31+
2632
/*!
2733
* \brief Plugin manager for loading/unloading plugins
2834
@author Gary Sherman
@@ -43,7 +49,13 @@ class QgsPluginManager : public QDialog, private Ui::QgsPluginManagerBase
4349
void unload();
4450
//! Gets the selected plugins
4551
std::vector<QgsPluginItem> getSelectedPlugins();
46-
public slots:
52+
//! Set lstPlugins table GUI
53+
void setTable();
54+
//! Resize columns to contents
55+
void resizeColumnsToContents();
56+
//! Sort model by column ascending
57+
void sortModel(int );
58+
public slots:
4759
//! Load selected plugins and close the dialog
4860
void on_btnOk_clicked();
4961
//! Select all plugins by setting their checkbox on
@@ -52,7 +64,8 @@ class QgsPluginManager : public QDialog, private Ui::QgsPluginManagerBase
5264
void on_btnClearAll_clicked();
5365
//! Close the dialog
5466
void on_btnClose_clicked();
55-
67+
private:
68+
QStandardItemModel *modelPlugins;
5669
};
5770

5871
#endif

‎src/ui/qgspluginmanagerbase.ui

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,41 @@
1616
<bool>true</bool>
1717
</property>
1818
<layout class="QGridLayout" >
19-
<property name="margin" >
19+
<property name="leftMargin" >
2020
<number>11</number>
2121
</property>
22-
<property name="spacing" >
22+
<property name="topMargin" >
23+
<number>11</number>
24+
</property>
25+
<property name="rightMargin" >
26+
<number>11</number>
27+
</property>
28+
<property name="bottomMargin" >
29+
<number>11</number>
30+
</property>
31+
<property name="horizontalSpacing" >
32+
<number>6</number>
33+
</property>
34+
<property name="verticalSpacing" >
2335
<number>6</number>
2436
</property>
2537
<item row="0" column="0" >
2638
<layout class="QHBoxLayout" >
27-
<property name="margin" >
28-
<number>11</number>
29-
</property>
3039
<property name="spacing" >
3140
<number>6</number>
3241
</property>
42+
<property name="leftMargin" >
43+
<number>11</number>
44+
</property>
45+
<property name="topMargin" >
46+
<number>11</number>
47+
</property>
48+
<property name="rightMargin" >
49+
<number>11</number>
50+
</property>
51+
<property name="bottomMargin" >
52+
<number>11</number>
53+
</property>
3354
<item>
3455
<widget class="QLabel" name="textLabel1" >
3556
<property name="text" >
@@ -52,56 +73,30 @@
5273
</item>
5374
</layout>
5475
</item>
55-
<item row="2" column="0" >
56-
<widget class="Q3ListView" name="lstPlugins" >
57-
<property name="font" >
58-
<font>
59-
<family>Arial</family>
60-
<pointsize>10</pointsize>
61-
<weight>50</weight>
62-
<italic>false</italic>
63-
<bold>false</bold>
64-
<underline>false</underline>
65-
<strikeout>false</strikeout>
66-
</font>
67-
</property>
68-
<column>
69-
<property name="text" >
70-
<string>Name</string>
71-
</property>
72-
</column>
73-
<column>
74-
<property name="text" >
75-
<string>Version</string>
76-
</property>
77-
</column>
78-
<column>
79-
<property name="text" >
80-
<string>Description</string>
81-
</property>
82-
</column>
83-
<column>
84-
<property name="text" >
85-
<string>Library Name</string>
86-
</property>
87-
</column>
88-
</widget>
89-
</item>
9076
<item row="1" column="0" >
9177
<widget class="QLabel" name="textLabel1_2" >
9278
<property name="text" >
9379
<string>To load a plugin, click the checkbox next to the plugin and click Ok</string>
9480
</property>
9581
</widget>
9682
</item>
97-
<item row="3" column="0" >
83+
<item row="4" column="0" >
9884
<layout class="QHBoxLayout" >
99-
<property name="margin" >
100-
<number>11</number>
101-
</property>
10285
<property name="spacing" >
10386
<number>6</number>
10487
</property>
88+
<property name="leftMargin" >
89+
<number>11</number>
90+
</property>
91+
<property name="topMargin" >
92+
<number>11</number>
93+
</property>
94+
<property name="rightMargin" >
95+
<number>11</number>
96+
</property>
97+
<property name="bottomMargin" >
98+
<number>11</number>
99+
</property>
105100
<item>
106101
<spacer>
107102
<property name="orientation" >
@@ -176,17 +171,20 @@
176171
</item>
177172
</layout>
178173
</item>
174+
<item row="2" column="0" >
175+
<widget class="QTableView" name="lstPlugins" >
176+
<property name="alternatingRowColors" >
177+
<bool>true</bool>
178+
</property>
179+
<property name="sortingEnabled" >
180+
<bool>true</bool>
181+
</property>
182+
</widget>
183+
</item>
179184
</layout>
180185
</widget>
181186
<layoutdefault spacing="6" margin="11" />
182187
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
183-
<customwidgets>
184-
<customwidget>
185-
<class>Q3ListView</class>
186-
<extends>Q3Frame</extends>
187-
<header>q3listview.h</header>
188-
</customwidget>
189-
</customwidgets>
190188
<resources/>
191189
<connections/>
192190
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.