BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParameterTuningModel Class Reference

The ParameterTuningModel class represents parameters which can be tuned in real time in ParameterTuningWidget. More...

Inheritance diagram for ParameterTuningModel:
[legend]
Collaboration diagram for ParameterTuningModel:
[legend]

Public Member Functions

 ParameterTuningModel (QObject *parent=0)
 
int columnCount (const QModelIndex &parent) const
 
Qt::ItemFlags flags (const QModelIndex &proxyIndex) const
 
ParameterItemgetParameterItem (const QModelIndex &proxyIndex) const
 Returns ParameterItem from given proxy index. More...
 
QMimeData * mimeData (const QModelIndexList &proxyIndexes) const
 
Qt::DropActions supportedDragActions () const
 
Qt::DropActions supportedDropActions () const
 

Static Public Member Functions

static QModelIndex toSourceIndex (QModelIndex index)
 

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const
 

Private Attributes

int m_columns
 

Detailed Description

The ParameterTuningModel class represents parameters which can be tuned in real time in ParameterTuningWidget.

In the fitting activity context handles dragging of ParameterItem's to the FitParametersWidget.

Definition at line 28 of file ParameterTuningModel.h.

Constructor & Destructor Documentation

◆ ParameterTuningModel()

ParameterTuningModel::ParameterTuningModel ( QObject *  parent = 0)

Definition at line 21 of file ParameterTuningModel.cpp.

21 : FilterPropertyProxy(2, parent) {}
FilterPropertyProxy(int columns, QObject *parent=0)

Member Function Documentation

◆ columnCount()

int FilterPropertyProxy::columnCount ( const QModelIndex &  parent) const
inherited

Definition at line 18 of file FilterPropertyProxy.cpp.

19 {
20  Q_UNUSED(parent);
21  return m_columns;
22 }

References FilterPropertyProxy::m_columns.

◆ filterAcceptsRow()

bool FilterPropertyProxy::filterAcceptsRow ( int  sourceRow,
const QModelIndex &  sourceParent 
) const
protectedinherited

Definition at line 33 of file FilterPropertyProxy.cpp.

34 {
35  QModelIndex index = sourceModel()->index(sourceRow, 1, sourceParent);
36  if (!sourceParent.isValid())
37  return true;
38  const QString modelType = index.data(SessionFlags::ModelTypeRole).toString();
39  if (modelType == "Property" || modelType == "GroupProperty" || modelType == "Vector")
40  return false;
41 
42  return true; //! sourceModel()->data(index, Qt::DisplayRole).isValid();
43 }

References SessionFlags::ModelTypeRole.

◆ flags()

Qt::ItemFlags ParameterTuningModel::flags ( const QModelIndex &  proxyIndex) const

Definition at line 23 of file ParameterTuningModel.cpp.

24 {
25  Qt::ItemFlags result = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
26 
27  QModelIndex sourceIndex = toSourceIndex(proxyIndex);
28  if (sourceIndex.isValid()) {
29  if (sourceIndex.column() == SessionFlags::ITEM_VALUE)
30  result |= Qt::ItemIsEditable;
31 
32  const QString modelType = sourceIndex.data(SessionFlags::ModelTypeRole).toString();
33  if (modelType == "Parameter" && getParameterItem(proxyIndex))
34  result |= Qt::ItemIsDragEnabled;
35  }
36  return result;
37 }
static QModelIndex toSourceIndex(QModelIndex index)
ParameterItem * getParameterItem(const QModelIndex &proxyIndex) const
Returns ParameterItem from given proxy index.

References getParameterItem(), SessionFlags::ITEM_VALUE, SessionFlags::ModelTypeRole, and FilterPropertyProxy::toSourceIndex().

Here is the call graph for this function:

◆ getParameterItem()

ParameterItem * ParameterTuningModel::getParameterItem ( const QModelIndex &  proxyIndex) const

Returns ParameterItem from given proxy index.

Definition at line 55 of file ParameterTuningModel.cpp.

56 {
57  SessionModel* sessionModel = dynamic_cast<SessionModel*>(sourceModel());
58  ASSERT(sessionModel);
59 
60  QModelIndex sourceIndex = toSourceIndex(proxyIndex);
61  if (sourceIndex.column() == 0) {
62  return dynamic_cast<ParameterItem*>(sessionModel->itemForIndex(sourceIndex));
63  }
64  return nullptr;
65 }
#define ASSERT(condition)
Definition: Assert.h:31
The ParameterItem class represent a tuning value in a parameter tuning tree.
SessionItem * itemForIndex(const QModelIndex &index) const

References ASSERT, SessionModel::itemForIndex(), and FilterPropertyProxy::toSourceIndex().

Referenced by flags(), ParameterTuningWidget::getSelectedParameters(), and mimeData().

Here is the call graph for this function:

◆ mimeData()

QMimeData * ParameterTuningModel::mimeData ( const QModelIndexList &  proxyIndexes) const

Definition at line 39 of file ParameterTuningModel.cpp.

40 {
41  QMimeData* mimeData = new QMimeData();
42 
43  for (auto proxyIndex : proxyIndexes) {
44  if (ParameterItem* parameterItem = getParameterItem(proxyIndex)) {
45  QString path = FitParameterHelper::getParameterItemPath(parameterItem);
46  mimeData->setData(SessionXML::LinkMimeType, path.toLatin1());
47  break;
48  }
49  }
50  return mimeData;
51 }
static QString getParameterItemPath(const ParameterItem *parameterItem)
return path to given item in the ParameterTreeContainer
QMimeData * mimeData(const QModelIndexList &proxyIndexes) const
const QString LinkMimeType
Definition: SessionXML.h:27

References getParameterItem(), FitParameterHelper::getParameterItemPath(), and SessionXML::LinkMimeType.

Here is the call graph for this function:

◆ supportedDragActions()

Qt::DropActions ParameterTuningModel::supportedDragActions ( ) const
inline

Definition at line 42 of file ParameterTuningModel.h.

43 {
44  return Qt::CopyAction;
45 }

◆ supportedDropActions()

Qt::DropActions ParameterTuningModel::supportedDropActions ( ) const
inline

Definition at line 47 of file ParameterTuningModel.h.

48 {
49  return Qt::IgnoreAction;
50 }

◆ toSourceIndex()

QModelIndex FilterPropertyProxy::toSourceIndex ( QModelIndex  index)
staticinherited

Definition at line 24 of file FilterPropertyProxy.cpp.

25 {
26  FilterPropertyProxy* proxy =
27  dynamic_cast<FilterPropertyProxy*>(const_cast<QAbstractItemModel*>(index.model()));
28  if (proxy)
29  return proxy->mapToSource(index);
30  return index;
31 }
The FilterPropertyProxy class filters out all PropertyItem's and similar from SessionModel to have on...

Referenced by SampleTreeWidget::addItem(), ParameterTuningDelegate::createEditor(), SampleTreeWidget::deleteItem(), flags(), getParameterItem(), SampleTreeWidget::showContextMenu(), and RealSpaceCanvas::updateToSelection().

Member Data Documentation

◆ m_columns

int FilterPropertyProxy::m_columns
privateinherited

Definition at line 40 of file FilterPropertyProxy.h.

Referenced by FilterPropertyProxy::columnCount().


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