BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::PropertyViewModel Class Reference

View model to show content of SessionModel in Qt widgets. More...

Inheritance diagram for ModelView::PropertyViewModel:
[legend]
Collaboration diagram for ModelView::PropertyViewModel:
[legend]

Public Member Functions

 PropertyViewModel (SessionModel *model, QObject *parent=nullptr)
 
void appendRow (ViewItem *parent, std::vector< std::unique_ptr< ViewItem >> items)
 Appends row of items to given parent. More...
 
void clearRows (ViewItem *parent)
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
std::vector< ViewItem * > findViews (const ModelView::SessionItem *item) const
 Returns vector of all ViewItem's representing given SessionItem. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 Returns the item flags for the given index. More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
QModelIndex indexFromItem (const ViewItem *item) const
 Returns the QModelIndex associated with the given item. More...
 
QModelIndexList indexOfSessionItem (const SessionItem *item) const
 Returns list of model indices representing given SessionItem. More...
 
void insertRow (ViewItem *parent, int row, std::vector< std::unique_ptr< ViewItem >> items)
 Insert a row of items at index 'row' to given parent. More...
 
ViewItemitemFromIndex (const QModelIndex &index) const
 Returns a pointer to the RefViewItem associated with the given index. More...
 
QModelIndex parent (const QModelIndex &child) const override
 
void removeRow (ViewItem *parent, int row)
 
ViewItemrootItem () const
 Returns a pointer to invisible root item. More...
 
SessionItemrootSessionItem ()
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
SessionItemsessionItemFromIndex (const QModelIndex &index) const
 
SessionModelsessionModel () const
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
void setRootSessionItem (SessionItem *item)
 
ViewItemviewItemFromIndex (const QModelIndex &index) const
 

Private Member Functions

void setRootViewItem (std::unique_ptr< ViewItem > root_item)
 Sets new root item. Previous item will be deleted, model will be reset. More...
 

Private Attributes

std::unique_ptr< ViewModelControllerm_controller
 
std::unique_ptr< ViewModelBaseImplp_impl
 

Detailed Description

View model to show content of SessionModel in Qt widgets.

Only property items are shown, also hides inactive items of GroupProperty.

Definition at line 25 of file propertyviewmodel.h.

Constructor & Destructor Documentation

◆ PropertyViewModel()

PropertyViewModel::PropertyViewModel ( SessionModel model,
QObject *  parent = nullptr 
)

Definition at line 20 of file propertyviewmodel.cpp.

21  : ViewModel(std::make_unique<PropertyViewModelController>(model, this), parent)
22 {
23 }
QModelIndex parent(const QModelIndex &child) const override
ViewModel(std::unique_ptr< ViewModelController > controller, QObject *parent=nullptr)
Definition: viewmodel.cpp:23

Member Function Documentation

◆ appendRow()

void ViewModelBase::appendRow ( ViewItem parent,
std::vector< std::unique_ptr< ViewItem >>  items 
)
inherited

Appends row of items to given parent.

Definition at line 165 of file viewmodelbase.cpp.

166 {
167  insertRow(parent, parent->rowCount(), std::move(items));
168 }
void insertRow(ViewItem *parent, int row, std::vector< std::unique_ptr< ViewItem >> items)
Insert a row of items at index 'row' to given parent.

References ModelView::ViewModelBase::insertRow(), and ModelView::ViewModelBase::parent().

Referenced by ModelView::ViewModelController::ViewModelControllerImpl::iterate(), and TEST_F().

Here is the call graph for this function:

◆ clearRows()

void ViewModelBase::clearRows ( ViewItem parent)
inherited

Definition at line 135 of file viewmodelbase.cpp.

136 {
137  if (!p_impl->item_belongs_to_model(parent))
138  throw std::runtime_error(
139  "Error in ViewModelBase: attempt to use parent from another model");
140 
141  if (!parent->rowCount())
142  return;
143 
144  beginRemoveRows(indexFromItem(parent), 0, parent->rowCount() - 1);
145  parent->clear();
146  endRemoveRows();
147 }
std::unique_ptr< ViewModelBaseImpl > p_impl
Definition: viewmodelbase.h:69
QModelIndex indexFromItem(const ViewItem *item) const
Returns the QModelIndex associated with the given item.

References ModelView::ViewModelBase::indexFromItem(), ModelView::ViewModelBase::p_impl, and ModelView::ViewModelBase::parent().

Referenced by ModelView::ViewModelController::ViewModelControllerImpl::remove_children_of_view(), and TEST_F().

Here is the call graph for this function:

◆ columnCount()

int ViewModelBase::columnCount ( const QModelIndex &  parent = QModelIndex()) const
overrideinherited

