Skip to content
Permalink
Browse files
Applied patch from #892 which removes qt3 deps for plugin manager. Mu…
…ito obrigado Fernando!

git-svn-id: http://svn.osgeo.org/qgis/trunk@7858 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 7, 2008
1 parent 089bb37 commit 516e6a5dd796d95cc14e67a6e3dcb611a66def4e
Showing with 173 additions and 120 deletions.
  1. +1 −0 src/app/qgisapp.cpp
  2. +108 −67 src/app/qgspluginmanager.cpp
  3. +15 −2 src/app/qgspluginmanager.h
  4. +49 −51 src/ui/qgspluginmanagerbase.ui
@@ -3717,6 +3717,7 @@ void QgisApp::zoomToLayerExtent()
void QgisApp::showPluginManager()
{
QgsPluginManager *pm = new QgsPluginManager(this);
pm->resizeColumnsToContents();
if (pm->exec())
{
// load selected plugins
@@ -22,7 +22,6 @@
#include <QApplication>
#include <QFileDialog>
#include <QLineEdit>
#include <Q3ListView>
#include <QMessageBox>
#include <QLibrary>
#include <QSettings>
@@ -60,6 +59,7 @@ QgsPluginManager::QgsPluginManager(QWidget * parent, Qt::WFlags fl)
QString libDir = baseDir + "/lib"; */

txtPluginDir->setText(pr->libraryDirectory().path());
setTable();
getPluginDescriptions();
getPythonPluginDescriptions();
}
@@ -69,6 +69,32 @@ QgsPluginManager::~QgsPluginManager()
{
}

void QgsPluginManager::setTable()
{
lstPlugins->setAlternatingRowColors(true);
modelPlugins= new QStandardItemModel(0,4);
modelPlugins->setHorizontalHeaderItem(0,new QStandardItem(tr("Name")));
modelPlugins->setHorizontalHeaderItem(1,new QStandardItem(tr("Version")));
modelPlugins->setHorizontalHeaderItem(2,new QStandardItem(tr("Description")));
modelPlugins->setHorizontalHeaderItem(3,new QStandardItem(tr("Library name")));
lstPlugins->setModel(modelPlugins);
// No vertical headers
lstPlugins->verticalHeader()->hide();
}

void QgsPluginManager::resizeColumnsToContents()
{
// Resize columns to contents.
lstPlugins->resizeColumnsToContents();
QgsDebugMsg("QgsPluginManager::resizeColumnsToContents\n");
}

void QgsPluginManager::sortModel(int column)
{
// Sort column ascending.
modelPlugins->sort(column);
QgsDebugMsg("QgsPluginManager::sortModel\n");
}

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

if (pluginName == "???" || description == "???" || version == "???")
continue;

// add to the list box
Q3CheckListItem *pl = new Q3CheckListItem(lstPlugins, pluginName, Q3CheckListItem::CheckBox);
pl->setText(1, version);
pl->setText(2, description);
pl->setText(3, "python:" + packageName);


//create the items
QStandardItem *myName=new QStandardItem(pluginName);
QStandardItem *myVersion=new QStandardItem(version);
QStandardItem *myDesc=new QStandardItem(description);
QStandardItem *myDir=new QStandardItem("python:" + packageName);
// myName have a checkbox
myName->setCheckable(true);
//read only
myName->setEditable(false);
myVersion->setEditable(false);
myDesc->setEditable(false);
myDir->setEditable(false);

// check to see if the plugin is loaded and set the checkbox accordingly
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();

QString libName = pRegistry->library(pluginName);
if (libName.length() == 0 || !pRegistry->isPythonPlugin(pluginName))
{
@@ -115,9 +148,13 @@ void QgsPluginManager::getPythonPluginDescriptions()
if (libName == packageName)
{
// set the checkbox
pl->setOn(true);
myName->setCheckState(Qt::Checked);
}
}
// Add items to model
QList<QStandardItem *> myItems;
myItems << myName << myVersion << myDesc << myDir;
modelPlugins->appendRow(myItems);
}
#endif
}
@@ -223,10 +260,18 @@ sharedLibExtension = "*.so*";
continue;
}

Q3CheckListItem *pl = new Q3CheckListItem(lstPlugins, pName(), Q3CheckListItem::CheckBox); //, pDesc(), pluginDir[i])
pl->setText(1, pVersion());
pl->setText(2, pDesc());
pl->setText(3, pluginDir[i]);
//create the items
QStandardItem *myName=new QStandardItem(pName());
QStandardItem *myVersion=new QStandardItem(pVersion());
QStandardItem *myDesc=new QStandardItem(pDesc());
QStandardItem *myDir=new QStandardItem(pluginDir[i]);
// myName have a checkbox
myName->setCheckable(true);
//read only
myName->setEditable(false);
myVersion->setEditable(false);
myDesc->setEditable(false);
myDir->setEditable(false);

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

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

delete myLib;
}
}


