Skip to content

Commit fd0768d

Browse files
committed
chore: backup plan to temporary switch back to legacy ItemModel
为 ItemModel 类添加了一些兼容目前接口行为的接口,以供临时切换任务栏 模型到 ItemModel 所需. 此 PR 中未进行实际的切换. Log:
1 parent f846ad0 commit fd0768d

File tree

3 files changed

+111
-33
lines changed

3 files changed

+111
-33
lines changed

panels/dock/taskmanager/itemmodel.cpp

Lines changed: 96 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "itemmodel.h"
66
#include "abstractitem.h"
7+
#include "appitem.h"
8+
#include "globals.h"
9+
#include "taskmanager.h"
710
#include "taskmanagersettings.h"
811

912
#include <algorithm>
@@ -32,17 +35,19 @@ ItemModel::ItemModel(QObject* parent)
3235

3336
QHash<int, QByteArray> ItemModel::roleNames() const
3437
{
35-
return {{ItemModel::ItemIdRole, "itemId"},
36-
{ItemModel::NameRole, "name"},
37-
{ItemModel::IconNameRole, "iconName"},
38-
{ItemModel::ActiveRole, "active"},
39-
{ItemModel::AttentionRole, "attention"},
40-
{ItemModel::MenusRole, "menus"},
41-
{ItemModel::DockedRole, "docked"},
42-
{ItemModel::WindowsRole, "windows"},
43-
{ItemModel::DesktopFilesIconsRole, "desktopfileIcons"},
38+
// clang-format off
39+
return {{ItemModel::ItemIdRole, MODEL_ITEMID},
40+
{TaskManager::NameRole, MODEL_NAME},
41+
{TaskManager::IconNameRole, MODEL_ICONNAME},
42+
{TaskManager::ActiveRole, MODEL_ACTIVE},
43+
{TaskManager::AttentionRole, MODEL_ATTENTION},
44+
{TaskManager::MenusRole, MODEL_MENUS},
45+
{TaskManager::DockedRole, MODEL_DOCKED},
46+
{TaskManager::WindowsRole, MODEL_WINDOWS},
47+
{TaskManager::WinIconRole, MODEL_WINICON},
4448
{ItemModel::DockedDirRole, "dockedDir"}
4549
};
50+
// clang-format on
4651
}
4752

4853
int ItemModel::rowCount(const QModelIndex &parent) const
@@ -57,18 +62,20 @@ QVariant ItemModel::data(const QModelIndex &index, int role) const
5762
}
5863

5964
auto item = m_items[index.row()];
65+
// clang-format off
6066
switch (role) {
6167
case ItemModel::ItemIdRole: return item->id();
62-
case ItemModel::NameRole: return item->name();
63-
case ItemModel::IconNameRole: return item->icon();
64-
case ItemModel::ActiveRole: return item->isActive();
65-
case ItemModel::AttentionRole: return item->isAttention();
66-
case ItemModel::MenusRole: return item->menus();
67-
case ItemModel::DockedRole: return item->isDocked();
68-
case ItemModel::WindowsRole: return item->data().toStringList();
69-
case ItemModel::DesktopFilesIconsRole: return item->data().toStringList();
68+
case TaskManager::NameRole: return item->name();
69+
case TaskManager::IconNameRole: return item->icon();
70+
case TaskManager::ActiveRole: return item->isActive();
71+
case TaskManager::AttentionRole: return item->isAttention();
72+
case TaskManager::MenusRole: return item->menus();
73+
case TaskManager::DockedRole: return item->isDocked();
74+
case TaskManager::WindowsRole: return item->data().toStringList();
75+
case TaskManager::WinIconRole: return item->data().toStringList();
7076
case ItemModel::DockedDirRole: return item->data().toString();
7177
}
78+
// clang-format on
7279
return QVariant();
7380
}
7481

@@ -89,6 +96,78 @@ QJsonArray ItemModel::dumpDockedItems() const
8996
return result;
9097
}
9198

