Commit b8b5a51b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

const'ify method + port some foreach(...)

parent cfc703d5
......@@ -40,12 +40,15 @@ QList<CTTask *> CTGlobalCron::tasks() const
logDebug() << "Global Cron Tasks";
QList<CTTask *> tasks;
foreach (CTCron *cron, mCtHost->crons) {
const auto crons = mCtHost->crons;
for (CTCron *cron : crons) {
if (cron->isSystemCron()) {
continue;
}
foreach (CTTask *task, cron->tasks()) {
const auto ctasks = cron->tasks();
for (CTTask *task : ctasks) {
tasks.append(task);
}
}
......@@ -57,12 +60,13 @@ QList<CTVariable *> CTGlobalCron::variables() const
logDebug() << "Global Cron Variables";
QList<CTVariable *> variables;
foreach (CTCron *cron, mCtHost->crons) {
const auto crons = mCtHost->crons;
for (CTCron *cron : crons) {
if (cron->isSystemCron()) {
continue;
}
foreach (CTVariable *variable, cron->variables()) {
const auto cvariables = cron->variables();
for (CTVariable *variable : cvariables) {
variables.append(variable);
}
}
......@@ -96,8 +100,8 @@ void CTGlobalCron::modifyTask(CTTask *task)
* actualCron could be NULL is the task came from clipboard because those tasks are never
* linked to an existing CTCron* object
*/
if (actualCron == nullptr || actualCron->userLogin() != task->userLogin) {
if (actualCron != nullptr) {
if (!actualCron || actualCron->userLogin() != task->userLogin) {
if (actualCron) {
actualCron->removeTask(task);
}
......@@ -116,8 +120,8 @@ void CTGlobalCron::modifyVariable(CTVariable *variable)
* actualCron could be NULL is the task came from clipboard because those tasks are never
* linked to an existing CTCron* object
*/
if (actualCron == nullptr || actualCron->userLogin() != variable->userLogin) {
if (actualCron != nullptr) {
if (!actualCron || actualCron->userLogin() != variable->userLogin) {
if (actualCron) {
actualCron->removeVariable(variable);
}
......
......@@ -17,7 +17,7 @@ QString CTHelper::exportComment(const QString &comment)
QString exportComment;
if (comment.isEmpty()) {
QString noComment = i18n("No comment");
const QString noComment = i18n("No comment");
exportComment += QLatin1String("#") + noComment + QLatin1String("\n");
return exportComment;
}
......
......@@ -7,3 +7,22 @@
*/
#include "ctInitializationError.h"
QString CTInitializationError::errorMessage() const
{
return mError;
}
void CTInitializationError::setErrorMessage(const QString &errorMessage)
{
this->mError = errorMessage;
}
bool CTInitializationError::hasErrorMessage() const
{
if (mError.isEmpty()) {
return false;
}
return true;
}
......@@ -15,24 +15,11 @@ class CTInitializationError
{
public:
QString errorMessage() const
{
return mError;
}
void setErrorMessage(const QString &errorMessage)
{
this->mError = errorMessage;
}
bool hasErrorMessage()
{
if (mError.isEmpty()) {
return false;
}
return true;
}
QString errorMessage() const;
void setErrorMessage(const QString &errorMessage);
bool hasErrorMessage() const;
private:
QString mError;
......
......@@ -27,7 +27,7 @@ int CTHour::findPeriod() const
QString CTHour::exportUnit() const
{
int period = findPeriod();
const int period = findPeriod();
if (period != 0 && period != 1) {
return QStringLiteral("*/%1").arg(QString::number(period));
}
......
......@@ -24,7 +24,8 @@ void KCronHelper::initUserCombo(QComboBox *userCombo, CrontabWidget *crontabWidg
QStringList users;
int selectedIndex = 0;
foreach (CTCron *ctCron, crontabWidget->ctHost()->crons) {
const auto crons = crontabWidget->ctHost()->crons;
for (CTCron *ctCron : crons) {
if (ctCron->isSystemCron()) {
continue;
}
......@@ -52,7 +53,7 @@ QTextEdit *KCronHelper::createCommentEdit(QWidget *parent)
edit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
edit->setTabChangesFocus(true);
QFontMetrics fontMetrics(edit->currentFont());
const QFontMetrics fontMetrics(edit->currentFont());
edit->setMaximumHeight(fontMetrics.lineSpacing() * 3); //TODO Choose a smarter value
return edit;
......
......@@ -110,7 +110,7 @@ void TasksWidget::runTaskNow() const
QStringList parameters;
parameters << QStringLiteral("-e") << QStringLiteral("bash") << QStringLiteral("-c");
parameters << commandList.join(QLatin1String(";"));
parameters << commandList.join(QLatin1Char(';'));
QProcess process;
process.startDetached(QStringLiteral("konsole"), parameters);
......@@ -149,7 +149,7 @@ void TasksWidget::modifySelection()
void TasksWidget::modifySelection(QTreeWidgetItem *item, int position)
{
TaskWidget *taskWidget = static_cast<TaskWidget *>(item);
if (taskWidget != nullptr) {
if (taskWidget) {
if (position == statusColumnIndex()) {
taskWidget->toggleEnable();
Q_EMIT taskModified(true);
......@@ -202,7 +202,8 @@ void TasksWidget::refreshTasks(CTCron *cron)
refreshHeaders();
//Add new items
foreach (CTTask *ctTask, cron->tasks()) {
const auto tasks = cron->tasks();
for (CTTask *ctTask : tasks) {
new TaskWidget(this, ctTask);
}
......@@ -285,8 +286,9 @@ void TasksWidget::prepareContextualMenu()
treeWidget()->addAction(mDeleteAction);
treeWidget()->addAction(createSeparator());
const auto cutCopyPasteActions = crontabWidget()->cutCopyPasteActions();
foreach (QAction *action, crontabWidget()->cutCopyPasteActions()) {
for (QAction *action : cutCopyPasteActions) {
treeWidget()->addAction(action);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment