Skip to content

Commit d95f5e9

Browse files
committed
chore: remove requestPreview from abstracttaskmanagerinterface.h
移除原本为图标预览所预留的 API,因为此接口计划调整形式. 原因是旧的接口传递的是 QModelIndexList, 当窗口数量变化时就无法主动 感知到变化,需要某种形式的刷新. 计划调整为使用 proxy model 的形式基 于原始模型提供的窗口信息过滤并展示对应的窗口预览, 这样当有新的符合 过滤条件的窗口出现或者窗口消失时, 视图即可直接因模型变化而刷新. 相关代理模型的实现也附带于本提交中,尽管目前并未实际用到. Log:
1 parent 45e47ee commit d95f5e9

11 files changed

Lines changed: 156 additions & 74 deletions

panels/dock/taskmanager/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ add_library(dock-taskmanager SHARED ${DBUS_INTERFACES}
7474
dockglobalelementmodel.h
7575
dockgroupmodel.cpp
7676
dockgroupmodel.h
77+
hoverpreviewproxymodel.cpp
78+
hoverpreviewproxymodel.h
7779
taskmanager.cpp
7880
taskmanager.h
7981
treelandwindow.cpp

panels/dock/taskmanager/abstracttaskmanagerinterface.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ class AbstractTaskManagerInterface
6666
{
6767
callInterfaceMethod(index, &AbstractTaskManagerInterface::requestUpdateWindowGeometry, geometry, delegate);
6868
}
69-
70-
virtual void
71-
requestPreview(const QModelIndexList &indexes, QObject *relativePositionItem, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction) const
72-
{
73-
callInterfaceMethod(indexes, &AbstractTaskManagerInterface::requestPreview, relativePositionItem, previewXoffset, previewYoffset, direction);
74-
}
7569
virtual void requestWindowsView(const QModelIndexList &indexes) const
7670
{
7771
callInterfaceMethod(indexes, &AbstractTaskManagerInterface::requestWindowsView);

panels/dock/taskmanager/dockglobalelementmodel.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
4141
}
4242
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
4343
if (std::get<1>(data) == m_appsModel && std::get<2>(data) >= first) {
44-
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) - -((last - first) + 1));
44+
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) - ((last - first) + 1));
4545
}
4646
});
4747
});
@@ -293,7 +293,9 @@ QVariant DockGlobalElementModel::data(const QModelIndex &index, int role) const
293293
if (model == m_activeAppModel) {
294294
return QStringList{model->index(row, 0).data(TaskManager::WinIdRole).toString()};
295295
}
296-
return QVariant();
296+
// For m_appsModel data, when it's GroupModel we can directly get all window IDs for this desktop ID
297+
QModelIndex groupIndex = model->index(row, 0);
298+
return groupIndex.data(TaskManager::WindowsRole).toStringList();
297299
}
298300
case TaskManager::MenusRole: {
299301
return getMenus(index);
@@ -384,25 +386,6 @@ void DockGlobalElementModel::requestUpdateWindowGeometry(const QModelIndex &inde
384386
Q_UNUSED(delegate)
385387
}
386388

387-
void DockGlobalElementModel::requestPreview(const QModelIndexList &indexes,
388-
QObject *relativePositionItem,
389-
int32_t previewXoffset,
390-
int32_t previewYoffset,
391-
uint32_t direction) const
392-
{
393-
QModelIndexList sourceIndexes;
394-
for (auto index : indexes) {
395-
auto data = m_data.value(index.row());
396-
auto id = std::get<0>(data);
397-
auto sourceModel = std::get<1>(data);
398-
auto sourceRow = std::get<2>(data);
399-
if (sourceModel == m_activeAppModel) {
400-
sourceIndexes.append(sourceModel->index(sourceRow, 0));
401-
}
402-
}
403-
m_activeAppModel->requestPreview(sourceIndexes, relativePositionItem, previewXoffset, previewYoffset, direction);
404-
}
405-
406389
void DockGlobalElementModel::requestWindowsView(const QModelIndexList &indexes) const
407390
{
408391
Q_UNUSED(indexes)

panels/dock/taskmanager/dockglobalelementmodel.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ class DockGlobalElementModel : public QAbstractListModel, public AbstractTaskMan
3434
void requestClose(const QModelIndex &index, bool force = false) const override;
3535
void requestUpdateWindowGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) const override;
3636

37-
void requestPreview(const QModelIndexList &indexes,
38-
QObject *relativePositionItem,
39-
int32_t previewXoffset,
40-
int32_t previewYoffset,
41-
uint32_t direction) const override;
4237
void requestWindowsView(const QModelIndexList &indexes) const override;
4338

4439
private:

panels/dock/taskmanager/dockgroupmodel.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,6 @@ void DockGroupModel::requestUpdateWindowGeometry(const QModelIndex &index, const
137137
Q_UNUSED(delegate)
138138
}
139139

140-
void DockGroupModel::requestPreview(const QModelIndexList &indexes,
141-
QObject *relativePositionItem,
142-
int32_t previewXoffset,
143-
int32_t previewYoffset,
144-
uint32_t direction) const
145-
{
146-
QModelIndexList proxyIndexes;
147-
for (auto index : indexes) {
148-
for (int i = 0; i < RoleGroupModel::rowCount(index); ++i) {
149-
auto proxyIndex = createIndex(i, 0, index.row());
150-
proxyIndexes.append(proxyIndex);
151-
}
152-
}
153-
154-
callInterfaceMethod(proxyIndexes, &AbstractTaskManagerInterface::requestPreview, relativePositionItem, previewXoffset, previewYoffset, direction);
155-
}
156-
157140
void DockGroupModel::requestWindowsView(const QModelIndexList &indexes) const
158141
{
159142
QModelIndexList sourceIndexes;
@@ -165,4 +148,4 @@ void DockGroupModel::requestWindowsView(const QModelIndexList &indexes) const
165148

166149
callInterfaceMethod(sourceIndexes, &AbstractTaskManagerInterface::requestWindowsView);
167150
}
168-
}
151+
}

