Skip to content

Commit

Permalink
Use const variables where possible
Browse files Browse the repository at this point in the history
It helps the compiler in the optimization process.
It helps the programmer understanding the code.
  • Loading branch information
luis-pereira committed Jan 5, 2017
1 parent 6319ed6 commit d785898
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lxqtapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Application::Application(int &argc, char** argv, bool handleQuitSignals)

void Application::updateTheme()
{
QString styleSheetKey = QFileInfo(applicationFilePath()).fileName();
const QString styleSheetKey = QFileInfo(applicationFilePath()).fileName();
setStyleSheet(lxqtTheme.qss(styleSheetKey));
emit themeChanged();
}
Expand All @@ -140,7 +140,7 @@ namespace
public:
static void signalHandler(int signo)
{
int ret = write(instance->mSignalSock[0], &signo, sizeof (int));
const int ret = write(instance->mSignalSock[0], &signo, sizeof (int));
if (sizeof (int) != ret)
qCritical() << QStringLiteral("unable to write into socketpair, %1").arg(strerror(errno));
}
Expand Down
6 changes: 3 additions & 3 deletions lxqtautostartentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AutostartEntry::AutostartEntry(const QString& name):
{
foreach (const QString& dir, XdgDirs::autostartDirs())
{
QString path = QString("%1/%2").arg(dir, name);
const QString path = QString("%1/%2").arg(dir, name);
if (QFile(path).exists())
{
mSystemFile.load(path);
Expand All @@ -49,7 +49,7 @@ AutostartEntry::AutostartEntry(const QString& name):
}
}

QString path = QString("%1/%2").arg(XdgDirs::autostartHome(), name);
const QString path = QString("%1/%2").arg(XdgDirs::autostartHome(), name);
if (QFile(path).exists())
{
mLocalFile.load(path);
Expand All @@ -59,7 +59,7 @@ AutostartEntry::AutostartEntry(const QString& name):

void AutostartEntry::setFile(const XdgDesktopFile& file)
{
bool local = isLocal();
const bool local = isLocal();
if (mSystem && local && file == mSystemFile)
{
removeLocal();
Expand Down
8 changes: 4 additions & 4 deletions lxqthtmldelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void HtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
options.icon = QIcon();

// icon size
QSize iconSize = icon.actualSize(mIconSize);
const QSize iconSize = icon.actualSize(mIconSize);
QRect iconRect = QRect(8, 8, iconSize.width(), iconSize.height());
if (is_right_to_left)
{
Expand All @@ -86,7 +86,7 @@ void HtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
// shift text right to make icon visible
painter->translate(iconRect.right() + 8, 0);
}
QRect clip(0, 0, options.rect.width() - iconRect.width() - 8, options.rect.height());
const QRect clip(0, 0, options.rect.width() - iconRect.width() - 8, options.rect.height());
painter->setClipRect(clip);

// set text color to red for selected item
Expand All @@ -112,8 +112,8 @@ QSize HtmlDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelInd
QStyleOptionViewItem options = option;
initStyleOption(&options, index);

QSize iconSize = options.icon.actualSize(mIconSize);
QRect iconRect = QRect(8, 8, iconSize.width(), iconSize.height());
const QSize iconSize = options.icon.actualSize(mIconSize);
const QRect iconRect = QRect(8, 8, iconSize.width(), iconSize.height());

QTextDocument doc;
doc.setHtml(options.text);
Expand Down
15 changes: 7 additions & 8 deletions lxqtplugininfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ bool PluginInfo::isValid() const
************************************************/
QLibrary* PluginInfo::loadLibrary(const QString& libDir) const
{
QString baseName, path;
QFileInfo fi = QFileInfo(fileName());
path = fi.canonicalPath();
baseName = value("X-LXQt-Library", fi.completeBaseName()).toString();
const QFileInfo fi = QFileInfo(fileName());
const QString path = fi.canonicalPath();
const QString baseName = value("X-LXQt-Library", fi.completeBaseName()).toString();

QString soPath = QDir(libDir).filePath(QString("lib%2.so").arg(baseName));
const QString soPath = QDir(libDir).filePath(QString("lib%2.so").arg(baseName));
QLibrary* library = new QLibrary(soPath);

if (!library->load())
Expand All @@ -87,7 +86,7 @@ QLibrary* PluginInfo::loadLibrary(const QString& libDir) const
return 0;
}

QString locale = QLocale::system().name();
const QString locale = QLocale::system().name();
QTranslator* translator = new QTranslator(library);

translator->load(QString("%1/%2/%2_%3.qm").arg(path, baseName, locale));
Expand All @@ -107,8 +106,8 @@ PluginInfoList PluginInfo::search(const QStringList& desktopFilesDirs, const QSt

foreach (const QString &desktopFilesDir, desktopFilesDirs)
{
QDir dir(desktopFilesDir);
QFileInfoList files = dir.entryInfoList(QStringList(nameFilter), QDir::Files | QDir::Readable);
const QDir dir(desktopFilesDir);
const QFileInfoList files = dir.entryInfoList(QStringList(nameFilter), QDir::Files | QDir::Readable);
foreach (const QFileInfo &file, files)
{
if (processed.contains(file.fileName()))
Expand Down
4 changes: 2 additions & 2 deletions lxqtpowermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LXQT_API MessageBox: public QMessageBox

static QWidget *parentWidget()
{
QWidgetList widgets = QApplication::topLevelWidgets();
const QWidgetList widgets = QApplication::topLevelWidgets();

if (widgets.count())
return widgets.at(0);
Expand Down Expand Up @@ -76,7 +76,7 @@ class LXQT_API MessageBox: public QMessageBox
protected:
virtual void resizeEvent(QResizeEvent* event)
{
QRect screen = QApplication::desktop()->screenGeometry();
const QRect screen = QApplication::desktop()->screenGeometry();
move((screen.width() - this->width()) / 2,
(screen.height() - this->height()) / 2);

Expand Down
6 changes: 3 additions & 3 deletions lxqtprogramfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ using namespace LXQt;

LXQT_API bool ProgramFinder::programExists(const QString& command)
{
QString program = programName(command);
const QString program = programName(command);
if (program[0] == QChar('/'))
{
QFileInfo fi(program);
return fi.isExecutable() && fi.isFile();
}

QString path = qgetenv("PATH");
const QString path = qgetenv("PATH");
foreach (const QString& dirName, path.split(":", QString::SkipEmptyParts))
{
QFileInfo fi(QDir(dirName), program);
const QFileInfo fi(QDir(dirName), program);
if (fi.isExecutable() && fi.isFile())
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions lxqtrotatedwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void RotatedWidget::adjustContentSize()
{
mContent->adjustSize();

QSize before = size();
const QSize before = size();

adjustSize();

Expand Down Expand Up @@ -147,7 +147,7 @@ void RotatedWidget::paintEvent(QPaintEvent */*event*/)
if (mOrigin == Qt::TopLeftCorner)
return;

QSize sz = mContent->size();
const QSize sz = mContent->size();

QPainter painter(this);

Expand Down
6 changes: 3 additions & 3 deletions lxqttranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void Translator::setTranslationSearchPaths(const QStringList &paths)
************************************************/
bool translate(const QString &name, const QString &owner)
{
QString locale = QLocale::system().name();
const QString locale = QLocale::system().name();
QTranslator *appTranslator = new QTranslator(qApp);

QStringList *paths = getSearchPaths();
Expand Down Expand Up @@ -132,7 +132,7 @@ bool translate(const QString &name, const QString &owner)
************************************************/
bool Translator::translateApplication(const QString &applicationName)
{
QString locale = QLocale::system().name();
const QString locale = QLocale::system().name();
QTranslator *qtTranslator = new QTranslator(qApp);

if (qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
Expand Down Expand Up @@ -170,7 +170,7 @@ bool Translator::translatePlugin(const QString &pluginName, const QString& type)
{
static QSet<QString> loadedPlugins;

QString fullName = type % QChar('/') % pluginName;
const QString fullName = type % QChar('/') % pluginName;
if (loadedPlugins.contains(fullName))
return true;

Expand Down

0 comments on commit d785898

Please sign in to comment.