Skip to content

Commit

Permalink
Refactored grass tools and plugin manager to always use qgsdetailedit…
Browse files Browse the repository at this point in the history
…emdata to represent the info to be display in items. This will let us switch between widget based and manually drawn implementations easily.

git-svn-id: http://svn.osgeo.org/qgis/trunk@8603 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jun 6, 2008
1 parent 4c5e0e1 commit bccd5a3
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 212 deletions.
134 changes: 66 additions & 68 deletions src/app/qgspluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
#include <dlfcn.h>
#endif
#endif


const int PLUGIN_DATA_ROLE=Qt::UserRole;
const int PLUGIN_LIBRARY_ROLE=Qt::UserRole + 1;
const int PLUGIN_LIBRARY_NAME_ROLE=Qt::UserRole + 2;
const int PLUGIN_FILTER_ROLE=Qt::UserRole + 3;

QgsPluginManager::QgsPluginManager(QgsPythonUtils* pythonUtils, QWidget * parent, Qt::WFlags fl)
: QDialog(parent, fl)
{
Expand Down Expand Up @@ -98,7 +105,6 @@ void QgsPluginManager::setTable()
mModelPlugins= new QStandardItemModel(0,1);
mModelProxy = new QSortFilterProxyModel(this);
mModelProxy->setSourceModel(mModelPlugins);
//mModelProxy->setFilterKeyColumn(0);
vwPlugins->setModel(mModelProxy);
vwPlugins->setFocus();
vwPlugins->setItemDelegateForColumn(0,new QgsDetailedItemDelegate());
Expand Down Expand Up @@ -138,31 +144,28 @@ void QgsPluginManager::getPythonPluginDescriptions()
QString description = mPythonUtils->getPluginMetadata(packageName, "description");
QString version = mPythonUtils->getPluginMetadata(packageName, "version");

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

// We will create two items for each row:
// The first has the following roles :
// - DisplayRole : the name and version of the version of the plugin e.g. Plugin Foo (version 1.0)
// - UserRole : the description of the plugin.
// And the second has these roles :
// - DisplayRole : the library name (without path) for the plugin e.g. libfoo.so
// - UserRole : the name of the plugin without version e.g. plugin foor
// The plugin name without version is used elsewhere in this class to match
// aganst plugins loaded in the plugin registry
QStandardItem * mypDetailItem = new QStandardItem(
pluginName + " (" + version + ")");
mypDetailItem->setData(description,Qt::UserRole);
QStandardItem * mypDetailItem = new QStandardItem( pluginName );
QString myLibraryName = "python:" + packageName;;
QStandardItem * mypLibraryNameItem = new QStandardItem(myLibraryName);
mypLibraryNameItem->setData(pluginName,Qt::UserRole);
// myName have a checkbox
mypDetailItem->setCheckable(true);
mypDetailItem->setData(myLibraryName, PLUGIN_LIBRARY_ROLE); //for loading libs later
mypDetailItem->setData(pluginName, PLUGIN_LIBRARY_NAME_ROLE); //for matching in registry later
QString mySearchText = pluginName + " - " + description;
mypDetailItem->setData(mySearchText , PLUGIN_FILTER_ROLE); //for filtering later
mypDetailItem->setCheckable(false);
mypDetailItem->setEditable(false);
// setData in the delegate with a variantised QgsDetailedItemData
QgsDetailedItemData myData;
myData.setTitle(pluginName + " (" + version + ")");
myData.setDetail(description);
//myData.setIcon(pixmap); //todo use a python logo here
myData.setCheckable(true);
myData.setRenderAsWidget(false);
QVariant myVariant = qVariantFromValue(myData);
mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);

// 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))
{
Expand All @@ -177,10 +180,8 @@ void QgsPluginManager::getPythonPluginDescriptions()
mypDetailItem->setCheckState(Qt::Checked);
}
}
// Add items to model
QList<QStandardItem *> myItems;
myItems << mypDetailItem << mypLibraryNameItem;
mModelPlugins->appendRow(myItems);
// Add item to model
mModelPlugins->appendRow(mypDetailItem);
}
}

