Skip to content

Commit

Permalink
Avoid unneeded QSettings instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 17, 2021
1 parent 174bf3f commit d36fb8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
23 changes: 17 additions & 6 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,37 @@ void ensureWindowOnScreen(QWidget *w)
ensureWindowOnScreen(w, pos);
}

} // namespace

QString getConfigurationFilePath(const char *suffix)
QString getConfigurationFilePathHelper()
{
const QSettings settings(
QSettings::IniFormat, QSettings::UserScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName() );
QString path = settings.fileName();
return settings.fileName();
}

} // namespace

const QString &getConfigurationFilePath()
{
static const QString path = getConfigurationFilePathHelper();
return path;
}

QString getConfigurationFilePath(const char *suffix)
{
QString path = getConfigurationFilePath();
// Replace suffix.
const int i = path.lastIndexOf(QLatin1Char('.'));
Q_ASSERT(i != -1);
Q_ASSERT( path.endsWith(QLatin1String(".ini")) );
return path.leftRef(i) + QLatin1String(suffix);
}

QString settingsDirectoryPath()
const QString &settingsDirectoryPath()
{
static const QString path =
QDir::cleanPath( getConfigurationFilePath("") + QLatin1String("/..") );
QDir::cleanPath( getConfigurationFilePath() + QLatin1String("/..") );
return path;
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class QString;
class QVariant;
class QWidget;

QString getConfigurationFilePath();

QString getConfigurationFilePath(const char *suffix);

QString settingsDirectoryPath();
Expand Down
6 changes: 2 additions & 4 deletions src/gui/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "ui_configtabappearance.h"

#include "common/config.h"
#include "common/log.h"
#include "gui/iconfont.h"
#include "platform/platformnativeinterface.h"
Expand Down Expand Up @@ -749,10 +750,7 @@ QColor evalColor(const QString &expression, const Theme &theme, const Values &va

QString defaultUserThemePath()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
return QDir::cleanPath(settings.fileName() + "/../themes");
return QDir::cleanPath(settingsDirectoryPath() + "/themes");
}

QStringList themePaths()
Expand Down

0 comments on commit d36fb8d

Please sign in to comment.