mirror of
https://invent.kde.org/plasma/plasma-desktop.git
synced 2026-11-03 22:59:45 -09:00
Pager's WindowModel adds a StackingOrder role (with rolename StackingOrder), but the source model already has this role with the same rolename. When we try to get the new property from qml for a delegate, we get many warnings of the type: qt.qml.propertyCache.append: Final member StackingOrder is overridden in class QQmlDMAbstractItemModelData. The override won't be used. The two properties (AbstractTaskModel's StackingOrder and pager's StackingOrder) usually give the same result, so there doesn't seem to break anything badly, but we can get rid of the warnings (and get the value as originally inteded) by giving the WindowModel role a unique name (PagerStackingOrder).
100 lines
2.6 KiB
C++
100 lines
2.6 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2016 Eike Hein <hein.org>
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "windowmodel.h"
|
|
#include "pagermodel.h"
|
|
|
|
#include <abstracttasksmodel.h>
|
|
|
|
#include <QGuiApplication>
|
|
#include <QMetaEnum>
|
|
#include <QScreen>
|
|
|
|
#include <KWindowSystem>
|
|
|
|
using namespace TaskManager;
|
|
|
|
class WindowModel::Private
|
|
{
|
|
public:
|
|
explicit Private(WindowModel *q);
|
|
|
|
PagerModel *pagerModel = nullptr;
|
|
|
|
private:
|
|
WindowModel *const q;
|
|
};
|
|
|
|
WindowModel::Private::Private(WindowModel *q)
|
|
: q(q)
|
|
{
|
|
Q_UNUSED(this->q);
|
|
}
|
|
|
|
WindowModel::WindowModel(PagerModel *parent)
|
|
: TaskFilterProxyModel(parent)
|
|
, d(new Private(this))
|
|
{
|
|
d->pagerModel = parent;
|
|
connect(parent, &PagerModel::pagerItemSizeChanged, this, &WindowModel::onPagerItemSizeChanged);
|
|
connect(this, &QAbstractItemModel::dataChanged, this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
|
|
if (roles.contains(AbstractTasksModel::StackingOrder)) {
|
|
Q_EMIT dataChanged(topLeft, bottomRight, {WindowModelRoles::PagerStackingOrder});
|
|
}
|
|
});
|
|
}
|
|
|
|
WindowModel::~WindowModel()
|
|
{
|
|
}
|
|
|
|
QHash<int, QByteArray> WindowModel::roleNames() const
|
|
{
|
|
QHash<int, QByteArray> roles = TaskFilterProxyModel::roleNames();
|
|
|
|
QMetaEnum e = metaObject()->enumerator(metaObject()->indexOfEnumerator("WindowModelRoles"));
|
|
|
|
for (int i = 0; i < e.keyCount(); ++i) {
|
|
roles.insert(e.value(i), e.key(i));
|
|
}
|
|
|
|
return roles;
|
|
}
|
|
|
|
QVariant WindowModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (role == AbstractTasksModel::Geometry) {
|
|
QRect windowGeo = TaskFilterProxyModel::data(index, role).toRect();
|
|
const QRect clampingRect(QPoint(0, 0), d->pagerModel->pagerItemSize());
|
|
|
|
if (filterByScreen() && screenGeometry().isValid()) {
|
|
const QPoint &screenOffset = screenGeometry().topLeft();
|
|
|
|
windowGeo.translate(0 - screenOffset.x(), 0 - screenOffset.y());
|
|
}
|
|
|
|
// Restrict to desktop/screen rect.
|
|
return windowGeo.intersected(clampingRect);
|
|
} else if (role == WindowModelRoles::PagerStackingOrder) {
|
|
const auto &winId = TaskFilterProxyModel::data(index, AbstractTasksModel::WinIdList);
|
|
const int z = d->pagerModel->stackingOrder(index);
|
|
|
|
if (z != -1) {
|
|
return z;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
return TaskFilterProxyModel::data(index, role);
|
|
}
|
|
|
|
void WindowModel::onPagerItemSizeChanged()
|
|
{
|
|
if (rowCount() > 0) {
|
|
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AbstractTasksModel::Geometry});
|
|
}
|
|
}
|
|
|
|
#include "moc_windowmodel.cpp"
|