99+
void ItemModel::requestActivate(const QModelIndex &index) const
100+
{
101+
QString itemId = data(index).toString();
102+
103+
auto item = ItemModel::instance()->getItemById(itemId);
104+
if (!item) {
105+
return;
106+
}
107+
108+
item->handleClick(QString());
109+
}
110+
111+
void ItemModel::requestNewInstance(const QModelIndex &index, const QString &action) const
112+
{
113+
QString itemId = data(index).toString();
114+
115+
auto item = ItemModel::instance()->getItemById(itemId);
116+
if (!item) {
117+
return;
118+
}
119+
120+
item->handleClick(DOCK_ACTIN_LAUNCH);
121+
}
122+
123+
void ItemModel::requestClose(const QModelIndex &index, bool force) const
124+
{
125+
QString itemId = data(index).toString();
126+
127+
auto item = ItemModel::instance()->getItemById(itemId);
128+
if (!item) {
129+
return;
130+
}
131+
132+
item->handleClick(force ? DOCK_ACTION_FORCEQUIT : DOCK_ACTION_CLOSEALL);
133+
}
134+
135+
void ItemModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
136+
{
137+
QString itemId = data(index).toString();
138+
139+
auto item = ItemModel::instance()->getItemById(itemId);
140+
if (!item) {
141+
return;
142+
}
143+
144+
// convert urls to string list
145+
QStringList urlsStr;
146+
for (auto url : std::as_const(urls)) {
147+
urlsStr.append(url.toString());
148+
}
149+
150+
item->handleFileDrop(urlsStr);
151+
}
152+
153+
void ItemModel::requestWindowsView(const QModelIndexList &indexes) const
154+
{
155+
// nothing here, dummy entry.
156+
}
157+
158+
void ItemModel::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
159+
{
160+
QString itemId = data(index).toString();
161+
162+
QPointer<AppItem> item = static_cast<AppItem *>(ItemModel::instance()->getItemById(itemId).get());
163+
if (item.isNull())
164+
return;
165+
166+
for (auto window : item->getAppendWindows()) {
167+
window->setWindowIconGeometry(qobject_cast<QWindow *>(delegate), geometry);
168+
}
169+
}
170+
92171
QPointer<AbstractItem> ItemModel::getItemById(const QString& id) const
93172
{
94173
auto it = std::find_if(m_items.begin(), m_items.end(),[id](QPointer<AbstractItem> item){

panels/dock/taskmanager/itemmodel.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@ class ItemModel : public QAbstractListModel
1414
Q_OBJECT
1515
public:
1616
enum Roles {
17-
ItemIdRole = Qt::UserRole + 1,
18-
NameRole,
19-
IconNameRole,
20-
ActiveRole,
21-
AttentionRole,
22-
MenusRole,
23-
DockedRole,
17+
ItemIdRole = Qt::UserRole + 64,
2418
// data type
25-
WindowsRole,
26-
DesktopFilesIconsRole,
2719
DockedDirRole,
2820
};
2921
Q_ENUM(Roles)
@@ -38,6 +30,13 @@ class ItemModel : public QAbstractListModel
3830
void addItem(QPointer<AbstractItem> item);
3931
QJsonArray dumpDockedItems() const;
4032

33+
void requestActivate(const QModelIndex &index) const;
34+
void requestNewInstance(const QModelIndex &index, const QString &action) const;
35+
void requestClose(const QModelIndex &index, bool force = false) const;
36+
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const;
37+
void requestWindowsView(const QModelIndexList &indexes) const;
38+
void requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) const;
39+
4140
private Q_SLOTS:
4241
void onItemDestroyed();
4342
void onItemChanged();

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,27 @@ HoverPreviewProxyModel *TaskManager::hoverPreviewModel() const
217217

218218
void TaskManager::requestActivate(const QModelIndex &index) const
219219
{
220-
m_itemModel->requestActivate(index);
220+
dataModel()->requestActivate(index);
221221
}
222222

223223
void TaskManager::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
224224
{
225-
m_itemModel->requestOpenUrls(index, urls);
225+
dataModel()->requestOpenUrls(index, urls);
226226
}
227227

228228
void TaskManager::requestNewInstance(const QModelIndex &index, const QString &action) const
229229
{
230-
m_itemModel->requestNewInstance(index, action);
230+
dataModel()->requestNewInstance(index, action);
231231
}
232232

233233
void TaskManager::requestClose(const QModelIndex &index, bool force) const
234234
{
235-
m_itemModel->requestClose(index, force);
235+
dataModel()->requestClose(index, force);
236236
}
237237

238238
void TaskManager::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
239239
{
240-
m_itemModel->requestUpdateWindowIconGeometry(index, geometry, delegate);
240+
dataModel()->requestUpdateWindowIconGeometry(index, geometry, delegate);
241241
}
242242

243243
void TaskManager::requestPreview(const QModelIndex &index, QObject *relativePositionItem, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction)
@@ -268,7 +268,7 @@ void TaskManager::requestPreview(const QModelIndex &index, QObject *relativePosi
268268

269269
void TaskManager::requestWindowsView(const QModelIndexList &indexes) const
270270
{
271-
m_itemModel->requestWindowsView(indexes);
271+
dataModel()->requestWindowsView(indexes);
272272
}
273273

274274
void TaskManager::handleWindowAdded(QPointer<AbstractWindow> window)
@@ -323,7 +323,7 @@ void TaskManager::dropFilesOnItem(const QString& itemId, const QStringList& urls
323323
urlList.append(QUrl::fromLocalFile(url));
324324
}
325325

326-
m_itemModel->requestOpenUrls(indexes.first(), urlList);
326+
dataModel()->requestOpenUrls(indexes.first(), urlList);
327327
}
328328

329329
void TaskManager::hideItemPreview()

0 commit comments

Comments
 (0)