Skip to content

Commit c093ab9

Browse files
committedSep 15, 2013
[Plugin Manager] New tab for all plugins. New class QgsPluginItemDelegate
1 parent b49df73 commit c093ab9

File tree

9 files changed

+207
-42
lines changed

9 files changed

+207
-42
lines changed
 

‎python/pyplugin_installer/installer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ def checkingDone(self):
143143
for key in plugins.all():
144144
if plugins.all()[key]["status"] == "new":
145145
status = self.tr("There is a new plugin available")
146-
tabIndex = 3 # tab 3 contains new plugins
146+
tabIndex = 4 # PLUGMAN_TAB_NEW
147147
# then check for updates (and eventually overwrite status)
148148
for key in plugins.all():
149149
if plugins.all()[key]["status"] == "upgradeable":
150150
status = self.tr("There is a plugin update available")
151-
tabIndex = 2 # tab 2 contains upgradeable plugins
151+
tabIndex = 3 # PLUGMAN_TAB_UPGRADEABLE
152152
# finally set the notify label
153153
if status:
154154
self.statusLabel.setText(u' <a href="%d">%s</a> ' % (tabIndex,status) )

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ SET(QGIS_APP_SRCS
152152
pluginmanager/qgspluginmanager_texts.cpp
153153
pluginmanager/qgsapppluginmanagerinterface.cpp
154154
pluginmanager/qgspluginsortfilterproxymodel.cpp
155+
pluginmanager/qgspluginitemdelegate.cpp
155156

156157
qgsnewspatialitelayerdialog.cpp
157158
)
@@ -286,6 +287,7 @@ SET (QGIS_APP_MOC_HDRS
286287
pluginmanager/qgspluginmanager.h
287288
pluginmanager/qgsapppluginmanagerinterface.h
288289
pluginmanager/qgspluginsortfilterproxymodel.h
290+
pluginmanager/qgspluginitemdelegate.h
289291

290292
qgsnewspatialitelayerdialog.h
291293
)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/***************************************************************************
2+
qgspluginitemdelegate.cpp - a QItemDelegate subclass for plugin manager
3+
-------------------
4+
begin : Fri Sep 13 2013, Brighton HF
5+
copyright : (C) 2013 Borys Jurgiel
6+
email : info@borysjurgiel.pl
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgspluginitemdelegate.h"
19+
#include <QPainter>
20+
#include <QFont>
21+
#include <QStyleOptionViewItem>
22+
#include <QModelIndex>
23+
#include <QApplication>
24+
#include "qgspluginsortfilterproxymodel.h"
25+
26+
27+
QgsPluginItemDelegate::QgsPluginItemDelegate( QObject * parent ) : QStyledItemDelegate( parent ) {}
28+
29+
30+
QSize QgsPluginItemDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const
31+
{
32+
Q_UNUSED( option );
33+
Q_UNUSED( index );
34+
return QSize( 20, 20 );
35+
}
36+
37+
38+
void QgsPluginItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
39+
{
40+
painter->save();
41+
painter->setRenderHint( QPainter::SmoothPixmapTransform );
42+
QStyle *style = QApplication::style();
43+
44+
// Draw the background
45+
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
46+
47+
// Draw the checkbox
48+
if ( index.flags() & Qt::ItemIsUserCheckable )
49+
{
50+
QStyleOptionButton checkBoxStyle;
51+
checkBoxStyle.rect = option.rect;
52+
if ( index.data( Qt::CheckStateRole ).toBool() )
53+
{
54+
checkBoxStyle.state = QStyle::State_On|QStyle::State_Enabled;
55+
}
56+
else
57+
{
58+
checkBoxStyle.state = QStyle::State_Off|QStyle::State_Enabled;
59+
}
60+
style->drawControl( QStyle::CE_CheckBox, &checkBoxStyle, painter );
61+
}
62+
63+
// Draw the icon
64+
QPixmap iconPixmap = index.data( Qt::DecorationRole ).value<QPixmap>();
65+
66+
if ( !iconPixmap.isNull() )
67+
{
68+
int iconSize = option.rect.height();
69+
painter->drawPixmap( option.rect.left() + 24 , option.rect.top(), iconSize, iconSize, iconPixmap );
70+
}
71+
72+
// Draw the text
73+
if ( option.state & QStyle::State_Selected )
74+
{
75+
painter->setPen( option.palette.highlightedText().color() );
76+
}
77+
else
78+
{
79+
painter->setPen( option.palette.text().color() );
80+
}
81+
82+
if ( ! index.data( PLUGIN_ERROR_ROLE ).toString().isEmpty() )
83+
{
84+
painter->setPen( Qt::red );
85+
}
86+
87+
if ( ! index.data( PLUGIN_ERROR_ROLE ).toString().isEmpty()
88+
|| index.data( PLUGIN_STATUS_ROLE ).toString() == QString( "upgradeable" )
89+
|| index.data( PLUGIN_STATUS_ROLE ).toString() == QString( "new" ) )
90+
{
91+
QFont font = painter->font();
92+
font.setBold( true );
93+
painter->setFont( font );
94+
}
95+
96+
painter->drawText( option.rect.left() + 48 , option.rect.bottom() - 3 , index.data( Qt::DisplayRole ).toString() );
97+
98+
painter->restore();
99+
}
100+
101+
102+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/***************************************************************************
2+
qgspluginitemdelegate.h - a QItemDelegate subclass for plugin manager
3+
-------------------
4+
begin : Fri Sep 13 2013, Brighton HF
5+
copyright : (C) 2013 Borys Jurgiel
6+
email : info@borysjurgiel.pl
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
#ifndef QGSPLUGINITEMDELEGATE_H
18+
#define QGSPLUGINITEMDELEGATE_H
19+
20+
#include <QStyledItemDelegate>
21+
22+
/**
23+
* A custom model/view delegate that can eithe display checkbox or empty space for proprer text alignment
24+
*/
25+
class QgsPluginItemDelegate : public QStyledItemDelegate
26+
{
27+
Q_OBJECT
28+
public:
29+
QgsPluginItemDelegate( QObject * parent = 0 );
30+
QSize sizeHint( const QStyleOptionViewItem & theOption, const QModelIndex & theIndex ) const;
31+
void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
32+
};
33+
34+
#endif //QGSPLUGINITEMDELEGATE_H

