Skip to content
Closed
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
2 changes: 1 addition & 1 deletion panels/dock/dockdbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ DockDBusProxy::DockDBusProxy(DockPanel* parent)
};

// TODO: DQmlGlobal maybe missing a signal which named `appletListChanged`?
QTimer *timer = new QTimer;
QTimer *timer = new QTimer(this);
timer->setInterval(1000);
connect(timer, &QTimer::timeout, this, [ = ] {
if (getOtherApplet()) {
Expand Down
2 changes: 1 addition & 1 deletion panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool DockPanel::init()
if (m_dockScreen) {
if (m_dockScreen != window()->screen() && qApp->screens().contains( m_dockScreen)) {
qWarning() << "m_dockScreen" << m_dockScreen << m_dockScreen->name() << "window()->screen()" << window()->screen() << window()->screen()->name();
QTimer::singleShot(10, this, [this](){
QTimer::singleShot(0, this, [this](){
window()->setScreen(m_dockScreen);
onWindowGeometryChanged();
});
Expand Down
139 changes: 71 additions & 68 deletions panels/dock/taskmanager/rolegroupmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,38 @@ void RoleGroupModel::setSourceModel(QAbstractItemModel *model)
continue;
}

auto list = m_map.value(data, nullptr);
if (nullptr == list) {
if (!m_map.contains(data)) {
beginInsertRows(QModelIndex(), m_rowMap.size(), m_rowMap.size());
list = new QList<int>();
list->append(i);
m_map.insert(data, list);
m_rowMap.append(list);
endInsertRows();
} else {
beginInsertRows(index(m_rowMap.indexOf(list), 0), list->size(), list->size());
list->append(i);
m_rowMap.append(data);
m_map.insert(data, QList<int>());
endInsertRows();
}

QList<int> &list = m_map[data];
int groupRow = m_rowMap.indexOf(data);

beginInsertRows(index(groupRow, 0), list.size(), list.size());
list.append(i);
endInsertRows();
}
});

connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) {
Q_UNUSED(parent)
for (int i = 0; i < m_rowMap.count(); ++i) {
auto sourceRows = m_rowMap.value(i);
for (int j = 0; j < sourceRows->size(); ++j) {
if (first <= sourceRows->value(j) && last >= sourceRows->value(j)) {
beginRemoveRows(index(m_rowMap.indexOf(sourceRows), 0), j, j);
sourceRows->removeAt(j);
for (int i = m_rowMap.count() - 1; i >= 0; --i) {
auto groupKey = m_rowMap.value(i);
QList<int> &sourceRows = m_map[groupKey];
for (int j = sourceRows.size() - 1; j >= 0; --j) {
if (first <= sourceRows.value(j) && last >= sourceRows.value(j)) {
beginRemoveRows(index(i, 0), j, j);
sourceRows.removeAt(j);
endRemoveRows();
--j;
}
}
if (sourceRows->size() == 0) {
beginRemoveRows(QModelIndex(), m_rowMap.indexOf(sourceRows), m_rowMap.indexOf(sourceRows));
m_map.remove(m_map.key(sourceRows));
m_rowMap.removeOne(sourceRows);
delete sourceRows;
if (sourceRows.isEmpty()) {
beginRemoveRows(QModelIndex(), i, i);
m_map.remove(groupKey);
m_rowMap.removeAt(i);
endRemoveRows();
}
}
Expand All @@ -97,14 +96,15 @@ void RoleGroupModel::setSourceModel(QAbstractItemModel *model)

for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
auto data = sourceModel()->index(i, 0).data(m_roleForDeduplication).toString();
auto list = m_map.value(data, nullptr);
if (list == nullptr)
if (!m_map.contains(data))
continue;

int childRow = list->indexOf(i);
const QList<int> &list = m_map.value(data);
int childRow = list.indexOf(i);
if (childRow >= 0) {
auto index = createIndex(childRow, 0, m_rowMap.indexOf(list));
Q_EMIT dataChanged(index, index, roles);
int groupRow = m_rowMap.indexOf(data);
auto proxyIndex = createIndex(childRow, 0, groupRow);
Q_EMIT dataChanged(proxyIndex, proxyIndex, roles);
}
}
});
Expand All @@ -122,8 +122,8 @@ int RoleGroupModel::rowCount(const QModelIndex &parent) const
return 0;
}

auto list = m_rowMap.value(parentRow, nullptr);
return (list != nullptr) ? list->size() : 0;
const QString groupKey = m_rowMap.value(parentRow);
return m_map.value(groupKey).size();
}

return m_rowMap.size();
Expand Down Expand Up @@ -154,8 +154,8 @@ bool RoleGroupModel::hasChildren(const QModelIndex &parent) const
if (parent.row() < 0 || parent.row() >= m_rowMap.size()) {
return false;
}
auto list = m_rowMap.value(parent.row(), nullptr);
return list && list->size() > 0;
const QString groupKey = m_rowMap.value(parent.row());
return m_map.contains(groupKey) && !m_map.value(groupKey).isEmpty();
}

// 这是子项:没有子节点
Expand All @@ -180,28 +180,30 @@ QVariant RoleGroupModel::data(const QModelIndex &index, int role) const

if (parentPos == -1) {
// 这是分组节点(顶级项目)
auto list = m_rowMap.value(index.row(), nullptr);
if (nullptr == list || list->isEmpty()) {
const QString groupKey = m_rowMap.value(index.row());
const QList<int> &list = m_map.value(groupKey);
if (list.isEmpty()) {
return QVariant();
}

// 对于分组节点,显示分组信息和数量
if (role == Qt::DisplayRole) {
QString groupValue = sourceModel()->index(list->first(), 0).data(m_roleForDeduplication).toString();
return QString("%1 (%2)").arg(groupValue).arg(list->size());
QString groupValue = sourceModel()->index(list.first(), 0).data(m_roleForDeduplication).toString();
return QString("%1 (%2)").arg(groupValue).arg(list.size());
} else {
// 对于其他角色,返回分组中第一个项目的数据
return sourceModel()->index(list->first(), 0).data(role);
return sourceModel()->index(list.first(), 0).data(role);
}
} else {
// 这是子项目
auto list = m_rowMap.value(parentPos);
if (list == nullptr || index.row() < 0 || index.row() >= list->size()) {
const QString groupKey = m_rowMap.value(parentPos);
const QList<int> &list = m_map.value(groupKey);
if (index.row() < 0 || index.row() >= list.size()) {
return QVariant();
}

// 直接返回对应源项目的数据
return sourceModel()->index(list->value(index.row()), 0).data(role);
return sourceModel()->index(list.value(index.row()), 0).data(role);
}
}

Expand All @@ -213,8 +215,9 @@ QModelIndex RoleGroupModel::index(int row, int column, const QModelIndex &parent
return QModelIndex();
}

auto list = m_rowMap.value(parentRow);
if (nullptr == list || row < 0 || row >= list->size()) {
const QString groupKey = m_rowMap.value(parentRow);
const QList<int> &list = m_map.value(groupKey);
if (row < 0 || row >= list.size()) {
return QModelIndex();
}

Expand Down Expand Up @@ -251,24 +254,25 @@ QModelIndex RoleGroupModel::mapToSource(const QModelIndex &proxyIndex) const
}

auto parentIndex = proxyIndex.parent();
QList<int> *list = nullptr;

if (parentIndex.isValid()) {
int parentRow = parentIndex.row();
if (parentRow < 0 || parentRow >= m_rowMap.size()) {
return QModelIndex();
}
list = m_rowMap.value(parentRow);
if (!list || proxyIndex.row() >= list->size()) {
const QString groupKey = m_rowMap.value(parentRow);
const QList<int> &list = m_map.value(groupKey);
if (proxyIndex.row() >= list.size()) {
return QModelIndex();
}
return sourceModel()->index(list->value(proxyIndex.row()), 0);
return sourceModel()->index(list.value(proxyIndex.row()), 0);
} else {
list = m_map.value(proxyIndex.data(m_roleForDeduplication).toString());
if (!list || list->isEmpty()) {
const QString groupKey = m_rowMap.value(proxyIndex.row());
const QList<int> &list = m_map.value(groupKey);
if (list.isEmpty()) {
return QModelIndex();
}
return sourceModel()->index(list->value(0), 0);
return sourceModel()->index(list.value(0), 0);
}
}

Expand All @@ -279,18 +283,20 @@ QModelIndex RoleGroupModel::mapFromSource(const QModelIndex &sourceIndex) const
return QModelIndex();
}

auto list = m_map.value(data, nullptr);
if (nullptr == list || 0 == list->size()) {
return {};
if (!m_map.contains(data)) {
return QModelIndex();
}

if (sourceIndex.row() == list->first()) {
return createIndex(m_rowMap.indexOf(list), 0, -1);
const QList<int> &list = m_map.value(data);
int groupRow = m_rowMap.indexOf(data);

if (sourceIndex.row() == list.first()) {
return createIndex(groupRow, 0, -1);
}

auto pos = list->indexOf(sourceIndex.row());
auto pos = list.indexOf(sourceIndex.row());
if (pos >= 0) {
return createIndex(pos, 0, m_rowMap.indexOf(list));
return createIndex(pos, 0, groupRow);
}

return QModelIndex();
Expand All @@ -299,7 +305,6 @@ QModelIndex RoleGroupModel::mapFromSource(const QModelIndex &sourceIndex) const
void RoleGroupModel::rebuildTreeSource()
{
beginResetModel();
qDeleteAll(m_rowMap);
m_map.clear();
m_rowMap.clear();

Expand All @@ -315,25 +320,23 @@ void RoleGroupModel::rebuildTreeSource()
continue;
}

auto list = m_map.value(data, nullptr);
if (nullptr == list) {
list = new QList<int>();
m_map.insert(data, list);
m_rowMap.append(list);
if (!m_map.contains(data)) {
m_rowMap.append(data);
m_map.insert(data, QList<int>());
}
list->append(i);
m_map[data].append(i);
}
endResetModel();
}

void RoleGroupModel::adjustMap(int base, int offset)
void RoleGroup_model::adjustMap(int base, int offset)
Copy link
Contributor

Choose a reason for hiding this comment

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

是不是误操作?

{
for (int i = 0; i < m_rowMap.count(); ++i) {
auto sourceRows = m_rowMap.value(i);
for (int j = 0; j < sourceRows->size(); ++j) {
if (sourceRows->value(j) < base)
QList<int> &sourceRows = m_map[m_rowMap.value(i)];
for (int j = 0; j < sourceRows.size(); ++j) {
if (sourceRows.value(j) < base)
continue;
(*sourceRows)[j] += offset;
sourceRows[j] += offset;
}
}
}
}
4 changes: 2 additions & 2 deletions panels/dock/taskmanager/rolegroupmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class RoleGroupModel : public QAbstractProxyModel
int m_roleForDeduplication;

// for order
QList<QList<int> *> m_rowMap;
QList<QString> m_rowMap;

// data 2 source row
QHash<QString, QList<int> *> m_map;
QHash<QString, QList<int>> m_map;
};
14 changes: 7 additions & 7 deletions shell/InWindowBlur.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import org.deepin.dtk 1.0 as D
Item {
id :control
property bool offscreen: false
property alias radius: blur.blurMax
property alias radius: blur.radius
property alias content: content
default property alias data: blitter.data
readonly property bool valid: blitter.blitterEnabled

// Note: The original MultiEffect was replaced with FastBlur to improve
// performance and reduce memory consumption. The 'saturation' property
// was removed as part of this optimization.

D.BackdropBlitter {
id: blitter
anchors.fill: parent
Expand All @@ -29,15 +33,11 @@ Item {
}
color: Window.window && Window.window.color.a < 1 ? D.ColorSelector.overlay : "transparent"

MultiEffect {
FastBlur {
id: blur
anchors.fill: parent
source: blitter.content
autoPaddingEnabled: false
blurEnabled: true
blur: 1.0
blurMax: 64
saturation: 0.4
radius: 64
}
}
}
Expand Down
Loading