Definition at line 70 of file viewmodelbase.cpp.

71 {
72  auto parent_item = itemFromIndex(parent);
73  return parent_item ? parent_item->columnCount() : rootItem()->columnCount();
74 }
int columnCount() const
Returns the number of child item columns that the item has.
Definition: viewitem.cpp:120
ViewItem * rootItem() const
Returns a pointer to invisible root item.
ViewItem * itemFromIndex(const QModelIndex &index) const
Returns a pointer to the RefViewItem associated with the given index.

References ModelView::ViewItem::columnCount(), ModelView::ViewModelBase::itemFromIndex(), ModelView::ViewModelBase::parent(), and ModelView::ViewModelBase::rootItem().

Referenced by ModelView::ViewModelBase::index(), and TEST_F().

Here is the call graph for this function:

◆ data()

QVariant ViewModelBase::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
overrideinherited

Definition at line 76 of file viewmodelbase.cpp.

77 {
78  if (!rootItem())
79  return QVariant();
80 
81  auto item = itemFromIndex(index);
82  return item ? item->data(role) : QVariant();
83 }
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override

References ModelView::ViewModelBase::index(), ModelView::ViewModelBase::itemFromIndex(), and ModelView::ViewModelBase::rootItem().

Referenced by gui2::DataViewModel::canDropMimeData(), gui2::DataViewModel::dropMimeData(), ModelView::ViewModel::headerData(), and TEST_F().

Here is the call graph for this function:

◆ findViews()

std::vector< ViewItem * > ViewModel::findViews ( const ModelView::SessionItem item) const
inherited

Returns vector of all ViewItem's representing given SessionItem.

Definition at line 81 of file viewmodel.cpp.

82 {
83  return m_controller->findViews(item);
84 }
std::unique_ptr< ViewModelController > m_controller
Definition: viewmodel.h:54

References ModelView::ViewModel::m_controller.

Referenced by TEST_F().

◆ flags()

Qt::ItemFlags ViewModelBase::flags ( const QModelIndex &  index) const
overrideinherited

Returns the item flags for the given index.

Definition at line 172 of file viewmodelbase.cpp.

173 {
174  Qt::ItemFlags result = QAbstractItemModel::flags(index);
175  if (auto item = itemFromIndex(index); item)
176  result |= item->flags();
177  return result;
178 }

References ModelView::ViewModelBase::index(), and ModelView::ViewModelBase::itemFromIndex().

Referenced by gui2::DataViewModel::flags(), and TEST_F().

Here is the call graph for this function:

◆ headerData()

QVariant ViewModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
overrideinherited

Definition at line 30 of file viewmodel.cpp.

31 {
32  if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
33  auto data = m_controller->horizontalHeaderLabels();
34  if (section < data.size())
35  return data.at(section);
36  }
37  return QVariant();
38 }
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override

References ModelView::ViewModelBase::data(), and ModelView::ViewModel::m_controller.

Here is the call graph for this function:

◆ index()

QModelIndex ViewModelBase::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
overrideinherited

Definition at line 42 of file viewmodelbase.cpp.

43 {
44  auto parent_item = itemFromIndex(parent) ? itemFromIndex(parent) : rootItem();
45  const bool is_valid_row = row >= 0 && row < rowCount(parent);
46  const bool is_valid_column = column >= 0 && column < columnCount(parent);
47  return is_valid_row && is_valid_column
48  ? createIndex(row, column, parent_item->child(row, column))
49  : QModelIndex();
50 }
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override

References ModelView::ViewModelBase::columnCount(), ModelView::ViewModelBase::itemFromIndex(), ModelView::ViewModelBase::parent(), ModelView::ViewModelBase::rootItem(), and ModelView::ViewModelBase::rowCount().

Referenced by ModelView::ViewModelBase::data(), gui2::DataViewModel::flags(), ModelView::ViewModelBase::flags(), ModelView::ViewModelBase::itemFromIndex(), ModelView::ViewModel::sessionItemFromIndex(), ModelView::ViewModelBase::setData(), TEST_F(), and ModelView::ViewModel::viewItemFromIndex().

Here is the call graph for this function:

◆ indexFromItem()

QModelIndex ViewModelBase::indexFromItem ( const ViewItem item) const
inherited

Returns the QModelIndex associated with the given item.

Definition at line 117 of file viewmodelbase.cpp.

118 {
119  return item && item->parent()
120  ? createIndex(item->row(), item->column(), const_cast<ViewItem*>(item))
121  : QModelIndex();
122 }
Represents the view of SessionItem's data in a single cell of ViewModel.
Definition: viewitem.h:29
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...
Definition: viewitem.cpp:181
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...
Definition: viewitem.cpp:190
ViewItem * parent() const
Definition: viewitem.cpp:158

