some static analyzer improvements for service runner

Summary:
- be more consty (and don't risk detatching containers)
- init members
- don't ql1s to qstring
- use auto when newing an object

Test Plan: test passes

Reviewers: broulik

Reviewed By: broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28138
wilder-portage-prov
Harald Sitter 6 years ago
parent 86f0e49150
commit fab5b5e26d
  1. 2
      runners/services/autotests/servicerunnertest.cpp
  2. 27
      runners/services/servicerunner.cpp
  3. 2
      runners/services/servicerunner.h

@ -29,7 +29,7 @@
#include "../servicerunner.h" #include "../servicerunner.h"
#include <locale.h> #include <clocale>
class ServiceRunnerTest : public QObject class ServiceRunnerTest : public QObject
{ {

@ -105,27 +105,27 @@ private:
return ret; return ret;
} }
qreal increaseMatchRelavance(const KService::Ptr &service, QVector<QStringRef> &strList, QString category) qreal increaseMatchRelavance(const KService::Ptr &service, const QVector<QStringRef> &strList, const QString &category)
{ {
//Increment the relevance based on all the words (other than the first) of the query list //Increment the relevance based on all the words (other than the first) of the query list
qreal relevanceIncrement = 0; qreal relevanceIncrement = 0;
for(int i=1; i<strList.size(); i++) for(int i = 1; i < strList.size(); ++i) {
{ const auto &str = strList.at(i);
if (category == QLatin1String("Name")) { if (category == QLatin1String("Name")) {
if (service->name().contains(strList[i], Qt::CaseInsensitive)) { if (service->name().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01; relevanceIncrement += 0.01;
} }
} else if (category == QLatin1String("GenericName")) { } else if (category == QLatin1String("GenericName")) {
if (service->genericName().contains(strList[i], Qt::CaseInsensitive)) { if (service->genericName().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01; relevanceIncrement += 0.01;
} }
} else if (category == QLatin1String("Exec")) { } else if (category == QLatin1String("Exec")) {
if (service->exec().contains(strList[i], Qt::CaseInsensitive)) { if (service->exec().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01; relevanceIncrement += 0.01;
} }
} else if (category == QLatin1String("Comment")) { } else if (category == QLatin1String("Comment")) {
if (service->comment().contains(strList[i], Qt::CaseInsensitive)) { if (service->comment().contains(str, Qt::CaseInsensitive)) {
relevanceIncrement += 0.01; relevanceIncrement += 0.01;
} }
} }
@ -337,7 +337,8 @@ private:
continue; continue;
} }
for (const KServiceAction &action : service->actions()) { const auto actions = service->actions();
for (const KServiceAction &action : actions) {
if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) { if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) {
continue; continue;
} }
@ -377,7 +378,7 @@ private:
QList<Plasma::QueryMatch> matches; QList<Plasma::QueryMatch> matches;
QString query; QString query;
QString term; QString term;
int weightedTermLength; int weightedTermLength = -1;
}; };
ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args) ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)
@ -391,9 +392,7 @@ ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:"))); addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:")));
} }
ServiceRunner::~ServiceRunner() ServiceRunner::~ServiceRunner() = default;
{
}
QStringList ServiceRunner::categories() const QStringList ServiceRunner::categories() const
{ {
@ -455,14 +454,14 @@ QMimeData * ServiceRunner::mimeDataForMatch(const Plasma::QueryMatch &match)
QString path = service->entryPath(); QString path = service->entryPath();
if (!QDir::isAbsolutePath(path)) { if (!QDir::isAbsolutePath(path)) {
path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/") + path); path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kservices5/") + path);
} }
if (path.isEmpty()) { if (path.isEmpty()) {
return nullptr; return nullptr;
} }
QMimeData *data = new QMimeData(); auto *data = new QMimeData();
data->setUrls(QList<QUrl>{QUrl::fromLocalFile(path)}); data->setUrls(QList<QUrl>{QUrl::fromLocalFile(path)});
return data; return data;
} }

@ -41,7 +41,7 @@ class ServiceRunner : public Plasma::AbstractRunner
~ServiceRunner() override; ~ServiceRunner() override;
void match(Plasma::RunnerContext &context) override; void match(Plasma::RunnerContext &context) override;
void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action) override; void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override;
QStringList categories() const override; QStringList categories() const override;
QIcon categoryIcon(const QString& category) const override; QIcon categoryIcon(const QString& category) const override;

Loading…
Cancel
Save