Skip to content

Commit a455f40

Browse files
committed
fix: WinSCP dock icon stayed when window closed
修复关闭 WinSCP 窗口时,dock 上仍会有一个残留的 WinSCP 图标的问题. 注:仍然注意到这个问题可能导致其他窗口 hover preview 数量变多,出现重 复窗口.此问题待继续排查. Log:
1 parent bc37147 commit a455f40

File tree

1 file changed

+121
-102
lines changed

1 file changed

+121
-102
lines changed

panels/dock/taskmanager/dockglobalelementmodel.cpp

Lines changed: 121 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -29,122 +29,141 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
2929
, m_activeAppModel(activeAppModel)
3030
{
3131
connect(TaskManagerSettings::instance(), &TaskManagerSettings::dockedElementsChanged, this, &DockGlobalElementModel::loadDockedElements);
32-
connect(m_appsModel, &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) {
33-
Q_UNUSED(parent)
34-
for (int i = first; i <= last; ++i) {
35-
auto it = std::find_if(m_data.begin(), m_data.end(), [this, &i](auto data) {
36-
return std::get<1>(data) == m_appsModel && std::get<2>(data) == i;
37-
});
38-
if (it != m_data.end()) {
39-
auto pos = it - m_data.begin();
40-
beginRemoveRows(QModelIndex(), pos, pos);
41-
m_data.remove(pos);
42-
endRemoveRows();
43-
}
44-
}
45-
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
46-
if (std::get<1>(data) == m_appsModel && std::get<2>(data) >= first) {
47-
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) - ((last - first) + 1));
48-
}
49-
});
50-
});
51-
52-
connect(m_activeAppModel, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) {
53-
Q_UNUSED(parent)
54-
for (int i = first; i <= last; ++i) {
55-
auto index = m_activeAppModel->index(i, 0);
56-
auto desktopId = index.data(TaskManager::DesktopIdRole).toString();
57-
58-
auto it = std::find_if(m_data.begin(), m_data.end(), [this, &desktopId](auto &data) {
59-
return m_appsModel == std::get<1>(data) && desktopId == std::get<0>(data);
60-
});
61-
62-
if (it != m_data.end()) {
63-
*it = std::make_tuple(desktopId, m_activeAppModel, i);
64-
auto pIndex = this->index(it - m_data.begin(), 0);
65-
Q_EMIT dataChanged(pIndex, pIndex, {TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});
66-
67-
} else {
68-
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
69-
m_data.append(std::make_tuple(desktopId, m_activeAppModel, i));
70-
endInsertRows();
71-
}
72-
}
73-
74-
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
75-
if (std::get<1>(data) == m_activeAppModel && std::get<2>(data) > first) {
76-
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) + ((last - first) + 1));
32+
connect(
33+
m_appsModel,
34+
&QAbstractItemModel::rowsRemoved,
35+
this,
36+
[this](const QModelIndex &parent, int first, int last) {
37+
Q_UNUSED(parent)
38+
for (int i = first; i <= last; ++i) {
39+
auto it = std::find_if(m_data.begin(), m_data.end(), [this, &i](auto data) {
40+
return std::get<1>(data) == m_appsModel && std::get<2>(data) == i;
41+
});
42+
if (it != m_data.end()) {
43+
auto pos = it - m_data.begin();
44+
beginRemoveRows(QModelIndex(), pos, pos);
45+
m_data.remove(pos);
46+
endRemoveRows();
47+
}
7748
}
78-
});
79-
});
80-
81-
connect(m_activeAppModel, &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) {
82-
Q_UNUSED(parent)
83-
for (int i = first; i <= last; ++i) {
84-
auto it = std::find_if(m_data.begin(), m_data.end(), [this, i](auto data) {
85-
return std::get<1>(data) == m_activeAppModel && std::get<2>(data) == i;
49+
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
50+
if (std::get<1>(data) == m_appsModel && std::get<2>(data) >= first) {
51+
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) - ((last - first) + 1));
52+
}
8653
});
54+
},
55+
Qt::QueuedConnection);
56+
57+
connect(
58+
m_activeAppModel,
59+
&QAbstractItemModel::rowsInserted,
60+
this,
61+
[this](const QModelIndex &parent, int first, int last) {
62+
Q_UNUSED(parent)
63+
for (int i = first; i <= last; ++i) {
64+
auto index = m_activeAppModel->index(i, 0);
65+
auto desktopId = index.data(TaskManager::DesktopIdRole).toString();
66+
67+
auto it = std::find_if(m_data.begin(), m_data.end(), [this, &desktopId](auto &data) {
68+
return m_appsModel == std::get<1>(data) && desktopId == std::get<0>(data);
69+
});
70+
71+
if (it != m_data.end()) {
72+
*it = std::make_tuple(desktopId, m_activeAppModel, i);
73+
auto pIndex = this->index(it - m_data.begin(), 0);
74+
Q_EMIT dataChanged(pIndex, pIndex, {TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});
8775

88-
if (it == m_data.end()) {
89-
qWarning() << "failed to find a running apps on dock" << i;
90-
continue;
76+
} else {
77+
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
78+
m_data.append(std::make_tuple(desktopId, m_activeAppModel, i));
79+
endInsertRows();
80+
}
9181
}
9282

93-
auto pos = it - m_data.begin();
94-
auto id = std::get<0>(*it);
95-
96-
auto oit = std::find_if(m_data.constBegin(), m_data.constEnd(), [this, &id, i](auto &data) {
97-
return std::get<0>(data) == id && std::get<1>(data) == m_activeAppModel && std::get<2>(data) != i;
83+
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
84+
if (std::get<1>(data) == m_activeAppModel && std::get<2>(data) > first) {
85+
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) + ((last - first) + 1));
86+
}
9887
});
88+
},
89+
Qt::QueuedConnection);
90+
91+
connect(
92+
m_activeAppModel,
93+
&QAbstractItemModel::rowsRemoved,
94+
this,
95+
[this](const QModelIndex &parent, int first, int last) {
96+
Q_UNUSED(parent)
97+
for (int i = first; i <= last; ++i) {
98+
auto it = std::find_if(m_data.begin(), m_data.end(), [this, i](auto data) {
99+
return std::get<1>(data) == m_activeAppModel && std::get<2>(data) == i;
100+
});
101+
102+
if (it == m_data.end()) {
103+
qWarning() << "failed to find a running apps on dock" << i;
104+
continue;
105+
}
99106

100-
if (oit == m_data.constEnd() && m_dockedElements.contains(std::make_tuple("desktop", id))) {
101-
auto pIndex = this->index(pos, 0);
102-
auto res = m_appsModel->match(m_appsModel->index(0, 0), TaskManager::DesktopIdRole, id, 1, Qt::MatchExactly);
103-
if (res.isEmpty()) {
107+
auto pos = it - m_data.begin();
108+
auto id = std::get<0>(*it);
109+
110+
auto oit = std::find_if(m_data.constBegin(), m_data.constEnd(), [this, &id, i](auto &data) {
111+
return std::get<0>(data) == id && std::get<1>(data) == m_activeAppModel && std::get<2>(data) != i;
112+
});
113+
114+
if (oit == m_data.constEnd() && m_dockedElements.contains(std::make_tuple("desktop", id))) {
115+
auto pIndex = this->index(pos, 0);
116+
auto res = m_appsModel->match(m_appsModel->index(0, 0), TaskManager::DesktopIdRole, id, 1, Qt::MatchExactly);
117+
if (res.isEmpty()) {
118+
beginRemoveRows(QModelIndex(), pos, pos);
119+
m_data.remove(pos);
120+
endRemoveRows();
121+
} else {
122+
auto row = res.first().row();
123+
*it = std::make_tuple(id, m_appsModel, row);
124+
Q_EMIT dataChanged(pIndex,
125+
pIndex,
126+
{TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});
127+
}
128+
} else {
104129
beginRemoveRows(QModelIndex(), pos, pos);
105130
m_data.remove(pos);
106131
endRemoveRows();
107-
} else {
108-
auto row = res.first().row();
109-
*it = std::make_tuple(id, m_appsModel, row);
110-
Q_EMIT dataChanged(pIndex, pIndex, {TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});
111132
}
112-
} else {
113-
beginRemoveRows(QModelIndex(), pos, pos);
114-
m_data.remove(pos);
115-
endRemoveRows();
116-
}
117-
}
118-
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
119-
if (std::get<1>(data) == m_activeAppModel && std::get<2>(data) >= first) {
120-
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) - ((last - first) + 1));
121133
}
122-
});
123-
});
124-
125-
connect(m_activeAppModel,
126-
&QAbstractItemModel::dataChanged,
127-
this,
128-
[this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
129-
int first = topLeft.row(), last = bottomRight.row();
130-
for (int i = first; i <= last; i++) {
131-
auto it = std::find_if(m_data.constBegin(), m_data.constEnd(), [this, i](auto data) {
132-
return std::get<1>(data) == m_activeAppModel && std::get<2>(data) == i;
133-
});
134-
135-
if (it == m_data.end())
136-
return;
137-
auto pos = it - m_data.constBegin();
138-
139-
auto oldRoles = roles;
140-
auto desktopId = roles.indexOf(TaskManager::DesktopIdRole);
141-
auto identifyId = roles.indexOf(TaskManager::IdentityRole);
142-
if (desktopId != -1 || identifyId != -1) {
143-
oldRoles.append(TaskManager::ItemIdRole);
144-
}
145-
Q_EMIT dataChanged(index(pos, 0), index(pos, 0), oldRoles);
134+
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
135+
if (std::get<1>(data) == m_activeAppModel && std::get<2>(data) >= first) {
136+
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) - ((last - first) + 1));
146137
}
147138
});
139+
},
140+
Qt::QueuedConnection);
141+
142+
connect(
143+
m_activeAppModel,
144+
&QAbstractItemModel::dataChanged,
145+
this,
146+
[this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
147+
int first = topLeft.row(), last = bottomRight.row();
148+
for (int i = first; i <= last; i++) {
149+
auto it = std::find_if(m_data.constBegin(), m_data.constEnd(), [this, i](auto data) {
150+
return std::get<1>(data) == m_activeAppModel && std::get<2>(data) == i;
151+
});
152+
153+
if (it == m_data.end())
154+
return;
155+
auto pos = it - m_data.constBegin();
156+
157+
auto oldRoles = roles;
158+
auto desktopId = roles.indexOf(TaskManager::DesktopIdRole);
159+
auto identifyId = roles.indexOf(TaskManager::IdentityRole);
160+
if (desktopId != -1 || identifyId != -1) {
161+
oldRoles.append(TaskManager::ItemIdRole);
162+
}
163+
Q_EMIT dataChanged(index(pos, 0), index(pos, 0), oldRoles);
164+
}
165+
},
166+
Qt::QueuedConnection);
148167

149168
QMetaObject::invokeMethod(this, &DockGlobalElementModel::loadDockedElements, Qt::QueuedConnection);
150169
}

0 commit comments

Comments
 (0)