Commit a6ad5bad authored by Laurent Montel's avatar Laurent Montel 😁

port to for(...:...)

parent e44ed33b
......@@ -27,6 +27,7 @@
#include "calendarutils.h"
#include "utils.h"
#include "helper_p.h"
#include <KCalCore/Incidence>
#include <Akonadi/Calendar/ETMCalendar>
......@@ -223,7 +224,7 @@ bool CalendarUtils::makeChildrenIndependent(const Akonadi::Item &item)
d->mMultiChange = MultiChange(item);
bool allStarted = true;
foreach (const Akonadi::Item &subInc, subIncs) {
for (const Akonadi::Item &subInc : qAsConst(subIncs)) {
d->mMultiChange.children.append(subInc.id());
allStarted = allStarted && makeIndependent(subInc);
}
......@@ -245,14 +246,14 @@ void CalendarUtils::purgeCompletedTodos()
KCalCore::Todo::List todos = calendar()->rawTodos();
KCalCore::Todo::List rootTodos;
foreach (const KCalCore::Todo::Ptr &todo, todos) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(todos)) {
if (todo && todo->relatedTo().isEmpty()) { // top level todo //REVIEW(AKONADI_PORT)
rootTodos.append(todo);
}
}
// now that we have a list of all root todos, check them and their children
foreach (const KCalCore::Todo::Ptr &todo, rootTodos) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(rootTodos)) {
d->purgeCompletedSubTodos(todo, allDeleted);
}
......
......@@ -19,6 +19,7 @@
#include "categoryhierarchyreader.h"
#include "categoryconfig.h"
#include "helper_p.h"
#include <KComboBox>
......@@ -59,7 +60,7 @@ void CategoryHierarchyReader::read(const QStringList &categories)
}
QStringList last_path;
foreach (const QString &category, sortedCategories) {
for (const QString &category : qAsConst(sortedCategories)) {
QStringList _path = path(category);
// we need to figure out where last item and the new one differ
......
......@@ -26,7 +26,7 @@
#include "kcalprefs.h"
#include "utils.h"
#include "helper_p.h"
#include <Akonadi/Calendar/IncidenceChanger>
#include <KCalCore/ICalFormat>
......@@ -237,10 +237,10 @@ void EventArchiver::archiveIncidences(const Akonadi::ETMCalendar::Ptr &calendar,
QStringList uids;
Incidence::List allIncidences = archiveCalendar->rawIncidences();
uids.reserve(incidences.count());
foreach (const KCalCore::Incidence::Ptr &incidence, incidences) {
for (const KCalCore::Incidence::Ptr &incidence : qAsConst(incidences)) {
uids.append(incidence->uid());
}
foreach (const KCalCore::Incidence::Ptr &incidence, allIncidences) {
for (const KCalCore::Incidence::Ptr &incidence : qAsConst(allIncidences)) {
if (!uids.contains(incidence->uid())) {
archiveCalendar->deleteIncidence(incidence);
}
......@@ -312,8 +312,8 @@ void EventArchiver::archiveIncidences(const Akonadi::ETMCalendar::Ptr &calendar,
changer->startAtomicOperation(i18n("Archiving events"));
// Delete archived events from calendar
Akonadi::Item::List items = calendar->itemList(incidences);
foreach (const Akonadi::Item &item, items) {
const Akonadi::Item::List items = calendar->itemList(incidences);
for (const Akonadi::Item &item : items) {
changer->deleteIncidence(item, widget);
} // TODO: Q_EMIT only after hearing back from incidence changer
changer->endAtomicOperation();
......
......@@ -92,7 +92,8 @@ void FreeBusyCalendar::setModel(FreeBusyItemModel *model)
void FreeBusyCalendar::deleteAllEvents()
{
foreach (const KCalCore::Event::Ptr &event, d->mCalendar->events()) {
const KCalCore::Event::List lstEvents = d->mCalendar->events();
for (const KCalCore::Event::Ptr &event : lstEvents) {
d->mCalendar->deleteEvent(event);
}
}
......
......@@ -19,6 +19,7 @@
*/
#include "freebusyitemmodel.h"
#include "helper_p.h"
#include <Akonadi/Calendar/FreeBusyManager>
......@@ -359,7 +360,7 @@ void FreeBusyItemModel::updateFreeBusyData(const FreeBusyItem::Ptr &item)
void FreeBusyItemModel::timerEvent(QTimerEvent *event)
{
killTimer(event->timerId());
Q_FOREACH (FreeBusyItem::Ptr item, d->mFreeBusyItems) {
for (FreeBusyItem::Ptr item : qAsConst(d->mFreeBusyItems)) {
if (item->updateTimerID() == event->timerId()) {
item->setUpdateTimerID(0);
item->startDownload(d->mForceDownload);
......@@ -381,7 +382,7 @@ void FreeBusyItemModel::slotInsertFreeBusy(const KCalCore::FreeBusy::Ptr &fb,
fb->sortList();
Q_FOREACH (FreeBusyItem::Ptr item, d->mFreeBusyItems) {
for (FreeBusyItem::Ptr item : qAsConst(d->mFreeBusyItems)) {
if (item->email() == email) {
item->setFreeBusy(fb);
const int row = d->mFreeBusyItems.indexOf(item);
......@@ -400,7 +401,7 @@ void FreeBusyItemModel::autoReload()
void FreeBusyItemModel::reload()
{
Q_FOREACH (FreeBusyItem::Ptr item, d->mFreeBusyItems) {
for (FreeBusyItem::Ptr item : qAsConst(d->mFreeBusyItems)) {
if (d->mForceDownload) {
item->startDownload(d->mForceDownload);
} else {
......
/*
Copyright (c) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef _HELPER_H
#define _HELPER_H
#include <qglobal.h>
#if QT_VERSION < QT_VERSION_CHECK(5,7,0)
namespace QtPrivate
{
template <typename T> struct QAddConst {
typedef const T Type;
};
}
// this adds const to non-const objects (like std::as_const)
template <typename T>
Q_DECL_CONSTEXPR typename QtPrivate::QAddConst<T>::Type &qAsConst(T &t) Q_DECL_NOTHROW { return t; }
// prevent rvalue arguments:
template <typename T>
void qAsConst(const T &&) Q_DECL_EQ_DELETE;
#endif
#endif
......@@ -54,7 +54,8 @@ public:
}
bool collectionMatchesMimeTypes() const
{
Q_FOREACH (const QString &type, allMimeTypes()) {
const QStringList lst = allMimeTypes();
for (const QString &type : lst) {
if (q->collection().contentMimeTypes().contains(type)) {
return true;
}
......
......@@ -28,6 +28,7 @@
#include "calprintdefaultplugins.h"
#include "kcalprefs.h"
#include "utils.h"
#include "helper_p.h"
#include <Item>
......@@ -502,7 +503,7 @@ void CalPrintIncidence::print(QPainter &p, int width, int height)
QString statusString;
QString datesString;
int count = 0;
foreach (const Akonadi::Item &item, relations) {
for (const Akonadi::Item &item : qAsConst(relations)) {
KCalCore::Todo::Ptr todo = CalendarSupport::todo(item);
++count;
if (!todo) { // defensive, skip any zero pointers
......@@ -864,7 +865,7 @@ void CalPrintDay::print(QPainter &p, int width, int height)
// split out the all day events as they will be printed in a separate box
KCalCore::Event::List alldayEvents, timedEvents;
foreach (const KCalCore::Event::Ptr &event, eventList) {
for (const KCalCore::Event::Ptr &event : qAsConst(eventList)) {
if (event->allDay()) {
alldayEvents.append(event);
} else {
......@@ -901,7 +902,7 @@ void CalPrintDay::print(QPainter &p, int width, int height)
eventBox.setTop(eventBox.top() + padding());
eventBox.setBottom(eventBox.top() + lineSpacing);
int count = 0;
foreach (const KCalCore::Event::Ptr &event, alldayEvents) {
for (const KCalCore::Event::Ptr &event : qAsConst(alldayEvents)) {
if (count == maxAllDayEvents) {
break;
}
......@@ -1609,7 +1610,7 @@ void CalPrintTodos::print(QPainter &p, int width, int height)
case TodosAll:
break;
case TodosUnfinished:
foreach (const KCalCore::Todo::Ptr &todo, todoList) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(todoList)) {
Q_ASSERT(todo);
if (!todo->isCompleted()) {
tempList.append(todo);
......@@ -1618,7 +1619,7 @@ void CalPrintTodos::print(QPainter &p, int width, int height)
todoList = tempList;
break;
case TodosDueRange:
foreach (const KCalCore::Todo::Ptr &todo, todoList) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(todoList)) {
Q_ASSERT(todo);
if (todo->hasDueDate()) {
if (todo->dtDue().date() >= mFromDate && todo->dtDue().date() <= mToDate) {
......@@ -1634,7 +1635,7 @@ void CalPrintTodos::print(QPainter &p, int width, int height)
// Print to-dos
int count = 0;
foreach (const KCalCore::Todo::Ptr &todo, todoList) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(todoList)) {
if ((mExcludeConfidential && todo->secrecy() == KCalCore::Incidence::SecrecyConfidential) ||
(mExcludePrivate && todo->secrecy() == KCalCore::Incidence::SecrecyPrivate)) {
continue;
......
......@@ -27,6 +27,7 @@
#include "cellitem.h"
#include "kcalprefs.h"
#include "utils.h"
#include "helper_p.h"
#include <Item>
......@@ -897,7 +898,7 @@ void CalPrintPluginBase::drawAgendaDayBox(QPainter &p, const KCalCore::Event::Li
if (expandable) {
// Adapt start/end times to include complete events
Q_FOREACH (const KCalCore::Event::Ptr &event, events) {
for (const KCalCore::Event::Ptr &event : qAsConst(events)) {
Q_ASSERT(event);
if ((excludeConfidential && event->secrecy() == KCalCore::Incidence::SecrecyConfidential) ||
(excludePrivate && event->secrecy() == KCalCore::Incidence::SecrecyPrivate)) {
......@@ -954,7 +955,7 @@ void CalPrintPluginBase::drawAgendaDayBox(QPainter &p, const KCalCore::Event::Li
QList<CellItem *> cells;
foreach (const KCalCore::Event::Ptr &event, events) {
for (const KCalCore::Event::Ptr &event : qAsConst(events)) {
if (event->allDay()) {
continue;
}
......@@ -1121,7 +1122,7 @@ void CalPrintPluginBase::drawDayBox(QPainter &p, const QDate &qd,
int textY = mSubHeaderHeight; // gives the relative y-coord of the next printed entry
unsigned int visibleEventsCounter = 0;
Q_FOREACH (const KCalCore::Event::Ptr &currEvent, eventList) {
for (const KCalCore::Event::Ptr &currEvent : qAsConst(eventList)) {
Q_ASSERT(currEvent);
if (!currEvent->allDay()) {
if (currEvent->dtEnd().toLocalZone().time() <= myFromTime ||
......@@ -1181,7 +1182,7 @@ void CalPrintPluginBase::drawDayBox(QPainter &p, const QDate &qd,
if (textY < box.height()) {
KCalCore::Todo::List todos = mCalendar->todos(qd);
foreach (const KCalCore::Todo::Ptr &todo, todos) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(todos)) {
if (!todo->allDay()) {
if ((todo->hasDueDate() && todo->dtDue().toLocalZone().time() <= myFromTime) ||
(todo->hasStartDate() && todo->dtStart().toLocalZone().time() > myToTime)) {
......@@ -1452,7 +1453,7 @@ void CalPrintPluginBase::drawTimeTable(QPainter &p,
KDateTime::Spec timeSpec = KSystemTimeZones::local();
while (curDate <= toDate) {
KCalCore::Event::List eventList = mCalendar->events(curDate, timeSpec);
Q_FOREACH (const KCalCore::Event::Ptr &event, eventList) {
for (const KCalCore::Event::Ptr &event : qAsConst(eventList)) {
Q_ASSERT(event);
if (event->allDay()) {
continue;
......@@ -1631,7 +1632,7 @@ void CalPrintPluginBase::drawMonth(QPainter &p, const QDate &dt,
QList<MonthEventStruct> monthentries;
KDateTime::Spec timeSpec = KSystemTimeZones::local();
Q_FOREACH (const KCalCore::Event::Ptr &e, events) {
for (const KCalCore::Event::Ptr &e : qAsConst(events)) {
if (!e) {
continue;
}
......@@ -2001,9 +2002,9 @@ void CalPrintPluginBase::drawTodo(int &count, const KCalCore::Todo::Ptr &todo, Q
// Make a list of all the sub-to-dos related to this to-do.
KCalCore::Todo::List t;
KCalCore::Incidence::List relations = mCalendar->childIncidences(todo->uid());
const KCalCore::Incidence::List relations = mCalendar->childIncidences(todo->uid());
foreach (const KCalCore::Incidence::Ptr &incidence, relations) {
for (const KCalCore::Incidence::Ptr &incidence : relations) {
// In the future, to-dos might also be related to events
// Manually check if the sub-to-do is in the list of to-dos to print
// The problem is that relations() does not apply filters, so
......@@ -2017,7 +2018,7 @@ void CalPrintPluginBase::drawTodo(int &count, const KCalCore::Todo::Ptr &todo, Q
#else
bool subtodoOk = false;
if (subtodo) {
foreach (const KCalCore::Todo::Ptr &tt, todoList) {
for (const KCalCore::Todo::Ptr &tt : qAsConst(todoList)) {
if (tt == subtodo) {
subtodoOk = true;
break;
......@@ -2057,14 +2058,14 @@ void CalPrintPluginBase::drawTodo(int &count, const KCalCore::Todo::Ptr &todo, Q
#else
KCalCore::Todo::List tl;
tl.reserve(t.count());
foreach (const KCalCore::Todo::Ptr &todo, t) {
for (const KCalCore::Todo::Ptr &todo : qAsConst(t)) {
tl.append(todo);
}
KCalCore::Todo::List sl = mCalendar->sortTodos(tl, sortField, sortDir);
#endif
int subcount = 0;
foreach (const KCalCore::Todo::Ptr &isl, sl) {
for (const KCalCore::Todo::Ptr &isl : qAsConst(sl)) {
count++;
if (++subcount == sl.size()) {
startpt.mHasLine = false;
......
......@@ -24,6 +24,7 @@
#include "utils.h"
#include <KConfigGroup>
#include "calendarsupport_debug.h"
#include "helper_p.h"
using namespace CalendarSupport;
......@@ -124,7 +125,7 @@ void CalPrintJournal::print(QPainter &p, int width, int height)
drawHeader(p, i18n("Journal entries"), QDate(), QDate(), headerBox);
y = headerHeight() + 15;
foreach (const KCalCore::Journal::Ptr &j, journals) {
for (const KCalCore::Journal::Ptr &j : qAsConst(journals)) {
drawJournal(j, p, x, y, width, height);
}
......
......@@ -24,6 +24,7 @@
#include "utils.h"
#include "kcalprefs.h"
#include "helper_p.h"
#include <Collection>
#include <CollectionDialog>
......@@ -342,7 +343,8 @@ bool CalendarSupport::canDecode(const QMimeData *md)
QList<QUrl> CalendarSupport::incidenceItemUrls(const QMimeData *mimeData)
{
QList<QUrl> urls;
Q_FOREACH (const QUrl &i, mimeData->urls()) {
const QList<QUrl> urlsList = mimeData->urls();
for (const QUrl &i : urlsList ) {
if (isValidIncidenceItemUrl(i)) {
urls.push_back(i);
}
......@@ -354,7 +356,8 @@ QList<QUrl> CalendarSupport::todoItemUrls(const QMimeData *mimeData)
{
QList<QUrl> urls;
Q_FOREACH (const QUrl &i, mimeData->urls()) {
const QList<QUrl> urlList = mimeData->urls();
for (const QUrl &i : urlList) {
if (isValidIncidenceItemUrl(i, QStringList() << KCalCore::Todo::todoMimeType())) {
urls.push_back(i);
}
......@@ -746,7 +749,7 @@ void CalendarSupport::saveAttachments(const Akonadi::Item &item, QWidget *parent
targetDir = QFileInfo(targetFile).absolutePath() + QLatin1Char('/');
}
Q_FOREACH (const Attachment::Ptr &attachment, attachments) {
for (const Attachment::Ptr &attachment : qAsConst(attachments)) {
targetFile = targetDir + attachment->label();
QUrl sourceUrl;
if (attachment->isUri()) {
......
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