Skip to content

Commit 3a4648f

Browse files
author
timlinux
committedJul 28, 2008
Theme related fixes:
- implemented 'fall back' support so that if a theme is missing icons, the default theme icons will be used instead. - use a static function in qgisapp to get theme icons and pixmaps - updated all icon fetching code to use the new methods above - updated qgsapplication so that it differentiates between active and default themes - fixed a bug in qgsoptions that prevented themes being changed in some cases. This is a part fix for #1054 - still need to do some work to make GRASS theming work properly git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8937 c8812cc2-4d05-0410-92ff-de0c093fc19c

34 files changed

+2532
-1543
lines changed
 

‎python/core/qgsapplication.sip‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
8282

8383
virtual ~QgsApplication();
8484

85-
//! Set the theme path to the specified theme.
86-
static void selectTheme(const QString theThemeName);
85+
//! Set the active theme path to the specified theme.
86+
static void setTheme(const QString theThemeName);
8787

8888
//! Returns the path to the authors file.
8989
static const QString authorsFilePath();
@@ -130,8 +130,11 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
130130
//! Returns the common root path of all application data directories.
131131
static const QString pkgDataPath();
132132

133-
//! Returns the path to the current theme directory.
134-
static const QString themePath();
133+
//! Returns the path to the currently active theme directory.
134+
static const QString activeThemePath();
135+
136+
//! Returns the path to the default theme directory.
137+
static const QString defaultThemePath();
135138

136139
//! Alters prefix path - used by 3rd party apps
137140
static void setPrefixPath(const QString thePrefixPath, bool useDefaultPaths = FALSE);

‎src/app/composer/qgscomposer.cpp‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,22 @@ QgsComposer::~QgsComposer()
109109

110110
void QgsComposer::setupTheme()
111111
{
112-
//calculate the active theme path
113-
QString myThemePath= QgsApplication::themePath();
114-
115-
116112
//now set all the icons
117-
mActionOpenTemplate->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileOpen.png")));
118-
mActionSaveTemplateAs->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSaveAs.png")));
119-
mActionExportAsImage->setIcon(QIcon(QPixmap(myThemePath + "/mActionExportMapServer.png")));
120-
mActionExportAsSVG->setIcon(QIcon(QPixmap(myThemePath + "/mActionSaveAsSVG.png")));
121-
mActionPrint->setIcon(QIcon(QPixmap(myThemePath + "/mActionFilePrint.png")));
122-
mActionZoomAll->setIcon(QIcon(QPixmap(myThemePath + "/mActionZoomFullExtent.png")));
123-
mActionZoomIn->setIcon(QIcon(QPixmap(myThemePath + "/mActionZoomIn.png")));
124-
mActionZoomOut->setIcon(QIcon(QPixmap(myThemePath + "/mActionZoomOut.png")));
125-
mActionRefreshView->setIcon(QIcon(QPixmap(myThemePath + "/mActionDraw.png")));
126-
mActionAddImage->setIcon(QIcon(QPixmap(myThemePath + "/mActionSaveMapAsImage.png")));
127-
mActionAddNewMap->setIcon(QIcon(QPixmap(myThemePath + "/mActionAddRasterLayer.png")));
128-
mActionAddNewLabel->setIcon(QIcon(QPixmap(myThemePath + "/mActionLabel.png")));
129-
mActionAddNewVectLegend->setIcon(QIcon(QPixmap(myThemePath + "/mActionAddLegend.png")));
130-
mActionAddNewScalebar->setIcon(QIcon(QPixmap(myThemePath + "/mActionScaleBar.png")));
131-
mActionSelectMoveItem->setIcon(QIcon(QPixmap(myThemePath + "/mActionPan.png")));
113+
mActionOpenTemplate->setIcon(QgisApp::getThemeIcon("/mActionFileOpen.png"));
114+
mActionSaveTemplateAs->setIcon(QgisApp::getThemeIcon("/mActionFileSaveAs.png"));
115+
mActionExportAsImage->setIcon(QgisApp::getThemeIcon("/mActionExportMapServer.png"));
116+
mActionExportAsSVG->setIcon(QgisApp::getThemeIcon("/mActionSaveAsSVG.png"));
117+
mActionPrint->setIcon(QgisApp::getThemeIcon("/mActionFilePrint.png"));
118+
mActionZoomAll->setIcon(QgisApp::getThemeIcon("/mActionZoomFullExtent.png"));
119+
mActionZoomIn->setIcon(QgisApp::getThemeIcon("/mActionZoomIn.png"));
120+
mActionZoomOut->setIcon(QgisApp::getThemeIcon("/mActionZoomOut.png"));
121+
mActionRefreshView->setIcon(QgisApp::getThemeIcon("/mActionDraw.png"));
122+
mActionAddImage->setIcon(QgisApp::getThemeIcon("/mActionSaveMapAsImage.png"));
123+
mActionAddNewMap->setIcon(QgisApp::getThemeIcon("/mActionAddRasterLayer.png"));
124+
mActionAddNewLabel->setIcon(QgisApp::getThemeIcon("/mActionLabel.png"));
125+
mActionAddNewVectLegend->setIcon(QgisApp::getThemeIcon("/mActionAddLegend.png"));
126+
mActionAddNewScalebar->setIcon(QgisApp::getThemeIcon("/mActionScaleBar.png"));
127+
mActionSelectMoveItem->setIcon(QgisApp::getThemeIcon("/mActionPan.png"));
132128
}
133129

134130
void QgsComposer::open ( void )

‎src/app/legend/qgslegend.cpp‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/* $Id$ */
2020

2121
#include "qgsapplication.h"
22+
#include "qgisapp.h"
2223
#include "qgslogger.h"
2324
#include "qgslegend.h"
2425
#include "qgslegendgroup.h"
@@ -87,8 +88,9 @@ QgsLegend::QgsLegend(QWidget * parent, const char *name)
8788
setColumnCount(1);
8889
header()->setHidden(1);
8990
setRootIsDecorated(true);
90-
9191
initPixmaps();
92+
93+
9294
}
9395

9496

@@ -400,8 +402,6 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
400402

401403
QMenu theMenu;
402404

403-
QString iconsPath = QgsApplication::themePath();
404-
405405
QgsLegendItem* li = dynamic_cast<QgsLegendItem*>(item);
406406
if (li)
407407
{
@@ -422,7 +422,7 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
422422
}
423423
else if(li->type() == QgsLegendItem::LEGEND_GROUP)
424424
{
425-
theMenu.addAction(QPixmap(iconsPath+QString("/mActionRemove.png")),
425+
theMenu.addAction(QgisApp::getThemeIcon("/mActionRemove.png"),
426426
tr("&Remove"), this, SLOT(legendGroupRemove()));
427427
}
428428

@@ -433,9 +433,9 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
433433

434434
}
435435

436-
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/folder_new.png"))), tr("&Add group"), this, SLOT(addGroup()));
437-
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionExpandTree.png"))), tr("&Expand all"), this, SLOT(expandAll()));
438-
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionCollapseTree.png"))), tr("&Collapse all"), this, SLOT(collapseAll()));
436+
theMenu.addAction(QgisApp::getThemeIcon("/folder_new.png"), tr("&Add group"), this, SLOT(addGroup()));
437+
theMenu.addAction(QgisApp::getThemeIcon("/mActionExpandTree.png"), tr("&Expand all"), this, SLOT(expandAll()));
438+
theMenu.addAction(QgisApp::getThemeIcon("/mActionCollapseTree.png"), tr("&Collapse all"), this, SLOT(collapseAll()));
439439

440440
QAction* showFileGroupsAction = theMenu.addAction(tr("Show file groups"), this, SLOT(showLegendLayerFileGroups()));
441441
showFileGroupsAction->setCheckable(true);
@@ -445,6 +445,14 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
445445
theMenu.exec(position);
446446
}
447447

448+
void QgsLegend::initPixmaps()
449+
{
450+
mPixmaps.mOriginalPixmap = QgisApp::getThemePixmap("/mActionFileSmall.png");
451+
mPixmaps.mInOverviewPixmap = QgisApp::getThemePixmap("/mActionInOverview.png");
452+
mPixmaps.mEditablePixmap = QgisApp::getThemePixmap("/mIconEditable.png");
453+
mPixmaps.mProjectionErrorPixmap = QgisApp::getThemePixmap("/mIconProjectionProblem.png");
454+
}
455+
448456
int QgsLegend::getItemPos(QTreeWidgetItem* item)
449457
{
450458
int counter = 1;
@@ -1828,15 +1836,6 @@ void QgsLegend::legendLayerAttributeTable()
18281836
tr("To open an attribute table, you must select a vector layer in the legend"));
18291837
}
18301838

