|
| 1 | +// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +#include "dockcombinemodel.h" |
| 6 | +#include "abstracttaskmanagerinterface.h" |
| 7 | +#include "globals.h" |
| 8 | +#include "rolecombinemodel.h" |
| 9 | +#include "taskmanager.h" |
| 10 | + |
| 11 | +namespace dock |
| 12 | +{ |
| 13 | +DockCombineModel::DockCombineModel(QAbstractItemModel *major, QAbstractItemModel *minor, int majorRoles, CombineFunc func, QObject *parent) |
| 14 | + : RoleCombineModel(major, minor, majorRoles, func, parent) |
| 15 | +{ |
| 16 | + // due to role has changed by RoleGroupModel, so we redirect role to TaskManager::Roles. |
| 17 | + m_roleMaps = {{TaskManager::ActiveRole, RoleCombineModel::roleNames().key(MODEL_ACTIVE)}, |
| 18 | + {TaskManager::AttentionRole, RoleCombineModel::roleNames().key(MODEL_ATTENTION)}, |
| 19 | + {TaskManager::DesktopIdRole, RoleCombineModel::roleNames().key(MODEL_DESKTOPID)}, |
| 20 | + {TaskManager::IconNameRole, RoleCombineModel::roleNames().key(MODEL_ICONNAME)}, |
| 21 | + {TaskManager::IdentityRole, RoleCombineModel::roleNames().key(MODEL_IDENTIFY)}, |
| 22 | + {TaskManager::ActionsRole, RoleCombineModel::roleNames().key(MODEL_ACTIONS)}, |
| 23 | + {TaskManager::NameRole, RoleCombineModel::roleNames().key(MODEL_NAME)}, |
| 24 | + {TaskManager::WinIdRole, RoleCombineModel::roleNames().key(MODEL_WINID)}, |
| 25 | + {TaskManager::WinTitleRole, RoleCombineModel::roleNames().key(MODEL_TITLE)}}; |
| 26 | +} |
| 27 | + |
| 28 | +QHash<int, QByteArray> DockCombineModel::roleNames() const |
| 29 | +{ |
| 30 | + return {{TaskManager::ActiveRole, MODEL_ACTIVE}, |
| 31 | + {TaskManager::AttentionRole, MODEL_ATTENTION}, |
| 32 | + {TaskManager::DesktopIdRole, MODEL_DESKTOPID}, |
| 33 | + {TaskManager::IconNameRole, MODEL_ICONNAME}, |
| 34 | + {TaskManager::IdentityRole, MODEL_IDENTIFY}, |
| 35 | + {TaskManager::ActionsRole, MODEL_ACTIONS}, |
| 36 | + {TaskManager::NameRole, MODEL_NAME}, |
| 37 | + {TaskManager::WinIdRole, MODEL_WINID}, |
| 38 | + {TaskManager::WinTitleRole, MODEL_TITLE}}; |
| 39 | +} |
| 40 | + |
| 41 | +QVariant DockCombineModel::data(const QModelIndex &index, int role) const |
| 42 | +{ |
| 43 | + switch (role) { |
| 44 | + case TaskManager::DesktopIdRole: { |
| 45 | + auto res = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::DesktopIdRole)).toString(); |
| 46 | + if (res.isEmpty()) { |
| 47 | + auto data = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::IdentityRole)).toStringList(); |
| 48 | + res = data.value(0, ""); |
| 49 | + } |
| 50 | + return res; |
| 51 | + } |
| 52 | + case TaskManager::IconNameRole: { |
| 53 | + auto icon = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::IconNameRole)).toString(); |
| 54 | + if (icon.isEmpty()) { |
| 55 | + icon = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::WinIconRole)).toString(); |
| 56 | + } |
| 57 | + return icon; |
| 58 | + } |
| 59 | + default: { |
| 60 | + auto newRole = m_roleMaps.value(role, -1); |
| 61 | + if (newRole == -1) { |
| 62 | + return QVariant(); |
| 63 | + } |
| 64 | + |
| 65 | + return RoleCombineModel::data(index, newRole); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + return QVariant(); |
| 70 | +} |
| 71 | + |
| 72 | +void DockCombineModel::requestActivate(const QModelIndex &index) const |
| 73 | +{ |
| 74 | + callInterfaceMethod(this, index, &AbstractTaskManagerInterface::requestActivate); |
| 75 | +} |
| 76 | + |
| 77 | +void DockCombineModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const |
| 78 | +{ |
| 79 | + callInterfaceMethod(this, index, &AbstractTaskManagerInterface::requestOpenUrls, urls); |
| 80 | +} |
| 81 | + |
| 82 | +void DockCombineModel::requestNewInstance(const QModelIndex &index, const QString &action) const |
| 83 | +{ |
| 84 | + callInterfaceMethod(this, index, &AbstractTaskManagerInterface::requestNewInstance, action); |
| 85 | +} |
| 86 | + |
| 87 | +void DockCombineModel::requestClose(const QModelIndex &index, bool force) const |
| 88 | +{ |
| 89 | + callInterfaceMethod(this, index, &AbstractTaskManagerInterface::requestClose, force); |
| 90 | +} |
| 91 | + |
| 92 | +void DockCombineModel::requestUpdateWindowGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const |
| 93 | +{ |
| 94 | + callInterfaceMethod(this, index, &AbstractTaskManagerInterface::requestUpdateWindowGeometry, geometry, delegate); |
| 95 | +} |
| 96 | + |
| 97 | +void DockCombineModel::requestPreview(const QModelIndexList &indexes, |
| 98 | + QObject *relativePositionItem, |
| 99 | + int32_t previewXoffset, |
| 100 | + int32_t previewYoffset, |
| 101 | + uint32_t direction) const |
| 102 | +{ |
| 103 | + callInterfaceMethod(this, indexes, &AbstractTaskManagerInterface::requestPreview, relativePositionItem, previewXoffset, previewYoffset, direction); |
| 104 | +} |
| 105 | + |
| 106 | +void DockCombineModel::requestWindowsView(const QModelIndexList &indexes) const |
| 107 | +{ |
| 108 | + callInterfaceMethod(this, indexes, &AbstractTaskManagerInterface::requestWindowsView); |
| 109 | +} |
| 110 | +} |
0 commit comments