1
0

item-widget-helpers.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain 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. #if QT_VERSION < QT_VERSION_CHECK(6, 4, 3)
  32. // Workaround for the SceneTree workaround for QTBUG-105870
  33. widget->setProperty("clearing", true);
  34. #endif
  35. widget->setCurrentItem(nullptr, QItemSelectionModel::Clear);
  36. for (int i = 0; i < widget->count(); i++)
  37. delete widget->itemWidget(widget->item(i));
  38. widget->clear();
  39. #if QT_VERSION < QT_VERSION_CHECK(6, 4, 3)
  40. // Workaround for the SceneTree workaround for QTBUG-105870
  41. widget->setProperty("clearing", false);
  42. #endif
  43. }