‎src/app/pluginmanager/qgspluginmanager.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "qgspluginmanager.h"
4040
#include "qgisplugin.h"
4141
#include "qgslogger.h"
42+
#include "qgspluginitemdelegate.h"
4243

4344
// Do we need this?
4445
// #define TESTLIB
@@ -87,6 +88,7 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
8788
mModelProxy->setDynamicSortFilter( true );
8889
mModelProxy->sort( 0, Qt::AscendingOrder );
8990
vwPlugins->setModel( mModelProxy );
91+
vwPlugins->setItemDelegate( new QgsPluginItemDelegate( vwPlugins ) );
9092
vwPlugins->setFocus();
9193

9294
// Preset widgets
@@ -493,29 +495,15 @@ void QgsPluginManager::reloadModelData()
493495

494496
if ( QFileInfo( iconPath ).isFile() )
495497
{
496-
mypDetailItem->setIcon( QPixmap( iconPath ) );
498+
mypDetailItem->setData( QPixmap( iconPath ), Qt::DecorationRole );
497499
}
498500
else
499501
{
500-
mypDetailItem->setIcon( QPixmap( QgsApplication::defaultThemePath() + "/plugin.png" ) );
502+
mypDetailItem->setData( QPixmap( QgsApplication::defaultThemePath() + "/plugin.png" ), Qt::DecorationRole );
501503
}
502504

503505
mypDetailItem->setEditable( false );
504506

