44
55#include " hoverpreviewproxymodel.h"
66#include " taskmanager.h"
7- #include " taskmanagersettings.h"
87
98#include < QDebug>
109
@@ -13,34 +12,30 @@ namespace dock
1312
1413HoverPreviewProxyModel::HoverPreviewProxyModel (QObject *parent)
1514 : QSortFilterProxyModel(parent)
16- , m_settings(TaskManagerSettings::instance())
1715{
1816 // 设置动态排序,确保模型变化时自动重新过滤
1917 setDynamicSortFilter (true );
2018}
2119
22- void HoverPreviewProxyModel::setFilterModelIndex ( const QModelIndex &index )
20+ void HoverPreviewProxyModel::setFilter (QString filter, enum FilterMode mode )
2321{
24- if (m_filterIndex == index)
25- return ;
22+ m_filter = filter;
23+ m_filterMode = mode ;
2624
27- m_filterIndex = index;
28-
29- // 触发过滤器重新计算
3025 invalidateFilter ();
3126}
3227
3328void HoverPreviewProxyModel::clearFilter ()
3429{
35- setFilterModelIndex ( QModelIndex () );
30+ setFilter ( QString (), FilterByAppId );
3631}
3732
3833bool HoverPreviewProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const
3934{
4035 Q_UNUSED (sourceParent)
4136
4237 // 如果没有设置过滤条件,则不显示任何行
43- if (!m_filterIndex. isValid ())
38+ if (m_filter. isEmpty ())
4439 return false ;
4540
4641 if (!sourceModel ())
@@ -56,27 +51,19 @@ bool HoverPreviewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
5651 if (winId == 0 )
5752 return false ;
5853
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-
54+ switch (m_filterMode) {
55+ case FilterByAppId: {
56+ QString currentDesktopId = sourceIndex.data (TaskManager::DesktopIdRole).toString ();
57+ return currentDesktopId == m_filter;
58+ }
59+ case FilterByWinId: {
60+ uint32_t targetWinId = m_filter.toUInt ();
6861 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 模式下,匹配同一应用的所有窗口
7862 return result;
7963 }
64+ }
65+
66+ return false ;
8067}
8168
8269}
0 commit comments