1831-
void QgsLegend::initPixmaps()
1832-
{
1833-
QString myThemePath = QgsApplication::themePath();
1834-
mPixmaps.mOriginalPixmap.load(myThemePath + "/mActionFileSmall.png");
1835-
mPixmaps.mInOverviewPixmap.load(myThemePath + "/mActionInOverview.png");
1836-
mPixmaps.mEditablePixmap.load(myThemePath + "/mIconEditable.png");
1837-
mPixmaps.mProjectionErrorPixmap.load(myThemePath + "/mIconProjectionProblem.png");
1838-
}
1839-
18401839
void QgsLegend::readProject(const QDomDocument & doc)
18411840
{
18421841
QDomNodeList nodes = doc.elementsByTagName("legend");

‎src/app/legend/qgslegend.h‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ class QgsLegend : public QTreeWidget
177177

178178
/**Returns structure with legend pixmaps*/
179179
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
180-
180+
181+
181182
void updateCheckStates(QTreeWidgetItem* item, Qt::CheckState state) {mStateOfCheckBoxes[item] = state;}
182183

183184
public slots:
@@ -400,21 +401,23 @@ this item may be moved back to the original position with resetToInitialPosition
400401
/** structure which holds pixmap which are used in legend */
401402
class QgsLegendPixmaps
402403
{
403-
public:
404-
//! Pixmap which is shown by default
405-
QPixmap mOriginalPixmap;
406-
407-
//! Pixmap to show a bogus vertex was encoutnered in this layer (applies to vector layers only)
408-
QPixmap mProjectionErrorPixmap;
404+
public:
405+
//! Pixmap which is shown by default
406+
QPixmap mOriginalPixmap;
409407

410-
//! Pixmap to show if this layer is represented in overview or now
411-
QPixmap mInOverviewPixmap;
408+
//! Pixmap to show a bogus vertex was encoutnered in this layer (applies to vector layers only)
409+
QPixmap mProjectionErrorPixmap;
412410

413-
//! Pixmap to show it this layer has currently editing turned on
414-
QPixmap mEditablePixmap;
411+
//! Pixmap to show if this layer is represented in overview or now
412+
QPixmap mInOverviewPixmap;
413+
414+
//! Pixmap to show it this layer has currently editing turned on
415+
QPixmap mEditablePixmap;
415416

416417
} mPixmaps;
417418

419+
420+
418421
signals:
419422
void zOrderChanged(QgsLegend * lv);
420423

‎src/app/legend/qgslegendgroup.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1919
***************************************************************************/
2020
#include "qgsapplication.h"
21+
#include "qgisapp.h"
2122
#include "qgslegendgroup.h"
2223
#include "qgslegendlayer.h"
2324
#include "qgslegendlayerfile.h"
@@ -30,7 +31,7 @@ QgsLegendGroup::QgsLegendGroup(QTreeWidgetItem * theItem ,QString theName)
3031
mType=LEGEND_GROUP;
3132
setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
3233
setCheckState (0, Qt::Checked);
33-
QIcon myIcon(QgsApplication::themePath()+"/mActionFolder.png");
34+
QIcon myIcon = QgisApp::getThemeIcon("/mActionFolder.png");
3435
setIcon(0, myIcon);
3536
}
3637
QgsLegendGroup::QgsLegendGroup(QTreeWidget* theListView, QString theString)
@@ -39,7 +40,7 @@ QgsLegendGroup::QgsLegendGroup(QTreeWidget* theListView, QString theString)
3940
mType=LEGEND_GROUP;
4041
setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
4142
setCheckState (0, Qt::Checked);
42-
QIcon myIcon(QgsApplication::themePath()+"/mActionFolder.png");
43+
QIcon myIcon = QgisApp::getThemeIcon("/mActionFolder.png");
4344
setIcon(0, myIcon);
4445
}
4546

@@ -48,7 +49,7 @@ QgsLegendGroup::QgsLegendGroup(QString name): QgsLegendItem()
4849
mType=LEGEND_GROUP;
4950
setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
5051
setCheckState (0, Qt::Checked);
51-
QIcon myIcon(QgsApplication::themePath()+"/mActionFolder.png");
52+
QIcon myIcon = QgisApp::getThemeIcon(+"/mActionFolder.png");
5253
setText(0, name);
5354
setIcon(0, myIcon);
5455
}

‎src/app/legend/qgslegendlayer.cpp‎

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
***************************************************************************/
2020

2121
#include "qgsapplication.h"
22+
#include "qgisapp.h"
2223
#include "qgslegend.h"
2324
#include "qgslegendlayer.h"
2425
#include "qgslegendlayerfile.h"
@@ -404,28 +405,27 @@ void QgsLegendLayer::updateIcon()
404405
QgsLegendLayerFile* theFile = firstLayerFile();
405406

406407
if(mapLayers().size() == 1)
408+
{
409+
//overview
410+
if(theFile->isInOverview())
407411
{
408-
409-
//overview
410-
if(theFile->isInOverview())
411-
{
412-
// Overlay the overview icon on the default icon
413-
QPixmap myPixmap(QgsApplication::themePath()+"mIconOverview.png");
414-
QPainter p(&newIcon);
415-
p.drawPixmap(0,0,myPixmap);
416-
p.end();
417-
}
418-
419-
//editable
420-
if(theLayer->isEditable())
421-
{
422-
// Overlay the editable icon on the default icon
423-
QPixmap myPixmap(QgsApplication::themePath()+"mIconEditable.png");
424-
QPainter p(&newIcon);
425-
p.drawPixmap(0,0,myPixmap);
426-
p.end();
427-
}
412+
// Overlay the overview icon on the default icon
413+
QPixmap myPixmap = QgisApp::getThemePixmap(+"mIconOverview.png");
414+
QPainter p(&newIcon);
415+
p.drawPixmap(0,0,myPixmap);
416+
p.end();
417+
}
418+
419+
//editable
420+
if(theLayer->isEditable())
421+
{
422+
// Overlay the editable icon on the default icon
423+
QPixmap myPixmap = QgisApp::getThemePixmap(+"mIconEditable.png");
424+
QPainter p(&newIcon);
425+
p.drawPixmap(0,0,myPixmap);
426+
p.end();
428427
}
428+
}
429429

430430
QIcon theIcon(newIcon);
431431
setIcon(0, theIcon);
@@ -436,48 +436,34 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
436436
QgsMapLayer* firstLayer = firstMapLayer();
437437
if(firstLayer)
438438
{
439-
QString myThemePath = QgsApplication::themePath();
440-
QString myPath;
441-
442439
if (firstLayer->type() == QgsMapLayer::VECTOR)
443440
{
444441
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>(firstLayer);
445442
switch(vlayer->vectorType())
446443
{
447444
case QGis::Point:
448-
myPath = myThemePath+"/mIconPointLayer.png";
445+
return QgisApp::getThemePixmap("/mIconPointLayer.png");
449446
break;
450447
case QGis::Line:
451-
myPath = myThemePath+"/mIconLineLayer.png";
448+
return QgisApp::getThemePixmap("/mIconLineLayer.png");
452449
break;
453450
case QGis::Polygon:
454-
myPath = myThemePath+"/mIconPolygonLayer.png";
451+
return QgisApp::getThemePixmap("/mIconPolygonLayer.png");
455452
break;
456453
default:
457-
myPath = myThemePath+"/mIconLayer.png";
454+
return QgisApp::getThemePixmap("/mIconLayer.png");
458455
}
459456
}
460457
else // RASTER
461458
{
462-
myPath = myThemePath+"/mIconLayer.png";
463-
}
464-
465-
466-
QFileInfo file(myPath);
467-
if(file.exists())
468-
{
469-
return QPixmap(file.absoluteFilePath());
459+
return QgisApp::getThemePixmap("/mIconLayer.png");
470460
}
471461
}
472-
473-
QPixmap emptyPixmap;
474-
return emptyPixmap;
475462
}
476463

477464

