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

Minor optimization

parent d9e52de4
......@@ -36,7 +36,7 @@ AlarmDialog::AlarmDialog(KCalCore::Incidence::IncidenceType incidenceType, QWidg
{
setWindowTitle(i18n("Create a new reminder"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
......@@ -214,7 +214,7 @@ void AlarmDialog::save(const KCalCore::Alarm::Ptr &alarm) const
QStringList addresses = KEmailAddress::splitAddressList(mUi->mEmailAddress->text());
KCalCore::Person::List add;
add.reserve(addresses.count());
for (QStringList::Iterator it = addresses.begin(); it != addresses.end(); ++it) {
for (QStringList::Iterator it = addresses.begin(), end = addresses.end(); it != end; ++it) {
add << KCalCore::Person::fromFullName(*it);
}
// TODO: Add a subject line and possibilities for attachments
......
......@@ -54,7 +54,7 @@ AttachmentEditDialog::AttachmentEditDialog(AttachmentIconItem *item,
mMimeType = db.mimeTypeForName(item->mimeType());
QWidget *page = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setDefault(true);
mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
......@@ -68,7 +68,7 @@ AttachmentEditDialog::AttachmentEditDialog(AttachmentIconItem *item,
mUi->mIcon->setPixmap(item->icon());
mUi->mInlineCheck->setChecked(item->isBinary());
QString typecomment = item->mimeType().isEmpty() ?
const QString typecomment = item->mimeType().isEmpty() ?
i18nc("@label unknown mimetype", "Unknown") :
mMimeType.comment();
mUi->mTypeLabel->setText(typecomment);
......
......@@ -217,7 +217,7 @@ QMimeData *AttachmentIconView::mimeData(const QList< QListWidgetItem *> items) c
// create a list of the URL:s that we want to drag
QList<QUrl> urls;
QStringList labels;
foreach (QListWidgetItem *it, items) {
for (QListWidgetItem *it : items) {
if (it->isSelected()) {
AttachmentIconItem *item = static_cast<AttachmentIconItem *>(it);
if (item->isBinary()) {
......
......@@ -49,7 +49,8 @@ void AttendeeEditor::slotCalculateTotal()
int empty = 0;
int count = 0;
foreach (KPIM::MultiplyingLine *line, lines()) {
const QList<KPIM::MultiplyingLine *> listLines = lines();
for (KPIM::MultiplyingLine *line : listLines) {
AttendeeLine *att = qobject_cast<AttendeeLine *>(line);
if (att) {
if (att->isEmpty()) {
......@@ -68,10 +69,10 @@ void AttendeeEditor::slotCalculateTotal()
AttendeeData::List AttendeeEditor::attendees() const
{
QList<KPIM::MultiplyingLineData::Ptr> dataList = allData();
const QList<KPIM::MultiplyingLineData::Ptr> dataList = allData();
AttendeeData::List attList;
//qCDebug(INCIDENCEEDITOR_LOG) << "num attendees:" << dataList.size();
foreach (const KPIM::MultiplyingLineData::Ptr &datum, dataList) {
for (const KPIM::MultiplyingLineData::Ptr &datum : dataList) {
AttendeeData::Ptr att = qSharedPointerDynamicCast<AttendeeData>(datum);
if (!att) {
continue;
......@@ -93,7 +94,8 @@ void AttendeeEditor::removeAttendee(const AttendeeData::Ptr &attendee)
void AttendeeEditor::setActions(AttendeeLine::AttendeeActions actions)
{
foreach (KPIM::MultiplyingLine *line, lines()) {
const QList<KPIM::MultiplyingLine *> listLines = lines();
for (KPIM::MultiplyingLine *line : listLines) {
AttendeeLine *att = qobject_cast<AttendeeLine *>(line);
att->setActions(actions);
}
......
......@@ -58,7 +58,7 @@ void AttendeeComboBox::addItem(const QIcon &icon, const QString &text)
void AttendeeComboBox::addItems(const QStringList &texts)
{
foreach (const QString &str, texts) {
for (const QString &str : texts) {
addItem(QIcon(), str);
}
if (mCurrentIndex == -1) {
......
......@@ -18,7 +18,7 @@
*/
#include "attendeetablemodel.h"
#include "helper_p.h"
#include <klocalizedstring.h>
#include <KCalCore/Attendee>
......@@ -247,7 +247,7 @@ void AttendeeTableModel::addEmptyAttendee()
{
if (mKeepEmpty) {
bool create = true;
foreach (const KCalCore::Attendee::Ptr &attendee, mAttendeeList) {
for (const KCalCore::Attendee::Ptr &attendee : qAsConst(mAttendeeList)) {
if (attendee->fullName().isEmpty()) {
create = false;
break;
......
......@@ -100,7 +100,8 @@ void AutoCheckTreeWidget::setAutoCheck(bool autoCheck)
QTreeWidgetItem *AutoCheckTreeWidget::findItem(QTreeWidgetItem *parent, const QString &text) const
{
if (parent) {
for (int i = 0; i < parent->childCount(); ++i) {
const int nbChild{parent->childCount()};
for (int i = 0; i < nbChild; ++i) {
if (parent->child(i)->text(0) == text) {
return parent->child(i);
}
......
......@@ -96,9 +96,8 @@ void CategoryWidget::setCategories(const QStringList &categoryList)
mWidgets->mCategories->clear();
mCategoryList.clear();
QStringList::ConstIterator it;
QStringList cats = mCategoryConfig->customCategories();
for (it = categoryList.begin(); it != categoryList.end(); ++it) {
for (QStringList::ConstIterator it = categoryList.begin(), end = categoryList.end(); it != end; ++it) {
if (!cats.contains(*it)) {
cats.append(*it);
}
......@@ -234,11 +233,8 @@ CategoryDialog::CategoryDialog(CategoryConfig *cc, QWidget *parent)
: QDialog(parent), d(nullptr)
{
setWindowTitle(i18n("Select Categories"));
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QDialogButtonBox *buttonBox = nullptr;
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel /*| QDialogButtonBox::Help*/ | QDialogButtonBox::Apply);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel /*| QDialogButtonBox::Help*/ | QDialogButtonBox::Apply, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
......
......@@ -46,7 +46,7 @@ CategoryEditDialog::CategoryEditDialog(CategoryConfig *categoryConfig,
{
setWindowTitle(i18n("Edit Categories"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
......
......@@ -78,9 +78,8 @@ void CategorySelectWidget::setCategories(const QStringList &categoryList)
mWidgets->mCategories->clear();
mCategoryList.clear();
QStringList::ConstIterator it;
QStringList cats = mCategoryConfig->customCategories();
for (it = categoryList.begin(); it != categoryList.end(); ++it) {
for (QStringList::ConstIterator it = categoryList.begin(), end = categoryList.end(); it != end; ++it) {
if (!cats.contains(*it)) {
cats.append(*it);
}
......@@ -167,10 +166,9 @@ CategorySelectDialog::CategorySelectDialog(CategoryConfig *cc, QWidget *parent)
: QDialog(parent), d(nullptr)
{
setWindowTitle(i18n("Select Categories"));
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox = nullptr;
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel /*| QDialogButtonBox::Help*/ | QDialogButtonBox::Apply);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel /*| QDialogButtonBox::Help*/ | QDialogButtonBox::Apply, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
......
/*
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)
template <typename... Args>
struct QNonConstOverload
{
template <typename R, typename T>
Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
{ return ptr; }
template <typename R, typename T>
static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
{ return ptr; }
};
template <typename... Args>
struct QConstOverload
{
template <typename R, typename T>
Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr)
{ return ptr; }
template <typename R, typename T>
static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr)
{ return ptr; }
};
template <typename... Args>
struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
{
using QConstOverload<Args...>::of;
using QConstOverload<Args...>::operator();
using QNonConstOverload<Args...>::of;
using QNonConstOverload<Args...>::operator();
template <typename R>
Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
{ return ptr; }
template <typename R>
static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
{ return ptr; }
};
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
......@@ -74,8 +74,7 @@ void IncidenceAttachment::load(const KCalCore::Incidence::Ptr &incidence)
mAttachmentView->clear();
KCalCore::Attachment::List attachments = incidence->attachments();
KCalCore::Attachment::List::ConstIterator it;
for (it = attachments.constBegin(); it != attachments.constEnd(); ++it) {
for (KCalCore::Attachment::List::ConstIterator it = attachments.constBegin(), end = attachments.constEnd(); it != end; ++it) {
new AttachmentIconItem((*it), mAttachmentView);
}
......
......@@ -221,9 +221,9 @@ void IncidenceAttendee::load(const KCalCore::Incidence::Ptr &incidence)
void IncidenceAttendee::save(const KCalCore::Incidence::Ptr &incidence)
{
incidence->clearAttendees();
KCalCore::Attendee::List attendees = mDataModel->attendees();
const KCalCore::Attendee::List attendees = mDataModel->attendees();
foreach (const KCalCore::Attendee::Ptr &attendee, attendees) {
for (const KCalCore::Attendee::Ptr &attendee : attendees) {
Q_ASSERT(attendee);
bool skip = false;
......@@ -422,7 +422,7 @@ void IncidenceAttendee::expandResult(KJob *job)
dataModel()->removeRow(row);
const KContacts::Addressee::List groupMembers = expandJob->contacts();
foreach (const KContacts::Addressee &member, groupMembers) {
for (const KContacts::Addressee &member : groupMembers) {
KCalCore::Attendee::Ptr newAt(new KCalCore::Attendee(member.realName(), member.preferredEmail(),
attendee->RSVP(),
attendee->status(),
......@@ -443,7 +443,7 @@ void IncidenceAttendee::slotSelectAddresses()
Akonadi::EmailAddressSelectionDialog *dialogPtr = dialog.data();
if (dialogPtr) {
const Akonadi::EmailAddressSelection::List list = dialogPtr->selectedAddresses();
foreach (const Akonadi::EmailAddressSelection &selection, list) {
for (const Akonadi::EmailAddressSelection &selection : list) {
if (selection.item().hasPayload<KContacts::ContactGroup>()) {
Akonadi::ContactGroupExpandJob *job =
new Akonadi::ContactGroupExpandJob(
......@@ -542,9 +542,9 @@ void IncidenceAttendee::slotConflictResolverAttendeeRemoved(const QModelIndex &i
void IncidenceAttendee::slotConflictResolverLayoutChanged()
{
KCalCore::Attendee::List attendees = mDataModel->attendees();
const KCalCore::Attendee::List attendees = mDataModel->attendees();
mConflictResolver->clearAttendees();
foreach (const KCalCore::Attendee::Ptr &attendee, attendees) {
for (const KCalCore::Attendee::Ptr &attendee : attendees) {
if (!attendee->email().isEmpty()) {
mConflictResolver->insertAttendee(attendee);
}
......
......@@ -19,6 +19,7 @@
*/
#include "incidencecategories.h"
#include "helper_p.h"
#include "editorconfig.h"
......@@ -88,7 +89,7 @@ QStringList IncidenceCategories::categories() const
{
QStringList list;
list.reserve(mSelectedTags.count() + mMissingCategories.count());
Q_FOREACH (const Akonadi::Tag &tag, mSelectedTags) {
for (const Akonadi::Tag &tag : qAsConst(mSelectedTags)) {
list << tag.name();
}
list << mMissingCategories;
......@@ -97,7 +98,7 @@ QStringList IncidenceCategories::categories() const
void IncidenceCategories::createMissingCategories()
{
Q_FOREACH (const QString &category, mMissingCategories) {
for (const QString &category : qAsConst(mMissingCategories)) {
Akonadi::Tag missingTag = Akonadi::Tag::genericTag(category);
Akonadi::TagCreateJob *createJob = new Akonadi::TagCreateJob(missingTag, this);
connect(createJob, &Akonadi::TagCreateJob::result, this, &IncidenceCategories::onMissingTagCreated);
......
......@@ -22,6 +22,7 @@
#include "individualmailcomponentfactory.h"
#include "individualmaildialog.h"
#include "helper_p.h"
#include <CalendarSupport/KCalPrefs>
......@@ -52,7 +53,7 @@ void IndividualMessageQueueJob::start()
QSet<QString> attendeesCc(QSet<QString>::fromList(addressAttribute().cc()));
QStringList attendeesAutoTo, attendeesAutoCc;
foreach (const KCalCore::Attendee::Ptr &attendee, mUpdate) {
for (const KCalCore::Attendee::Ptr &attendee : qAsConst(mUpdate)) {
if (attendeesTo.contains(attendee->email())) {
attendeesAutoTo.append(attendee->fullName());
}
......@@ -65,7 +66,7 @@ void IndividualMessageQueueJob::start()
}
QStringList attendeesComposerTo, attendeesComposerCc;
foreach (const KCalCore::Attendee::Ptr &attendee, mEdit) {
for (const KCalCore::Attendee::Ptr &attendee : qAsConst(mEdit)) {
if (attendeesTo.contains(attendee->email())) {
attendeesComposerTo.append(attendee->fullName());
}
......
......@@ -43,7 +43,7 @@ IndividualMailDialog::IndividualMailDialog(const QString &question, const KCalCo
QWidget *widget = new QWidget();
QGridLayout *layout = new QGridLayout(widget);
int row = 0;
foreach (const KCalCore::Attendee::Ptr &attendee, attendees) {
for (const KCalCore::Attendee::Ptr &attendee : attendees) {
QComboBox *options = new QComboBox();
options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Send update"), QVariant(Update));
options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Send no update"), QVariant(NoUpdate));
......
......@@ -18,7 +18,7 @@
*/
#include "ktimezonecombobox.h"
#include "helper_p.h"
#include <KCalCore/ICalTimeZones>
#include <KLocalizedString>
......@@ -48,13 +48,14 @@ void KTimeZoneComboBox::Private::fillComboBox()
mZones.clear();
// Read all system time zones
foreach (const QByteArray &id, QTimeZone::availableTimeZoneIds()) {
const QList<QByteArray> lstTimeZoneIds = QTimeZone::availableTimeZoneIds();
for (const QByteArray &id : lstTimeZoneIds) {
mZones.push_back(QString::fromLatin1(id));
}
mZones.sort();
// Prepend the list of additional timezones
foreach (const QByteArray &id, mAdditionalZones)
for (const QByteArray &id : qAsConst(mAdditionalZones))
mZones.prepend(QString::fromLatin1(id));
// Prepend Local, UTC and Floating, for convenience
......@@ -63,7 +64,7 @@ void KTimeZoneComboBox::Private::fillComboBox()
mZones.prepend(QString::fromLatin1(QTimeZone::systemTimeZoneId())); // index=0
// Put translated zones into the combobox
foreach (const QString &z, mZones) {
for (const QString &z : qAsConst(mZones)) {
mParent->addItem(i18n(z.toUtf8().constData()).replace(QLatin1Char('_'), QLatin1Char(' ')));
}
}
......@@ -90,7 +91,7 @@ void KTimeZoneComboBox::selectTimeSpec(const KDateTime::Spec &spec)
int nCurrentlySet = -1;
int i = 0;
foreach (const QString &z, d->mZones) {
for (const QString &z : qAsConst(d->mZones)) {
if (z == spec.timeZone().name()) {
nCurrentlySet = i;
break;
......
......@@ -19,6 +19,7 @@
*
*/
#include "resourceitem.h"
#include "helper_p.h"
#include <kldap/ldapserver.h>
......@@ -43,7 +44,7 @@ ResourceItem::ResourceItem(const KLDAP::LdapDN &dn, const QStringList &attrs, co
mLdapClient.setAttributes(attrs);
} else {
itemData.reserve(mAttrs.count());
foreach (const QString &header, mAttrs) {
for (const QString &header : qAsConst(mAttrs)) {
itemData << header;
}
}
......@@ -67,7 +68,7 @@ int ResourceItem::childNumber() const
{
if (parentItem) {
int i = 0;
foreach (const ResourceItem::Ptr &child, parentItem->childItems) {
for (const ResourceItem::Ptr &child : qAsConst(parentItem->childItems)) {
if (child == this) {
return i;
}
......@@ -154,7 +155,7 @@ void ResourceItem::slotLDAPResult(const KLDAP::LdapClient &/*client*/,
const KLDAP::LdapObject &obj)
{
mLdapObject = obj;
foreach (const QString &header, mAttrs) {
for (const QString &header : qAsConst(mAttrs)) {
if (!obj.attributes()[header].isEmpty()) {
itemData << QString::fromUtf8(obj.attributes()[header][0]);
} else {
......
......@@ -109,7 +109,7 @@ public:
ResourceManagement::ResourceManagement(QWidget *parent)
: QDialog(parent)
{
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
......@@ -273,7 +273,7 @@ void ResourceManagement::slotOwnerSearchFinished()
QStringList list;
const QList<QByteArray> values = it.value();
list.reserve(values.count());
foreach (const QByteArray &value, values) {
for (const QByteArray &value : values) {
list << QString::fromUtf8(value);
}
mUi->formOwner->addRow(translateLDAPAttributeForDisplay(key), new QLabel(list.join(QLatin1Char('\n'))));
......
......@@ -20,6 +20,7 @@
*/
#include "resourcemodel.h"
#include "ldaputils.h"
#include "helper_p.h"
#include <KEmailAddress>
#include <QDebug>
......@@ -198,7 +199,7 @@ void ResourceModel::slotLDAPCollectionData(const KLDAP::LdapResultObject::List &
//qDebug() << "Found ldapCollections";
foreach (const KLDAP::LdapResultObject &result, results) {
for (const KLDAP::LdapResultObject &result : qAsConst(results)) {
ResourceItem::Ptr item(new ResourceItem(result.object.dn(), headers, *result.client, rootItem));
item->setLdapObject(result.object);
......@@ -218,14 +219,14 @@ void ResourceModel::slotLDAPCollectionData(const KLDAP::LdapResultObject::List &
void ResourceModel::slotLDAPSearchData(const KLDAP::LdapResultObject::List &results)
{
foreach (const KLDAP::LdapResultObject &result, results) {
for (const KLDAP::LdapResultObject &result : qAsConst(results)) {
//Add the found items to all collections, where it is member
QList<ResourceItem::Ptr> parents = ldapCollectionsMap.values(result.object.dn().toString());
if (parents.isEmpty()) {
parents << rootItem;
}
foreach (const ResourceItem::Ptr &parent, parents) {
for (const ResourceItem::Ptr &parent : qAsConst(parents)) {
ResourceItem::Ptr item(new ResourceItem(result.object.dn(), headers, *result.client, parent));
item->setLdapObject(result.object);
......
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