Skip to content

Commit 1dbc598

Browse files
committed
fix: improve window grouping and drag reordering in dock
1. Fixed window grouping logic to correctly group windows by application after drag reordering 2. Enhanced window insertion algorithm to find the last window of an app even when windows are not consecutive 3. Added moveItem() method to properly handle item movement in the model 4. Connected windowSplitChanged signal to trigger re-grouping when window split mode changes 5. Updated QML drag handlers to use moveItem() when window split is enabled Log: Fixed dock task manager window grouping issues after drag reordering Influence: 1. Test dragging windows in dock when window split is disabled - windows should stay grouped by application 2. Test dragging windows in dock when window split is enabled - windows should move independently 3. Verify that window grouping is maintained after toggling window split mode 4. Test drag and drop reordering of both individual windows and application groups 5. Verify that the dock maintains correct ordering after multiple drag operations fix: 修复任务管理器停靠栏窗口分组和拖拽重排序问题 1. 修复窗口分组逻辑,确保拖拽重排序后窗口能正确按应用程序分组 2. 改进窗口插入算法,即使窗口不连续也能找到应用程序的最后一个窗口 3. 添加 moveItem() 方法以正确处理模型中的项目移动 4. 连接 windowSplitChanged 信号,在窗口分割模式更改时触发重新分组 5. 更新 QML 拖拽处理程序,在窗口分割启用时使用 moveItem() 方法 Log: 修复停靠栏任务管理器拖拽重排序后的窗口分组问题 Influence: 1. 测试在窗口分割禁用时拖拽停靠栏中的窗口 - 窗口应按应用程序保持分组 2. 测试在窗口分割启用时拖拽停靠栏中的窗口 - 窗口应独立移动 3. 验证切换窗口分割模式后窗口分组是否保持正确 4. 测试单个窗口和应用程序组的拖拽重排序功能 5. 验证多次拖拽操作后停靠栏是否保持正确的排序 PMS: BUG-343469
1 parent 2ebeb46 commit 1dbc598

6 files changed

Lines changed: 85 additions & 8 deletions

File tree

panels/dock/taskmanager/dockglobalelementmodel.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
2929
, m_activeAppModel(activeAppModel)
3030
{
3131
connect(TaskManagerSettings::instance(), &TaskManagerSettings::dockedElementsChanged, this, &DockGlobalElementModel::loadDockedElements);
32+
connect(TaskManagerSettings::instance(), &TaskManagerSettings::windowSplitChanged, this, &DockGlobalElementModel::groupItemsByApp);
33+
3234
connect(
3335
m_appsModel,
3436
&QAbstractItemModel::rowsRemoved,
@@ -96,10 +98,13 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
9698
}
9799

98100
// There are already windows for this app: insert the new window
99-
// right after the last existing one so that all windows stay together.
101+
// right after the last (rightmost) existing one.
102+
// Search the entire list since windows may not be consecutive after drag reorder.
100103
auto lastIt = firstIt;
101-
while (lastIt + 1 != m_data.end() && std::get<0>(*(lastIt + 1)) == desktopId) {
102-
++lastIt;
104+
for (auto it = firstIt + 1; it != m_data.end(); ++it) {
105+
if (std::get<0>(*it) == desktopId) {
106+
lastIt = it;
107+
}
103108
}
104109

105110
auto insertRow = (lastIt - m_data.begin()) + 1;
@@ -487,4 +492,52 @@ void DockGlobalElementModel::requestWindowsView(const QModelIndexList &indexes)
487492
{
488493
Q_UNUSED(indexes)
489494
}
495+
496+
void DockGlobalElementModel::moveItem(int from, int to)
497+
{
498+
if (from < 0 || from >= m_data.size() || to < 0 || to >= m_data.size() || from == to)
499+
return;
500+
501+
int destRow = from < to ? to + 1 : to;
502+
503+
if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), destRow))
504+
return;
505+
506+
m_data.move(from, to);
507+
endMoveRows();
508+
}
509+
510+
void DockGlobalElementModel::groupItemsByApp()
511+
{
512+
if (m_data.isEmpty())
513+
return;
514+
515+
if (TaskManagerSettings::instance()->isWindowSplit())
516+
return;
517+
518+
for (int i = 0; i < m_data.size(); ++i) {
519+
const QString &currentId = std::get<0>(m_data.at(i));
520+
521+
int insertPos = i + 1;
522+
523+
while (insertPos < m_data.size() && std::get<0>(m_data.at(insertPos)) == currentId) {
524+
++insertPos;
525+
}
526+
527+
for (int j = insertPos; j < m_data.size(); ++j) {
528+
if (std::get<0>(m_data.at(j)) != currentId)
529+
continue;
530+
531+
int destRow = insertPos < j ? insertPos : insertPos + 1;
532+
if (!beginMoveRows(QModelIndex(), j, j, QModelIndex(), destRow))
533+
continue;
534+
m_data.move(j, insertPos);
535+
endMoveRows();
536+
537+
++insertPos;
538+
}
539+
540+
i = insertPos - 1;
541+
}
542+
}
490543
}

