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

Represents the view of SessionItem's data in a single cell of ViewModel. More...

Inheritance diagram for ModelView::ViewItem:
[legend]

Classes

struct  ViewItemImpl
 

Public Member Functions

virtual ~ViewItem ()
 
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...
 
virtual QVariant data (int qt_role) const
 Returns the data for given role according to Qt::ItemDataRole namespace definitions. More...
 
virtual Qt::ItemFlags flags () const
 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

 ViewItem (SessionItem *item, int role)
 
void setParent (ViewItem *parent)
 

Private Attributes

std::unique_ptr< ViewItemImplp_impl
 

Detailed Description

Represents the view of SessionItem's data in a single cell of ViewModel.

Definition at line 29 of file viewitem.h.

Constructor & Destructor Documentation

◆ ~ViewItem()

ViewItem::~ViewItem ( )
virtualdefault

◆ ViewItem()

ViewItem::ViewItem ( SessionItem item,
int  role 
)
protected

Definition at line 105 of file viewitem.cpp.

105  : p_impl(std::make_unique<ViewItemImpl>(item, role))
106 {
107 }
std::unique_ptr< ViewItemImpl > p_impl
Definition: viewitem.h:70
SessionItem * item() const
Definition: viewitem.cpp:168

Member Function Documentation

◆ appendRow()

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

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 }

References p_impl.

◆ child()

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

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 column(), p_impl, and row().

Here is the call graph for this function:

◆ children()

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

Definition at line 237 of file viewitem.cpp.

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

References p_impl.

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

◆ clear()

void ViewItem::clear ( )

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 p_impl.

◆ column()

int ViewItem::column ( ) const

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 p_impl, and parent().

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

Here is the call graph for this function:

◆ columnCount()

int ViewItem::columnCount ( ) const

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 p_impl.

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

◆ data()

QVariant ViewItem::data ( int  qt_role) const
virtual

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

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

Reimplemented in ModelView::ViewDataItem, ModelView::ViewLabelItem, and ModelView::ViewEmptyItem.

Definition at line 199 of file viewitem.cpp.

200 {
201  if (!p_impl->item)
202  return QVariant();
203 
204  if (qt_role == Qt::DisplayRole || qt_role == Qt::EditRole)
205  return Utils::toQtVariant(p_impl->data());
206 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
207  else if (qt_role == Qt::ForegroundRole)
208 #else
209  else if (qt_role == Qt::TextColorRole)
210 #endif
211  return Utils::TextColorRole(*p_impl->item);
212  else if (qt_role == Qt::ToolTipRole)
213  return Utils::ToolTipRole(*p_impl->item);
214  else
215  return QVariant();
216 }
MVVM_VIEWMODEL_EXPORT QVariant TextColorRole(const SessionItem &item)
Returns text color for given item.
MVVM_VIEWMODEL_EXPORT QVariant ToolTipRole(const SessionItem &item)
Returns tooltip role for given item.
MVVM_MODEL_EXPORT Variant toQtVariant(const Variant &custom)
Converts custom variant to standard variant which Qt views will understand.
QVariant ToolTipRole(const SessionItem &item, int ncol=0)
Returns tooltip for given item.
QVariant ForegroundRole(const SessionItem &item)
Returns text color for given item.

References SessionItemUtils::ForegroundRole(), p_impl, ModelView::Utils::TextColorRole(), ModelView::Utils::ToolTipRole(), SessionItemUtils::ToolTipRole(), and ModelView::Utils::toQtVariant().

Referenced by ModelView::PropertyFlatView::PropertyFlatViewImpl::create_label(), ModelView::ViewLabelItem::data(), and ModelView::ViewDataItem::data().

Here is the call graph for this function:

◆ flags()

Qt::ItemFlags ViewItem::flags ( ) const
virtual

Returns Qt's item flags.

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

Reimplemented in ModelView::ViewDataItem.

Definition at line 231 of file viewitem.cpp.

232 {
233  Qt::ItemFlags result = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
234  return result;
235 }

Referenced by ModelView::ViewDataItem::flags(), and TEST_F().

◆ insertRow()

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

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 p_impl, and row().

Here is the call graph for this function:

◆ item()

◆ item_role()

int ViewItem::item_role ( ) const

Definition at line 173 of file viewitem.cpp.

174 {
175  return p_impl->role;
176 }

References p_impl.

Referenced by TEST_F().

◆ parent()

ViewItem * ViewItem::parent ( ) const

◆ removeRow()

void ViewItem::removeRow ( int  row)

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 p_impl, and row().

Here is the call graph for this function:

◆ row()

int ViewItem::row ( ) const

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 p_impl, and parent().

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

Here is the call graph for this function:

◆ rowCount()

int ViewItem::rowCount ( ) const

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 p_impl.

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

◆ setData()

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

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 p_impl, and ModelView::Utils::toCustomVariant().

Referenced by TEST_F().

Here is the call graph for this function:

◆ setParent()

void ViewItem::setParent ( ViewItem parent)
protected

Definition at line 242 of file viewitem.cpp.

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

References p_impl, and parent().

Here is the call graph for this function:

Member Data Documentation

◆ p_impl

std::unique_ptr<ViewItemImpl> ModelView::ViewItem::p_impl
private

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