23 std::unique_ptr<ViewItem>
root;
47 return is_valid_row && is_valid_column
48 ? createIndex(row, column, parent_item->child(row, column))
55 auto parent_item = child_item->parent();
58 : createIndex(parent_item->row(), parent_item->column(), parent_item);
82 return item ? item->data(role) : QVariant();
91 bool result = item->setData(value, role);
93 dataChanged(
index,
index, QVector<int>() << role);
104 return p_impl->root.get();
119 return item && item->
parent()
127 throw std::runtime_error(
128 "Error in ViewModelBase: attempt to use parent from another model");
138 throw std::runtime_error(
139 "Error in ViewModelBase: attempt to use parent from another model");
152 std::vector<std::unique_ptr<ViewItem>> items)
155 throw std::runtime_error(
156 "Error in ViewModelBase: attempt to use parent from another model");
159 parent->insertRow(row, std::move(items));
174 Qt::ItemFlags result = QAbstractItemModel::flags(
index);
176 result |= item->flags();
184 p_impl->root = std::move(root_item);
Represents the view of SessionItem's data in a single cell of ViewModel.
int columnCount() const
Returns the number of child item columns that the item has.
int row() const
Returns the row where the item is located in its parent's child table, or -1 if the item has no paren...
int rowCount() const
Returns the number of child item rows that the item has.
int column() const
Returns the column where the item is located in its parent's child table, or -1 if the item has no pa...
ViewItem * parent() const
Base class for all view models to show content of SessionModel in Qt views.
void removeRow(ViewItem *parent, int row)
void appendRow(ViewItem *parent, std::vector< std::unique_ptr< ViewItem >> items)
Appends row of items to given parent.
ViewItem * rootItem() const
Returns a pointer to invisible root item.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
void clearRows(ViewItem *parent)
ViewModelBase(QObject *parent=nullptr)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
std::unique_ptr< ViewModelBaseImpl > p_impl
QModelIndex indexFromItem(const ViewItem *item) const
Returns the QModelIndex associated with the given item.
void insertRow(ViewItem *parent, int row, std::vector< std::unique_ptr< ViewItem >> items)
Insert a row of items at index 'row' to given parent.
QModelIndex parent(const QModelIndex &child) const override
void setRootViewItem(std::unique_ptr< ViewItem > root_item)
Sets new root item. Previous item will be deleted, model will be reset.
~ViewModelBase() override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
ViewItem * itemFromIndex(const QModelIndex &index) const
Returns a pointer to the RefViewItem associated with the given index.
materialitems.h Collection of materials to populate MaterialModel.
std::unique_ptr< ViewItem > root
ViewModelBaseImpl(ViewModelBase *model)
bool item_belongs_to_model(ViewItem *item)