Skip to content

Commit e4e8b71

Browse files
committed
chore: use roles defined in TaskManager class
此提交旨在为后续切换组合模型做准备,是原重构分支包含的部分变更. Log:
1 parent d7fd85d commit e4e8b71

File tree

4 files changed

+32
-43
lines changed

4 files changed

+32
-43
lines changed

panels/dock/taskmanager/abstractwindow.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ class AbstractWindow : public QObject
2424
Q_PROPERTY(bool shouldSkip READ shouldSkip NOTIFY shouldSkipChanged FINAL)
2525

2626
public:
27-
enum Roles {
28-
winIdRole = Qt::UserRole + 1,
29-
pidRole,
30-
identityRole,
31-
winIconRole,
32-
winTitleRole,
33-
activieRole,
34-
shouldSkipRole
35-
};
36-
Q_ENUM(Roles)
37-
3827
virtual ~AbstractWindow() {};
3928

4029
virtual uint32_t id() = 0;

panels/dock/taskmanager/abstractwindowmonitor.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "abstractwindowmonitor.h"
66
#include "abstractwindow.h"
7+
#include "globals.h"
8+
#include "taskmanager.h"
79

810
namespace dock {
911
AbstractWindowMonitor::AbstractWindowMonitor(QObject* parent)
@@ -13,15 +15,13 @@ AbstractWindowMonitor::AbstractWindowMonitor(QObject* parent)
1315

1416
QHash<int, QByteArray> AbstractWindowMonitor::roleNames() const
1517
{
16-
return {
17-
{AbstractWindow::winIdRole, "winId"},
18-
{AbstractWindow::pidRole, "pid"},
19-
{AbstractWindow::identityRole, "identity"},
20-
{AbstractWindow::winIconRole, "icon"},
21-
{AbstractWindow::winTitleRole, "title"},
22-
{AbstractWindow::activieRole, "isActive"},
23-
{AbstractWindow::shouldSkipRole, "shouldSkip"}
24-
};
18+
return {{TaskManager::WinIdRole, MODEL_WINID},
19+
{TaskManager::PidRole, MODEL_PID},
20+
{TaskManager::IdentityRole, MODEL_IDENTIFY},
21+
{TaskManager::WinIconRole, MODEL_WINICON},
22+
{TaskManager::WinTitleRole, MODEL_TITLE},
23+
{TaskManager::ActiveRole, "isActive"},
24+
{TaskManager::ShouldSkipRole, MODEL_SHOULDSKIP}};
2525
}
2626

2727
int AbstractWindowMonitor::rowCount(const QModelIndex &parent) const
@@ -37,20 +37,20 @@ QVariant AbstractWindowMonitor::data(const QModelIndex &index, int role) const
3737
auto window = m_trackedWindows[pos];
3838

3939
switch (role) {
40-
case AbstractWindow::winIdRole:
41-
return window->id();
42-
case AbstractWindow::pidRole:
43-
return window->pid();
44-
case AbstractWindow::identityRole:
45-
return window->identity();
46-
case AbstractWindow::winIconRole:
47-
return window->icon();
48-
case AbstractWindow::winTitleRole:
49-
return window->title();
50-
case AbstractWindow::activieRole:
51-
return window->isActive();
52-
case AbstractWindow::shouldSkipRole:
53-
return window->shouldSkip();
40+
case TaskManager::WinIdRole:
41+
return window->id();
42+
case TaskManager::PidRole:
43+
return window->pid();
44+
case TaskManager::IdentityRole:
45+
return window->identity();
46+
case TaskManager::WinIconRole:
47+
return window->icon();
48+
case TaskManager::WinTitleRole:
49+
return window->title();
50+
case TaskManager::ActiveRole:
51+
return window->isActive();
52+
case TaskManager::ShouldSkipRole:
53+
return window->shouldSkip();
5454
}
5555

5656
return QVariant();
@@ -65,33 +65,33 @@ void AbstractWindowMonitor::trackWindow(AbstractWindow* window)
6565
connect(window, &AbstractWindow::pidChanged, this, [this, window](){
6666
auto pos = m_trackedWindows.indexOf(window);
6767
auto modelIndex = index(pos);
68-
Q_EMIT dataChanged(modelIndex, modelIndex, {AbstractWindow::pidRole});
68+
Q_EMIT dataChanged(modelIndex, modelIndex, {TaskManager::PidRole});
6969
});
7070
connect(window, &AbstractWindow::identityChanged, this, [this, window](){
7171
auto pos = m_trackedWindows.indexOf(window);
7272
auto modelIndex = index(pos);
73-
Q_EMIT dataChanged(modelIndex, modelIndex, {AbstractWindow::identityRole});
73+
Q_EMIT dataChanged(modelIndex, modelIndex, {TaskManager::IdentityRole});
7474
});
7575
connect(window, &AbstractWindow::iconChanged, this, [this, window](){
7676
auto pos = m_trackedWindows.indexOf(window);
7777
auto modelIndex = index(pos);
78-
Q_EMIT dataChanged(modelIndex, modelIndex, {AbstractWindow::winIconRole});
78+
Q_EMIT dataChanged(modelIndex, modelIndex, {TaskManager::WinIconRole});
7979
});
8080
connect(window, &AbstractWindow::titleChanged, this, [this, window](){
8181
auto pos = m_trackedWindows.indexOf(window);
8282
auto modelIndex = index(pos);
83-
Q_EMIT dataChanged(modelIndex, modelIndex, {AbstractWindow::winTitleRole});
83+
Q_EMIT dataChanged(modelIndex, modelIndex, {TaskManager::WinTitleRole});
8484
});
8585

8686
connect(window, &AbstractWindow::isActiveChanged, this, [this, window](){
8787
auto pos = m_trackedWindows.indexOf(window);
8888
auto modelIndex = index(pos);
89-
Q_EMIT dataChanged(modelIndex, modelIndex, {AbstractWindow::activieRole});
89+
Q_EMIT dataChanged(modelIndex, modelIndex, {TaskManager::ActiveRole});
9090
});
9191
connect(window, &AbstractWindow::shouldSkipChanged, this, [this, window](){
9292
auto pos = m_trackedWindows.indexOf(window);
9393
auto modelIndex = index(pos);
94-
Q_EMIT dataChanged(modelIndex, modelIndex, {AbstractWindow::shouldSkipRole});
94+
Q_EMIT dataChanged(modelIndex, modelIndex, {TaskManager::ShouldSkipRole});
9595
});
9696
}
9797

panels/dock/taskmanager/abstractwindowmonitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include "abstractwindow.h"
8+
#include "taskmanager.h"
89

910
#include <cstdint>
1011

@@ -20,7 +21,7 @@ class AbstractWindowMonitor : public QAbstractListModel
2021
public:
2122
QHash<int, QByteArray> roleNames() const override;
2223
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
23-
QVariant data(const QModelIndex &index, int role = AbstractWindow::winIdRole) const override;
24+
QVariant data(const QModelIndex &index, int role = TaskManager::WinIdRole) const override;
2425

2526
void trackWindow(AbstractWindow* window);
2627
void destroyWindow(AbstractWindow * window);

panels/dock/taskmanager/taskmanager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "abstracttaskmanagerinterface.h"
88
#include "abstractwindow.h"
9-
#include "abstractwindowmonitor.h"
109
#include "containment.h"
1110
#include "dockcombinemodel.h"
1211
#include "dockglobalelementmodel.h"
@@ -17,7 +16,7 @@
1716

1817
namespace dock {
1918
class AppItem;
20-
19+
class AbstractWindowMonitor;
2120
class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManagerInterface
2221
{
2322
Q_OBJECT

0 commit comments

Comments
 (0)