LevelTreeModel.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef CRYINCLUDE_EDITOR_LEVEL_ITEM_MODEL_H
  9. #define CRYINCLUDE_EDITOR_LEVEL_ITEM_MODEL_H
  10. #pragma once
  11. #if !defined(Q_MOC_RUN)
  12. #include <QStandardItemModel>
  13. #include <QSortFilterProxyModel>
  14. #endif
  15. class QString;
  16. class QStandardItem;
  17. class LevelTreeModelFilter
  18. : public QSortFilterProxyModel
  19. {
  20. Q_OBJECT
  21. public:
  22. explicit LevelTreeModelFilter(QObject* parent = nullptr);
  23. bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
  24. void setFilterText(const QString&);
  25. QVariant data(const QModelIndex& index, int role) const override;
  26. private:
  27. QString m_filterText;
  28. };
  29. class LevelTreeModel
  30. : public QStandardItemModel
  31. {
  32. Q_OBJECT
  33. public:
  34. enum Role
  35. {
  36. FullPathRole = Qt::UserRole + 1,
  37. IsLevelFolderRole
  38. };
  39. explicit LevelTreeModel(QObject* parent = nullptr);
  40. ~LevelTreeModel();
  41. void ReloadTree(bool recurseIfNoLevels);
  42. void AddItem(const QString& name, const QModelIndex& parent); // Called when clicking "New folder"
  43. QVariant data(const QModelIndex& index, int role) const override;
  44. private:
  45. void ReloadTree(QStandardItem* root, bool recurseIfNoLevels);
  46. };
  47. #endif