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

Use Q_EMIT + const'ify

parent 689bd09e
......@@ -25,12 +25,6 @@
#include "logging.h"
class CrontabPrinterPrivate
{
public:
};
CrontabPrinter::CrontabPrinter(CrontabWidget *crontabWidget)
{
mCrontabWidget = crontabWidget;
......
......@@ -18,7 +18,6 @@ class QString;
class CrontabWidget;
class CrontabPrinterPrivate;
class QPrinter;
/**
*Provides a wrapper for simple printing of text.
......
......@@ -233,7 +233,7 @@ void CrontabWidget::copy()
if (mVariablesWidget->treeWidget()->hasFocus()) {
logDebug() << "Variables copying";
QList<VariableWidget *> variablesWidget = mVariablesWidget->selectedVariablesWidget();
const QList<VariableWidget *> variablesWidget = mVariablesWidget->selectedVariablesWidget();
foreach (VariableWidget *variableWidget, variablesWidget) {
CTVariable *variable = new CTVariable(*(variableWidget->getCTVariable()));
mClipboardVariables.append(variable);
......@@ -271,13 +271,13 @@ void CrontabWidget::paste()
logDebug() << "Paste content";
if (mTasksWidget->treeWidget()->hasFocus()) {
foreach (CTTask *task, mClipboardTasks) {
for (CTTask *task : qAsConst(mClipboardTasks)) {
mTasksWidget->addTask(new CTTask(*task));
}
}
if (mVariablesWidget->treeWidget()->hasFocus()) {
foreach (CTVariable *variable, mClipboardVariables) {
for (CTVariable *variable : qAsConst(mClipboardVariables)) {
mVariablesWidget->addVariable(new CTVariable(*variable));
}
}
......
......@@ -24,15 +24,14 @@ CTMinute::CTMinute()
int CTMinute::findPeriod() const
{
QList<int> periods;
periods << 1 << 2 << 5 << 10 << 15 << 20 << 30;
const QList<int> periods {1, 2, 5, 10, 15, 20, 30};
return CTUnit::findPeriod(periods);
}
QString CTMinute::exportUnit() const
{
int period = findPeriod();
const int period = findPeriod();
if (period != 0 && period != 1) {
return QStringLiteral("*/%1").arg(QString::number(period));
}
......
......@@ -85,11 +85,11 @@ void CTUnit::parse(const QString &tokenString)
// loop through each subelement
tokStr += QLatin1Char(',');
while ((commapos = tokStr.indexOf(QLatin1String(","))) > 0) {
while ((commapos = tokStr.indexOf(QLatin1Char(','))) > 0) {
subelement = tokStr.mid(0, commapos);
// find "/" to determine step
slashpos = subelement.indexOf(QLatin1String("/"));
slashpos = subelement.indexOf(QLatin1Char('/'));
if (slashpos == -1) {
step = 1;
slashpos = subelement.length();
......@@ -101,10 +101,10 @@ void CTUnit::parse(const QString &tokenString)
}
// find "=" to determine range
dashpos = subelement.indexOf(QLatin1String("-"));
dashpos = subelement.indexOf(QLatin1Char('-'));
if (dashpos == -1) {
// deal with "*"
if (subelement.mid(0, slashpos) == QLatin1String("*")) {
if (subelement.mid(0, slashpos) == QLatin1Char('*')) {
beginat = mMin;
endat = mMax;
} else {
......
......@@ -104,7 +104,7 @@ CTHost *GenericListWidget::ctHost() const
void GenericListWidget::resizeColumnContents()
{
//Resize all columns except the last one (which always take the last available space)
for (int i = 0; i < mTreeWidget->columnCount()-1; ++i) {
for (int i = 0, total = mTreeWidget->columnCount()-1; i < total; ++i) {
mTreeWidget->resizeColumnToContents(i);
}
}
......
......@@ -51,8 +51,8 @@ QList<TaskWidget *> TasksWidget::selectedTasksWidget() const
{
QList<TaskWidget *> tasksWidget;
QList<QTreeWidgetItem *> tasksItems = treeWidget()->selectedItems();
foreach (QTreeWidgetItem *item, tasksItems) {
const QList<QTreeWidgetItem *> tasksItems = treeWidget()->selectedItems();
for (QTreeWidgetItem *item : tasksItems) {
TaskWidget *taskWidget = static_cast<TaskWidget *>(item);
tasksWidget.append(taskWidget);
}
......@@ -63,7 +63,7 @@ QList<TaskWidget *> TasksWidget::selectedTasksWidget() const
TaskWidget *TasksWidget::firstSelectedTaskWidget() const
{
QTreeWidgetItem *item = firstSelected();
if (item == nullptr) {
if (!item) {
return nullptr;
}
......@@ -90,14 +90,15 @@ void TasksWidget::runTaskNow() const
QString echoMessage = i18nc("Do not use any quote characters (') in this string", "End of script execution. Type Enter or Ctrl+C to exit.");
CTCron *ctCron = crontabWidget()->currentCron();
if (ctCron == nullptr) {
if (!ctCron) {
logDebug() << "Unable to find the related CtCron, please report this bug to KCron developer";
return;
}
QStringList commandList;
foreach (CTVariable *variable, ctCron->variables()) {
const auto variables = ctCron->variables();
for (CTVariable *variable : variables) {
commandList << QStringLiteral("export %1=\"%2\"").arg(variable->variable, variable->value);
}
......@@ -124,7 +125,7 @@ void TasksWidget::createTask()
if (result == QDialog::Accepted) {
addTask(task);
emit taskModified(true);
Q_EMIT taskModified(true);
changeCurrentSelection();
} else {
......@@ -151,7 +152,7 @@ void TasksWidget::modifySelection(QTreeWidgetItem *item, int position)
if (taskWidget != nullptr) {
if (position == statusColumnIndex()) {
taskWidget->toggleEnable();
emit taskModified(true);
Q_EMIT taskModified(true);
} else {
CTTask *task = taskWidget->getCTTask();
TaskEditorDialog taskEditorDialog(task, i18n("Modify Task"), crontabWidget());
......@@ -160,7 +161,7 @@ void TasksWidget::modifySelection(QTreeWidgetItem *item, int position)
if (result == QDialog::Accepted) {
crontabWidget()->currentCron()->modifyTask(task);
taskWidget->refresh();
emit taskModified(true);
Q_EMIT taskModified(true);
}
}
}
......@@ -186,7 +187,7 @@ void TasksWidget::deleteSelection()
}
if (deleteSomething) {
emit taskModified(true);
Q_EMIT taskModified(true);
changeCurrentSelection();
}
......
......@@ -46,9 +46,9 @@ private:
/**
* Variable
*/
CTVariable *ctVariable;
CTVariable *ctVariable = nullptr;
VariablesWidget *variablesWidget;
VariablesWidget *variablesWidget = nullptr;
};
#endif // VARIABLE_WIDGET_H
......@@ -57,7 +57,7 @@ void VariablesWidget::modifySelection(QTreeWidgetItem *item, int position)
if (variableWidget != nullptr) {
if (position == statusColumnIndex()) {
variableWidget->toggleEnable();
emit variableModified(true);
Q_EMIT variableModified(true);
} else {
CTVariable *variable = variableWidget->getCTVariable();
VariableEditorDialog variableEditorDialog(variable, i18n("Modify Variable"), crontabWidget());
......@@ -67,7 +67,7 @@ void VariablesWidget::modifySelection(QTreeWidgetItem *item, int position)
crontabWidget()->currentCron()->modifyVariable(variable);
variableWidget->refresh();
emit variableModified(true);
Q_EMIT variableModified(true);
}
}
}
......@@ -111,7 +111,7 @@ void VariablesWidget::deleteSelection()
}
if (deleteSomething) {
emit variableModified(true);
Q_EMIT variableModified(true);
changeCurrentSelection();
}
}
......@@ -144,7 +144,7 @@ void VariablesWidget::createVariable()
if (result == QDialog::Accepted) {
addVariable(variable);
emit variableModified(true);
Q_EMIT variableModified(true);
changeCurrentSelection();
} else {
delete variable;
......
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