Skip to content

Commit a525f6e

Browse files
author
timlinux
committedJul 28, 2008
Final fixes to default theme overlays and support for theme selection in grass plugin. I have added setThemeName and themeName accessor and mutator to qgsapplication which return the theme name only sans path. Various other changes were made to support properly masking themes with missing icons so that the default icon is used instead.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8941 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

4 files changed

+69
-29
lines changed

4 files changed

+69
-29
lines changed
 

‎python/core/qgsapplication.sip

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

8383
virtual ~QgsApplication();
8484

85-
//! Set the active theme path to the specified theme.
86-
static void setTheme(const QString theThemeName);
85+
/** Set the active theme to the specified theme.
86+
* The theme name should be a single word e.g. 'default','classic'.
87+
* The theme search path usually will be pkgDataPath + "/themes/" + themName + "/"
88+
* but plugin writers etc can use themeName() as a basis for searching
89+
* for resources in their own datastores e.g. a Qt4 resource bundle.
90+
* @Note A basic test will be carried out to ensure the theme search path
91+
* based on the supplied theme name exists. If it does not the theme name will
92+
* be reverted to 'default'.
93+
*/
94+
static void setThemeName(const QString theThemeName);
95+
96+
/** Set the active theme to the specified theme.
97+
* The theme name should be a single word e.g. 'default','classic'.
98+
* The theme search path usually will be pkgDataPath + "/themes/" + themName + "/"
99+
* but plugin writers etc can use this method as a basis for searching
100+
* for resources in their own datastores e.g. a Qt4 resource bundle.
101+
*/
102+
static const QString themeName();
87103

88104
//! Returns the path to the authors file.
89105
static const QString authorsFilePath();

‎src/app/qgisapp.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
445445
mFullScreenMode = false;
446446
show();
447447
qApp->processEvents();
448+
//finally show all the application settings as initialised above
449+
QgsApplication::showSettings();
448450
} // QgisApp ctor
449451

450452

