Skip to content
Open
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
66 changes: 44 additions & 22 deletions panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,51 @@
endInsertRows();
}

bool BubbleModel::isReplaceBubble(const BubbleItem *bubble) const
int BubbleModel::replaceBubbleIndex(const NotifyEntity &entity) const

Check warning on line 87 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'replaceBubbleIndex' is never used.
{
return replaceBubbleIndex(bubble) >= 0;
if (entity.isReplace()) {
for (int i = 0; i < m_bubbles.size(); i++) {
const auto item = m_bubbles[i];

Check warning on line 91 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'item' can be declared as pointer to const
if (!item)
continue;

if (item->appName() != entity.appName())
continue;

if (item->bubbleId() == entity.bubbleId()) {
return i;
}
}
}
return -1;
}

void BubbleModel::updateBubbleInPlace(int replaceIndex, const NotifyEntity &entity)

Check warning on line 106 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'updateBubbleInPlace' is never used.
{
if (replaceIndex < 0 || replaceIndex >= m_bubbles.size() || !entity.isReplace())
return;

// dataChanged 通知视图刷新
// 前提:内容变更不会引起气泡高度变化,否则布局不刷新(应改用 replaceBubble)。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这个调用方怎么知道内容不会引起高度变化呢?

auto oldBubble = m_bubbles[replaceIndex];
if (oldBubble) {
oldBubble->setEntity(entity);
Q_EMIT dataChanged(index(replaceIndex), index(replaceIndex));
}
}

BubbleItem *BubbleModel::replaceBubble(BubbleItem *bubble)
void BubbleModel::replaceBubble(int replaceIndex, BubbleItem *bubble)

Check warning on line 120 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'replaceBubble' is never used.
{
Q_ASSERT(isReplaceBubble(bubble));
const auto replaceIndex = replaceBubbleIndex(bubble);
if (!bubble) {
return;
}

if (replaceIndex < 0 || replaceIndex >= m_bubbles.size()) {
qWarning() << "replaceBubble called with invalid index:" << replaceIndex;
bubble->deleteLater();
return;
}

const auto oldBubble = m_bubbles[replaceIndex];

// Use remove + insert instead of dataChanged to force the view
Expand All @@ -105,7 +141,9 @@
m_bubbles.insert(replaceIndex, bubble);
endInsertRows();

return oldBubble;
if (oldBubble) {
oldBubble->deleteLater();
}
}

void BubbleModel::clear()
Expand Down Expand Up @@ -261,22 +299,6 @@
}
}

int BubbleModel::replaceBubbleIndex(const BubbleItem *bubble) const
{
if (bubble->isReplace()) {
for (int i = 0; i < m_bubbles.size(); i++) {
auto item = m_bubbles[i];
if (item->appName() != bubble->appName())
continue;

if (item->bubbleId() == bubble->bubbleId()) {
return i;
}
}
}
return -1;
}

void BubbleModel::updateBubbleTimeTip()
{
if (m_bubbles.isEmpty()) {
Expand Down
6 changes: 3 additions & 3 deletions panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class BubbleModel : public QAbstractListModel
public:
void push(BubbleItem *bubble);

BubbleItem *replaceBubble(BubbleItem *bubble);
bool isReplaceBubble(const BubbleItem *bubble) const;
int replaceBubbleIndex(const NotifyEntity &entity) const;
void updateBubbleInPlace(int replaceIndex, const NotifyEntity &entity);
void replaceBubble(int replaceIndex, BubbleItem *bubble);

QList<BubbleItem *> items() const;

Expand All @@ -64,7 +65,6 @@ class BubbleModel : public QAbstractListModel
private:
void insertBubble(BubbleItem *bubble);
void updateBubbleCount(int count);
int replaceBubbleIndex(const BubbleItem *bubble) const;
void updateBubbleTimeTip();
void updateContentRowCount(int rowCount);

Expand Down
18 changes: 11 additions & 7 deletions panels/notification/bubble/bubblepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,21 @@ void BubblePanel::addBubble(qint64 id)
return;
}

const auto replaceIndex = m_bubbles->replaceBubbleIndex(entity);
if (replaceIndex >= 0
&& entity.hints().value("x-deepin-SilentReplace").toBool()) {
m_bubbles->updateBubbleInPlace(replaceIndex, entity);
return;
}

auto bubble = new BubbleItem(entity);
const auto enabled = enablePreview(entity.appId());
bubble->setEnablePreview(enabled);
if (m_bubbles->isReplaceBubble(bubble)) {
auto oldBubble = m_bubbles->replaceBubble(bubble);
if (oldBubble) {
oldBubble->deleteLater();
}
} else {
m_bubbles->push(bubble);
if (replaceIndex >= 0) {
m_bubbles->replaceBubble(replaceIndex, bubble);
return;
}
m_bubbles->push(bubble);
}

void BubblePanel::closeBubble(qint64 id)
Expand Down
Loading