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

Strategy for ComponentProxyModel which makes it identical to source model. More...

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

Public Types

using map_t = QMap< QPersistentModelIndex, QPersistentModelIndex >
 

Public Member Functions

void buildModelMap (SessionModel *source, ComponentProxyModel *proxy)
 
virtual void onDataChanged (SessionModel *source, ComponentProxyModel *proxy)
 
const map_tproxySourceParent ()
 
void setRootIndex (const QModelIndex &sourceRootIndex)
 
const map_tsourceToProxy ()
 

Protected Member Functions

QModelIndex createProxyIndex (int nrow, int ncol, void *adata)
 Method to ask proxy to create an index using friendship of ProxyModelStrategy and ComponentProxyModel. More...
 
bool processSourceIndex (const QModelIndex &index)
 Builds one-to-one mapping for source and proxy. More...
 

Protected Attributes

ComponentProxyModelm_proxy
 
QMap< QPersistentModelIndex, QPersistentModelIndex > m_proxySourceParent
 
SessionModelm_source
 
QPersistentModelIndex m_sourceRootIndex
 
QMap< QPersistentModelIndex, QPersistentModelIndex > m_sourceToProxy
 Mapping of proxy model indices to indices of parent in source model. More...
 

Detailed Description

Strategy for ComponentProxyModel which makes it identical to source model.

Definition at line 57 of file ProxyModelStrategy.h.

Member Typedef Documentation

◆ map_t

using ProxyModelStrategy::map_t = QMap<QPersistentModelIndex, QPersistentModelIndex>
inherited

Definition at line 28 of file ProxyModelStrategy.h.

Member Function Documentation

◆ buildModelMap()

void ProxyModelStrategy::buildModelMap ( SessionModel source,
ComponentProxyModel proxy 
)
inherited

Definition at line 21 of file ProxyModelStrategy.cpp.

22 {
23  m_sourceToProxy.clear();
24  m_proxySourceParent.clear();
25  m_source = source;
26  m_proxy = proxy;
27 
28  ModelUtils::iterate_if(m_sourceRootIndex, source, [=](const QModelIndex& index) -> bool {
29  return processSourceIndex(index);
30  });
31 
32  // kind of hack since we have to visit col=1 which has QModelIndex() parent
33  if (m_sourceRootIndex.isValid())
35 }
QMap< QPersistentModelIndex, QPersistentModelIndex > m_sourceToProxy
Mapping of proxy model indices to indices of parent in source model.
QPersistentModelIndex m_sourceRootIndex
SessionModel * m_source
ComponentProxyModel * m_proxy
QMap< QPersistentModelIndex, QPersistentModelIndex > m_proxySourceParent
virtual bool processSourceIndex(const QModelIndex &index)=0
Mapping of proxy model indices to indices in source model.
void iterate_if(const QModelIndex &index, const QAbstractItemModel *model, const std::function< bool(const QModelIndex &)> &fun)
Iterates through all model indices and calls user function.
Definition: ModelUtils.cpp:47

References ModelUtils::iterate_if(), ProxyModelStrategy::m_proxy, ProxyModelStrategy::m_proxySourceParent, ProxyModelStrategy::m_source, ProxyModelStrategy::m_sourceRootIndex, ProxyModelStrategy::m_sourceToProxy, and ProxyModelStrategy::processSourceIndex().

Referenced by ComponentProxyStrategy::onDataChanged().

Here is the call graph for this function:

◆ createProxyIndex()

QModelIndex ProxyModelStrategy::createProxyIndex ( int  nrow,
int  ncol,
void *  adata 
)
protectedinherited

Method to ask proxy to create an index using friendship of ProxyModelStrategy and ComponentProxyModel.

Definition at line 62 of file ProxyModelStrategy.cpp.

63 {
64  ASSERT(m_proxy);
65  return m_proxy->createIndex(nrow, ncol, adata);
66 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, and ProxyModelStrategy::m_proxy.

Referenced by ComponentProxyStrategy::processDefaultItem(), ComponentProxyStrategy::processGroupItem(), ComponentProxyStrategy::processRootItem(), processSourceIndex(), and ComponentProxyStrategy::processSubGroupItem().

◆ onDataChanged()

void ProxyModelStrategy::onDataChanged ( SessionModel source,
ComponentProxyModel proxy 
)
virtualinherited

Reimplemented in ComponentProxyStrategy.

Definition at line 37 of file ProxyModelStrategy.cpp.

38 {
39  Q_UNUSED(source);
40  Q_UNUSED(proxy);
41  // we do not expect here change of model layout
42 }

◆ processSourceIndex()

bool IndentityProxyStrategy::processSourceIndex ( const QModelIndex &  index)
protectedvirtual

Builds one-to-one mapping for source and proxy.

Implements ProxyModelStrategy.

Definition at line 70 of file ProxyModelStrategy.cpp.

71 {
72  QPersistentModelIndex proxyIndex =
73  createProxyIndex(index.row(), index.column(), index.internalPointer());
74  m_sourceToProxy.insert(QPersistentModelIndex(index), proxyIndex);
75 
76  QPersistentModelIndex sourceParent;
77  if (index.parent().isValid())
78  sourceParent = index.parent();
79 
80  m_proxySourceParent.insert(proxyIndex, sourceParent);
81 
82  return true;
83 }
QModelIndex createProxyIndex(int nrow, int ncol, void *adata)
Method to ask proxy to create an index using friendship of ProxyModelStrategy and ComponentProxyModel...

References ProxyModelStrategy::createProxyIndex(), ProxyModelStrategy::m_proxySourceParent, and ProxyModelStrategy::m_sourceToProxy.

Here is the call graph for this function:

◆ proxySourceParent()

const ProxyModelStrategy::map_t & ProxyModelStrategy::proxySourceParent ( )
inherited

Definition at line 49 of file ProxyModelStrategy.cpp.

50 {
51  return m_proxySourceParent;
52 }

References ProxyModelStrategy::m_proxySourceParent.

◆ setRootIndex()

void ProxyModelStrategy::setRootIndex ( const QModelIndex &  sourceRootIndex)
inherited

Definition at line 54 of file ProxyModelStrategy.cpp.

55 {
56  m_sourceRootIndex = QPersistentModelIndex(sourceRootIndex);
57 }

References ProxyModelStrategy::m_sourceRootIndex.

◆ sourceToProxy()

const ProxyModelStrategy::map_t & ProxyModelStrategy::sourceToProxy ( )
inherited

Definition at line 44 of file ProxyModelStrategy.cpp.

45 {
46  return m_sourceToProxy;
47 }

References ProxyModelStrategy::m_sourceToProxy.

Member Data Documentation

◆ m_proxy

ComponentProxyModel* ProxyModelStrategy::m_proxy
protectedinherited

◆ m_proxySourceParent

◆ m_source

SessionModel* ProxyModelStrategy::m_source
protectedinherited

◆ m_sourceRootIndex

QPersistentModelIndex ProxyModelStrategy::m_sourceRootIndex
protectedinherited

◆ m_sourceToProxy

QMap<QPersistentModelIndex, QPersistentModelIndex> ProxyModelStrategy::m_sourceToProxy
protectedinherited

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