@@ -82,6 +82,8 @@ void BubbleModel::clear()
8282 qDeleteAll (m_bubbles);
8383 m_bubbles.clear ();
8484 endResetModel ();
85+ m_delayBubbles.clear ();
86+ m_delayRemovedBubble = -1 ;
8587
8688 updateLevel ();
8789 m_updateTimeTipTimer->stop ();
@@ -111,8 +113,8 @@ void BubbleModel::remove(int index)
111113 if (m_bubbles.count () >= BubbleMaxCount) {
112114 beginInsertRows (QModelIndex (), displayRowCount () - 1 , displayRowCount () - 1 );
113115 endInsertRows ();
114- updateLevel ();
115116 }
117+ updateLevel ();
116118}
117119
118120void BubbleModel::remove (const BubbleItem *bubble)
@@ -125,8 +127,16 @@ void BubbleModel::remove(const BubbleItem *bubble)
125127
126128BubbleItem *BubbleModel::removeById (qint64 id)
127129{
130+ if (id == m_delayRemovedBubble) {
131+ // Delayed remove
132+ if (!m_delayBubbles.contains (id)) {
133+ m_delayBubbles.append (id);
134+ }
135+ return nullptr ;
136+ }
128137 for (const auto &item : m_bubbles) {
129138 if (item->id () == id) {
139+ m_delayBubbles.removeAll (id);
130140 remove (m_bubbles.indexOf (item));
131141 return item;
132142 }
@@ -158,6 +168,8 @@ QVariant BubbleModel::data(const QModelIndex &index, int role) const
158168 switch (role) {
159169 case BubbleModel::AppName:
160170 return m_bubbles[row]->appName ();
171+ case BubbleModel::Id:
172+ return m_bubbles[row]->id ();
161173 case BubbleModel::Body:
162174 return m_bubbles[row]->body ();
163175 case BubbleModel::Summary:
@@ -190,6 +202,7 @@ QHash<int, QByteArray> BubbleModel::roleNames() const
190202{
191203 QHash<int , QByteArray> mapRoleNames;
192204 mapRoleNames[BubbleModel::AppName] = " appName" ;
205+ mapRoleNames[BubbleModel::Id] = " id" ;
193206 mapRoleNames[BubbleModel::Body] = " body" ;
194207 mapRoleNames[BubbleModel::Summary] = " summary" ;
195208 mapRoleNames[BubbleModel::IconName] = " iconName" ;
@@ -219,6 +232,27 @@ void BubbleModel::setBubbleCount(int count)
219232 BubbleMaxCount = count;
220233}
221234
235+ qint64 BubbleModel::delayRemovedBubble () const
236+ {
237+ return m_delayRemovedBubble;
238+ }
239+
240+ void BubbleModel::setDelayRemovedBubble (qint64 newDelayRemovedBubble)
241+ {
242+ if (m_delayRemovedBubble == newDelayRemovedBubble)
243+ return ;
244+ const auto oldDelayRemovedBubble = m_delayRemovedBubble;
245+ if (m_delayBubbles.contains (oldDelayRemovedBubble)) {
246+ // Remove last delayed bubble.
247+ QTimer::singleShot (DelayRemovBubbleTime, this , [this , oldDelayRemovedBubble]() {
248+ removeById (oldDelayRemovedBubble);
249+ });
250+ }
251+
252+ m_delayRemovedBubble = newDelayRemovedBubble;
253+ emit delayRemovedBubbleChanged ();
254+ }
255+
222256int BubbleModel::replaceBubbleIndex (const BubbleItem *bubble) const
223257{
224258 if (bubble->replacesId () != NoReplaceId) {
0 commit comments