Expand Down Expand Up @@ -262,19 +263,28 @@ sharedLibExtension = "*.so*";
version_t *pVersion = (version_t *) myLib->resolve("version");

// show the values (or lack of) for each function
if(pName){
if(pName)
{
QgsDebugMsg("Plugin name: " + pName());
}else{
}
else
{
QgsDebugMsg("Plugin name not returned when queried\n");
}
if(pDesc){
if(pDesc)
{
QgsDebugMsg("Plugin description: " + pDesc());
}else{
}
else
{
QgsDebugMsg("Plugin description not returned when queried\n");
}
if(pVersion){
if(pVersion)
{
QgsDebugMsg("Plugin version: " + pVersion());
}else{
}
else
{
QgsDebugMsg("Plugin version not returned when queried\n");
}

Expand All @@ -285,39 +295,20 @@ sharedLibExtension = "*.so*";
continue;
}

// We will create two items for each row:
// The first has the following roles :
// - DisplayRole : the name and version of the version of the plugin e.g. Plugin Foo (version 1.0)
// - UserRole : the description of the plugin.
// And the second has these roles :
// - DisplayRole : the library name (without path) for the plugin e.g. libfoo.so
// - UserRole : the name of the plugin without version e.g. plugin foor
// The plugin name without version is used elsewhere in this class to match
// aganst plugins loaded in the plugin registry

QStandardItem * mypDetailItem = new QStandardItem(
pName() + " (" + pVersion() + ")");
//
// Uncomment this block to render item using simple painter technique
//
mypDetailItem->setData(pDesc(),Qt::UserRole);
//
//Uncomment this block to used widget based detail items (experimental)
//
/*
QString myLibraryName = pluginDir[i];
QStandardItem * mypDetailItem = new QStandardItem(myLibraryName);
mypDetailItem->setData(myLibraryName,PLUGIN_LIBRARY_ROLE);
mypDetailItem->setData(pName(), PLUGIN_LIBRARY_NAME_ROLE); //for matching in registry later
QgsDetailedItemData myData;
myData.setTitle(pName());
myData.setDetail(pDesc());
myData.setRenderAsWidget(false);
QVariant myVariant = qVariantFromValue(myData);
//round trip test - delete this...no need to uncomment
//QgsDetailedItemData myData2 = qVariantValue<QgsDetailedItemData>(myVariant);
//Q_ASSERT(myData.title() == myData2.title());
//round trip test ends
mypDetailItem->setData(myVariant,Qt::UserRole);
*/
QString myLibraryName = pluginDir[i];
QStandardItem * mypLibraryNameItem = new QStandardItem(myLibraryName);
mypLibraryNameItem->setData(pName(),Qt::UserRole);
mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
// Let the first col have a checkbox
mypDetailItem->setCheckable(true);
mypDetailItem->setEditable(false);
Expand All @@ -326,9 +317,9 @@ sharedLibExtension = "*.so*";

// check to see if the plugin is loaded and set the checkbox accordingly
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
QString libName = pRegistry->library(pName());

// get the library using the plugin description
QString libName = pRegistry->library(pName());
if (libName.length() == 0)
{
QgsDebugMsg("Couldn't find library name in the registry");
Expand All @@ -343,9 +334,7 @@ sharedLibExtension = "*.so*";
}
}
// Add items to model
QList<QStandardItem *> myItems;
myItems << mypDetailItem << mypLibraryNameItem;
mModelPlugins->appendRow(myItems);
mModelPlugins->appendRow(mypDetailItem);

delete myLib;
}
Expand All @@ -369,15 +358,16 @@ void QgsPluginManager::unload()
QModelIndex myIndex=mModelPlugins->index(row,0);
if (mModelPlugins->data(myIndex,Qt::CheckStateRole).toInt() == 0)
{
// Get the second col index now since it stores the
// plugin name without version string in its data UserRole [ts]
myIndex=mModelPlugins->index(row,1);
// iThe plugin name without version string in its data PLUGIN_LIB [ts]
myIndex=mModelPlugins->index(row,0);
// its off -- see if it is loaded and if so, unload it
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
#ifdef QGISDEBUG
std::cout << "Checking to see if " << mModelPlugins->data(myIndex, Qt::UserRole).toString().toLocal8Bit().data() << " is loaded" << std::endl;
std::cout << "Checking to see if " <<
mModelPlugins->data(myIndex, PLUGIN_LIBRARY_NAME_ROLE).toString().toLocal8Bit().data() <<
" is loaded" << std::endl;
#endif
QString pluginName = mModelPlugins->data(myIndex,Qt::UserRole).toString();
QString pluginName = mModelPlugins->data(myIndex,PLUGIN_LIBRARY_NAME_ROLE).toString();
if (pRegistry->isPythonPlugin(pluginName))
{
if (mPythonUtils && mPythonUtils->isEnabled())
Expand Down Expand Up @@ -412,10 +402,10 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
{
if (mModelPlugins->item(row,0)->checkState() == Qt::Checked)
{
QString pluginName = mModelPlugins->item(row,1)->data(Qt::UserRole).toString();
QString pluginName = mModelPlugins->item(row,0)->data(PLUGIN_LIBRARY_NAME_ROLE).toString();
bool pythonic = false;

QString library = mModelPlugins->item(row,1)->text();
QString library = mModelPlugins->item(row,0)->data(PLUGIN_LIBRARY_ROLE).toString();
if (library.left(7) == "python:")
{
library = library.mid(7);
Expand All @@ -425,7 +415,15 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
{
library = lblPluginDir->text() + QDir::separator() + library;
}
pis.push_back(QgsPluginItem(pluginName, mModelPlugins->item(row,0)->text(), library, 0, pythonic));
// Ctor params for plugin item:
//QgsPluginItem(QString name=0,
// QString description=0,
// QString fullPath=0,
// QString type=0,
// bool python=false);
pis.push_back(QgsPluginItem(pluginName,
mModelPlugins->item(row,0)->data(PLUGIN_FILTER_ROLE).toString(),
library, 0, pythonic));
}

}
Expand Down Expand Up @@ -462,7 +460,7 @@ void QgsPluginManager::on_vwPlugins_clicked(const QModelIndex &theIndex )
// little hoop to get the correct item
//
QStandardItem * mypItem =
mModelPlugins->findItems(theIndex.data(Qt::DisplayRole).toString()).first();
mModelPlugins->findItems(theIndex.data(Qt ::DisplayRole).toString()).first();
if ( mypItem->checkState() == Qt::Checked )
{
mypItem->setCheckState(Qt::Unchecked);
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsdetaileditemdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsdetaileditemdata.h"
QgsDetailedItemData::QgsDetailedItemData()
{
mRenderAsWidgetFlag=false;
}

QgsDetailedItemData::~QgsDetailedItemData()
Expand Down Expand Up @@ -47,6 +48,10 @@ void QgsDetailedItemData::setChecked(bool theFlag)
{
mCheckedFlag = theFlag;
}
void QgsDetailedItemData::setRenderAsWidget(bool theFlag)
{
mRenderAsWidgetFlag = theFlag;
}

QString QgsDetailedItemData::title()
{
Expand All @@ -72,3 +77,9 @@ bool QgsDetailedItemData::isChecked()
{
return mCheckedFlag;
}

bool QgsDetailedItemData::isRenderedAsWidget()
{
return mRenderAsWidgetFlag;
}

9 changes: 9 additions & 0 deletions src/gui/qgsdetaileditemdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ class QgsDetailedItemData
void setIcon(QPixmap theIcon);
void setCheckable(bool theFlag);
void setChecked(bool theFlag);
/** This is a hint to the delegate to render using
* a widget rather than manually painting every
* part of the list item.
* @note the delegate may completely ignore this
* depending on the delegate implementation.
*/
void setRenderAsWidget(bool theFlag);

QString title();
QString detail();
QPixmap icon();
bool isCheckable();
bool isChecked();
bool isRenderedAsWidget();

private:
QString mTitle;
Expand All @@ -50,6 +58,7 @@ class QgsDetailedItemData
QPixmap mPixmap;
bool mCheckableFlag;
bool mCheckedFlag;
bool mRenderAsWidgetFlag;
};

// Make QVariant aware of this data type (see qtdocs star
Expand Down
Loading

0 comments on commit bccd5a3

Please sign in to comment.