@@ -1267,12 +1269,9 @@ void QgisApp::setTheme(QString theThemeName)
12671269
// the themes directory and builds a list of themes (ie subdirectories)
12681270
// for the user to choose from.
12691271
//
1270-
// TODO: Check as each icon is grabbed and if it doesn't exist, use the
1271-
// one from the default theme (which is installed with qgis and should
1272-
// always be good)
12731272
*/
1274-
QgsApplication::setTheme(theThemeName);
1275-
QgsDebugMsg("Setting theme to \n" + QgsApplication::activeThemePath());
1273+
QgsApplication::setThemeName(theThemeName);
1274+
QgsDebugMsg("Setting theme to \n" + theThemeName);
12761275
mActionFileNew->setIcon(getThemeIcon( "/mActionFileNew.png"));
12771276
mActionFileSave->setIcon(getThemeIcon( "/mActionFileSave.png"));
12781277
mActionFileSaveAs->setIcon(getThemeIcon( "/mActionFileSaveAs.png"));
@@ -1670,8 +1669,6 @@ void QgisApp::about()
16701669
void QgisApp::restoreSessionPlugins(QString thePluginDirString)
16711670
{
16721671
QSettings mySettings;
1673-
1674-
QgsApplication::showSettings();
16751672
QgsDebugMsg("\n\n*************************************************");
16761673
QgsDebugMsg("Restoring plugins from last session " + thePluginDirString);
16771674

@@ -5567,15 +5564,17 @@ void QgisApp::setupProxy()
55675564

55685565
QIcon QgisApp::getThemeIcon(const QString theName)
55695566
{
5570-
if (QFile::exists(QgsApplication::activeThemePath() + theName))
5567+
QString myPreferredPath = QgsApplication::activeThemePath() + theName;
5568+
QString myDefaultPath = QgsApplication::defaultThemePath() + theName;
5569+
if (QFile::exists(myPreferredPath))
55715570
{
5572-
return QIcon(QgsApplication::activeThemePath() + theName);
5571+
return QIcon(myPreferredPath);
55735572
}
5574-
else if (QFile::exists(QgsApplication::defaultThemePath() + theName))
5573+
else if (QFile::exists(myDefaultPath))
55755574
{
55765575
//could still return an empty icon if it
55775576
//doesnt exist in the default theme either!
5578-
return QIcon(QgsApplication::defaultThemePath() + theName);
5577+
return QIcon(myDefaultPath);
55795578
}
55805579
else
55815580
{
@@ -5585,15 +5584,17 @@ QIcon QgisApp::getThemeIcon(const QString theName)
55855584

55865585
QPixmap QgisApp::getThemePixmap(const QString theName)
55875586
{
5588-
if (QFile::exists(QgsApplication::activeThemePath() + theName))
5587+
QString myPreferredPath = QgsApplication::activeThemePath() + theName;
5588+
QString myDefaultPath = QgsApplication::defaultThemePath() + theName;
5589+
if (QFile::exists(myPreferredPath))
55895590
{
5590-
return QPixmap(QgsApplication::activeThemePath() + theName);
5591+
return QPixmap(myPreferredPath);
55915592
}
55925593
else
55935594
{
55945595
//could still return an empty icon if it
55955596
//doesnt exist in the default theme either!
5596-
return QPixmap(QgsApplication::defaultThemePath() + theName);
5597+
return QPixmap(myDefaultPath);
55975598
}
55985599
}
55995600

‎src/core/qgsapplication.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
QString QgsApplication::mPrefixPath;
3535
QString QgsApplication::mPluginPath;
3636
QString QgsApplication::mPkgDataPath;
37-
QString QgsApplication::mThemePath;
37+
QString QgsApplication::mThemeName;
3838

3939
/*!
4040
\class QgsApplication
@@ -91,7 +91,6 @@ void QgsApplication::setPluginPath(const QString thePluginPath)
9191
void QgsApplication::setPkgDataPath(const QString thePkgDataPath)
9292
{
9393
mPkgDataPath = thePkgDataPath;
94-
mThemePath = mPkgDataPath + QString("/themes/default/");
9594
}
9695

9796
const QString QgsApplication::prefixPath()
@@ -108,30 +107,36 @@ const QString QgsApplication::pkgDataPath()
108107
}
109108
const QString QgsApplication::defaultThemePath()
110109
{
111-
return mPkgDataPath + QString("/themes/default/");
110+
return mPkgDataPath + "/themes/default/";
112111
}
113112
const QString QgsApplication::activeThemePath()
114113
{
115-
return mThemePath;
114+
return mPkgDataPath + "/themes/" + mThemeName + "/";
116115
}
117116

118117
/*!
119118
Set the theme path to the specified theme.
120119
*/
121-
void QgsApplication::setTheme(const QString theThemeName)
120+
void QgsApplication::setThemeName(const QString theThemeName)
122121
{
123-
QString myPath = mPkgDataPath + QString("/themes/") + theThemeName + QString("/");
122+
QString myPath = mPkgDataPath + "/themes/" + theThemeName + "/";
124123
//check it exists and if not roll back to default theme
125124
if (QFile::exists(myPath))
126125
{
127-
mThemePath = myPath;
126+
mThemeName = theThemeName;
128127
}
129128
else
130129
{
131-
mThemePath = defaultThemePath();
130+
mThemeName = "default";
132131
}
133132
}
134-
133+
/*!
134+
* Get the active theme name
135+
*/
136+
const QString QgsApplication::themeName()
137+
{
138+
return mThemeName;
139+
}
135140
/*!
136141
Returns the path to the authors file.
137142
*/
@@ -269,7 +274,9 @@ void QgsApplication::showSettings()
269274
qDebug("Prefix :" + mPrefixPath.toLocal8Bit());
270275
qDebug("Plugin Path :" + mPluginPath.toLocal8Bit());
271276
qDebug("PkgData Path :" + mPkgDataPath.toLocal8Bit());
272-
qDebug("Theme Path :" + mThemePath.toLocal8Bit());
277+
qDebug("Active Theme Name :" + themeName().toLocal8Bit());
278+
qDebug("Active Theme Path :" + activeThemePath().toLocal8Bit());
279+
qDebug("Default Theme Path :" + defaultThemePath().toLocal8Bit());
273280
qDebug("User DB Path :" + qgisMasterDbFilePath().toLocal8Bit());
274281
qDebug("**********************************\n");
275282
}

‎src/core/qgsapplication.h

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

27-
//! Set the active theme path to the specified theme.
28-
static void setTheme(const QString theThemeName);
27+
/** Set the active theme to the specified theme.
28+
* The theme name should be a single word e.g. 'default','classic'.
29+
* The theme search path usually will be pkgDataPath + "/themes/" + themName + "/"
30+
* but plugin writers etc can use themeName() as a basis for searching
31+
* for resources in their own datastores e.g. a Qt4 resource bundle.
32+
* @Note A basic test will be carried out to ensure the theme search path
33+
* based on the supplied theme name exists. If it does not the theme name will
34+
* be reverted to 'default'.
35+
*/
36+
static void setThemeName(const QString theThemeName);
37+
38+
/** Set the active theme to the specified theme.
39+
* The theme name should be a single word e.g. 'default','classic'.
40+
* The theme search path usually will be pkgDataPath + "/themes/" + themName + "/"
41+
* but plugin writers etc can use this method as a basis for searching
42+
* for resources in their own datastores e.g. a Qt4 resource bundle.
43+
*/
44+
static const QString themeName() ;
2945

3046
//! Returns the path to the authors file.
3147
static const QString authorsFilePath();
@@ -123,7 +139,7 @@ class CORE_EXPORT QgsApplication: public QApplication
123139
static QString mPrefixPath;
124140
static QString mPluginPath;
125141
static QString mPkgDataPath;
126-
static QString mThemePath;
142+
static QString mThemeName;
127143
};
128144

129145
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.