1
0

item-widget-helpers.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /******************************************************************************
  2. Copyright (C) 2015 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <QListWidget>
  15. QListWidgetItem *TakeListItem(QListWidget *widget, int row)
  16. {
  17. QListWidgetItem *item = widget->item(row);
  18. if (item)
  19. delete widget->itemWidget(item);
  20. return widget->takeItem(row);
  21. }
  22. void DeleteListItem(QListWidget *widget, QListWidgetItem *item)
  23. {
  24. if (item) {
  25. delete widget->itemWidget(item);
  26. delete item;
  27. }
  28. }
  29. void ClearListItems(QListWidget *widget)
  30. {
  31. // Workaround for the SceneTree workaround for QTBUG-105870
  32. widget->setProperty("clearing", true);
  33. widget->setCurrentItem(nullptr, QItemSelectionModel::Clear);
  34. for (int i = 0; i < widget->count(); i++)
  35. delete widget->itemWidget(widget->item(i));
  36. widget->clear();
  37. widget->setProperty("clearing", false);
  38. }