|
| 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 | + , AbstractTaskManagerInterface(this) |
| 16 | +{ |
| 17 | + // due to role has changed by RoleGroupModel, so we redirect role to TaskManager::Roles. |
| 18 | + m_roleMaps = {{TaskManager::ActiveRole, RoleCombineModel::roleNames().key(MODEL_ACTIVE)}, |
| 19 | + {TaskManager::AttentionRole, RoleCombineModel::roleNames().key(MODEL_ATTENTION)}, |
| 20 | + {TaskManager::DesktopIdRole, RoleCombineModel::roleNames().key(MODEL_DESKTOPID)}, |
| 21 | + {TaskManager::IconNameRole, RoleCombineModel::roleNames().key(MODEL_ICONNAME)}, |
| 22 | + {TaskManager::IdentityRole, RoleCombineModel::roleNames().key(MODEL_IDENTIFY)}, |
| 23 | + {TaskManager::ActionsRole, RoleCombineModel::roleNames().key(MODEL_ACTIONS)}, |
| 24 | + {TaskManager::NameRole, RoleCombineModel::roleNames().key(MODEL_NAME)}, |
| 25 | + {TaskManager::WinIdRole, RoleCombineModel::roleNames().key(MODEL_WINID)}, |
| 26 | + {TaskManager::WinTitleRole, RoleCombineModel::roleNames().key(MODEL_TITLE)}}; |
| 27 | +} |
| 28 | + |
| 29 | +QHash<int, QByteArray> DockCombineModel::roleNames() const |
| 30 | +{ |
| 31 | + return {{TaskManager::ActiveRole, MODEL_ACTIVE}, |
| 32 | + {TaskManager::AttentionRole, MODEL_ATTENTION}, |
| 33 | + {TaskManager::DesktopIdRole, MODEL_DESKTOPID}, |
| 34 | + {TaskManager::IconNameRole, MODEL_ICONNAME}, |
| 35 | + {TaskManager::IdentityRole, MODEL_IDENTIFY}, |
| 36 | + {TaskManager::ActionsRole, MODEL_ACTIONS}, |
| 37 | + {TaskManager::NameRole, MODEL_NAME}, |
| 38 | + {TaskManager::WinIdRole, MODEL_WINID}, |
| 39 | + {TaskManager::WinTitleRole, MODEL_TITLE}}; |
| 40 | +} |
| 41 | + |
| 42 | +QVariant DockCombineModel::data(const QModelIndex &index, int role) const |
| 43 | +{ |
| 44 | + switch (role) { |
| 45 | + case TaskManager::DesktopIdRole: { |
| 46 | + auto res = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::DesktopIdRole)).toString(); |
| 47 | + if (res.isEmpty()) { |
| 48 | + auto data = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::IdentityRole)).toStringList(); |
| 49 | + res = data.value(0, ""); |
| 50 | + } |
| 51 | + return res; |
| 52 | + } |
| 53 | + case TaskManager::IconNameRole: { |
| 54 | + auto icon = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::IconNameRole)).toString(); |
| 55 | + if (icon.isEmpty()) { |
| 56 | + icon = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::WinIconRole)).toString(); |
| 57 | + } |
| 58 | + return icon; |
| 59 | + } |
| 60 | + default: { |
| 61 | + auto newRole = m_roleMaps.value(role, -1); |
| 62 | + if (newRole == -1) { |
| 63 | + return QVariant(); |
| 64 | + } |
| 65 | + |
| 66 | + return RoleCombineModel::data(index, newRole); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return QVariant(); |
| 71 | +} |
| 72 | +} |
0 commit comments