-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program 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 General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "kitemlistheaderwidget.h"
-
-#include <kitemviews/kitemmodelbase.h>
+#include "kitemviews/kitemmodelbase.h"
#include <QApplication>
#include <QGraphicsSceneHoverEvent>
KItemListHeaderWidget::KItemListHeaderWidget(QGraphicsWidget* parent) :
QGraphicsWidget(parent),
m_automaticColumnResizing(true),
- m_model(0),
+ m_model(nullptr),
m_offset(0),
m_columns(),
m_columnWidths(),
void KItemListHeaderWidget::setColumns(const QList<QByteArray>& roles)
{
- foreach (const QByteArray& role, roles) {
+ for (const QByteArray& role : roles) {
if (!m_columnWidths.contains(role)) {
- m_columnWidths.remove(role);
m_preferredColumnWidths.remove(role);
}
}
void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
- Q_UNUSED(option);
- Q_UNUSED(widget);
+ Q_UNUSED(option)
+ Q_UNUSED(widget)
if (!m_model) {
return;
qreal x = -m_offset;
int orderIndex = 0;
- foreach (const QByteArray& role, m_columns) {
+ for (const QByteArray& role : qAsConst(m_columns)) {
const qreal roleWidth = m_columnWidths.value(role);
const QRectF rect(x, 0, roleWidth, size().height());
paintRole(painter, role, rect, orderIndex, widget);
const Qt::SortOrder current = (m_model->sortOrder() == Qt::AscendingOrder) ?
Qt::DescendingOrder : Qt::AscendingOrder;
m_model->setSortOrder(current);
- emit sortOrderChanged(current, previous);
+ Q_EMIT sortOrderChanged(current, previous);
} else {
// Change the sort role and reset to the ascending order
const QByteArray previous = m_model->sortRole();
const QByteArray current = m_columns[m_pressedRoleIndex];
- m_model->setSortRole(current);
- emit sortRoleChanged(current, previous);
+ const bool resetSortOrder = m_model->sortOrder() == Qt::DescendingOrder;
+ m_model->setSortRole(current, !resetSortOrder);
+ Q_EMIT sortRoleChanged(current, previous);
- if (m_model->sortOrder() == Qt::DescendingOrder) {
+ if (resetSortOrder) {
m_model->setSortOrder(Qt::AscendingOrder);
- emit sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder);
+ Q_EMIT sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder);
}
}
break;
case ResizeRoleOperation: {
const QByteArray pressedRole = m_columns[m_pressedRoleIndex];
const qreal currentWidth = m_columnWidths.value(pressedRole);
- emit columnWidthChangeFinished(pressedRole, currentWidth);
+ Q_EMIT columnWidthChangeFinished(pressedRole, currentWidth);
break;
}
m_columnWidths.insert(pressedRole, currentWidth);
update();
- emit columnWidthChanged(pressedRole, currentWidth, previousWidth);
+ Q_EMIT columnWidthChanged(pressedRole, currentWidth, previousWidth);
break;
}
const QByteArray role = m_columns[m_movingRole.index];
const int previousIndex = m_movingRole.index;
m_movingRole.index = targetIndex;
- emit columnMoved(role, targetIndex, previousIndex);
+ Q_EMIT columnMoved(role, targetIndex, previousIndex);
m_movingRole.xDec = event->pos().x() - roleXPosition(role);
}
setColumnWidth(role, preferredColumnWidth(role));
qreal currentWidth = columnWidth(role);
- emit columnWidthChanged(role, currentWidth, previousWidth);
- emit columnWidthChangeFinished(role, currentWidth);
+ Q_EMIT columnWidthChanged(role, currentWidth, previousWidth);
+ Q_EMIT columnWidthChangeFinished(role, currentWidth);
}
}
void KItemListHeaderWidget::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
update();
}
void KItemListHeaderWidget::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
update();
}
QWidget* widget) const
{
// The following code is based on the code from QHeaderView::paintSection().
- // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies).
QStyleOptionHeader option;
option.section = orderIndex;
option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal;
int index = -1;
qreal x = -m_offset;
- foreach (const QByteArray& role, m_columns) {
+ for (const QByteArray& role : qAsConst(m_columns)) {
++index;
x += m_columnWidths.value(role);
if (pos.x() <= x) {
qreal KItemListHeaderWidget::roleXPosition(const QByteArray& role) const
{
qreal x = -m_offset;
- foreach (const QByteArray& visibleRole, m_columns) {
+ for (const QByteArray& visibleRole : qAsConst(m_columns)) {
if (visibleRole == role) {
return x;
}