node_list.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* node_list.h - node list model
  2. * Copyright (C) 2017-2018 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. #include <core/node_tree/path.h>
  22. namespace rainynite::studio {
  23. /**
  24. * Node list model - stores list of node paths
  25. *
  26. * TODO: hide details in pimpl?
  27. */
  28. class NodeListModel : public QAbstractItemModel, public ContextListener {
  29. public:
  30. explicit NodeListModel(QObject* parent = nullptr);
  31. virtual ~NodeListModel();
  32. public:
  33. QVariant data(QModelIndex const& index, int role) const override;
  34. Qt::ItemFlags flags(QModelIndex const& index) const override;
  35. QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override;
  36. QModelIndex index(int row, int column, QModelIndex const& parent={}) const override;
  37. QModelIndex parent(QModelIndex const& index) const override;
  38. int rowCount(QModelIndex const& parent={}) const override;
  39. int columnCount(QModelIndex const& parent={}) const override;
  40. public:
  41. bool removeRows(int row, int count, QModelIndex const& parent={}) override;
  42. /**
  43. * Insert node only if it isn't already in model
  44. * @return true if node was added
  45. */
  46. bool insert_unique_node(core::NodeTreeIndex node, int position=-1);
  47. /// Get list of all nodes
  48. // vector<shared_ptr<core::AbstractValue>> const& get_all_nodes() const {
  49. // return nodes;
  50. // }
  51. shared_ptr<core::AbstractValue> get_node(QModelIndex const& index) const;
  52. core::NodeTreeIndex get_inner_index(QModelIndex const& index) const;
  53. protected:
  54. /// Insert node at position
  55. void insert_node(core::NodeTreePath const& node, int position=-1);
  56. private:
  57. vector<core::NodeTreePath> nodes;
  58. };
  59. } // namespace rainynite::studio
  60. #endif