panels/dock/taskmanager/dockglobalelementmodel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44
#pragma once
@@ -36,12 +36,15 @@ class DockGlobalElementModel : public QAbstractListModel, public AbstractTaskMan
3636

3737
void requestWindowsView(const QModelIndexList &indexes) const override;
3838

39+
void moveItem(int from, int to);
40+
3941
public slots:
4042
void initDockedElements(bool unused);
4143

4244
private:
4345
void loadDockedElements();
4446
QString getMenus(const QModelIndex &index) const;
47+
void groupItemsByApp();
4548

4649
private:
4750
// id, model, and pos

panels/dock/taskmanager/dockitemmodel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ void DockItemModel::setSourceModel(QAbstractItemModel *model)
7979
auto last = bottomRight.row();
8080
Q_EMIT dataChanged(index(first, 0), index(last, 0), roles);
8181
});
82+
connect(sourceModel(), &QAbstractItemModel::rowsMoved, this, [this](const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) {
83+
if (parent.isValid() || m_isUpdating)
84+
return;
85+
beginMoveRows(QModelIndex(), start, end, QModelIndex(), row);
86+
endMoveRows();
87+
});
8288

8389
auto bottomRight = this->index(std::min(currentCount, newCount), 0);
8490
Q_EMIT dataChanged(index(0, 0), bottomRight);

panels/dock/taskmanager/package/TaskManager.qml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ ContainmentItem {
262262
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
263263
let currentIndex = taskmanager.Applet.windowSplit ? taskmanager.findAppIndexByWindow(appId, launcherDndWinId) : taskmanager.findAppIndex(appId)
264264
if (currentIndex !== -1 && targetIndex !== -1 && currentIndex !== targetIndex) {
265-
visualModel.items.move(currentIndex, targetIndex)
265+
if(taskmanager.Applet.windowSplit) {
266+
taskmanager.Applet.moveItem(currentIndex, targetIndex)
267+
} else {
268+
visualModel.items.move(currentIndex, targetIndex)
269+
}
266270
}
267271
}
268272

@@ -273,7 +277,11 @@ ContainmentItem {
273277
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
274278
let currentIndex = taskmanager.Applet.windowSplit ? taskmanager.findAppIndexByWindow(appId, launcherDndWinId) : taskmanager.findAppIndex(appId)
275279
if (currentIndex !== -1 && targetIndex !== -1 && currentIndex !== targetIndex) {
276-
visualModel.items.move(currentIndex, targetIndex)
280+
if(taskmanager.Applet.windowSplit) {
281+
taskmanager.Applet.moveItem(currentIndex, targetIndex)
282+
} else {
283+
visualModel.items.move(currentIndex, targetIndex)
284+
}
277285
}
278286
let appIds = []
279287
for (let i = 0; i < visualModel.items.count; i++) {

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -484,6 +484,12 @@ void TaskManager::saveDockElementsOrder(const QStringList &appIds)
484484
TaskManagerSettings::instance()->setDockedElements(newDockedElements);
485485
}
486486

487+
void TaskManager::moveItem(int from, int to)
488+
{
489+
if (m_dockGlobalElementModel)
490+
m_dockGlobalElementModel->moveItem(from, to);
491+
}
492+
487493
QString TaskManager::getTrashTipText()
488494
{
489495
const auto count = queryTrashCount();

panels/dock/taskmanager/taskmanager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -100,6 +100,7 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
100100

101101
Q_INVOKABLE void activateWindow(uint32_t windowID);
102102
Q_INVOKABLE void saveDockElementsOrder(const QStringList &appIds);
103+
Q_INVOKABLE void moveItem(int from, int to);
103104
Q_INVOKABLE QString getTrashTipText();
104105

105106
Q_INVOKABLE bool isTrashEmpty() const;

0 commit comments

Comments
 (0)