void QgsPluginManager::on_btnOk_clicked()
{
unload();
@@ -266,59 +314,56 @@ void QgsPluginManager::unload()
#ifdef QGISDEBUG
std::cout << "Checking for plugins to unload" << std::endl;
#endif
Q3CheckListItem *lvi = (Q3CheckListItem *) lstPlugins->firstChild();
while (lvi != 0)
for (int row=0;row < modelPlugins->rowCount();row++)
{
// FPV - I want to use index. You can do evrething with item.
QModelIndex myIndex=modelPlugins->index(row,0);
if (modelPlugins->data(myIndex,Qt::CheckStateRole).toInt() == 0)
{
if (!lvi->isOn())
{
// its off -- see if it is loaded and if so, unload it
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
// its off -- see if it is loaded and if so, unload it
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
#ifdef QGISDEBUG
std::cout << "Checking to see if " << lvi->text(0).toLocal8Bit().data() << " is loaded" << std::endl;
std::cout << "Checking to see if " << modelPlugins->data(myIndex).toString().toLocal8Bit().data() << " is loaded" << std::endl;
#endif

QString pluginName = lvi->text(0);

if (pRegistry->isPythonPlugin(pluginName))
{
QString pluginName = modelPlugins->data(myIndex).toString();
if (pRegistry->isPythonPlugin(pluginName))
{
#ifdef HAVE_PYTHON
QString packageName = pRegistry->library(pluginName);
QgsPythonUtils::unloadPlugin(packageName);

//disable it to the qsettings file
settings.writeEntry("/PythonPlugins/" + packageName, false);
QString packageName = pRegistry->library(pluginName);
QgsPythonUtils::unloadPlugin(packageName);
//disable it to the qsettings file
settings.setValue("/PythonPlugins/" + packageName, false);
#endif
}
else // C++ plugin
{
QgisPlugin *plugin = pRegistry->plugin(pluginName);
if (plugin)
{
plugin->unload();
}
//disable it to the qsettings file [ts]
settings.writeEntry("/Plugins/" + pluginName, false);
}

// remove the plugin from the registry
pRegistry->removePlugin(pluginName);
}
else // C++ plugin
{
QgisPlugin *plugin = pRegistry->plugin(pluginName);
if (plugin)
{
plugin->unload();
}
lvi = (Q3CheckListItem *) lvi->nextSibling();
//disable it to the qsettings file [ts]
settings.setValue("/Plugins/" + pluginName, false);
}
// remove the plugin from the registry
pRegistry->removePlugin(pluginName);
}
}
}

std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
{
std::vector < QgsPluginItem > pis;
Q3CheckListItem *lvi = (Q3CheckListItem *) lstPlugins->firstChild();
while (lvi != 0)
// FPV - I want to use item here. You can do everything with index if you want.
for (int row=0;row < modelPlugins->rowCount();row++)
{
if (lvi->isOn())
QStandardItem *myItem=modelPlugins->item(row,0);
if (modelPlugins->item(row,0)->checkState() == Qt::Checked)
{
QString pluginName = lvi->text(0);
QString pluginName = modelPlugins->item(row,0)->text();
bool pythonic = false;
QString library = lvi->text(3);

QString library = modelPlugins->item(row,3)->text();
if (library.left(7) == "python:")
{
library = library.mid(7);
@@ -328,34 +373,30 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
{
library = txtPluginDir->text() + "/" + library;
}

pis.push_back(QgsPluginItem(pluginName, lvi->text(2), library, 0, pythonic));
pis.push_back(QgsPluginItem(pluginName, modelPlugins->item(row,2)->text(), library, 0, pythonic));
}
lvi = (Q3CheckListItem *) lvi->nextSibling();

}
return pis;
}

void QgsPluginManager::on_btnSelectAll_clicked()
{
// select all plugins
Q3CheckListItem *child = dynamic_cast<Q3CheckListItem *>(lstPlugins->firstChild());
while(child)
for (int row=0;row < modelPlugins->rowCount();row++)
{
child->setOn(true);
child = dynamic_cast<Q3CheckListItem *>(child->nextSibling());
QStandardItem *myItem=modelPlugins->item(row,0);
myItem->setCheckState(Qt::Checked);
}

}

void QgsPluginManager::on_btnClearAll_clicked()
{
// clear all selection checkboxes
Q3CheckListItem *child = dynamic_cast<Q3CheckListItem *>(lstPlugins->firstChild());
while(child)
// clear all selection checkboxes
for (int row=0;row < modelPlugins->rowCount();row++)
{
child->setOn(false);
child = dynamic_cast<Q3CheckListItem *>(child->nextSibling());
QStandardItem *myItem=modelPlugins->item(row,0);
myItem->setCheckState(Qt::Unchecked);
}
}

@@ -19,10 +19,16 @@
#ifndef QGSPLUGINMANAGER_H
#define QGSPLUGINMANAGER_H
#include <vector>
#include <QTableView>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QHeaderView>
#include "ui_qgspluginmanagerbase.h"
#include "qgisgui.h"

class QgsPluginItem;
class QTableView;

/*!
* \brief Plugin manager for loading/unloading plugins
@author Gary Sherman
@@ -43,7 +49,13 @@ class QgsPluginManager : public QDialog, private Ui::QgsPluginManagerBase
void unload();
//! Gets the selected plugins
std::vector<QgsPluginItem> getSelectedPlugins();
public slots:
//! Set lstPlugins table GUI
void setTable();
//! Resize columns to contents
void resizeColumnsToContents();
//! Sort model by column ascending
void sortModel(int );
public slots:
//! Load selected plugins and close the dialog
void on_btnOk_clicked();
//! Select all plugins by setting their checkbox on
@@ -52,7 +64,8 @@ class QgsPluginManager : public QDialog, private Ui::QgsPluginManagerBase
void on_btnClearAll_clicked();
//! Close the dialog
void on_btnClose_clicked();

private:
QStandardItemModel *modelPlugins;
};

#endif
Loading

0 comments on commit 516e6a5

Please sign in to comment.