item-widget-helpers.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "item-widget-helpers.hpp"
  15. #include <QListWidget>
  16. QListWidgetItem *TakeListItem(QListWidget *widget, int row)
  17. {
  18. QListWidgetItem *item = widget->item(row);
  19. if (item)
  20. delete widget->itemWidget(item);
  21. return widget->takeItem(row);
  22. }
  23. void DeleteListItem(QListWidget *widget, QListWidgetItem *item)
  24. {
  25. if (item) {
  26. delete widget->itemWidget(item);
  27. delete item;
  28. }
  29. }
  30. void ClearListItems(QListWidget *widget)
  31. {
  32. #if QT_VERSION < QT_VERSION_CHECK(6, 4, 3)
  33. // Workaround for the SceneTree workaround for QTBUG-105870
  34. widget->setProperty("clearing", true);
  35. #endif
  36. widget->setCurrentItem(nullptr, QItemSelectionModel::Clear);
  37. for (int i = 0; i < widget->count(); i++)
  38. delete widget->itemWidget(widget->item(i));
  39. widget->clear();
  40. #if QT_VERSION < QT_VERSION_CHECK(6, 4, 3)
  41. // Workaround for the SceneTree workaround for QTBUG-105870
  42. widget->setProperty("clearing", false);
  43. #endif
  44. }