node_list.h 2.4 KB

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