2015-06-27 18:44:36 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2015 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <QListWidget>
|
|
|
|
|
|
|
|
QListWidgetItem *TakeListItem(QListWidget *widget, int row)
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = widget->item(row);
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
delete widget->itemWidget(item);
|
|
|
|
|
|
|
|
return widget->takeItem(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteListItem(QListWidget *widget, QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
if (item) {
|
|
|
|
delete widget->itemWidget(item);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearListItems(QListWidget *widget)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < widget->count(); i++)
|
|
|
|
delete widget->itemWidget(widget->item(i));
|
|
|
|
|
UI: Do not delete via takeItem in ClearListItems
Apparently some raw lingering pointers to the item widgets may be
present inside of the QListView if you delete the item widgets directly,
and the only way to ensure those pointers are properly cleared is to
call ->clear() on the list widget instead of deleting each item
individually.
We were deleting each item individually because we thought that
->deleteLater might be also be called on other data within, but after
some testing, that turned out to not be the case, so it's safe to call
->clear() on the list widget.
As a note, deleting item widgets directly is dangerous due to the
potential for lingering raw internal pointers, and our case is unique
where we can get away with it; do not delete list item widgets directly
unless you intend on calling ->clear() or ->takeItem on the specific
item you do it to after.
Again, the reason why we are deleting list widget items manually is due
to the fact that Qt will always use ->deleteLater() on them if they are
not deleted manually, which puts their deletion on the queue. Only
problem is they cannot be removed from the queue once added, so
lingering references to sources will persist until the queue processes
them, which causes major problems if we need those objects deleted right
away.
2015-07-02 21:56:30 -07:00
|
|
|
widget->clear();
|
2015-06-27 18:44:36 -07:00
|
|
|
}
|