Commit 00b69bf8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

port for(...:...). Minor optimization

parent 37941c32
......@@ -99,11 +99,12 @@ QString AclUtils::permissionsToUserString(KIMAP::Acl::Rights permissions)
QString AclUtils::guessUserName(const QString &loginName, const QString &serverName)
{
if (loginName.contains(QLatin1Char('@'))) {
int pos = loginName.indexOf(QLatin1Char('@'));
if (pos != -1) {
// strip of the domain part and use user name only
return loginName.left(loginName.indexOf(QLatin1Char('@')));
return loginName.left(pos);
} else {
int pos = serverName.lastIndexOf(QLatin1Char('.'));
pos = serverName.lastIndexOf(QLatin1Char('.'));
if (pos == -1) { // no qualified domain name, only hostname
return QStringLiteral("%1@%2").arg(loginName, serverName);
}
......
......@@ -105,8 +105,7 @@ void ConfigurePluginsWidget::doResetToDefaultsOther()
void ConfigurePluginsWidget::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "ConfigurePluginsWidget");
QList<int> size;
size << 400 << 100;
const QList<int> size = {400, 100};
mSplitter->setSizes(group.readEntry("splitter", size));
}
......
......@@ -16,6 +16,7 @@
*/
#include "customtoolsplugin.h"
#include "helper_p.h"
#include "customtoolsviewinterface.h"
#include "customtoolswidgetng.h"
#include "customtools/customtoolspluginmanager.h"
......@@ -68,7 +69,7 @@ void CustomToolsWidgetNg::initializeView(KActionCollection *ac)
void CustomToolsWidgetNg::slotToolsWasClosed()
{
Q_FOREACH (PimCommon::CustomToolsViewInterface *interface, d->mListInterfaceView) {
for (PimCommon::CustomToolsViewInterface *interface : qAsConst(d->mListInterfaceView)) {
interface->action()->setChecked(false);
}
hide();
......@@ -79,7 +80,7 @@ void CustomToolsWidgetNg::slotActivateView(QWidget *w)
if (w) {
d->mStackedWidget->setCurrentWidget(w);
setVisible(true);
Q_FOREACH (PimCommon::CustomToolsViewInterface *interface, d->mListInterfaceView) {
for (PimCommon::CustomToolsViewInterface *interface : qAsConst(d->mListInterfaceView)) {
if (interface != w) {
interface->action()->setChecked(false);
}
......@@ -95,7 +96,7 @@ QList<KToggleAction *> CustomToolsWidgetNg::actionList() const
{
QList<KToggleAction *> lstActions;
lstActions.reserve(d->mListInterfaceView.count());
Q_FOREACH (PimCommon::CustomToolsViewInterface *interface, d->mListInterfaceView) {
for (PimCommon::CustomToolsViewInterface *interface : qAsConst(d->mListInterfaceView)) {
lstActions << interface->action();
}
return lstActions;
......@@ -104,7 +105,7 @@ QList<KToggleAction *> CustomToolsWidgetNg::actionList() const
void CustomToolsWidgetNg::setText(const QString &text)
{
if (isVisible()) {
Q_FOREACH (PimCommon::CustomToolsViewInterface *interface, d->mListInterfaceView) {
for (PimCommon::CustomToolsViewInterface *interface : qAsConst(d->mListInterfaceView)) {
if (interface == d->mStackedWidget->currentWidget()) {
interface->setText(text);
break;
......
......@@ -56,9 +56,8 @@ CheckedCollectionWidget::CheckedCollectionWidget(const QString &mimetype, QWidge
: QWidget(parent),
d(new PimCommon::CheckedCollectionWidgetPrivate)
{
QVBoxLayout *vbox = new QVBoxLayout;
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
setLayout(vbox);
// Create a new change recorder.
Akonadi::ChangeRecorder *changeRecorder = new Akonadi::ChangeRecorder(this);
......
......@@ -62,16 +62,15 @@ SelectMultiCollectionDialog::~SelectMultiCollectionDialog()
void SelectMultiCollectionDialog::initialize(const QString &mimetype, const QList<Akonadi::Collection::Id> &selectedCollection)
{
setWindowTitle(i18n("Select Multiple Folders"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SelectMultiCollectionDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SelectMultiCollectionDialog::reject);
d->mSelectMultiCollection = new SelectMultiCollectionWidget(mimetype, selectedCollection);
d->mSelectMultiCollection = new SelectMultiCollectionWidget(mimetype, selectedCollection, this);
mainLayout->addWidget(d->mSelectMultiCollection);
mainLayout->addWidget(buttonBox);
readConfig();
......
......@@ -50,9 +50,8 @@ SelectMultiCollectionWidget::~SelectMultiCollectionWidget()
void SelectMultiCollectionWidget::initialize(const QString &mimetype)
{
QVBoxLayout *vbox = new QVBoxLayout;
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
setLayout(vbox);
mCheckedCollectionWidget = new PimCommon::CheckedCollectionWidget(mimetype);
......
/*
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
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