References ModelView::ViewItem::column(), ModelView::ViewItem::parent(), and ModelView::ViewItem::row().

Referenced by ModelView::ViewModelBase::clearRows(), ModelView::ViewModel::indexOfSessionItem(), ModelView::ViewModelBase::insertRow(), ModelView::ViewModelBase::ViewModelBaseImpl::item_belongs_to_model(), ModelView::ViewModelBase::removeRow(), and TEST_F().

Here is the call graph for this function:

◆ indexOfSessionItem()

QModelIndexList ViewModel::indexOfSessionItem ( const SessionItem item) const
inherited

Returns list of model indices representing given SessionItem.

Definition at line 71 of file viewmodel.cpp.

72 {
73  QModelIndexList result;
74  for (auto view : m_controller->findViews(item))
75  result.push_back(indexFromItem(view));
76  return result;
77 }

References ModelView::ViewModelBase::indexFromItem(), and ModelView::ViewModel::m_controller.

Referenced by gui2::DataSelectionModel::selectItems(), gui2::LayerSelectionModel::selectItems(), gui2::MaterialSelectionModel::selectItems(), and TEST_F().

Here is the call graph for this function:

◆ insertRow()

void ViewModelBase::insertRow ( ViewItem parent,
int  row,
std::vector< std::unique_ptr< ViewItem >>  items 
)
inherited

Insert a row of items at index 'row' to given parent.

Definition at line 151 of file viewmodelbase.cpp.

153 {
154  if (!p_impl->item_belongs_to_model(parent))
155  throw std::runtime_error(
156  "Error in ViewModelBase: attempt to use parent from another model");
157 
158  beginInsertRows(indexFromItem(parent), row, row);
159  parent->insertRow(row, std::move(items));
160  endInsertRows();
161 }

References ModelView::ViewModelBase::indexFromItem(), ModelView::ViewModelBase::p_impl, and ModelView::ViewModelBase::parent().

Referenced by ModelView::ViewModelBase::appendRow(), ModelView::ViewModelController::ViewModelControllerImpl::insert_view(), and TEST_F().

Here is the call graph for this function:

◆ itemFromIndex()

ViewItem * ViewModelBase::itemFromIndex ( const QModelIndex &  index) const
inherited

Returns a pointer to the RefViewItem associated with the given index.

If index is invalid, returns nullptr.

Definition at line 110 of file viewmodelbase.cpp.

111 {
112  return index.isValid() ? static_cast<ViewItem*>(index.internalPointer()) : nullptr;
113 }

References ModelView::ViewModelBase::index().

Referenced by ModelView::ViewModelBase::columnCount(), ModelView::ViewModelBase::data(), ModelView::ViewModelController::ViewModelControllerImpl::findViews(), ModelView::ViewModelBase::flags(), ModelView::ViewModelBase::index(), ModelView::ViewModelBase::parent(), ModelView::ViewModelBase::rowCount(), ModelView::ViewModel::sessionItemFromIndex(), ModelView::ViewModelBase::setData(), TEST_F(), and ModelView::ViewModel::viewItemFromIndex().

Here is the call graph for this function:

◆ parent()

QModelIndex ViewModelBase::parent ( const QModelIndex &  child) const
overrideinherited

Definition at line 52 of file viewmodelbase.cpp.

53 {
54  if (auto child_item = itemFromIndex(child); child_item) {
55  auto parent_item = child_item->parent();
56  return parent_item == rootItem()
57  ? QModelIndex()
58  : createIndex(parent_item->row(), parent_item->column(), parent_item);
59  }
60 
61  return QModelIndex();
62 }

References ModelView::ViewModelBase::itemFromIndex(), and ModelView::ViewModelBase::rootItem().

Referenced by ModelView::ViewModelBase::appendRow(), gui2::DataViewModel::canDropMimeData(), ModelView::ViewModelBase::clearRows(), ModelView::ViewModelBase::columnCount(), gui2::DataViewModel::dropMimeData(), ModelView::ViewModelBase::index(), ModelView::ViewModelBase::insertRow(), ModelView::ViewModelBase::removeRow(), ModelView::ViewModelBase::rowCount(), and TEST_F().

Here is the call graph for this function:

◆ removeRow()

void ViewModelBase::removeRow ( ViewItem parent,
int  row 
)
inherited

Definition at line 124 of file viewmodelbase.cpp.

125 {
126  if (!p_impl->item_belongs_to_model(parent))
127  throw std::runtime_error(
128  "Error in ViewModelBase: attempt to use parent from another model");
129 
130  beginRemoveRows(indexFromItem(parent), row, row);
131  parent->removeRow(row);
132  endRemoveRows();
133 }

