Commit 926fed97 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent a0bc656e
Pipeline #48545 canceled with stage
......@@ -1683,7 +1683,7 @@ QPoint Agenda::contentsToGrid(const QPoint &pos) const
? d->mColumns - pos.x() / d->mGridSpacingX
: pos.x() / d->mGridSpacingX);
int gy = int(pos.y() / d->mGridSpacingY);
return QPoint(gx, gy);
return {gx, gy};
}
/*
......@@ -1695,7 +1695,7 @@ QPoint Agenda::gridToContents(const QPoint &gpos) const
? (d->mColumns - gpos.x()) * d->mGridSpacingX
: gpos.x() * d->mGridSpacingX);
int y = int(gpos.y() * d->mGridSpacingY);
return QPoint(x, y);
return {x, y};
}
/*
......@@ -2328,7 +2328,7 @@ QSize Agenda::sizeHint() const
if (d->mAllDayMode) {
return QWidget::sizeHint();
} else {
return QSize(parentWidget()->width(), d->mGridSpacingY * d->mRows);
return {parentWidget()->width(), d->mGridSpacingY * d->mRows};
}
}
......
......@@ -62,8 +62,8 @@ class AgendaItem : public QWidget, public CalendarSupport::CellItem
{
Q_OBJECT
public:
typedef QPointer<AgendaItem> QPtr;
typedef QList<QPtr> List;
using QPtr = QPointer<AgendaItem>;
using List = QList<QPtr>;
AgendaItem(EventView *eventView, const MultiViewCalendar::Ptr &calendar, const KCalendarCore::Incidence::Ptr &incidence, int itemPos, int itemCount, const QDateTime &qd, bool isSelected,
QWidget *parent);
......
......@@ -755,7 +755,7 @@ void AgendaView::init(QDate start, QDate end)
d->mAllDayAgenda = allDayScrollArea->agenda();
/* Create the main agenda widget and the related widgets */
QWidget *agendaFrame = new QWidget(d->mSplitterAgenda);
auto *agendaFrame = new QWidget(d->mSplitterAgenda);
auto agendaLayout = new QHBoxLayout(agendaFrame);
agendaLayout->setContentsMargins(0, 0, 0, 0);
agendaLayout->setSpacing(SPACING);
......@@ -1240,7 +1240,7 @@ void AgendaView::createDayLabels(bool force)
for (const QString &text : texts) {
// Compute a small version of the holiday string for AlternateLabel
const KWordWrap ww = KWordWrap::formatText(fm, topDayLabelBox->rect(), 0, text, -1);
AlternateLabel *label = new AlternateLabel(
auto *label = new AlternateLabel(
ww.truncatedString(), text, text, topDayLabelBox);
topDayLabelBoxLayout->addWidget(label);
label->setAlignment(Qt::AlignCenter);
......@@ -1421,7 +1421,7 @@ void AgendaView::createTimeBarHeaders()
const auto lst = d->mTimeLabelsZone->timeLabels();
for (QScrollArea *area : lst) {
auto timeLabel = static_cast<TimeLabels *>(area->widget());
QLabel *label
auto *label
= new QLabel(timeLabel->header().replace(QLatin1Char('/'), QStringLiteral("/ ")),
d->mTimeBarHeaderFrame);
d->mTimeBarHeaderFrame->layout()->addWidget(label);
......@@ -1628,7 +1628,7 @@ void AgendaView::updateEventDates(AgendaItem *item, bool addIncidence, Akonadi::
QDate AgendaView::startDate() const
{
if (d->mSelectedDates.isEmpty()) {
return QDate();
return {};
}
return d->mSelectedDates.first();
}
......@@ -1636,7 +1636,7 @@ QDate AgendaView::startDate() const
QDate AgendaView::endDate() const
{
if (d->mSelectedDates.isEmpty()) {
return QDate();
return {};
}
return d->mSelectedDates.last();
}
......
......@@ -230,7 +230,7 @@ private:
bool displayIncidence(const KCalendarCore::Incidence::Ptr &incidence, bool createSelected);
#ifndef EVENTVIEWS_NODECOS
typedef QList<EventViews::CalendarDecoration::Decoration *> DecorationList;
using DecorationList = QList<EventViews::CalendarDecoration::Decoration *>;
bool loadDecorations(const QStringList &decorations, DecorationList &decoList);
void placeDecorationsFrame(QFrame *frame, bool decorationsFound, bool isTop);
void placeDecorations(EventViews::AgendaView::DecorationList &decoList, const QDate &date, QWidget *labelBox, bool forWeek);
......
......@@ -266,10 +266,10 @@ QDate Decoration::weekDate(const QDate &date)
QDate Decoration::monthDate(const QDate &date)
{
return QDate(date.year(), date.month(), 1);
return {date.year(), date.month(), 1};
}
QDate Decoration::yearDate(const QDate &date)
{
return QDate(date.year(), 1, 1);
return {date.year(), 1, 1};
}
......@@ -30,7 +30,7 @@ class EVENTVIEWS_EXPORT Element : public QObject
Q_OBJECT
public:
typedef QList<Element *> List;
using List = QList<Element *>;
explicit Element(const QString &id);
~Element() override;
......@@ -149,7 +149,7 @@ public:
return QStringLiteral("Calendar/Decoration");
}
typedef QList<Decoration *> List;
using List = QList<Decoration *>;
Decoration();
~Decoration() override;
......
......@@ -323,7 +323,7 @@ void TimeLabels::paintEvent(QPaintEvent *)
QSize TimeLabels::sizeHint() const
{
return QSize(mMiniWidth, mRows * mCellHeight);
return {mMiniWidth, mRows * mCellHeight};
}
void TimeLabels::contextMenuEvent(QContextMenuEvent *event)
......
......@@ -17,13 +17,13 @@ class Agenda;
class TimeLabelsZone;
class Prefs;
typedef QSharedPointer<Prefs> PrefsPtr;
using PrefsPtr = QSharedPointer<Prefs>;
class TimeLabels : public QFrame
{
Q_OBJECT
public:
typedef QList<TimeLabels *> List;
using List = QList<TimeLabels *>;
TimeLabels(const QTimeZone &zone, int rows, TimeLabelsZone *parent = nullptr, Qt::WindowFlags f = {});
......
......@@ -17,7 +17,7 @@ class Agenda;
class AgendaView;
class Prefs;
typedef QSharedPointer<Prefs> PrefsPtr;
using PrefsPtr = QSharedPointer<Prefs>;
class TimeLabelsZone : public QWidget
{
......
......@@ -36,7 +36,7 @@ enum {
TimeZoneNameRole = Qt::UserRole
};
typedef QPair<QString, QByteArray> TimeZoneNamePair;
using TimeZoneNamePair = QPair<QString, QByteArray>;
static QString tzWithUTC(const QByteArray &zoneId)
{
......
......@@ -12,7 +12,7 @@
namespace EventViews {
class Prefs;
typedef QSharedPointer<Prefs> PrefsPtr;
using PrefsPtr = QSharedPointer<Prefs>;
class TimeScaleConfigDialog : public QDialog, private Ui::TimeScaleEditWidget
{
......
......@@ -115,7 +115,7 @@ QColor MultiViewCalendar::resourceColor(const KCalendarCore::Incidence::Ptr &inc
if (cal) {
return cal->resourceColor(incidence);
}
return QColor();
return {};
}
Akonadi::Item MultiViewCalendar::item(const KCalendarCore::Incidence::Ptr &incidence) const
......
......@@ -22,7 +22,7 @@ class AgendaView;
class EVENTVIEWS_EXPORT ViewCalendar
{
public:
typedef QSharedPointer<ViewCalendar> Ptr;
using Ptr = QSharedPointer<ViewCalendar>;
virtual ~ViewCalendar();
virtual bool isValid(const KCalendarCore::Incidence::Ptr &incidence) const = 0;
......@@ -38,7 +38,7 @@ public:
class AkonadiViewCalendar : public ViewCalendar
{
public:
typedef QSharedPointer<AkonadiViewCalendar> Ptr;
using Ptr = QSharedPointer<AkonadiViewCalendar>;
~AkonadiViewCalendar() override;
bool isValid(const KCalendarCore::Incidence::Ptr &incidence) const override;
......@@ -59,7 +59,7 @@ public:
class MultiViewCalendar : public ViewCalendar
{
public:
typedef QSharedPointer<MultiViewCalendar> Ptr;
using Ptr = QSharedPointer<MultiViewCalendar>;
~MultiViewCalendar() override;
ViewCalendar::Ptr findCalendar(const KCalendarCore::Incidence::Ptr &incidence) const;
......
......@@ -43,8 +43,8 @@ enum {
class EventViewPrivate;
class Prefs;
typedef QSharedPointer<Prefs> PrefsPtr;
typedef QSharedPointer<CalendarSupport::KCalPrefs> KCalPrefsPtr;
using PrefsPtr = QSharedPointer<Prefs>;
using KCalPrefsPtr = QSharedPointer<CalendarSupport::KCalPrefs>;
/**
EventView is the abstract base class from which all other calendar views
......
......@@ -55,7 +55,7 @@ void EventViews::setResourceColor(const Akonadi::Collection &coll, const QColor
QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr &preferences)
{
if (!coll.isValid()) {
return QColor();
return {};
}
const QString id = QString::number(coll.id());
// Color stored in eventviewsrc (and in memory)
......@@ -78,7 +78,7 @@ QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr
QColor EventViews::resourceColor(const Akonadi::Item &item, const PrefsPtr &preferences)
{
if (!item.isValid()) {
return QColor();
return {};
}
return resourceColor(item.parentCollection(), preferences);
}
......
......@@ -26,7 +26,7 @@ class QDate;
*/
namespace EventViews {
class Prefs;
typedef QSharedPointer<Prefs> PrefsPtr;
using PrefsPtr = QSharedPointer<Prefs>;
/**
Returns a nice QColor for text, give the input color &c.
......
......@@ -62,7 +62,7 @@ void JournalDateView::addJournal(const Akonadi::Item &j)
return;
}
QWidget *container = new QWidget(this);
auto *container = new QWidget(this);
layout()->addWidget(container);
auto layout = new QHBoxLayout(container);
layout->addStretch(1);
......
......@@ -26,7 +26,7 @@ class JournalFrame : public QFrame
{
Q_OBJECT
public:
typedef QList<JournalFrame *> List;
using List = QList<JournalFrame *>;
JournalFrame(const Akonadi::Item &journal, const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent);
......@@ -92,7 +92,7 @@ class JournalDateView : public QFrame
{
Q_OBJECT
public:
typedef QList<JournalDateView *> List;
using List = QList<JournalDateView *>;
JournalDateView(const Akonadi::ETMCalendar::Ptr &, QWidget *parent);
~JournalDateView();
......
......@@ -603,6 +603,6 @@ void ListView::clear()
QSize ListView::sizeHint() const
{
const QSize s = EventView::sizeHint();
return QSize(s.width() + style()->pixelMetric(QStyle::PM_ScrollBarExtent) + 1,
s.height());
return {s.width() + style()->pixelMetric(QStyle::PM_ScrollBarExtent) + 1,
s.height()};
}
......@@ -27,7 +27,7 @@ ScrollIndicator::ScrollIndicator(ScrollIndicator::ArrowDirection dir)
QRectF ScrollIndicator::boundingRect() const
{
return QRectF(-mWidth / 2, -mHeight / 2, mWidth, mHeight);
return {-mWidth / 2, -mHeight / 2, mWidth, mHeight};
}
void ScrollIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
......@@ -205,8 +205,8 @@ QPainterPath MonthGraphicsItem::widgetPath(bool border) const
QRectF MonthGraphicsItem::boundingRect() const
{
// width - 2 because of the cell-dividing line with width == 1 at beginning and end
return QRectF(0, 0, (daySpan() + 1) * mMonthItem->monthScene()->columnWidth() - 2,
mMonthItem->monthScene()->itemHeight());
return {0, 0, (daySpan() + 1) * mMonthItem->monthScene()->columnWidth() - 2,
mMonthItem->monthScene()->itemHeight()};
}
void MonthGraphicsItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
......
......@@ -118,7 +118,7 @@ class MonthGraphicsItem : public QObject, public QGraphicsItem
Q_INTERFACES(QGraphicsItem)
public:
typedef QList<MonthGraphicsItem *> List;
using List = QList<MonthGraphicsItem *>;
explicit MonthGraphicsItem(MonthItem *manager);
~MonthGraphicsItem();
......
......@@ -343,7 +343,7 @@ bool IncidenceMonthItem::greaterThanFallback(const MonthItem *other) const
QDate IncidenceMonthItem::realStartDate() const
{
if (!mIncidence) {
return QDate();
return {};
}
const QDateTime dt = mIncidence->dateTime(Incidence::RoleDisplayStart);
......@@ -355,7 +355,7 @@ QDate IncidenceMonthItem::realStartDate() const
QDate IncidenceMonthItem::realEndDate() const
{
if (!mIncidence) {
return QDate();
return {};
}
const QDateTime dt = mIncidence->dateTime(KCalendarCore::Incidence::RoleDisplayEnd);
......
......@@ -148,11 +148,11 @@ MultiAgendaView::MultiAgendaView(QWidget *parent)
QFontMetrics fm(font());
int topLabelHeight = 2 * fm.height() + fm.lineSpacing();
QWidget *topSideBox = new QWidget(this);
auto *topSideBox = new QWidget(this);
auto topSideBoxVBoxLayout = new QVBoxLayout(topSideBox);
topSideBoxVBoxLayout->setContentsMargins(0, 0, 0, 0);
QWidget *topSideSpacer = new QWidget(topSideBox);
auto *topSideSpacer = new QWidget(topSideBox);
topSideBoxVBoxLayout->addWidget(topSideSpacer);
topSideSpacer->setFixedHeight(topLabelHeight);
......@@ -163,17 +163,17 @@ MultiAgendaView::MultiAgendaView(QWidget *parent)
d->mLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
d->mLabel->setWordWrap(true);
QWidget *sideBox = new QWidget(d->mLeftSplitter);
auto *sideBox = new QWidget(d->mLeftSplitter);
auto sideBoxVBoxLayout = new QVBoxLayout(sideBox);
sideBoxVBoxLayout->setContentsMargins(0, 0, 0, 0);
// compensate for the frame the agenda views but not the timelabels have
QWidget *timeLabelTopAlignmentSpacer = new QWidget(sideBox);
auto *timeLabelTopAlignmentSpacer = new QWidget(sideBox);
sideBoxVBoxLayout->addWidget(timeLabelTopAlignmentSpacer);
d->mTimeLabelsZone = new TimeLabelsZone(sideBox, PrefsPtr(new Prefs()));
QWidget *timeLabelBotAlignmentSpacer = new QWidget(sideBox);
auto *timeLabelBotAlignmentSpacer = new QWidget(sideBox);
sideBoxVBoxLayout->addWidget(timeLabelBotAlignmentSpacer);
d->mLeftBottomSpacer = new QWidget(topSideBox);
......@@ -466,12 +466,12 @@ void MultiAgendaView::slotClearTimeSpanSelection()
AgendaView *MultiAgendaView::Private::createView(const QString &title)
{
QWidget *box = new QWidget(mTopBox);
auto *box = new QWidget(mTopBox);
mTopBox->layout()->addWidget(box);
auto layout = new QVBoxLayout(box);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(new ElidedLabel(title));
AgendaView *av = new AgendaView(q->preferences(),
auto *av = new AgendaView(q->preferences(),
q->startDateTime().date(),
q->endDateTime().date(),
true,
......
......@@ -207,7 +207,7 @@ private:
Private *const d;
};
typedef QSharedPointer<Prefs> PrefsPtr;
using PrefsPtr = QSharedPointer<Prefs>;
}
#endif
......@@ -45,7 +45,7 @@ void TimelineItem::insertIncidence(const Akonadi::Item &aitem, const QDateTime &
end = end.addDays(1);
}
typedef QList<QStandardItem *> ItemList;
using ItemList = QList<QStandardItem *>;
ItemList list = mItemMap.value(aitem.id());
for (ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) {
if (static_cast<TimelineSubItem *>(*it)->startTime() == start
......@@ -78,7 +78,7 @@ void TimelineItem::removeIncidence(const Akonadi::Item &incidence)
void TimelineItem::moveItems(const Akonadi::Item &incidence, int delta, int duration)
{
typedef QList<QStandardItem *> ItemList;
using ItemList = QList<QStandardItem *>;
ItemList list = mItemMap.value(incidence.id());
const ItemList::ConstIterator end(list.constEnd());
for (ItemList::ConstIterator it = list.constBegin(); it != end; ++it) {
......
......@@ -95,7 +95,7 @@ public:
QModelIndex indexBelow(const QModelIndex &idx) const override
{
if (!idx.isValid()) {
return QModelIndex();
return {};
}
return idx.model()->index(idx.row() + 1, idx.column(), idx.parent());
}
......@@ -103,7 +103,7 @@ public:
QModelIndex indexAbove(const QModelIndex &idx) const override
{
if (!idx.isValid()) {
return QModelIndex();
return {};
}
return idx.model()->index(idx.row() - 1, idx.column(), idx.parent());
}
......
......@@ -108,7 +108,7 @@ void IncidenceTreeModel::Private::dumpTree()
QModelIndex IncidenceTreeModel::Private::indexForNode(const Node::Ptr &node) const
{
if (!node) {
return QModelIndex();
return {};
}
const int row = node->parentNode ? node->parentNode->directChilds.indexOf(node)
: m_toplevelNodeList.indexOf(node);
......@@ -737,7 +737,7 @@ QModelIndex IncidenceTreeModel::mapFromSource(const QModelIndex &sourceIndex) co
qCWarning(CALENDARVIEW_LOG)
<< "IncidenceTreeModel::mapFromSource() source index is invalid";
// Q_ASSERT( false );
return QModelIndex();
return {};
}
if (!sourceModel()) {
......@@ -761,7 +761,7 @@ QModelIndex IncidenceTreeModel::mapFromSource(const QModelIndex &sourceIndex) co
QModelIndex IncidenceTreeModel::mapToSource(const QModelIndex &proxyIndex) const
{
if (!proxyIndex.isValid() || !sourceModel()) {
return QModelIndex();
return {};
}
Q_ASSERT(proxyIndex.column() < columnCount());
......@@ -799,7 +799,7 @@ QModelIndex IncidenceTreeModel::parent(const QModelIndex &child) const
if (!child.isValid()) {
qCWarning(CALENDARVIEW_LOG) << "IncidenceTreeModel::parent(): child is invalid";
Q_ASSERT(false);
return QModelIndex();
return {};
}
Q_ASSERT(child.model() == this);
......@@ -837,7 +837,7 @@ QModelIndex IncidenceTreeModel::index(int row, int column, const QModelIndex &pa
<< "; row=" << row << "; column=" << column
<< "; rowCount() = " << rowCount( parent ); */
// Q_ASSERT( false );
return QModelIndex();
return {};
}
Q_ASSERT(column >= 0);
......
......@@ -20,13 +20,13 @@
#include <QPersistentModelIndex>
#include <KCalendarCore/Incidence>
typedef QString Uid;
typedef QString ParentUid;
using Uid = QString;
using ParentUid = QString;
struct Node {
typedef QSharedPointer<Node> Ptr;
typedef QMap<Akonadi::Item::Id, Ptr> Map;
typedef QVector<Ptr> List;
using Ptr = QSharedPointer<Node>;
using Map = QMap<Akonadi::Item::Id, Ptr>;
using List = QVector<Ptr>;
QPersistentModelIndex sourceIndex; // because ETM::modelIndexesForItem is so slow
Akonadi::Item::Id id;
......@@ -39,8 +39,8 @@ struct Node {
/** Just a struct to contain some data before we create the node */
struct PreNode {
typedef QSharedPointer<PreNode> Ptr;
typedef QVector<Ptr> List;
using Ptr = QSharedPointer<PreNode>;
using List = QVector<Ptr>;
KCalendarCore::Incidence::Ptr incidence;
QPersistentModelIndex sourceIndex;
Akonadi::Item item;
......
......@@ -347,5 +347,5 @@ QSize TodoRichTextDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
// This row might not have a checkbox, so give it more height so it appears the same size as other rows.
const int checkboxHeight = QApplication::style()->sizeFromContents(QStyle::CT_CheckBox, &option,
QSize()).height();
return QSize(ret.width(), qMax(ret.height(), checkboxHeight));
return {ret.width(), qMax(ret.height(), checkboxHeight)};
}
......@@ -827,7 +827,7 @@ Qt::ItemFlags TodoModel::flags(const QModelIndex &index) const
QModelIndex TodoModel::mapFromSource(const QModelIndex &sourceIndex) const
{
if (!sourceModel() || !sourceIndex.isValid()) {
return QModelIndex();
return {};
}
Q_ASSERT(sourceIndex.internalPointer());
......@@ -838,7 +838,7 @@ QModelIndex TodoModel::mapFromSource(const QModelIndex &sourceIndex) const
QModelIndex TodoModel::mapToSource(const QModelIndex &proxyIndex) const
{
if (!sourceModel() || !proxyIndex.isValid()) {
return QModelIndex();
return {};
}
if (proxyIndex.column() != 0) {
......@@ -878,7 +878,7 @@ QModelIndex TodoModel::index(int row, int column, const QModelIndex &parent) con
return createIndex(row, column, index.internalPointer());
}
return QModelIndex();
return {};
}
QModelIndex TodoModel::parent(const QModelIndex &child) const
......@@ -896,7 +896,7 @@ QModelIndex TodoModel::parent(const QModelIndex &child) const
return createIndex(parentIndex.row(), child.column(), parentIndex.internalPointer());
}
return QModelIndex();
return {};
}
QModelIndex TodoModel::buddy(const QModelIndex &index) const
......
......@@ -295,7 +295,7 @@ TodoView::TodoView(const EventViews::PrefsPtr &prefs, bool sidebarView, QWidget
auto dummyLayout = new QHBoxLayout();
dummyLayout->setContentsMargins(0, 0, mView->frameWidth() /*right*/, 0);
if (!mSidebarView) {
QFrame *f = new QFrame(this);
auto *f = new QFrame(this);
f->setFrameShape(QFrame::VLine);
f->setFrameShadow(QFrame::Sunken);
dummyLayout->addWidget(f);
......
......@@ -118,7 +118,7 @@ QModelIndex TodoViewView::moveCursor(CursorAction cursorAction, Qt::KeyboardModi
return tmp;
}
}
return QModelIndex();
return {};
}
case MovePrevious:
{
......@@ -170,7 +170,7 @@ QModelIndex TodoViewView::getNextEditableIndex(const QModelIndex &cur, int inc)
return tmp;
}
}
return QModelIndex();
return {};
}
void TodoViewView::mouseReleaseEvent(QMouseEvent *event)
......
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