@@ -42,15 +42,15 @@ HighlightManager::HighlightManager()
4242 * Called to add item to list. Item is only added if absent.
4343 * Returns true if item was added, otherwise false.
4444 */
45- bool HighlightManager::add (TreeItem *itemToAdd )
45+ bool HighlightManager::add (TreeItem *item )
4646{
4747 // Lock to ensure thread safety
4848 QMutexLocker locker (&m_mutex);
4949
5050 // Check so that the item isn't already in the list
51- if (!m_items.contains (itemToAdd )) {
52- m_items.insert (itemToAdd );
53- emit updateHighlight (itemToAdd );
51+ if (!m_items.contains (item )) {
52+ m_items.insert (item );
53+ emit updateHighlight (item );
5454 return true ;
5555 }
5656 return false ;
@@ -60,20 +60,34 @@ bool HighlightManager::add(TreeItem *itemToAdd)
6060 * Called to remove item from list.
6161 * Returns true if item was removed, otherwise false.
6262 */
63- bool HighlightManager::remove (TreeItem *itemToRemove )
63+ bool HighlightManager::remove (TreeItem *item )
6464{
6565 // Lock to ensure thread safety
6666 QMutexLocker locker (&m_mutex);
6767
6868 // Remove item and return result
69- const bool removed = m_items.remove (itemToRemove );
69+ const bool removed = m_items.remove (item );
7070
7171 if (removed) {
72- emit updateHighlight (itemToRemove );
72+ emit updateHighlight (item );
7373 }
7474 return removed;
7575}
7676
77+ /*
78+ * Called to remove item from list.
79+ * Will not emit a signal. Called when destroying an item
80+ * Returns true if item was removed, otherwise false.
81+ */
82+ bool HighlightManager::reset (TreeItem *item)
83+ {
84+ // Lock to ensure thread safety
85+ QMutexLocker locker (&m_mutex);
86+
87+ // Remove item and return result
88+ return m_items.remove (item);
89+ }
90+
7791bool HighlightManager::startTimer (QTime expirationTime)
7892{
7993 // Lock to ensure thread safety
@@ -163,6 +177,9 @@ TreeItem::TreeItem(const QVariant &data) :
163177
164178TreeItem::~TreeItem ()
165179{
180+ if (m_highlightManager) {
181+ m_highlightManager->reset (this );
182+ }
166183 qDeleteAll (m_childItems);
167184}
168185
@@ -273,7 +290,7 @@ void TreeItem::setHighlighted(bool highlighted, const QTime &ts)
273290 }
274291
275292 // If we have a parent, call recursively to update highlight status of parents.
276- // This will ensure that the root of a leaf that is changed also is highlighted.
293+ // This will ensure that the root of a leaf that is changed is also highlighted.
277294 // Only updates that really changes values will trigger highlight of parents.
278295 if (m_parentItem) {
279296 m_parentItem->setHighlighted (highlighted, ts);
0 commit comments