Commit 4fbd835b authored by David Jarvie's avatar David Jarvie
Browse files

Fix clazy and clang warnings

parent 2679582b
Pipeline #34732 failed with stage
in 8 minutes and 31 seconds
/*
* akonadicollectionsearch.cpp - Search Akonadi Collections
* Program: kalarm
* SPDX-FileCopyrightText: 2014, 2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2014-2020 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -142,7 +142,7 @@ void AkonadiCollectionSearch::itemFetchResult(KJob* j)
else if (mGid.isEmpty())
continue;
ItemDeleteJob* djob = new ItemDeleteJob(item, this);
mItemDeleteJobs[djob] = mItemFetchJobs[job];
mItemDeleteJobs[djob] = mItemFetchJobs.value(job);
connect(djob, &ItemDeleteJob::result, this, &AkonadiCollectionSearch::itemDeleteResult);
}
}
......
......@@ -246,17 +246,18 @@ QVector<KAEvent> BirthdayDlg::events() const
{
QVector<KAEvent> list;
const QModelIndexList indexes = mListView->selectionModel()->selectedRows();
int count = indexes.count();
const int count = indexes.count();
if (!count)
return list;
list.reserve(count);
const QDate today = KADateTime::currentLocalDate();
const KADateTime todayStart(today, KADateTime::LocalZone);
int thisYear = today.year();
int reminder = mReminder->minutes();
for (int i = 0; i < count; ++i)
const int thisYear = today.year();
const int reminder = mReminder->minutes();
for (const QModelIndex& index : indexes)
{
const QModelIndex nameIndex = indexes[i].model()->index(indexes[i].row(), 0);
const QModelIndex birthdayIndex = indexes[i].model()->index(indexes[i].row(), 1);
const QModelIndex nameIndex = index.model()->index(index.row(), 0);
const QModelIndex birthdayIndex = index.model()->index(index.row(), 1);
const QString name = nameIndex.data(Qt::DisplayRole).toString();
QDate date = birthdayIndex.data(BirthdayModel::DateRole).toDate();
date.setDate(thisYear, date.month(), date.day());
......@@ -269,8 +270,8 @@ QVector<KAEvent> BirthdayDlg::events() const
mFlags, true);
float fadeVolume;
int fadeSecs;
float volume = mSoundPicker->volume(fadeVolume, fadeSecs);
int repeatPause = mSoundPicker->repeatPause();
const float volume = mSoundPicker->volume(fadeVolume, fadeSecs);
const int repeatPause = mSoundPicker->repeatPause();
event.setAudioFile(mSoundPicker->file().toDisplayString(), volume, fadeVolume, fadeSecs, repeatPause);
const QVector<int> months(1, date.month());
event.setRecurAnnualByDate(1, months, 0, KARecurrence::defaultFeb29Type(), -1, QDate());
......@@ -345,8 +346,8 @@ void BirthdayDlg::resizeViewColumns()
*/
void BirthdayDlg::slotTextLostFocus()
{
QString prefix = mPrefix->text();
QString suffix = mSuffix->text();
const QString prefix = mPrefix->text();
const QString suffix = mSuffix->text();
if (prefix != mPrefixText || suffix != mSuffixText)
{
// Text has changed - re-evaluate the selection list
......
......@@ -60,7 +60,7 @@ DeferAlarmDlg::DeferAlarmDlg(const DateTime& initialDT, bool anyTimeOption, bool
{
QPushButton* deferButton = mButtonBox->addButton(i18nc("@action:button", "Cancel Deferral"), QDialogButtonBox::ActionRole);
deferButton->setWhatsThis(i18nc("@info:whatsthis", "Cancel the deferred alarm. This does not affect future recurrences."));
connect(mButtonBox, &QDialogButtonBox::clicked,
connect(mButtonBox, &QDialogButtonBox::clicked, this,
[this, deferButton](QAbstractButton* btn)
{
if (btn == deferButton)
......
......@@ -197,7 +197,7 @@ void DisplayCalendar::close()
mOpen = false;
// Events list should be empty, but just in case...
for (KAEvent* event : mEventList)
for (KAEvent* event : qAsConst(mEventList))
{
mEventMap.remove(event->id());
delete event;
......@@ -213,7 +213,7 @@ void DisplayCalendar::close()
void DisplayCalendar::updateKAEvents()
{
qCDebug(KALARM_LOG) << "DisplayCalendar::updateKAEvents";
for (KAEvent* event : mEventList)
for (KAEvent* event : qAsConst(mEventList))
{
mEventMap.remove(event->id());
delete event;
......@@ -224,7 +224,7 @@ void DisplayCalendar::updateKAEvents()
return;
const Event::List kcalevents = cal->rawEvents();
for (Event::Ptr kcalevent : kcalevents)
for (const Event::Ptr& kcalevent : kcalevents)
{
if (kcalevent->alarms().isEmpty())
continue; // ignore events without alarms
......
......@@ -70,7 +70,7 @@ inline QString recurText(const KAEvent& event)
{
QString r;
if (event.repetition())
r = QStringLiteral("%1 / %2").arg(event.recurrenceText()).arg(event.repetitionText());
r = QStringLiteral("%1 / %2").arg(event.recurrenceText(), event.repetitionText());
else
r = event.recurrenceText();
return i18nc("@title:tab", "Recurrence - [%1]", r);
......
......@@ -1913,7 +1913,7 @@ QSize CommandEdit::minimumSizeHint() const
TextEdit::TextEdit(QWidget* parent)
: KTextEdit(parent)
{
QSize tsize = sizeHint();
QSize tsize = TextEdit::minimumSizeHint(); // avoid calling virtual method from constructor
tsize.setHeight(fontMetrics().lineSpacing()*13/4 + 2*frameWidth());
setMinimumSize(tsize);
}
......
......@@ -2757,7 +2757,7 @@ KAlarmApp::ProcData::~ProcData()
while (!tempFiles.isEmpty())
{
// Delete the temporary file called by the XTerm command
QFile f(tempFiles.first());
QFile f(tempFiles.constFirst());
f.remove();
tempFiles.removeFirst();
}
......
/*
* kamail.cpp - email functions
* Program: kalarm
* SPDX-FileCopyrightText: 2002-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2002-2020 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -275,7 +275,7 @@ void KAMail::slotEmailSent(KJob* job)
errmsgs = errors(job->errorString(), SEND_ERROR);
}
JobData jobdata;
if (mJobs.isEmpty() || mJobData.isEmpty() || job != mJobs.head())
if (mJobs.isEmpty() || mJobData.isEmpty() || job != qAsConst(mJobs).head())
{
// The queue has been corrupted, so we can't locate the job's data
qCCritical(KALARM_LOG) << "KAMail::slotEmailSent: Wrong job at head of queue: wiping queue";
......@@ -297,8 +297,9 @@ void KAMail::slotEmailSent(KJob* job)
if (!mJobs.isEmpty())
{
// Send the next queued email
connect(mJobs.head(), &KJob::result, instance(), &KAMail::slotEmailSent);
mJobs.head()->start();
auto job = mJobs.head();
connect(job, &KJob::result, instance(), &KAMail::slotEmailSent);
job->start();
}
}
......@@ -350,7 +351,7 @@ void initHeaders(KMime::Message& message, KAMail::JobData& data)
QString KAMail::appendBodyAttachments(KMime::Message& message, JobData& data)
{
const QStringList attachments = data.event.emailAttachments();
if (!attachments.count())
if (attachments.isEmpty())
{
// There are no attachments, so simply append the message body
message.contentType()->setMimeType("text/plain");
......@@ -870,7 +871,6 @@ using namespace KMime::HeaderParsing;
bool parseUserName( const char* & scursor, const char * const send,
QString & result, bool isCRLF ) {
QString maybeLocalPart;
QString tmp;
if ( scursor != send ) {
......
/*
* label.cpp - label with radiobutton buddy option
* Program: kalarm
* SPDX-FileCopyrightText: 2004-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2004-2020 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -22,7 +22,7 @@ Label::Label(const QString& text, QWidget* parent, Qt::WindowFlags f)
Label::Label(QWidget* buddy, const QString& text, QWidget* parent, Qt::WindowFlags f)
: QLabel(text, parent, f)
{
setBuddy(buddy);
Label::setBuddy(buddy);
}
/******************************************************************************
......
......@@ -101,8 +101,8 @@ int PackedLayout::arrange(const QRect& rect, bool set) const
int x = rect.x();
int y = rect.y();
int yrow = 0;
QList<QRect> posn;
QList<QLayoutItem*> items;
QVector<QRect> posn;
QVector<QLayoutItem*> items;
for (QLayoutItem* item : qAsConst(mItems))
{
if (item->isEmpty())
......
......@@ -232,7 +232,7 @@ TimePeriod::Units TimePeriod::setDateOnly(const Duration& perod, bool dateOnly,
mUnitsCombo->insertItem(1, i18n_hours_mins());
mDateOnlyOffset = 0;
adjustDayWeekShown();
mUnitsCombo->setCurrentIndex(index += 2);
mUnitsCombo->setCurrentIndex(index + 2);
}
else if (dateOnly && !mDateOnlyOffset)
{
......
......@@ -336,7 +336,7 @@ void MainWindow::resourcesResized()
{
if (!mShown || mResizing)
return;
QList<int> widths = mSplitter->sizes();
const QList<int> widths = mSplitter->sizes();
if (widths.count() > 1)
{
mResourcesWidth = widths[0];
......@@ -783,10 +783,11 @@ void MainWindow::slotReactivate()
void MainWindow::slotEnable()
{
bool enable = mActionEnableEnable; // save since changed in response to KAlarm::enableEvent()
QVector<KAEvent> events = mListView->selectedEvents();
const QVector<KAEvent> events = mListView->selectedEvents();
QVector<KAEvent> eventCopies;
for (int i = 0, end = events.count(); i < end; ++i)
eventCopies += events[i];
eventCopies.reserve(events.count());
for (const KAEvent& event : events)
eventCopies += event;
KAlarm::enableEvents(eventCopies, enable, this);
slotSelection(); // update Enable/Disable action text
}
......@@ -1006,7 +1007,7 @@ void MainWindow::slotRedo()
*/
void MainWindow::slotUndoItem(QAction* action)
{
int id = mUndoMenuIds[action];
int id = mUndoMenuIds.value(action);
Undo::undo(id, this, Undo::actionText(Undo::UNDO, id));
}
......@@ -1015,7 +1016,7 @@ void MainWindow::slotUndoItem(QAction* action)
*/
void MainWindow::slotRedoItem(QAction* action)
{
int id = mUndoMenuIds[action];
int id = mUndoMenuIds.value(action);
Undo::redo(id, this, Undo::actionText(Undo::REDO, id));
}
......@@ -1045,15 +1046,14 @@ void MainWindow::initUndoMenu(QMenu* menu, Undo::Type type)
menu->clear();
mUndoMenuIds.clear();
const QString& action = (type == Undo::UNDO) ? undoTextStripped : redoTextStripped;
QList<int> ids = Undo::ids(type);
for (int i = 0, end = ids.count(); i < end; ++i)
const QList<int> ids = Undo::ids(type);
for (const int id : ids)
{
int id = ids[i];
QString actText = Undo::actionText(type, id);
QString descrip = Undo::description(type, id);
QString text = descrip.isEmpty()
? i18nc("@action Undo/Redo [action]", "%1 %2", action, actText)
: i18nc("@action Undo [action]: message", "%1 %2: %3", action, actText, descrip);
const QString actText = Undo::actionText(type, id);
const QString descrip = Undo::description(type, id);
const QString text = descrip.isEmpty()
? i18nc("@action Undo/Redo [action]", "%1 %2", action, actText)
: i18nc("@action Undo [action]: message", "%1 %2: %3", action, actText, descrip);
QAction* act = menu->addAction(text);
mUndoMenuIds[act] = id;
}
......@@ -1206,7 +1206,6 @@ void MainWindow::executeDropEvent(MainWindow* win, QDropEvent* e)
const QMimeData* data = e->mimeData();
KAEvent::SubAction action = KAEvent::MESSAGE;
AlarmText alarmText;
QList<QUrl> urls;
MemoryCalendar::Ptr calendar(new MemoryCalendar(Preferences::timeSpecAsZone()));
#ifndef NDEBUG
const QString fmts = data->formats().join(QLatin1String(", "));
......@@ -1364,9 +1363,8 @@ void MainWindow::slotCalendarStatusChanged()
// Find whether there are any writable calendars
bool active = !Resources::enabledResources(CalEvent::ACTIVE, true).isEmpty();
bool templat = !Resources::enabledResources(CalEvent::TEMPLATE, true).isEmpty();
for (int i = 0, end = mWindowList.count(); i < end; ++i)
for (MainWindow* w : qAsConst(mWindowList))
{
MainWindow* w = mWindowList[i];
w->mActionImportAlarms->setEnabled(active || templat);
w->mActionImportBirthdays->setEnabled(active);
w->mActionCreateTemplate->setEnabled(templat);
......
......@@ -19,7 +19,7 @@
#include <KCalendarCore/Calendar>
#include <QList>
#include <QVector>
#include <QMap>
class QDragEnterEvent;
......@@ -105,6 +105,7 @@ class MainWindow : public MainWindowBase, public KCalendarCore::Calendar::Calend
void slotPreferences();
void slotShowMenubar();
void slotConfigureKeys();
void slotConfigureNotifications();
void slotConfigureToolbar();
void slotNewToolbarConfig();
void slotQuit();
......@@ -132,7 +133,7 @@ class MainWindow : public MainWindowBase, public KCalendarCore::Calendar::Calend
void editAlarmDeleted(QObject*);
private:
typedef QList<MainWindow*> WindowList;
typedef QVector<MainWindow*> WindowList;
explicit MainWindow(bool restored);
void createListView(bool recreate);
......
......@@ -1277,8 +1277,9 @@ bool MessageDisplayHelper::haveErrorMessage(unsigned msg) const
{
if (!mErrorMessages.contains(mEventId))
mErrorMessages.insert(mEventId, 0);
const bool result = (mErrorMessages[mEventId] & msg);
mErrorMessages[mEventId] |= msg;
unsigned& message = mErrorMessages[mEventId];
const bool result = (message & msg);
message |= msg;
return result;
}
......@@ -1286,10 +1287,11 @@ void MessageDisplayHelper::clearErrorMessage(unsigned msg) const
{
if (mErrorMessages.contains(mEventId))
{
if (mErrorMessages[mEventId] == msg)
unsigned& message = mErrorMessages[mEventId];
if (message == msg)
mErrorMessages.remove(mEventId);
else
mErrorMessages[mEventId] &= ~msg;
message &= ~msg;
}
}
......
......@@ -143,7 +143,7 @@ MessageNotification::MessageNotification(const KAEvent& event, const KAAlarm& al
qCDebug(KALARM_LOG) << "MessageNotification():" << mEventId();
MNSessionManager::create();
if (!(flags & (NoInitView | AlwaysHide)))
setUpDisplay();
MessageNotification::setUpDisplay(); // avoid calling virtual method from constructor
connect(this, QOverload<unsigned int>::of(&KNotification::activated), this, &MessageNotification::buttonActivated);
connect(this, &KNotification::closed, this, &MessageNotification::slotClosed);
......@@ -167,7 +167,7 @@ MessageNotification::MessageNotification(const KAEvent& event, const DateTime& a
{
qCDebug(KALARM_LOG) << "MessageNotification(errmsg)";
MNSessionManager::create();
setUpDisplay();
MessageNotification::setUpDisplay(); // avoid calling virtual method from constructor
connect(this, QOverload<unsigned int>::of(&KNotification::activated), this, &MessageNotification::buttonActivated);
connect(this, &KNotification::closed, this, &MessageNotification::slotClosed);
......@@ -217,8 +217,6 @@ void MessageNotification::setUpDisplay()
setNotificationTitle(texts.title);
QString messageText;
// Show the alarm date/time. Any reminder indication is shown in the
// notification title.
// Alarm date/time: display time zone if not local time zone.
......
......@@ -131,7 +131,7 @@ MessageWindow::MessageWindow(const KAEvent& event, const KAAlarm& alarm, int fla
setWindowModality(Qt::WindowModal);
setObjectName(QStringLiteral("MessageWindow")); // used by LikeBack
if (!(flags & (NoInitView | AlwaysHide)))
setUpDisplay();
MessageWindow::setUpDisplay(); // avoid calling virtual method from constructor
connect(mHelper, &MessageDisplayHelper::textsChanged, this, &MessageWindow::textsChanged);
connect(mHelper, &MessageDisplayHelper::commandExited, this, &MessageWindow::commandCompleted);
......@@ -163,7 +163,7 @@ MessageWindow::MessageWindow(const KAEvent& event, const DateTime& alarmDateTime
setWindowModality(Qt::WindowModal);
setObjectName(QStringLiteral("ErrorWin")); // used by LikeBack
getWorkAreaAndModal();
setUpDisplay();
MessageWindow::setUpDisplay(); // avoid calling virtual method from constructor
connect(mHelper, &MessageDisplayHelper::textsChanged, this, &MessageWindow::textsChanged);
......@@ -891,7 +891,7 @@ void MessageWindow::showEvent(QShowEvent* se)
*/
bool execComplete = true;
QSize s = sizeHint(); // fit the window round the message
if (mAction() == KAEvent::FILE && !mErrorMsgs().count())
if (mAction() == KAEvent::FILE && mErrorMsgs().isEmpty())
Config::readWindowSize("FileMessage", s);
resize(s);
......@@ -1045,7 +1045,7 @@ void MessageWindow::resizeEvent(QResizeEvent* re)
}
else
{
if (mShown && mAction() == KAEvent::FILE && !mErrorMsgs().count())
if (mShown && mAction() == KAEvent::FILE && mErrorMsgs().isEmpty())
Config::writeWindowSize("FileMessage", re->size());
MainWindowBase::resizeEvent(re);
}
......
/*
* pickfileradio.cpp - radio button with an associated file picker
* Program: kalarm
* SPDX-FileCopyrightText: 2005-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2005-2020 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -47,7 +47,7 @@ void PickFileRadio::init(QPushButton* button, LineEdit* edit)
connect(mEdit, &LineEdit::textChanged, this, &PickFileRadio::fileChanged);
}
connect(mGroup, &ButtonGroup::buttonSet, this, &PickFileRadio::slotSelectionChanged);
setReadOnly(RadioButton::isReadOnly());
PickFileRadio::setReadOnly(RadioButton::isReadOnly()); // avoid calling virtual method from constructor
}
void PickFileRadio::setReadOnly(bool ro)
......
......@@ -401,17 +401,18 @@ void PrefsTabBase::showEvent(QShowEvent*)
{
int wid = 0;
int i;
const int end = mLabels.count();
QList<int> xpos;
for (i = 0; i < end; ++i)
const int labelCount = mLabels.count();
QVector<int> xpos;
xpos.reserve(labelCount);
for (const QLabel* label : qAsConst(mLabels))
{
const int x = mLabels[i]->mapTo(this, QPoint(0, 0)).x();
const int x = label->mapTo(this, QPoint(0, 0)).x();
xpos += x;
const int w = x + mLabels[i]->sizeHint().width();
const int w = x + label->sizeHint().width();
if (w > wid)
wid = w;
}
for (i = 0; i < end; ++i)
for (i = 0; i < labelCount; ++i)
{
mLabels[i]->setFixedWidth(wid - xpos[i]);
mLabels[i]->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
......@@ -624,7 +625,7 @@ TimePrefTab::TimePrefTab(StackedScrollGroup* scrollGroup)
// Default time zone
QHBoxLayout* itemBox = new QHBoxLayout();
itemBox->setContentsMargins(0, 0, 0, 0);
qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
topLayout()->addLayout(itemBox);
QWidget* widget = new QWidget; // this is to control the QWhatsThis text display area
itemBox->addWidget(widget);
......@@ -645,7 +646,7 @@ TimePrefTab::TimePrefTab(StackedScrollGroup* scrollGroup)
// Holiday region
itemBox = new QHBoxLayout();
itemBox->setContentsMargins(0, 0, 0, 0);
qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
topLayout()->addLayout(itemBox);
widget = new QWidget; // this is to control the QWhatsThis text display area
itemBox->addWidget(widget);
......@@ -682,7 +683,7 @@ TimePrefTab::TimePrefTab(StackedScrollGroup* scrollGroup)
// Start-of-day time
itemBox = new QHBoxLayout();
itemBox->setContentsMargins(0, 0, 0, 0);
qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
topLayout()->addLayout(itemBox);
widget = new QWidget; // this is to control the QWhatsThis text display area
itemBox->addWidget(widget);
......
......@@ -56,11 +56,11 @@ protected:
void showEvent(QShowEvent*) override;
private:
static int mIndentWidth; // indent width for checkboxes etc.
static int mGridIndentWidth; // minimum grid column indent width for checkboxes etc.
QVBoxLayout* mTopLayout;
QList<QLabel*> mLabels; // labels to right-align
bool mLabelsAligned {false}; // labels have been aligned
static int mIndentWidth; // indent width for checkboxes etc.
static int mGridIndentWidth; // minimum grid column indent width for checkboxes etc.
QVBoxLayout* mTopLayout;
QVector<QLabel*> mLabels; // labels to right-align
bool mLabelsAligned {false}; // labels have been aligned
};
......
......@@ -886,7 +886,7 @@ void RecurrenceEdit::set(const KAEvent& event)
mExceptionDates = event.recurrence()->exDates();
std::sort(mExceptionDates.begin(), mExceptionDates.end());
mExceptionDateList->clear();
for (const QDate& exceptionDate : mExceptionDates)
for (const QDate& exceptionDate : qAsConst(mExceptionDates))
new QListWidgetItem(QLocale().toString(exceptionDate, QLocale::LongFormat), mExceptionDateList);
enableExceptionButtons();
mExcludeHolidays->setChecked(event.holidaysExcluded());
......
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