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

Represents data role of SessionItem in any cell of Qt's trees and tables. More...

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

Public Member Functions

 ViewDataItem (SessionItem *item)
 
void appendRow (std::vector< std::unique_ptr< ViewItem >> items)
 Appends a row containing items. More...
 
ViewItemchild (int row, int column) const
 
std::vector< ViewItem * > children () const
 
void clear ()
 
int column () const
 Returns the column where the item is located in its parent's child table, or -1 if the item has no parent. More...
 
int columnCount () const
 Returns the number of child item columns that the item has. More...
 
QVariant data (int role) const override
 Returns the data for given role according to Qt::ItemDataRole namespace definitions. More...
 
Qt::ItemFlags flags () const override
 Returns Qt's item flags. More...
 
void insertRow (int row, std::vector< std::unique_ptr< ViewItem >> items)
 Insert a row of items at index 'row'. More...
 
SessionItemitem () const
 
int item_role () const
 
ViewItemparent () const
 
void removeRow (int row)
 Removes row of items at given 'row'. Items will be deleted. More...
 
int row () const
 Returns the row where the item is located in its parent's child table, or -1 if the item has no parent. More...
 
int rowCount () const
 Returns the number of child item rows that the item has. More...
 
virtual bool setData (const QVariant &value, int qt_role)
 Sets the data to underlying SessionItem. More...
 

Protected Member Functions

void setParent (ViewItem *parent)
 

Private Attributes

std::unique_ptr< ViewItemImplp_impl
 

Detailed Description

Represents data role of SessionItem in any cell of Qt's trees and tables.

Definition at line 50 of file standardviewitems.h.

Constructor & Destructor Documentation

◆ ViewDataItem()

ViewDataItem::ViewDataItem ( SessionItem item)
explicit

Definition at line 41 of file standardviewitems.cpp.

ViewItem(SessionItem *item, int role)
Definition: viewitem.cpp:105
SessionItem * item() const
Definition: viewitem.cpp:168
const int DATA
main data role
Definition: mvvm_types.h:30

Member Function Documentation

◆ appendRow()

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

Appends a row containing items.

Number of items should be the same as columnCount() (if there are already some rows). If it is a first row, then items can be of any size.

Definition at line 128 of file viewitem.cpp.

129 {
130  for (auto& x : items)
131  x->setParent(this);
132  p_impl->appendRow(std::move(items));
133 }
std::unique_ptr< ViewItemImpl > p_impl
Definition: viewitem.h:70

References ModelView::ViewItem::p_impl.

◆ child()

ViewItem * ViewItem::child ( int  row,
int  column 
) const
inherited

Definition at line 163 of file viewitem.cpp.

164 {
165  return p_impl->child(row, column);
166 }
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

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

Here is the call graph for this function:

◆ children()

std::vector< ViewItem * > ViewItem::children ( ) const
inherited

Definition at line 237 of file viewitem.cpp.

238 {
239  return p_impl->get_children();
240 }

References ModelView::ViewItem::p_impl.

Referenced by ModelView::ViewModelController::ViewModelControllerImpl::remove_children_of_view().

◆ clear()

void ViewItem::clear ( )
inherited

Definition at line 151 of file viewitem.cpp.

152 {
153  p_impl->children.clear();
154  p_impl->rows = 0;
155  p_impl->columns = 0;
156 }

References ModelView::ViewItem::p_impl.

◆ column()

int ViewItem::column ( ) const
inherited

Returns the column where the item is located in its parent's child table, or -1 if the item has no parent.

Definition at line 190 of file viewitem.cpp.

191 {
192  auto index = parent() ? parent()->p_impl->index_of_child(this) : -1;
193  return index >= 0 ? index % parent()->p_impl->columns : -1;
194 }
ViewItem * parent() const
Definition: viewitem.cpp:158

References ModelView::ViewItem::p_impl, and ModelView::ViewItem::parent().

Referenced by ModelView::ViewItem::ViewItemImpl::child(), ModelView::ViewItem::child(), and ModelView::ViewModelBase::indexFromItem().

Here is the call graph for this function:

◆ columnCount()

int ViewItem::columnCount ( ) const
inherited

Returns the number of child item columns that the item has.

Definition at line 120 of file viewitem.cpp.

121 {
122  return p_impl->columns;
123 }

References ModelView::ViewItem::p_impl.

Referenced by ModelView::ViewModelBase::columnCount().

◆ data()

QVariant ViewDataItem::data ( int  qt_role) const
overridevirtual

Returns the data for given role according to Qt::ItemDataRole namespace definitions.

Converts data and roles from underlying SessionItem to what Qt expects.

Reimplemented from ModelView::ViewItem.

Definition at line 52 of file standardviewitems.cpp.