505-
// set item display style
506-
if ( ! it->value( "error" ).isEmpty() )
507-
{
508-
QBrush brush = mypDetailItem->foreground();
509-
brush.setColor( Qt::red );
510-
mypDetailItem->setForeground( brush );
511-
}
512-
if ( ! it->value( "error" ).isEmpty() || it->value( "status" ) == "upgradeable" || it->value( "status" ) == "new" )
513-
{
514-
QFont font = mypDetailItem->font();
515-
font.setBold( true );
516-
mypDetailItem->setFont( font );
517-
}
518-
519507
// Set checkable if the plugin is installed and not disabled due to incompatibility.
520508
// Broken plugins are checkable to to allow disabling them
521509
mypDetailItem->setCheckable( it->value( "installed" ) == "true" && it->value( "error" ) != "incompatible" );
@@ -552,17 +540,18 @@ void QgsPluginManager::reloadModelData()
552540
if ( hasReinstallablePlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Reinstallable", "category: plugins that are installed and available" ) , "installedZ" ) );
553541
if ( hasUpgradeablePlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Upgradeable", "category: plugins that are installed and there is a newer version available" ), "upgradeableZ" ) );
554542
if ( hasNewerPlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Downgradeable", "category: plugins that are installed and there is an OLDER version available" ), "newerZ" ) );
543+
if ( hasAvailablePlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Installable", "category: plugins that are available for installation" ), "not installedZ" ) );
555544
}
556545

557546
updateTabTitle();
558547

559548
buttonUpgradeAll->setEnabled( hasUpgradeablePlugins() );
560549

561550
// Disable tabs that are empty because of no suitable plugins in the model.
562-
mOptionsListWidget->item( 1 )->setHidden( ! hasAvailablePlugins() );
563-
mOptionsListWidget->item( 2 )->setHidden( ! hasUpgradeablePlugins() );
564-
mOptionsListWidget->item( 3 )->setHidden( ! hasNewPlugins() );
565-
mOptionsListWidget->item( 4 )->setHidden( ! hasInvalidPlugins() );
551+
mOptionsListWidget->item( PLUGMAN_TAB_NOT_INSTALLED )->setHidden( ! hasAvailablePlugins() );
552+
mOptionsListWidget->item( PLUGMAN_TAB_UPGRADEABLE )->setHidden( ! hasUpgradeablePlugins() );
553+
mOptionsListWidget->item( PLUGMAN_TAB_NEW )->setHidden( ! hasNewPlugins() );
554+
mOptionsListWidget->item( PLUGMAN_TAB_INVALID )->setHidden( ! hasInvalidPlugins() );
566555
}
567556

568557

@@ -973,27 +962,32 @@ void QgsPluginManager::setCurrentTab( int idx )
973962
QString tabTitle;
974963
switch ( idx )
975964
{
976-
case 0:
965+
case PLUGMAN_TAB_ALL:
966+
// all (statuses ends with Z are for spacers to always sort properly)
967+
acceptedStatuses << "installed" << "not installed" << "orphan" << "newer" << "upgradeable" << "not installedZ" << "installedZ" << "upgradeableZ" << "orphanZ" << "newerZZ" << "" ;
968+
tabTitle = "all_plugins";
969+
break;
970+
case PLUGMAN_TAB_INSTALLED:
977971
// installed (statuses ends with Z are for spacers to always sort properly)
978972
acceptedStatuses << "installed" << "orphan" << "newer" << "upgradeable" << "installedZ" << "upgradeableZ" << "orphanZ" << "newerZZ" << "" ;
979973
tabTitle = "installed_plugins";
980974
break;
981-
case 1:
975+
case PLUGMAN_TAB_NOT_INSTALLED:
982976
// not installed (get more)
983977
acceptedStatuses << "not installed" << "new" ;
984-
tabTitle = "get_more_plugins";
978+
tabTitle = "not_installed_plugins";
985979
break;
986-
case 2:
980+
case PLUGMAN_TAB_UPGRADEABLE:
987981
// upgradeable
988982
acceptedStatuses << "upgradeable" ;
989983
tabTitle = "upgradeable_plugins";
990984
break;
991-
case 3:
985+
case PLUGMAN_TAB_NEW:
992986
// new
993987
acceptedStatuses << "new" ;
994988
tabTitle = "new_plugins";
995989
break;
996-
case 4:
990+
case PLUGMAN_TAB_INVALID:
997991
// invalid
998992
acceptedStatuses << "invalid" ;
999993
tabTitle = "invalid_plugins";

‎src/app/pluginmanager/qgspluginmanager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include "qgspythonutils.h"
3131
#include "qgspluginsortfilterproxymodel.h"
3232

33+
const int PLUGMAN_TAB_ALL = 0;
34+
const int PLUGMAN_TAB_INSTALLED = 1;
35+
const int PLUGMAN_TAB_NOT_INSTALLED = 2;
36+
const int PLUGMAN_TAB_UPGRADEABLE = 3;
37+
const int PLUGMAN_TAB_NEW = 4;
38+
const int PLUGMAN_TAB_INVALID = 5;
39+
3340
/*!
3441
* \brief Plugin manager for browsing, (un)installing and (un)loading plugins
3542
@author Gary Sherman

‎src/app/pluginmanager/qgspluginmanager_texts.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,39 @@ void QgsPluginManager::initTabDescriptions()
88
if ( !mTabDescriptions.isEmpty() )
99
return;
1010

11-
mTabDescriptions.insert( "installed_plugins", tr( "<h3>Installed Plugins</h3>\
11+
mTabDescriptions.insert( "all_plugins", tr( "<h3>All Plugins</h3>\
12+
\
1213
<p>\
13-
On the left you see the list of <b>installed plugins</b> on your system. Both python and cpp \
14-
plugins are listed. Some plugins come with your QGIS installation while most of\
15-
them are made available via the plugin repositories.\
14+
On the left you see the list of all plugins available for your QGIS, both installed and available for download. \
15+
Some plugins come with your QGIS installation while most of them are made available via the plugin repositories.\
1616
</p>\
1717
\
1818
<p>\
1919
You can temporarily enable or disable a plugin.\
20-
To <i>enable</i> or <i>disable</i> a plugin,\
21-
click its checkbox or doubleclick its name...\
20+
To <i>enable</i> or <i>disable</i> a plugin, click its checkbox or doubleclick its name...\
2221
</p>\
2322
\
2423
<p>\
25-
Plugins showing in <span style='color:red'>red</span> are not loaded because there is a problem. Consult the \
26-
'Invalid' tab to see more details, or to reinstall or uninstall this plugin.\
24+
Plugins showing in <span style='color:red'>red</span> are not loaded because there is a problem. They are also listed \
25+
on the 'Invalid' tab. Click on the plugin name to see more details, or to reinstall or uninstall this plugin.\
26+
</p>\
27+
" ) );
28+
29+
30+
31+
mTabDescriptions.insert( "installed_plugins", tr( "<h3>Installed Plugins</h3>\
32+
\
33+
<p>\
34+
Here you only see plugins <b>installed on your QGIS</b>.\
35+
</p>\
36+
<p>\
37+
Click on the name to see details. \
38+
</p>\
39+
<p>\
40+
Click the checkbox or doubleclick the name to <i>activate</i> or <i>deactivate</i> the plugin.\
41+
</p>\
42+
<p>\
43+
You can change the sorting via the context menu (right click).\
2744
</p>\
2845
" ) );
2946

@@ -40,7 +57,7 @@ plugins are available in the repositories.\
4057

4158

4259

43-
mTabDescriptions.insert( "get_more_plugins", tr( "<h3>Get more plugins</h3>\
60+
mTabDescriptions.insert( "not_installed_plugins", tr( "<h3>Not installed plugins</h3>\
4461
\
4562
<p>\
4663
Here you see the list of all plugins available in the repositories, but which are <b>not yet installed</b>.\

‎src/app/pluginmanager/qgspluginsortfilterproxymodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool QgsPluginSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QMode
3232
{
3333
// it's a status spacer.
3434
// TODO: the condition below is only suitable for status spacers
35-
return ( filterByStatus( inx ) && mAcceptedStatuses.count() > 1 && sourceModel()->data( inx, SPACER_ROLE ).toString() == mAcceptedSpacers );
35+
return ( filterByStatus( inx ) && mAcceptedStatuses.count() > 2 && sourceModel()->data( inx, SPACER_ROLE ).toString() == mAcceptedSpacers );
3636
}
3737

3838
return ( filterByStatus( inx ) && sourceModel()->data( inx, filterRole() ).toString().contains( filterRegExp() ) );

‎src/ui/qgspluginmanagerbase.ui

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@
104104
<property name="wordWrap">
105105
<bool>true</bool>
106106
</property>
107+
<item>
108+
<property name="text">
109+
<string>All</string>
110+
</property>
111+
<property name="icon">
112+
<iconset resource="../../images/images.qrc">
113+
<normaloff>:/images/themes/default/propertyicons/plugins.svg</normaloff>:/images/themes/default/propertyicons/plugins.svg</iconset>
114+
</property>
115+
</item>
107116
<item>
108117
<property name="text">
109118
<string>Installed</string>
@@ -121,14 +130,14 @@
121130
</item>
122131
<item>
123132
<property name="text">
124-
<string>Get more</string>
133+
<string>Not installed</string>
125134
</property>
126135
<property name="toolTip">
127136
<string>Not installed plugins available for download</string>
128137
</property>
129138
<property name="icon">
130139
<iconset resource="../../images/images.qrc">
131-
<normaloff>:/images/themes/default/propertyicons/plugins.svg</normaloff>:/images/themes/default/propertyicons/plugins.svg</iconset>
140+
<normaloff>:/images/themes/default/propertyicons/plugin.svg</normaloff>:/images/themes/default/propertyicons/plugin.svg</iconset>
132141
</property>
133142
<property name="flags">
134143
<set>ItemIsSelectable|ItemIsEnabled</set>
@@ -556,8 +565,8 @@
556565
<rect>
557566
<x>0</x>
558567
<y>0</y>
559-
<width>547</width>
560-
<height>748</height>
568+
<width>352</width>
569+
<height>758</height>
561570
</rect>
562571
</property>
563572
<layout class="QVBoxLayout" name="verticalLayout_10">

0 commit comments

Comments
 (0)
Please sign in to comment.