123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include <core/node_info.h>
- #include <util/strings.h>
- #include "node_list.h"
- namespace rainynite::studio {
- NodeListModel::NodeListModel(QObject* parent) :
- QAbstractItemModel(parent)
- {
- }
- NodeListModel::~NodeListModel() {
- }
- QVariant NodeListModel::data(QModelIndex const& index, int role) const {
- if (!index.isValid() || index.column() != 0 || index.parent().isValid())
- return {};
- switch (role) {
- case Qt::DisplayRole: {
- return util::str(core::node_name(*get_node(index)));
- } break;
- default:
- return {};
- }
- }
- Qt::ItemFlags NodeListModel::flags(QModelIndex const& ) const {
- return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
- }
- QVariant NodeListModel::headerData(int , Qt::Orientation , int ) const {
- return {};
- }
- QModelIndex NodeListModel::index(int row, int column, QModelIndex const& parent) const {
- if (parent.isValid() || column != 0)
- return {};
- return createIndex(row, column, nullptr);
- }
- QModelIndex NodeListModel::parent(QModelIndex const& ) const {
- return {};
- }
- int NodeListModel::rowCount(QModelIndex const& parent) const {
- if (parent.isValid())
- return 0;
- return nodes.size();
- }
- int NodeListModel::columnCount(QModelIndex const& ) const {
- return 1;
- }
- bool NodeListModel::removeRows(int row, int count, QModelIndex const& parent) {
- if (parent.isValid())
- return false;
- beginRemoveRows(parent, row, row+count-1);
- nodes.erase(nodes.begin()+row, nodes.begin()+row+count);
- endRemoveRows();
- return true;
- }
- void NodeListModel::insert_node(shared_ptr<core::AbstractValue> node, int position) {
- if (position < 0)
- position = nodes.size();
- beginInsertRows({}, position, position+1);
- nodes.insert(nodes.begin()+position, node);
- endInsertRows();
- }
- bool NodeListModel::insert_unique_node(shared_ptr<core::AbstractValue> node, int position) {
- if (std::find(nodes.begin(), nodes.end(), node) == nodes.end()) {
- insert_node(node, position);
- return true;
- }
- return false;
- }
- shared_ptr<core::AbstractValue> NodeListModel::get_node(QModelIndex const& index) const {
- return nodes[index.row()];
- }
- }
|