Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 15 additions & 28 deletions panels/dock/taskmanager/hoverpreviewproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,38 @@

#include "hoverpreviewproxymodel.h"
#include "taskmanager.h"
#include "taskmanagersettings.h"

#include <QDebug>

Check warning on line 8 in panels/dock/taskmanager/hoverpreviewproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace dock
{

HoverPreviewProxyModel::HoverPreviewProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
, m_settings(TaskManagerSettings::instance())
{
// 设置动态排序,确保模型变化时自动重新过滤
setDynamicSortFilter(true);
}

void HoverPreviewProxyModel::setFilterModelIndex(const QModelIndex &index)
void HoverPreviewProxyModel::setFilter(QString filter, enum FilterMode mode)
{
if (m_filterIndex == index)
return;
m_filter = filter;
m_filterMode = mode;

m_filterIndex = index;

// 触发过滤器重新计算
invalidateFilter();
}

void HoverPreviewProxyModel::clearFilter()
{
setFilterModelIndex(QModelIndex());
setFilter(QString(), FilterByAppId);
}

bool HoverPreviewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_UNUSED(sourceParent)

// 如果没有设置过滤条件,则不显示任何行
if (!m_filterIndex.isValid())
if (m_filter.isEmpty())
return false;

if (!sourceModel())
Expand All @@ -56,27 +51,19 @@
if (winId == 0)
return false;

// 根据 noTaskGrouping 配置采用不同的过滤策略
bool isWindowSplit = (m_settings && m_settings->isWindowSplit());

if (isWindowSplit) {
// noTaskGrouping = true: 精确匹配该模型索引对应的窗口
// 比较窗口ID是否匹配
QVariant filterWinId = m_filterIndex.data(TaskManager::WinIdRole);
uint32_t targetWinId = filterWinId.toUInt();

switch (m_filterMode) {
case FilterByAppId: {
QString currentDesktopId = sourceIndex.data(TaskManager::DesktopIdRole).toString();
return currentDesktopId == m_filter;
}
case FilterByWinId: {
uint32_t targetWinId = m_filter.toUInt();
bool result = (winId == targetWinId && targetWinId != 0);
Comment on lines +60 to 61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential silent conversion issue when using QString::toUInt().

If m_filter is not numeric, toUInt() returns 0, which may cause incorrect filtering. Please validate m_filter or handle conversion errors.

// 在 WindowSplit 模式下,精确匹配单个窗口
return result;
} else {
// noTaskGrouping = false: 基于 DesktopIdRole 匹配应用的所有窗口
QVariant currentDesktopId = sourceIndex.data(TaskManager::DesktopIdRole);
QVariant filterDesktopId = m_filterIndex.data(TaskManager::DesktopIdRole);

bool result = (currentDesktopId.toString() == filterDesktopId.toString());
// 在 Grouped 模式下,匹配同一应用的所有窗口
return result;
}
}

return false;
}

}
20 changes: 8 additions & 12 deletions panels/dock/taskmanager/hoverpreviewproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ class HoverPreviewProxyModel : public QSortFilterProxyModel
public:
explicit HoverPreviewProxyModel(QObject *parent = nullptr);

enum FilterMode {
FilterByAppId,
FilterByWinId,
};

/**
* @brief 设置要预览的模型索引,在 noTaskGrouping 模式下精确匹配该窗口
* @param index 要预览的模型索引,无效索引则清除过滤条件
*/
void setFilterModelIndex(const QModelIndex &index);

/**
* @brief 获取当前过滤的模型索引
* @return 当前过滤的模型索引
*/
QModelIndex filterModelIndex() const
{
return m_filterIndex;
}
void setFilter(QString filter, enum FilterMode mode);

/**
* @brief 清除过滤条件,重置模型状态
Expand All @@ -48,8 +44,8 @@ class HoverPreviewProxyModel : public QSortFilterProxyModel
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;

private:
QModelIndex m_filterIndex; // 当前过滤的模型索引
TaskManagerSettings *m_settings; // 任务管理器设置,用于获取 noTaskGrouping 状态
FilterMode m_filterMode;
QString m_filter;
};

}
8 changes: 7 additions & 1 deletion panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ void TaskManager::requestPreview(const QModelIndex &index, QObject *relativePosi
}

// Set the preview filter condition based on the incoming model index
m_hoverPreviewModel->setFilterModelIndex(index);
if (windowSplit()) {
QString winId = index.data(TaskManager::WinIdRole).toString();
m_hoverPreviewModel->setFilter(winId, HoverPreviewProxyModel::FilterByWinId);
} else {
QString appId = index.data(TaskManager::DesktopIdRole).toString();
m_hoverPreviewModel->setFilter(appId, HoverPreviewProxyModel::FilterByAppId);
}

// Check if there are any windows after filtering
if (m_hoverPreviewModel->rowCount() == 0) {
Expand Down