References ModelView::ViewModelBase::indexFromItem(), ModelView::ViewModelBase::p_impl, and ModelView::ViewModelBase::parent().

Referenced by ModelView::ViewModelController::ViewModelControllerImpl::remove_row_of_views(), and TEST_F().

Here is the call graph for this function:

◆ rootItem()

◆ rootSessionItem()

SessionItem * ViewModel::rootSessionItem ( )
inherited

Definition at line 45 of file viewmodel.cpp.

46 {
47  return m_controller->rootSessionItem();
48 }

References ModelView::ViewModel::m_controller.

◆ rowCount()

int ViewModelBase::rowCount ( const QModelIndex &  parent = QModelIndex()) const
overrideinherited

Definition at line 64 of file viewmodelbase.cpp.

65 {
66  auto parent_item = itemFromIndex(parent);
67  return parent_item ? parent_item->rowCount() : rootItem()->rowCount();
68 }
int rowCount() const
Returns the number of child item rows that the item has.
Definition: viewitem.cpp:113

References ModelView::ViewModelBase::itemFromIndex(), ModelView::ViewModelBase::parent(), ModelView::ViewModelBase::rootItem(), and ModelView::ViewItem::rowCount().

Referenced by ModelView::ViewModelBase::index(), and TEST_F().

Here is the call graph for this function:

◆ sessionItemFromIndex()

SessionItem * ViewModel::sessionItemFromIndex ( const QModelIndex &  index) const
inherited

Definition at line 59 of file viewmodel.cpp.

60 {
61  return index.isValid() ? itemFromIndex(index)->item() : m_controller->rootSessionItem();
62 }
SessionItem * item() const
Definition: viewitem.cpp:168

References ModelView::ViewModelBase::index(), ModelView::ViewItem::item(), ModelView::ViewModelBase::itemFromIndex(), and ModelView::ViewModel::m_controller.

Referenced by gui2::DataViewModel::canDropMimeData(), gui2::DataViewModel::dropMimeData(), gui2::DataViewModel::flags(), and TEST_F().

Here is the call graph for this function:

◆ sessionModel()

SessionModel * ViewModel::sessionModel ( ) const
inherited

Definition at line 40 of file viewmodel.cpp.

41 {
42  return m_controller->sessionModel();
43 }

References ModelView::ViewModel::m_controller.

Referenced by ModelView::ViewModel::ViewModel(), and gui2::DataViewModel::dropMimeData().

◆ setData()

bool ViewModelBase::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
overrideinherited

Definition at line 85 of file viewmodelbase.cpp.

86 {
87  if (!index.isValid())
88  return false;
89 
90  if (auto item = itemFromIndex(index); item) {
91  bool result = item->setData(value, role);
92  if (result)
93  dataChanged(index, index, QVector<int>() << role);
94  return result;
95  }
96 
97  return false;
98 }

References ModelView::ViewModelBase::index(), and ModelView::ViewModelBase::itemFromIndex().

Referenced by TEST_F().

Here is the call graph for this function:

◆ setRootSessionItem()

void ViewModel::setRootSessionItem ( SessionItem item)
inherited

Definition at line 52 of file viewmodel.cpp.

53 {
54  if (!item)
55  throw std::runtime_error("Error in ViewModel: atttemp to set nulptr as root item");
56  m_controller->setRootSessionItem(item);
57 }

References ModelView::ViewModel::m_controller.

Referenced by gui2::ImportDataEditor::ImportDataEditor(), ModelView::PropertyTreeView::setItem(), and TEST_F().

◆ setRootViewItem()

void ViewModelBase::setRootViewItem ( std::unique_ptr< ViewItem root_item)
privateinherited

Sets new root item. Previous item will be deleted, model will be reset.

Definition at line 182 of file viewmodelbase.cpp.

183 {
184  p_impl->root = std::move(root_item);
185 }

References ModelView::ViewModelBase::p_impl.

Referenced by ModelView::ViewModelBase::ViewModelBase(), and ModelView::ViewModelController::ViewModelControllerImpl::setRootSessionItemIntern().

◆ viewItemFromIndex()

ViewItem * ViewModel::viewItemFromIndex ( const QModelIndex &  index) const
inherited

Definition at line 64 of file viewmodel.cpp.

65 {
66  return itemFromIndex(index);
67 }

References ModelView::ViewModelBase::index(), and ModelView::ViewModelBase::itemFromIndex().

Here is the call graph for this function:

Member Data Documentation

◆ m_controller

◆ p_impl


The documentation for this class was generated from the following files: