Skip to content

Commit 3a4648f

Browse files
author
timlinux
committed
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
1 parent 91d5f39 commit 3a4648f

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

0 commit comments

Comments
 (0)