478465
void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
479466
{
480-
QString iconsPath = QgsApplication::themePath();
481467
std::list<QgsLegendLayerFile*> files = legendLayerFiles();
482468
QgsMapLayer* firstLayer = NULL;
483469
if (files.size() > 0)
@@ -486,7 +472,7 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction
486472
}
487473

488474
// zoom to layer extent
489-
theMenu.addAction(QIcon(iconsPath+QString("/mActionZoomToLayer.png")),
475+
theMenu.addAction(QgisApp::getThemeIcon("/mActionZoomToLayer.png"),
490476
tr("&Zoom to layer extent"), legend(), SLOT(legendLayerZoom()));
491477
if (firstLayer && firstLayer->type() == QgsMapLayer::RASTER)
492478
{
@@ -499,7 +485,7 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction
499485
showInOverviewAction->setChecked(isInOverview());
500486

501487
// remove from canvas
502-
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionRemove.png"))),
488+
theMenu.addAction(QgisApp::getThemeIcon("/mActionRemove.png"),
503489
tr("&Remove"), legend(), SLOT(legendLayerRemove()));
504490

505491
theMenu.addSeparator();

‎src/app/legend/qgslegendlayerfile.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
***************************************************************************/
2020

2121
#include "qgsapplication.h"
22+
#include "qgisapp.h"
2223
#include "qgslegend.h"
2324
#include "qgslegendlayer.h"
2425
#include "qgslegendlayerfile.h"
@@ -104,7 +105,7 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(const QgsLegendItem* li) c
104105

105106
QPixmap QgsLegendLayerFile::getOriginalPixmap() const
106107
{
107-
QPixmap myPixmap(QgsApplication::themePath()+"mActionFileSmall.png");
108+
QPixmap myPixmap = QgisApp::getThemePixmap("mActionFileSmall.png");
108109
return myPixmap;
109110
}
110111

@@ -148,7 +149,7 @@ void QgsLegendLayerFile::setIconAppearance(bool inOverview,
148149
if (inOverview)
149150
{
150151
// Overlay the overview icon on the default icon
151-
QPixmap myPixmap(QgsApplication::themePath()+"mIconOverview.png");
152+
QPixmap myPixmap = QgisApp::getThemePixmap("mIconOverview.png");
152153
QPainter p(&newIcon);
153154
p.drawPixmap(0,0,myPixmap);
154155
p.end();
@@ -157,7 +158,7 @@ void QgsLegendLayerFile::setIconAppearance(bool inOverview,
157158
if (editable)
158159
{
159160
// Overlay the editable icon on the default icon
160-
QPixmap myPixmap(QgsApplication::themePath()+"mIconEditable.png");
161+
QPixmap myPixmap = QgisApp::getThemePixmap("mIconEditable.png");
161162
QPainter p(&newIcon);
162163
p.drawPixmap(0,0,myPixmap);
163164
p.end();
@@ -494,10 +495,9 @@ void QgsLegendLayerFile::layerNameChanged()
494495
void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
495496
{
496497
QgsMapLayer* lyr = layer();
497-
QString iconsPath = QgsApplication::themePath();
498498

499499
// zoom to layer extent
500-
theMenu.addAction(QIcon(iconsPath+QString("/mActionZoomToLayer.png")),
500+
theMenu.addAction(QgisApp::getThemeIcon("/mActionZoomToLayer.png"),
501501
tr("&Zoom to layer extent"), legend(), SLOT(legendLayerZoom()));
502502

503503
// show in overview
@@ -508,7 +508,7 @@ void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAc
508508
showInOverviewAction->blockSignals(false);
509509

510510
// remove from canvas
511-
theMenu.addAction(QIcon(iconsPath+QString("/mActionRemove.png")),
511+
theMenu.addAction(QgisApp::getThemeIcon("/mActionRemove.png"),
512512
tr("&Remove"), legend(), SLOT(legendLayerRemove()));
513513

514514
theMenu.addSeparator();

‎src/app/legend/qgslegendpropertygroup.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1919
***************************************************************************/
2020
#include "qgsapplication.h"
21+
#include "qgisapp.h"
2122
#include "qgslegendpropertygroup.h"
2223
#include <QCoreApplication>
2324
#include <QIcon>
@@ -26,7 +27,7 @@ QgsLegendPropertyGroup::QgsLegendPropertyGroup(QTreeWidgetItem* theLegendItem, Q
2627
: QgsLegendItem(theLegendItem,theString )
2728
{
2829
mType=LEGEND_PROPERTY_GROUP;
29-
QIcon myIcon(QgsApplication::themePath()+"/mIconProperties.png");
30+
QIcon myIcon = QgisApp::getThemeIcon("/mIconProperties.png");
3031
setText(0, theString);
3132
setIcon(0,myIcon);
3233
}

‎src/app/legend/qgslegendsymbologygroup.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1919
***************************************************************************/
2020
#include "qgsapplication.h"
21+
#include "qgisapp.h"
2122
#include "qgslegendlayerfile.h"
2223
#include "qgslegendlayerfilegroup.h"
2324
#include "qgslegendsymbologygroup.h"
@@ -29,7 +30,7 @@ QgsLegendSymbologyGroup::QgsLegendSymbologyGroup(QTreeWidgetItem * theItem, QStr
2930
: QgsLegendItem( theItem, theString)
3031
{
3132
mType = LEGEND_SYMBOL_GROUP;
32-
QIcon myIcon(QgsApplication::themePath()+"/mIconSymbology.png");
33+
QIcon myIcon = QgisApp::getThemeIcon("/mIconSymbology.png");
3334
setText(0, theString);
3435
setIcon(0,myIcon);
3536
}

‎src/app/qgisapp.cpp‎

Lines changed: 154 additions & 134 deletions
Large diffs are not rendered by default.

‎src/app/qgisapp.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ class QgisApp : public QMainWindow
162162
* (as documented in Qt documentation.
163163
*/
164164
void setupProxy();
165+
//! Helper to get a theme icon. It will fall back to the
166+
//default theme if the active theme does not have the required
167+
//icon.
168+
static QIcon getThemeIcon(const QString theName);
169+
//! Helper to get a theme icon as a pixmap. It will fall back to the
170+
//default theme if the active theme does not have the required
171+
//icon.
172+
static QPixmap getThemePixmap(const QString theName);
165173
//private slots:
166174
public slots:
167175
//! About QGis
@@ -589,9 +597,6 @@ class Tools
589597

590598
QgsMapTool *mNonEditMapTool;
591599

592-
//!The name of the active theme
593-
QString mThemeName;
594-
595600
//! Widget that will live on the statusbar to display "scale 1:"
596601
QLabel * mScaleLabel;
597602
//! Widget that will live on the statusbar to display scale value

‎src/app/qgsattributetabledisplay.cpp‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,14 @@ QgsAttributeTable *QgsAttributeTableDisplay::table()
109109
}
110110
void QgsAttributeTableDisplay::setTheme()
111111
{
112-
QString myIconPath = QgsApplication::themePath();
113-
mAddAttributeButton->setIcon(QPixmap(myIconPath+"/mActionNewAttribute.png"));
114-
mRemoveSelectionButton->setIcon(QPixmap(myIconPath+"/mActionUnselectAttributes.png"));
115-
mSelectedToTopButton->setIcon(QPixmap(myIconPath+"/mActionSelectedToTop.png"));
116-
mInvertSelectionButton->setIcon(QPixmap(myIconPath+"/mActionInvertSelection.png"));
117-
mCopySelectedRowsButton->setIcon(QPixmap(myIconPath+"/mActionCopySelected.png"));
118-
mZoomMapToSelectedRowsButton->setIcon(QPixmap(myIconPath+"/mActionZoomToSelected.png"));
119-
mAddAttributeButton->setIcon(QPixmap(myIconPath+"/mActionNewAttribute.png"));
120-
mDeleteAttributeButton->setIcon(QPixmap(myIconPath+"/mActionDeleteAttribute.png"));
112+
mAddAttributeButton->setIcon(QgisApp::getThemeIcon("/mActionNewAttribute.png"));
113+
mRemoveSelectionButton->setIcon(QgisApp::getThemeIcon("/mActionUnselectAttributes.png"));
114+
mSelectedToTopButton->setIcon(QgisApp::getThemeIcon("/mActionSelectedToTop.png"));
115+
mInvertSelectionButton->setIcon(QgisApp::getThemeIcon("/mActionInvertSelection.png"));
116+
mCopySelectedRowsButton->setIcon(QgisApp::getThemeIcon("/mActionCopySelected.png"));
117+
mZoomMapToSelectedRowsButton->setIcon(QgisApp::getThemeIcon("/mActionZoomToSelected.png"));
118+
mAddAttributeButton->setIcon(QgisApp::getThemeIcon("/mActionNewAttribute.png"));
119+
mDeleteAttributeButton->setIcon(QgisApp::getThemeIcon("/mActionDeleteAttribute.png"));
121120
}
122121

123122
void QgsAttributeTableDisplay::setTitle(QString title)

‎src/app/qgscustomprojectiondialog.cpp‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
//qgis includes
2222
#include "qgis.h" //<--magick numbers
23+
#include "qgisapp.h" //<--theme icons
2324
#include "qgsapplication.h"
2425
#include "qgslogger.h"
2526

@@ -44,16 +45,13 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog(QWidget *parent, Qt::WFlags
4445
{
4546
setupUi(this);
4647

47-
QString myThemePath = QgsApplication::themePath();
48-
pbnFirst->setIcon(QPixmap(myThemePath+"mIconFirst.png"));
49-
QString myString = "Setting first button to : " + myThemePath+"mIconFirst.png";
50-
qDebug(myString.toLocal8Bit());
51-
pbnPrevious->setIcon(QPixmap(myThemePath+"mIconPrevious.png"));
52-
pbnNext->setIcon(QPixmap(myThemePath+"mIconNext.png"));
53-
pbnLast->setIcon(QPixmap(myThemePath+"mIconLast.png"));
54-
pbnNew->setIcon(QPixmap(myThemePath+"mIconNew.png"));
55-
pbnSave->setIcon(QPixmap(myThemePath+"mActionFileSave.png"));
56-
pbnDelete->setIcon(QPixmap(myThemePath+"mIconDelete.png"));
48+
pbnFirst->setIcon(QgisApp::getThemeIcon("mIconFirst.png"));
49+
pbnPrevious->setIcon(QgisApp::getThemeIcon("mIconPrevious.png"));
50+
pbnNext->setIcon(QgisApp::getThemeIcon("mIconNext.png"));
51+
pbnLast->setIcon(QgisApp::getThemeIcon("mIconLast.png"));
52+
pbnNew->setIcon(QgisApp::getThemeIcon("mIconNew.png"));
53+
pbnSave->setIcon(QgisApp::getThemeIcon("mActionFileSave.png"));
54+
pbnDelete->setIcon(QgisApp::getThemeIcon("mIconDelete.png"));
5755
// user database is created at QGIS startup in QgisApp::createDB
5856
// we just check whether there is our database [MD]
5957
QFileInfo myFileInfo;
@@ -701,8 +699,7 @@ void QgsCustomProjectionDialog::on_pbnNew_clicked()
701699
if (pbnNew->text()==tr("Abort"))
702700
{
703701
//if we get here, user has aborted add record
704-
QString myThemePath = QgsApplication::themePath();
705-
pbnNew->setIcon(QPixmap(myThemePath+"mIconNew.png"));
702+
pbnNew->setIcon(QgisApp::getThemeIcon("mIconNew.png"));
706703
//next line needed for new/abort logic
707704
pbnNew->setText(tr("New"));
708705
//get back to the last used record before insert was pressed
@@ -724,8 +721,7 @@ void QgsCustomProjectionDialog::on_pbnNew_clicked()
724721
pbnNext->setEnabled(false);
725722
pbnLast->setEnabled(false);
726723
pbnDelete->setEnabled(false);
727-
QString myThemePath = QgsApplication::themePath();
728-
pbnNew->setIcon(QPixmap(myThemePath+"mIconNew.png"));
724+
pbnNew->setIcon(QgisApp::getThemeIcon("mIconNew.png"));
729725
//next line needed for new/abort logic
730726
pbnNew->setText(tr("Abort"));
731727
//clear the controls

‎src/app/qgsdbtablemodel.cpp‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsdbtablemodel.h"
1919
#include "qgsapplication.h"
20+
#include "qgisapp.h"
2021

2122
QgsDbTableModel::QgsDbTableModel(): QStandardItemModel(), mTableCount(0)
2223
{
@@ -53,12 +54,10 @@ void QgsDbTableModel::addTableEntry(QString type, QString schemaName, QString ta
5354
}
5455

5556
//path to icon for specified type
56-
QString myThemePath = QgsApplication::themePath();
5757
QString typeName;
58-
QString iconFile;
5958

6059
QGis::WKBTYPE wkbType = qgisTypeFromDbType(type);
61-
iconFile = iconFilePathForType(wkbType);
60+
QIcon iconFile = iconForType(wkbType);
6261

6362
QList<QStandardItem*> childItemList;
6463
QStandardItem* schemaNameItem = new QStandardItem(schemaName);
@@ -197,9 +196,9 @@ void QgsDbTableModel::setGeometryTypesForTable(const QString& schema, const QStr
197196
}
198197

199198
QGis::WKBTYPE wkbType = qgisTypeFromDbType(typeList.at(0));
200-
QString iconPath = iconFilePathForType(wkbType);
199+
QIcon myIcon = iconForType(wkbType);
201200
itemFromIndex(currentTypeIndex)->setText(typeList.at(0)); //todo: add other rows
202-
itemFromIndex(currentTypeIndex)->setIcon(QIcon(iconPath));
201+
itemFromIndex(currentTypeIndex)->setIcon(myIcon);
203202
if(!geomColText.contains(" AS "))
204203
{
205204
itemFromIndex(currentGeomColumnIndex)->setText(geomColText + " AS " + typeList.at(0));
@@ -214,22 +213,21 @@ void QgsDbTableModel::setGeometryTypesForTable(const QString& schema, const QStr
214213
}
215214
}
216215

217-
QString QgsDbTableModel::iconFilePathForType(QGis::WKBTYPE type) const
216+
QIcon QgsDbTableModel::iconForType(QGis::WKBTYPE type) const
218217
{
219-
QString myThemePath = QgsApplication::themePath();
220218
if(type == QGis::WKBPoint || type == QGis::WKBPoint25D || type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D)
221219
{
222-
return myThemePath+"/mIconPointLayer.png";
220+
return QgisApp::getThemeIcon("/mIconPointLayer.png");
223221
}
224222
else if(type == QGis::WKBLineString || type == QGis::WKBLineString25D || type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D)
225223
{
226-
return myThemePath+"/mIconLineLayer.png";
224+
return QgisApp::getThemeIcon("/mIconLineLayer.png");
227225
}
228226
else if(type == QGis::WKBPolygon || type == QGis::WKBPolygon25D || type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D)
229227
{
230-
return myThemePath+"/mIconPolygonLayer.png";
228+
return QgisApp::getThemeIcon("/mIconPolygonLayer.png");
231229
}
232-
else return "";
230+
else return QIcon();
233231
}
234232

235233
QString QgsDbTableModel::displayStringForType(QGis::WKBTYPE type) const

‎src/app/qgsdbtablemodel.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include <QStandardItemModel>
19+
class QIcon;
1920
#include "qgis.h"
2021

2122
/**A model that holds the tables of a database in a hierarchy where the
@@ -41,7 +42,7 @@ class QgsDbTableModel: public QStandardItemModel
4142
/**Number of tables in the model*/
4243
int mTableCount;
4344

44-
QString iconFilePathForType(QGis::WKBTYPE type) const;
45+
QIcon iconForType(QGis::WKBTYPE type) const;
4546
QString displayStringForType(QGis::WKBTYPE type) const;
4647
/**Returns qgis wkbtype from database typename*/
4748
QGis::WKBTYPE qgisTypeFromDbType(const QString& dbType) const;

‎src/app/qgsgeomtypedialog.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
#include "qgsgeomtypedialog.h"
2020
#include "qgsapplication.h"
21+
#include "qgisapp.h" // <- for theme icons
2122
#include <QPushButton>
2223

2324
QgsGeomTypeDialog::QgsGeomTypeDialog(QWidget *parent, Qt::WFlags fl)
2425
: QDialog(parent, fl)
2526
{
2627
setupUi(this);
27-
QString myThemePath = QgsApplication::themePath();
28-
mAddAttributeButton->setIcon(QIcon(QPixmap(myThemePath + "/mActionNewAttribute.png")));
29-
mRemoveAttributeButton->setIcon(QIcon(QPixmap(myThemePath + "/mActionDeleteAttribute.png")));
28+
mAddAttributeButton->setIcon(QgisApp::getThemeIcon("/mActionNewAttribute.png"));
29+
mRemoveAttributeButton->setIcon(QgisApp::getThemeIcon("/mActionDeleteAttribute.png"));
3030
mTypeBox->addItem(tr("Real"),"Real");
3131
mTypeBox->addItem(tr("Integer"),"Integer");;
3232
mTypeBox->addItem(tr("String"),"String");

‎src/app/qgsidentifyresults.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsidentifyresults.h"
2121
#include "qgscontexthelp.h"
2222
#include "qgsapplication.h"
23+
#include "qgisapp.h"
2324

2425
#include <QCloseEvent>
2526
#include <QLabel>
@@ -210,8 +211,7 @@ void QgsIdentifyResults::addAction(QTreeWidgetItem * fnode, int id, QString fiel
210211
labels << field << value << "action" << QString::number(id);
211212
QTreeWidgetItem *item = new QTreeWidgetItem(fnode, labels );
212213

213-
QPixmap pm ( QgsApplication::themePath() + "/mAction.png" );
214-
item->setIcon ( 0, QIcon(pm) );
214+
item->setIcon ( 0, QgisApp::getThemeIcon("/mAction.png") );
215215
}
216216

217217
/** Add a feature node to the list */

‎src/app/qgsrasterlayerproperties.cpp‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgslogger.h"
1919
#include "qgsapplication.h"
20+
#include "qgisapp.h"
2021
#include "qgscoordinatetransform.h"
2122
#include "qgsrasterlayerproperties.h"
2223
#include "qgslayerprojectionselector.h"
@@ -280,18 +281,17 @@ QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *pa
280281

281282
cboxTransparencyBand->addItem(TRSTRING_NOT_SET);
282283

283-
QString myThemePath = QgsApplication::themePath();
284-
QPixmap myPyramidPixmap(myThemePath + "/mIconPyramid.png");
285-
QPixmap myNoPyramidPixmap(myThemePath + "/mIconNoPyramid.png");
284+
QIcon myPyramidPixmap(QgisApp::getThemeIcon("/mIconPyramid.png"));
285+
QIcon myNoPyramidPixmap(QgisApp::getThemeIcon("/mIconNoPyramid.png"));
286286

287-
pbnAddValuesManually->setIcon(QIcon(myThemePath + "/mActionNewAttribute.png"));
288-
pbnAddValuesFromDisplay->setIcon(QIcon(myThemePath + "/mActionContextHelp.png"));
289-
pbnRemoveSelectedRow->setIcon(QIcon(myThemePath + "/mActionDeleteAttribute.png"));
290-
pbnDefaultValues->setIcon(QIcon(myThemePath + "/mActionCopySelected.png"));
291-
pbnImportTransparentPixelValues->setIcon(QIcon(myThemePath + "/mActionFileOpen.png"));
292-
pbnExportTransparentPixelValues->setIcon(QIcon(myThemePath + "/mActionFileSave.png"));
293-
pbtnMakeBandCombinationDefault->setIcon(QIcon(myThemePath + "/mActionFileSave.png"));
294-
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QIcon(myThemePath + "/mActionFileSave.png"));
287+
pbnAddValuesManually->setIcon(QgisApp::getThemeIcon("/mActionNewAttribute.png"));
288+
pbnAddValuesFromDisplay->setIcon(QgisApp::getThemeIcon("/mActionContextHelp.png"));
289+
pbnRemoveSelectedRow->setIcon(QgisApp::getThemeIcon("/mActionDeleteAttribute.png"));
290+
pbnDefaultValues->setIcon(QgisApp::getThemeIcon("/mActionCopySelected.png"));
291+
pbnImportTransparentPixelValues->setIcon(QgisApp::getThemeIcon("/mActionFileOpen.png"));
292+
pbnExportTransparentPixelValues->setIcon(QgisApp::getThemeIcon("/mActionFileSave.png"));
293+
pbtnMakeBandCombinationDefault->setIcon(QgisApp::getThemeIcon("/mActionFileSave.png"));
294+
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QgisApp::getThemeIcon("/mActionFileSave.png"));
295295

296296
// Only do pyramids if dealing directly with GDAL.
297297
if (mRasterLayerIsGdal)
@@ -1616,9 +1616,8 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
16161616
// repopulate the pyramids list
16171617
//
16181618
lbxPyramidResolutions->clear();
1619-
QString myThemePath = QgsApplication::themePath();
1620-
QPixmap myPyramidPixmap(myThemePath + "/mIconPyramid.png");
1621-
QPixmap myNoPyramidPixmap(myThemePath + "/mIconNoPyramid.png");
1619+
QIcon myPyramidPixmap(QgisApp::getThemeIcon("/mIconPyramid.png"));
1620+
QIcon myNoPyramidPixmap(QgisApp::getThemeIcon("/mIconNoPyramid.png"));
16221621

16231622
QgsRasterLayer::RasterPyramidList::iterator myRasterPyramidIterator;
16241623
for ( myRasterPyramidIterator=myPyramidList.begin();

‎src/core/qgsapplication.cpp‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,30 @@ const QString QgsApplication::pkgDataPath()
106106
{
107107
return mPkgDataPath;
108108
}
109-
const QString QgsApplication::themePath()
109+
const QString QgsApplication::defaultThemePath()
110+
{
111+
return mPkgDataPath + QString("/themes/default/");
112+
}
113+
const QString QgsApplication::activeThemePath()
110114
{
111115
return mThemePath;
112116
}
113117

114118
/*!
115119
Set the theme path to the specified theme.
116120
*/
117-
void QgsApplication::selectTheme(const QString theThemeName)
121+
void QgsApplication::setTheme(const QString theThemeName)
118122
{
119-
mThemePath = mPkgDataPath + QString("/themes/") + theThemeName + QString("/");
123+
QString myPath = mPkgDataPath + QString("/themes/") + theThemeName + QString("/");
124+
//check it exists and if not roll back to default theme
125+
if (QFile::exists(myPath))
126+
{
127+
mThemePath = myPath;
128+
}
129+
else
130+
{
131+
mThemePath = defaultThemePath();
132+
}
120133
}
121134

122135
/*!

‎src/core/qgsapplication.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class CORE_EXPORT QgsApplication: public QApplication
2424
QgsApplication(int & argc, char ** argv, bool GUIenabled);
2525
virtual ~QgsApplication();
2626

27-
//! Set the theme path to the specified theme.
28-
static void selectTheme(const QString theThemeName);
27+
//! Set the active theme path to the specified theme.
28+
static void setTheme(const QString theThemeName);
2929

3030
//! Returns the path to the authors file.
3131
static const QString authorsFilePath();
@@ -75,8 +75,11 @@ class CORE_EXPORT QgsApplication: public QApplication
7575
//! Returns the common root path of all application data directories.
7676
static const QString pkgDataPath();
7777

78-
//! Returns the path to the current theme directory.
79-
static const QString themePath();
78+
//! Returns the path to the currently active theme directory.
79+
static const QString activeThemePath();
80+
81+
//! Returns the path to the default theme directory.
82+
static const QString defaultThemePath();
8083

8184
//! Alters prefix path - used by 3rd party apps
8285
static void setPrefixPath(const QString thePrefixPath, bool useDefaultPaths = FALSE);

‎src/core/raster/qgsrasterlayer.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2954,7 +2954,7 @@ QPixmap QgsRasterLayer::getLegendQPixmap(bool theWithNameFlag)
29542954
QPainter myQPainter(&myQPixmap2);
29552955

29562956
//load up the pyramid icons
2957-
QString myThemePath = QgsApplication::themePath();
2957+
QString myThemePath = QgsApplication::activeThemePath();
29582958
QPixmap myPyramidPixmap(myThemePath + "/mIconPyramid.png");
29592959
QPixmap myNoPyramidPixmap(myThemePath + "/mIconNoPyramid.png");
29602960

‎src/plugins/georeferencer/qgspointdialog.cpp‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,35 +479,33 @@ void QgsPointDialog::initialize()
479479
{
480480
setupUi(this);
481481

482-
QString myIconPath = QgsApplication::themePath();
483-
484482
// setup actions
485483
//
486-
mActionZoomIn= new QAction(QIcon(myIconPath+"/mActionZoomIn.png"), tr("Zoom In"), this);
484+
mActionZoomIn= new QAction(getThemeIcon("/mActionZoomIn.png"), tr("Zoom In"), this);
487485
mActionZoomIn->setShortcut(tr("z"));
488486
mActionZoomIn->setStatusTip(tr("Zoom In"));
489487
connect(mActionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
490488
//
491-
mActionZoomOut= new QAction(QIcon(myIconPath+"/mActionZoomOut.png"), tr("Zoom Out"), this);
489+
mActionZoomOut= new QAction(getThemeIcon("/mActionZoomOut.png"), tr("Zoom Out"), this);
492490
mActionZoomOut->setShortcut(tr("Z"));
493491
mActionZoomOut->setStatusTip(tr("Zoom Out"));
494492
connect(mActionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
495493
//
496-
mActionZoomToLayer= new QAction(QIcon(myIconPath+"/mActionZoomToLayer.png"), tr("Zoom To Layer"), this);
494+
mActionZoomToLayer= new QAction(getThemeIcon("/mActionZoomToLayer.png"), tr("Zoom To Layer"), this);
497495
//mActionZoomToLayer->setShortcut(tr("Ctrl+O"));
498496
mActionZoomToLayer->setStatusTip(tr("Zoom to Layer"));
499497
connect(mActionZoomToLayer, SIGNAL(triggered()), this, SLOT(zoomToLayer()));
500498
//
501-
mActionPan= new QAction(QIcon(myIconPath+"/mActionPan.png"), tr("Pan Map"), this);
499+
mActionPan= new QAction(getThemeIcon("/mActionPan.png"), tr("Pan Map"), this);
502500
mActionPan->setStatusTip(tr("Pan the map"));
503501
connect(mActionPan, SIGNAL(triggered()), this, SLOT(pan()));
504502
//
505-
mActionAddPoint= new QAction(QIcon(myIconPath+"/mActionCapturePoint.png"), tr("Add Point"), this);
503+
mActionAddPoint= new QAction(getThemeIcon("/mActionCapturePoint.png"), tr("Add Point"), this);
506504
mActionAddPoint->setShortcut(tr("."));
507505
mActionAddPoint->setStatusTip(tr("Capture Points"));
508506
connect(mActionAddPoint, SIGNAL(triggered()), this, SLOT(addPoint()));
509507
//
510-
mActionDeletePoint = new QAction(QIcon(myIconPath+"/mActionDeleteSelected.png"), tr("Delete Point"), this);
508+
mActionDeletePoint = new QAction(getThemeIcon("/mActionDeleteSelected.png"), tr("Delete Point"), this);
511509
mActionDeletePoint->setStatusTip(tr("Delete Selected"));
512510
connect(mActionDeletePoint, SIGNAL(triggered()), this, SLOT(deletePoint()));
513511

@@ -565,3 +563,19 @@ void QgsPointDialog::initialize()
565563
pbnGenerateWorldFile->setEnabled(false);
566564
pbnGenerateAndLoad->setEnabled(false);
567565
}
566+
567+
// Note this code is duplicated from qgisapp.cpp because
568+
// I didnt want to make plugins on qgsapplication [TS]
569+
QIcon QgsPointDialog::getThemeIcon(const QString theName)
570+
{
571+
if (QFile::exists(QgsApplication::activeThemePath() + theName))
572+
{
573+
return QIcon(QgsApplication::activeThemePath() + theName);
574+
}
575+
else
576+
{
577+
//could still return an empty icon if it
578+
//doesnt exist in the default theme either!
579+
return QIcon(QgsApplication::defaultThemePath() + theName);
580+
}
581+
}

‎src/plugins/georeferencer/qgspointdialog.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class QAction;
2626
class QActionGroup;
27+
class QIcon;
2728
class QgsGeorefDataPoint;
2829
class QgsMapTool;
2930
class QgisInterface;
@@ -66,6 +67,7 @@ public slots:
6667
QString guessWorldFileName(const QString& raster);
6768

6869
void enableModifiedRasterControls(bool state);
70+
QIcon getThemeIcon(const QString theName);
6971

7072
QActionGroup* mMapToolGroup;
7173
QAction* mActionZoomIn;

‎src/plugins/gps_importer/qgsgpsplugin.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void QgsGPSPlugin::help()
109109
//implement me!
110110
}
111111

112-
// Slot called when the buffer menu item is activated
112+
// Slot called when the menu item is activated
113113
void QgsGPSPlugin::run()
114114
{
115115
// find all GPX layers

‎src/plugins/grass/qgsgrassbrowser.cpp‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,49 +65,48 @@ QgsGrassBrowser::QgsGrassBrowser ( QgisInterface *iface,
6565
QActionGroup *ag = new QActionGroup ( this );
6666
QToolBar *tb = addToolBar(tr("Tools"));
6767

68-
QString myIconPath = QgsApplication::themePath() + "/grass/";
6968
mActionAddMap = new QAction(
70-
QIcon(myIconPath+"grass_add_map.png"),
69+
getThemeIcon("grass_add_map.png"),
7170
tr("Add selected map to canvas"), this);
7271
mActionAddMap->setEnabled(false);
7372
ag->addAction ( mActionAddMap );
7473
tb->addAction ( mActionAddMap );
7574
connect ( mActionAddMap, SIGNAL(triggered()), this, SLOT(addMap()) );
7675

7776
mActionCopyMap = new QAction(
78-
QIcon(myIconPath+"grass_copy_map.png"),
77+
getThemeIcon("grass_copy_map.png"),
7978
tr("Copy selected map"), this);
8079
mActionCopyMap->setEnabled(false);
8180
ag->addAction ( mActionCopyMap );
8281
tb->addAction ( mActionCopyMap );
8382
connect ( mActionCopyMap, SIGNAL(triggered()), this, SLOT(copyMap()) );
8483

8584
mActionRenameMap = new QAction(
86-
QIcon(myIconPath+"grass_rename_map.png"),
85+
getThemeIcon("grass_rename_map.png"),
8786
tr("Rename selected map"), this);
8887
mActionRenameMap->setEnabled(false);
8988
ag->addAction ( mActionRenameMap );
9089
tb->addAction ( mActionRenameMap );
9190
connect ( mActionRenameMap, SIGNAL(triggered()), this, SLOT(renameMap()) );
9291

9392
mActionDeleteMap = new QAction(
94-
QIcon(myIconPath+"grass_delete_map.png"),
93+
getThemeIcon("grass_delete_map.png"),
9594
tr("Delete selected map"), this);
9695
mActionDeleteMap->setEnabled(false);
9796
ag->addAction ( mActionDeleteMap );
9897
tb->addAction ( mActionDeleteMap );
9998
connect ( mActionDeleteMap, SIGNAL(triggered()), this, SLOT(deleteMap()) );
10099

101100
mActionSetRegion = new QAction(
102-
QIcon(myIconPath+"grass_set_region.png"),
101+
getThemeIcon("grass_set_region.png"),
103102
tr("Set current region to selected map"), this);
104103
mActionSetRegion->setEnabled(false);
105104
ag->addAction ( mActionSetRegion );
106105
tb->addAction ( mActionSetRegion );
107106
connect ( mActionSetRegion, SIGNAL(triggered()), this, SLOT(setRegion()) );
108107

109108
mActionRefresh = new QAction(
110-
QIcon(myIconPath+"grass_refresh.png"),
109+
getThemeIcon("grass_refresh.png"),
111110
tr("Refresh"), this);
112111
ag->addAction ( mActionRefresh );
113112
tb->addAction ( mActionRefresh );

‎src/plugins/grass/qgsgrassbrowser.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class QAction;
2222
class QTreeView;
2323
class QTextBrowser;
2424
class QDirModel;
25+
class QIcon;
2526

2627
class QgisInterface;
2728
#include "qgsgrassmodel.h"
@@ -80,6 +81,7 @@ public slots:
8081
void regionChanged();
8182

8283
private:
84+
QIcon getThemeIcon(const QString theName);
8385
QgisInterface *mIface;
8486

8587
//! Current GISBASE

‎src/plugins/grass/qgsgrassedit.cpp‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern "C" {
7272
#include "qgsgrassedit.h"
7373
#include "qgsgrassedittools.h"
7474
#include "qgsgrassutils.h"
75+
#include "qgsgrassplugin.h"
7576

7677
#ifdef _MSC_VER
7778
#define round(x) ((x) >= 0 ? floor((x)+0.5) : floor((x)-0.5))
@@ -216,77 +217,76 @@ void QgsGrassEdit::init()
216217

217218
connect ( mCanvas, SIGNAL(keyPressed(QKeyEvent *)), this, SLOT(keyPress(QKeyEvent *)) );
218219

219-
QString myIconPath = QgsApplication::themePath() + "/grass/";
220220

221221
mToolBar = addToolBar(tr("Edit tools"));
222222

223223
mNewPointAction = new QAction(
224-
QIcon(myIconPath+"grass_new_point.png"), tr("New point"), this);
224+
QgsGrassPlugin::getThemeIcon("grass_new_point.png"), tr("New point"), this);
225225
mNewPointAction->setShortcut ( QKeySequence(Qt::Key_F1) );
226226
mToolBar->addAction ( mNewPointAction );
227227
connect ( mNewPointAction, SIGNAL(triggered()), this, SLOT(newPoint()) );
228228

229229
mNewLineAction = new QAction(
230-
QIcon(myIconPath+"grass_new_line.png"), tr("New line"), this);
230+
QgsGrassPlugin::getThemeIcon("grass_new_line.png"), tr("New line"), this);
231231
mNewLineAction->setShortcut ( QKeySequence(Qt::Key_F2) );
232232
mToolBar->addAction ( mNewLineAction );
233233
connect ( mNewLineAction, SIGNAL(triggered()), this, SLOT(newLine()) );
234234

235235
mNewBoundaryAction = new QAction(
236-
QIcon(myIconPath+"grass_new_boundary.png"), tr("New boundary"), this);
236+
QgsGrassPlugin::getThemeIcon("grass_new_boundary.png"), tr("New boundary"), this);
237237
mNewBoundaryAction->setShortcut ( QKeySequence(Qt::Key_F3) );
238238
mToolBar->addAction ( mNewBoundaryAction );
239239
connect ( mNewBoundaryAction, SIGNAL(triggered()), this, SLOT(newBoundary()) );
240240

241241
mNewCentroidAction = new QAction(
242-
QIcon(myIconPath+"grass_new_centroid.png"), tr("New centroid"), this);
242+
QgsGrassPlugin::getThemeIcon("grass_new_centroid.png"), tr("New centroid"), this);
243243
mNewCentroidAction->setShortcut ( QKeySequence(Qt::Key_F4) );
244244
mToolBar->addAction ( mNewCentroidAction );
245245
connect ( mNewCentroidAction, SIGNAL(triggered()), this, SLOT(newCentroid()) );
246246

247247
mMoveVertexAction = new QAction(
248-
QIcon(myIconPath+"grass_move_vertex.png"), tr("Move vertex"), this);
248+
QgsGrassPlugin::getThemeIcon("grass_move_vertex.png"), tr("Move vertex"), this);
249249
mMoveVertexAction->setShortcut ( QKeySequence(Qt::Key_F5) );
250250
mToolBar->addAction ( mMoveVertexAction );
251251
connect ( mMoveVertexAction, SIGNAL(triggered()), this, SLOT(moveVertex()) );
252252

253253
mAddVertexAction = new QAction(
254-
QIcon(myIconPath+"grass_add_vertex.png"), tr("Add vertex"), this);
254+
QgsGrassPlugin::getThemeIcon("grass_add_vertex.png"), tr("Add vertex"), this);
255255
mAddVertexAction->setShortcut ( QKeySequence(Qt::Key_F6) );
256256
mToolBar->addAction ( mAddVertexAction );
257257
connect ( mAddVertexAction, SIGNAL(triggered()), this, SLOT(addVertex()) );
258258

259259
mDeleteVertexAction = new QAction(
260-
QIcon(myIconPath+"grass_delete_vertex.png"), tr("Delete vertex"), this);
260+
QgsGrassPlugin::getThemeIcon("grass_delete_vertex.png"), tr("Delete vertex"), this);
261261
mDeleteVertexAction->setShortcut ( QKeySequence(Qt::Key_F7) );
262262
mToolBar->addAction ( mDeleteVertexAction );
263263
connect ( mDeleteVertexAction, SIGNAL(triggered()), this, SLOT(deleteVertex()) );
264264

265265
mMoveLineAction = new QAction(
266-
QIcon(myIconPath+"grass_move_line.png"), tr("Move element"), this);
266+
QgsGrassPlugin::getThemeIcon("grass_move_line.png"), tr("Move element"), this);
267267
mMoveLineAction->setShortcut ( QKeySequence(Qt::Key_F9) );
268268
mToolBar->addAction ( mMoveLineAction );
269269
connect ( mMoveLineAction, SIGNAL(triggered()), this, SLOT(moveLine()) );
270270

271271
mSplitLineAction = new QAction(
272-
QIcon(myIconPath+"grass_split_line.png"), tr("Split line"), this);
272+
QgsGrassPlugin::getThemeIcon("grass_split_line.png"), tr("Split line"), this);
273273
mSplitLineAction->setShortcut ( QKeySequence(Qt::Key_F10) );
274274
mToolBar->addAction ( mSplitLineAction );
275275
connect ( mSplitLineAction, SIGNAL(triggered()), this, SLOT(splitLine()) );
276276

277277
mDeleteLineAction = new QAction(
278-
QIcon(myIconPath+"grass_delete_line.png"), tr("Delete element"), this);
278+
QgsGrassPlugin::getThemeIcon("grass_delete_line.png"), tr("Delete element"), this);
279279
mDeleteLineAction->setShortcut ( QKeySequence(Qt::Key_F11) );
280280
mToolBar->addAction ( mDeleteLineAction );
281281
connect ( mDeleteLineAction, SIGNAL(triggered()), this, SLOT(deleteLine()) );
282282

283283
mEditAttributesAction = new QAction(
284-
QIcon(myIconPath+"grass_edit_attributes.png"), tr("Edit attributes"), this);
284+
QgsGrassPlugin::getThemeIcon("grass_edit_attributes.png"), tr("Edit attributes"), this);
285285
mToolBar->addAction ( mEditAttributesAction );
286286
connect ( mEditAttributesAction, SIGNAL(triggered()), this, SLOT(editAttributes()) );
287287

288288
mCloseEditAction = new QAction(
289-
QIcon(myIconPath+"grass_close_edit.png"), tr("Close"), this);
289+
QgsGrassPlugin::getThemeIcon("grass_close_edit.png"), tr("Close"), this);
290290
mToolBar->addAction ( mCloseEditAction );
291291
connect ( mCloseEditAction, SIGNAL(triggered()), this, SLOT(closeEdit()) );
292292

‎src/plugins/grass/qgsgrassmapcalc.cpp‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "qgsvectorlayer.h"
5454
#include "qgsdataprovider.h"
5555
#include "qgsfield.h"
56+
#include "qgsgrassplugin.h"
5657

5758
extern "C" {
5859
#include <grass/gis.h>
@@ -105,47 +106,46 @@ QgsGrassMapcalc::QgsGrassMapcalc (
105106

106107
mView->setCanvas ( mCanvas );
107108

108-
QString myIconPath = QgsApplication::themePath() + "/grass/";
109109

110110
QActionGroup *ag = new QActionGroup ( this );
111111
QToolBar *tb = addToolBar(tr("Mapcalc tools"));
112112

113-
mActionAddMap = new QAction( QIcon(myIconPath+"mapcalc_add_map.png"),
113+
mActionAddMap = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_add_map.png"),
114114
tr("Add map"), this);
115115
mActionAddMap->setCheckable ( true );
116116
ag->addAction ( mActionAddMap );
117117
tb->addAction ( mActionAddMap );
118118
connect ( mActionAddMap, SIGNAL(triggered()), this, SLOT(addMap()) );
119119

120-
mActionAddConstant = new QAction( QIcon(myIconPath+"mapcalc_add_constant.png"),
120+
mActionAddConstant = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_add_constant.png"),
121121
tr("Add constant value"), this);
122122
mActionAddConstant->setCheckable ( true );
123123
ag->addAction ( mActionAddConstant );
124124
tb->addAction ( mActionAddConstant );
125125
connect ( mActionAddConstant, SIGNAL(triggered()), this, SLOT(addConstant()) );
126126

127-
mActionAddFunction = new QAction( QIcon(myIconPath+"mapcalc_add_function.png"),
127+
mActionAddFunction = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_add_function.png"),
128128
tr("Add operator or function"), this);
129129
mActionAddFunction->setCheckable ( true );
130130
ag->addAction ( mActionAddFunction );
131131
tb->addAction ( mActionAddFunction );
132132
connect ( mActionAddFunction, SIGNAL(triggered()), this, SLOT(addFunction()) );
133133

134-
mActionAddConnection = new QAction( QIcon(myIconPath+"mapcalc_add_connection.png"),
134+
mActionAddConnection = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_add_connection.png"),
135135
tr("Add connection"), this);
136136
mActionAddConnection->setCheckable ( true );
137137
ag->addAction ( mActionAddConnection );
138138
tb->addAction ( mActionAddConnection );
139139
connect ( mActionAddConnection, SIGNAL(triggered()), this, SLOT(addConnection()) );
140140

141-
mActionSelectItem = new QAction( QIcon(myIconPath+"mapcalc_select.png"),
141+
mActionSelectItem = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_select.png"),
142142
tr("Select item"), this);
143143
mActionSelectItem->setCheckable ( true );
144144
ag->addAction ( mActionSelectItem );
145145
tb->addAction ( mActionSelectItem );
146146
connect ( mActionSelectItem, SIGNAL(triggered()), this, SLOT(selectItem()) );
147147

148-
mActionDeleteItem = new QAction( QIcon(myIconPath+"mapcalc_delete.png"),
148+
mActionDeleteItem = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_delete.png"),
149149
tr("Delete selected item"), this);
150150
mActionDeleteItem->setCheckable ( true );
151151
mActionDeleteItem->setEnabled ( false );
@@ -155,18 +155,18 @@ QgsGrassMapcalc::QgsGrassMapcalc (
155155

156156
mActionAddMap->setOn(true);
157157

158-
mActionLoad = new QAction( QIcon(myIconPath+"mapcalc_open.png"),
158+
mActionLoad = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_open.png"),
159159
tr("Open"), this);
160160
tb->addAction ( mActionLoad );
161161
connect ( mActionLoad, SIGNAL(triggered()), this, SLOT(load()) );
162162

163-
mActionSave = new QAction( QIcon(myIconPath+"mapcalc_save.png"),
163+
mActionSave = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_save.png"),
164164
tr("Save"), this);
165165
tb->addAction ( mActionSave );
166166
connect ( mActionSave, SIGNAL(triggered()), this, SLOT(save()) );
167167
mActionSave->setEnabled(false);
168168

169-
mActionSaveAs = new QAction( QIcon(myIconPath+"mapcalc_save_as.png"),
169+
mActionSaveAs = new QAction( QgsGrassPlugin::getThemeIcon("mapcalc_save_as.png"),
170170
tr("Save as"), this);
171171
tb->addAction ( mActionSaveAs );
172172
connect ( mActionSaveAs, SIGNAL(triggered()), this, SLOT(saveAs()) );

‎src/plugins/grass/qgsgrassmodel.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "qgis.h"
3737
#include "qgsapplication.h"
3838
#include "qgslogger.h"
39+
#include "qgsgrassplugin.h"
3940

4041
extern "C" {
4142
#include <grass/gis.h>
@@ -488,12 +489,11 @@ QgsGrassModel::QgsGrassModel ( QObject * parent )
488489

489490
mIconFile = QIcon(style->standardPixmap(QStyle::SP_FileIcon));
490491

491-
QString iconPath = QgsApplication::themePath();
492-
mIconPointLayer = QIcon ( iconPath+"/mIconPointLayer.png" );
493-
mIconLineLayer = QIcon ( iconPath+"/mIconLineLayer.png" );
494-
mIconPolygonLayer = QIcon ( iconPath+"/mIconPolygonLayer.png" );
495-
mIconVectorLayer = QIcon ( iconPath+"/grass/grass_browser_vector_layer.png" );
496-
mIconRasterLayer = QIcon ( iconPath+"/grass/grass_browser_raster_layer.png" );
492+
mIconPointLayer = QgsGrassPlugin::getThemeIcon("/mIconPointLayer.png" );
493+
mIconLineLayer = QgsGrassPlugin::getThemeIcon("/mIconLineLayer.png" );
494+
mIconPolygonLayer = QgsGrassPlugin::getThemeIcon("/mIconPolygonLayer.png" );
495+
mIconVectorLayer = QgsGrassPlugin::getThemeIcon("/grass/grass_browser_vector_layer.png" );
496+
mIconRasterLayer = QgsGrassPlugin::getThemeIcon("/grass/grass_browser_raster_layer.png" );
497497

498498
mRoot = new QgsGrassModelItem();
499499
mRoot->mType = QgsGrassModel::Location;

‎src/plugins/grass/qgsgrassmodule.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern "C" {
9090
#include "qgsgrassmapcalc.h"
9191
#include "qgsgrasstools.h"
9292
#include "qgsgrassselect.h"
93+
#include "qgsgrassplugin.h"
9394

9495
#include <gdal.h> // to collect version information
9596

@@ -2102,10 +2103,9 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
21022103
&& region != "no"
21032104
)
21042105
{
2105-
QString iconPath = QgsApplication::themePath() + "/grass/";
21062106

21072107
mRegionButton = new QPushButton(
2108-
QIcon(iconPath+"grass_set_region.png"), "" );
2108+
QgsGrassPlugin::getThemeIcon("grass_set_region.png"), "" );
21092109

21102110
mRegionButton->setToolTip ( tr("Use region of this map") );
21112111
mRegionButton->setCheckable ( true );

‎src/plugins/grass/qgsgrassnewmapsetbase.ui‎

Lines changed: 2121 additions & 1194 deletions
Large diffs are not rendered by default.

‎src/plugins/grass/qgsgrassplugin.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/* $Id$ */
1717

1818
// includes
19+
#include "qgsapplication.h"
1920
#include "qgsmaplayer.h"
2021
#include "qgisinterface.h"
2122
#include "qgsmapcanvas.h"
@@ -39,6 +40,7 @@
3940
#include <qregexp.h>
4041
#include <qglobal.h>
4142
#include <qinputdialog.h>
43+
#include <QIcon>
4244
//Added by qt3to4:
4345
#include <QPixmap>
4446
#include <Q3PointArray>
@@ -810,6 +812,22 @@ void QgsGrassPlugin::unload()
810812
disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead()));
811813
disconnect( qgis, SIGNAL( newProject() ), this, SLOT(newProject()));
812814
}
815+
// Note this code is duplicated from qgisapp.cpp because
816+
// I didnt want to make plugins dependent on qgsapplication
817+
// and because it needs grass specific path [TS]
818+
QIcon QgsGrassPlugin::getThemeIcon(const QString theName)
819+
{
820+
if (QFile::exists(QgsApplication::activeThemePath() + "/grass/" + theName))
821+
{
822+
return QIcon(QgsApplication::activeThemePath() + theName);
823+
}
824+
else
825+
{
826+
//could still return an empty icon if it
827+
//doesnt exist in the default theme either!
828+
return QIcon(QgsApplication::defaultThemePath() + "/grass/" + theName);
829+
}
830+
}
813831

814832
/**
815833
* Required extern functions needed for every plugin

‎src/plugins/grass/qgsgrassplugin.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class QgsGrassTools;
3131
class QgsGrassNewMapset;
3232
class QgsGrassRegion;
3333
class QToolBar;
34+
class QIcon;
3435
/**
3536
* \class QgsGrassPlugin
3637
* \brief OpenModeller plugin for QGIS
@@ -69,6 +70,8 @@ Q_OBJECT public:
6970
QPen & regionPen(void);
7071
//! Set Region Pen
7172
void setRegionPen(QPen &);
73+
//! Get a plugin icon resource using the active theme
74+
static QIcon getThemeIcon(const QString theName);
7275

7376
public slots:
7477
//! init the gui

‎tests/src/core/testqgsapplication.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void TestQgsApplication::initTestCase()
4646

4747
void TestQgsApplication::checkTheme()
4848
{
49-
QString myIconPath = QgsApplication::themePath();
49+
QString myIconPath = QgsApplication::defaultThemePath();
5050
QPixmap myPixmap;
5151
myPixmap.load(myIconPath+"/mIconProjectionDisabled.png");
5252
qDebug("Checking if a theme icon exists:");

0 commit comments

Comments
 (0)
Please sign in to comment.