BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ProxyModelStrategy Class Referenceabstract

Base class for proxy strategies in ComponentProxyModel. More...

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

Public Types

using map_t = QMap< QPersistentModelIndex, QPersistentModelIndex >
 

Public Member Functions

 ProxyModelStrategy ()
 
virtual ~ProxyModelStrategy ()=default
 
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...
 
virtual bool processSourceIndex (const QModelIndex &index)=0
 Mapping of proxy model indices to indices in source model. 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

Base class for proxy strategies in ComponentProxyModel.

Definition at line 26 of file ProxyModelStrategy.h.

Member Typedef Documentation

◆ map_t

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

Definition at line 28 of file ProxyModelStrategy.h.

Constructor & Destructor Documentation

◆ ProxyModelStrategy()

ProxyModelStrategy::ProxyModelStrategy ( )

Definition at line 19 of file ProxyModelStrategy.cpp.

19 : m_source(nullptr), m_proxy(nullptr) {}
SessionModel * m_source
ComponentProxyModel * m_proxy

◆ ~ProxyModelStrategy()

virtual ProxyModelStrategy::~ProxyModelStrategy ( )
virtualdefault

Member Function Documentation

◆ buildModelMap()

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

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
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(), m_proxy, m_proxySourceParent, m_source, m_sourceRootIndex, m_sourceToProxy, and processSourceIndex().

Referenced by ComponentProxyStrategy::onDataChanged().

Here is the call graph for this function:

◆ createProxyIndex()

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

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

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

◆ onDataChanged()

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

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()

virtual bool ProxyModelStrategy::processSourceIndex ( const QModelIndex &  index)
protectedpure virtual

Mapping of proxy model indices to indices in source model.

Implemented in IndentityProxyStrategy, and ComponentProxyStrategy.

Referenced by buildModelMap().

◆ proxySourceParent()

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

Definition at line 49 of file ProxyModelStrategy.cpp.

50 {
51  return m_proxySourceParent;
52 }

References m_proxySourceParent.

◆ setRootIndex()

void ProxyModelStrategy::setRootIndex ( const QModelIndex &  sourceRootIndex)

Definition at line 54 of file ProxyModelStrategy.cpp.

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

References m_sourceRootIndex.

◆ sourceToProxy()

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

Definition at line 44 of file ProxyModelStrategy.cpp.

45 {
46  return m_sourceToProxy;
47 }

References m_sourceToProxy.

Member Data Documentation

◆ m_proxy

ComponentProxyModel* ProxyModelStrategy::m_proxy
protected

Definition at line 52 of file ProxyModelStrategy.h.

Referenced by buildModelMap(), and createProxyIndex().

◆ m_proxySourceParent

◆ m_source

SessionModel* ProxyModelStrategy::m_source
protected

◆ m_sourceRootIndex

QPersistentModelIndex ProxyModelStrategy::m_sourceRootIndex
protected

◆ m_sourceToProxy

QMap<QPersistentModelIndex, QPersistentModelIndex> ProxyModelStrategy::m_sourceToProxy
protected

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