53 {
54  if (role == Qt::DecorationRole)
55  return Utils::DecorationRole(*item());
56  else if (role == Qt::CheckStateRole)
57  return Utils::CheckStateRole(*item());
58 
59  return ViewItem::data(role);
60 }
virtual QVariant data(int qt_role) const
Returns the data for given role according to Qt::ItemDataRole namespace definitions.
Definition: viewitem.cpp:199
MVVM_VIEWMODEL_EXPORT QVariant DecorationRole(const SessionItem &item)
Returns decoration role for given item.
MVVM_VIEWMODEL_EXPORT QVariant CheckStateRole(const SessionItem &item)
Returns check state role of given item.
QVariant DecorationRole(const SessionItem &item)
Returns tooltip for given item.
QVariant CheckStateRole(const SessionItem &item)
Returns check state for given item.

References SessionItemUtils::CheckStateRole(), ModelView::Utils::CheckStateRole(), ModelView::ViewItem::data(), SessionItemUtils::DecorationRole(), ModelView::Utils::DecorationRole(), and ModelView::ViewItem::item().

Referenced by TEST_F().

Here is the call graph for this function:

◆ flags()

Qt::ItemFlags ViewDataItem::flags ( ) const
overridevirtual

Returns Qt's item flags.

Converts internal SessionItem's status enable/disabled/readonly to what Qt expects.

Reimplemented from ModelView::ViewItem.

Definition at line 43 of file standardviewitems.cpp.

44 {
45  Qt::ItemFlags result = ViewItem::flags();
46  if (item() && item()->isEditable() && item()->isEnabled() && item()->data<QVariant>().isValid())
47  result |= Qt::ItemIsEditable;
48 
49  return result;
50 }
virtual Qt::ItemFlags flags() const
Returns Qt's item flags.
Definition: viewitem.cpp:231

References ModelView::ViewItem::flags(), and ModelView::ViewItem::item().

Referenced by TEST_F().

Here is the call graph for this function:

◆ insertRow()

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

Insert a row of items at index 'row'.

Definition at line 137 of file viewitem.cpp.

138 {
139  for (auto& x : items)
140  x->setParent(this);
141  p_impl->insertRow(row, std::move(items));
142 }

References ModelView::ViewItem::p_impl, and ModelView::ViewItem::row().

Here is the call graph for this function:

◆ item()

◆ item_role()

int ViewItem::item_role ( ) const
inherited

Definition at line 173 of file viewitem.cpp.

174 {
175  return p_impl->role;
176 }

References ModelView::ViewItem::p_impl.

Referenced by TEST_F().

◆ parent()

◆ removeRow()

void ViewItem::removeRow ( int  row)
inherited

Removes row of items at given 'row'. Items will be deleted.

Definition at line 146 of file viewitem.cpp.

147 {
148  p_impl->removeRow(row);
149 }

References ModelView::ViewItem::p_impl, and ModelView::ViewItem::row().

Here is the call graph for this function:

◆ row()

int ViewItem::row ( ) const
inherited

Returns the row where the item is located in its parent's child table, or -1 if the item has no parent.

Definition at line 181 of file viewitem.cpp.

182 {
183  auto index = parent() ? parent()->p_impl->index_of_child(this) : -1;
184  return index >= 0 ? index / parent()->p_impl->columns : -1;
185 }

References ModelView::ViewItem::p_impl, and ModelView::ViewItem::parent().

Referenced by ModelView::ViewItem::ViewItemImpl::child(), ModelView::ViewItem::child(), ModelView::ViewModelBase::indexFromItem(), ModelView::ViewItem::ViewItemImpl::insertRow(), ModelView::ViewItem::insertRow(), ModelView::ViewModelController::ViewModelControllerImpl::remove_row_of_views(), ModelView::ViewItem::ViewItemImpl::removeRow(), and ModelView::ViewItem::removeRow().

Here is the call graph for this function:

◆ rowCount()

int ViewItem::rowCount ( ) const
inherited

Returns the number of child item rows that the item has.

Definition at line 113 of file viewitem.cpp.

114 {
115  return p_impl->rows;
116 }

References ModelView::ViewItem::p_impl.

Referenced by ModelView::ViewModelBase::rowCount().

◆ setData()

bool ViewItem::setData ( const QVariant &  value,
int  qt_role 
)
virtualinherited

Sets the data to underlying SessionItem.

Converts data and roles from Qt definitions to what SessionItem expects.

Definition at line 221 of file viewitem.cpp.

222 {
223  if (p_impl->item && qt_role == Qt::EditRole)
224  return p_impl->item->setData(Utils::toCustomVariant(value), p_impl->role);
225  return false;
226 }
MVVM_MODEL_EXPORT Variant toCustomVariant(const Variant &standard)
Converts Qt variant to custom variant on board of SessionItem.

References ModelView::ViewItem::p_impl, and ModelView::Utils::toCustomVariant().

Referenced by TEST_F().

Here is the call graph for this function:

◆ setParent()

void ViewItem::setParent ( ViewItem parent)
protectedinherited

Definition at line 242 of file viewitem.cpp.

243 {
244  p_impl->parent_view_item = parent;
245 }

References ModelView::ViewItem::p_impl, and ModelView::ViewItem::parent().

Here is the call graph for this function:

Member Data Documentation

◆ p_impl


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