panels/dock/taskmanager/dockgroupmodel.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ class DockGroupModel : public RoleGroupModel, public AbstractTaskManagerInterfac
2222
void requestActivate(const QModelIndex &index) const override;
2323
void requestClose(const QModelIndex &index, bool force = false) const override;
2424
void requestUpdateWindowGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) const override;
25-
void requestPreview(const QModelIndexList &indexes,
26-
QObject *relativePositionItem,
27-
int32_t previewXoffset,
28-
int32_t previewYoffset,
29-
uint32_t direction) const override;
3025
void requestWindowsView(const QModelIndexList &indexes) const override;
3126

3227
private:

panels/dock/taskmanager/dockitemmodel.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ DockItemModel::DockItemModel(QAbstractItemModel *globalModel, QObject *parent)
1919
, m_isUpdating(false)
2020
{
2121
auto updateSourceModel = [this]() {
22-
if (TaskManagerSettings::instance()->isWindowSplit() == m_split)
22+
bool isWindowSplit = TaskManagerSettings::instance()->isWindowSplit();
23+
if (isWindowSplit == m_split)
2324
return;
2425

25-
m_split = TaskManagerSettings::instance()->isWindowSplit();
26-
if (m_split) {
26+
m_split = isWindowSplit;
27+
28+
if (isWindowSplit) {
2729
setSourceModel(m_globalModel);
2830
m_groupModel.reset(nullptr);
2931
} else {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "hoverpreviewproxymodel.h"
6+
#include "taskmanager.h"
7+
#include "taskmanagersettings.h"
8+
9+
#include <QDebug>
10+
11+
namespace dock
12+
{
13+
14+
HoverPreviewProxyModel::HoverPreviewProxyModel(QObject *parent)
15+
: QSortFilterProxyModel(parent)
16+
, m_settings(TaskManagerSettings::instance())
17+
{
18+
// 设置动态排序,确保模型变化时自动重新过滤
19+
setDynamicSortFilter(true);
20+
}
21+
22+
void HoverPreviewProxyModel::setFilterModelIndex(const QModelIndex &index)
23+
{
24+
if (m_filterIndex == index)
25+
return;
26+
27+
m_filterIndex = index;
28+
29+
// 触发过滤器重新计算
30+
invalidateFilter();
31+
}
32+
33+
void HoverPreviewProxyModel::clearFilter()
34+
{
35+
setFilterModelIndex(QModelIndex());
36+
}
37+
38+
bool HoverPreviewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
39+
{
40+
Q_UNUSED(sourceParent)
41+
42+
// 如果没有设置过滤条件,则不显示任何行
43+
if (!m_filterIndex.isValid())
44+
return false;
45+
46+
if (!sourceModel())
47+
return false;
48+
49+
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0);
50+
if (!sourceIndex.isValid())
51+
return false;
52+
53+
// 确保有实际的窗口ID
54+
QVariant winIdData = sourceIndex.data(TaskManager::WinIdRole);
55+
uint32_t winId = winIdData.toUInt();
56+
if (winId == 0)
57+
return false;
58+
59+
// 根据 noTaskGrouping 配置采用不同的过滤策略
60+
bool isWindowSplit = (m_settings && m_settings->isWindowSplit());
61+
62+
if (isWindowSplit) {
63+
// noTaskGrouping = true: 精确匹配该模型索引对应的窗口
64+
// 比较窗口ID是否匹配
65+
QVariant filterWinId = m_filterIndex.data(TaskManager::WinIdRole);
66+
uint32_t targetWinId = filterWinId.toUInt();
67+
68+
bool result = (winId == targetWinId && targetWinId != 0);
69+
// 在 WindowSplit 模式下,精确匹配单个窗口
70+
return result;
71+
} else {
72+
// noTaskGrouping = false: 基于 DesktopIdRole 匹配应用的所有窗口
73+
QVariant currentDesktopId = sourceIndex.data(TaskManager::DesktopIdRole);
74+
QVariant filterDesktopId = m_filterIndex.data(TaskManager::DesktopIdRole);
75+
76+
bool result = (currentDesktopId.toString() == filterDesktopId.toString());
77+
// 在 Grouped 模式下,匹配同一应用的所有窗口
78+
return result;
79+
}
80+
}
81+
82+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#pragma once
6+
7+
#include <QSortFilterProxyModel>
8+
9+
namespace dock
10+
{
11+
12+
class TaskManagerSettings;
13+
14+
/**
15+
* @brief HoverPreviewProxyModel - 专用于任务栏 hover 预览的代理模型
16+
*
17+
* 该模型用于过滤出特定应用的所有窗口,确保预览窗口与实际窗口状态保持同步
18+
* 支持 noTaskGrouping 模式,在该模式下只显示特定窗口而非整个应用的窗口
19+
*/
20+
class HoverPreviewProxyModel : public QSortFilterProxyModel
21+
{
22+
Q_OBJECT
23+
24+
public:
25+
explicit HoverPreviewProxyModel(QObject *parent = nullptr);
26+
27+
/**
28+
* @brief 设置要预览的模型索引,在 noTaskGrouping 模式下精确匹配该窗口
29+
* @param index 要预览的模型索引,无效索引则清除过滤条件
30+
*/
31+
void setFilterModelIndex(const QModelIndex &index);
32+
33+
/**
34+
* @brief 获取当前过滤的模型索引
35+
* @return 当前过滤的模型索引
36+
*/
37+
QModelIndex filterModelIndex() const
38+
{
39+
return m_filterIndex;
40+
}
41+
42+
/**
43+
* @brief 清除过滤条件,重置模型状态
44+
*/
45+
void clearFilter();
46+
47+
protected:
48+
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
49+
50+
private:
51+
QModelIndex m_filterIndex; // 当前过滤的模型索引
52+
TaskManagerSettings *m_settings; // 任务管理器设置,用于获取 noTaskGrouping 状态
53+
};
54+
55+
}

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,11 @@ void TaskManager::requestUpdateWindowGeometry(const QModelIndex &index, const QR
194194
m_itemModel->requestUpdateWindowGeometry(index, geometry, delegate);
195195
}
196196

197-
void TaskManager::requestPreview(const QModelIndexList &indexes,
198-
QObject *relativePositionItem,
199-
int32_t previewXoffset,
200-
int32_t previewYoffset,
201-
uint32_t direction) const
197+
void TaskManager::requestPreview(const QModelIndex &index, QObject *relativePositionItem, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction)
202198
{
203-
for (auto index : indexes) {
204-
qDebug() << "requestPreview" << index << index.model() << (index.model() == m_itemModel);
205-
}
206-
m_itemModel->requestPreview(indexes, relativePositionItem, previewXoffset, previewYoffset, direction);
199+
// TODO: implement this
207200
}
201+
208202
void TaskManager::requestWindowsView(const QModelIndexList &indexes) const
209203
{
210204
m_itemModel->requestWindowsView(indexes);
@@ -353,9 +347,9 @@ bool TaskManager::requestDockByDesktopId(const QString& desktopID)
353347
if (desktopID.startsWith("internal/")) return false;
354348
QString appId = desktopIdToAppId(desktopID);
355349
// 检查应用是否已经在任务栏中,如果是则返回 false
356-
if (IsDocked(appId))
350+
if (IsDocked(appId))
357351
return false;
358-
352+
359353
return RequestDock(appId);
360354
}
361355

0 commit comments

Comments
 (0)