node_list.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * node_list.h - node list model
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __STUDIO__MODELS__NODE_LIST_H__CE0F8EE4
  19. #define __STUDIO__MODELS__NODE_LIST_H__CE0F8EE4
  20. #include <QAbstractItemModel>
  21. namespace rainynite::studio {
  22. class NodeListModel : public QAbstractItemModel
  23. {
  24. public:
  25. explicit NodeListModel(QObject* parent = nullptr);
  26. virtual ~NodeListModel();
  27. public:
  28. QVariant data(QModelIndex const& index, int role) const override;
  29. Qt::ItemFlags flags(QModelIndex const& index) const override;
  30. QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override;
  31. QModelIndex index(int row, int column, QModelIndex const& parent={}) const override;
  32. QModelIndex parent(QModelIndex const& index) const override;
  33. int rowCount(QModelIndex const& parent={}) const override;
  34. int columnCount(QModelIndex const& parent={}) const override;
  35. public:
  36. bool removeRows(int row, int count, QModelIndex const& parent={}) override;
  37. /// Insert node at position
  38. void insert_node(shared_ptr<core::AbstractValue> node, int position=-1);
  39. /**
  40. * Insert node only if it isn't already in model
  41. * @return true if node was added
  42. */
  43. bool insert_unique_node(shared_ptr<core::AbstractValue> node, int position=-1);
  44. /// Get list of all nodes
  45. vector<shared_ptr<core::AbstractValue>> const& get_all_nodes() const {
  46. return nodes;
  47. }
  48. shared_ptr<core::AbstractValue> get_node(QModelIndex const& index) const;
  49. private:
  50. vector<shared_ptr<core::AbstractValue>> nodes;
  51. };
  52. } // namespace rainynite::studio
  53. #endif