BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ProxyModelStrategy.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ProxyModelStrategy.h
6 //! @brief Defines class ProxyModelStrategy
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_COREGUI_MODELS_PROXYMODELSTRATEGY_H
16 #define BORNAGAIN_GUI_COREGUI_MODELS_PROXYMODELSTRATEGY_H
17 
18 #include <QPersistentModelIndex>
19 
20 class SessionModel;
22 class SessionItem;
23 
24 //! Base class for proxy strategies in ComponentProxyModel.
25 
27 public:
28  using map_t = QMap<QPersistentModelIndex, QPersistentModelIndex>;
29 
31  virtual ~ProxyModelStrategy() = default;
32 
33  void buildModelMap(SessionModel* source, ComponentProxyModel* proxy);
34  virtual void onDataChanged(SessionModel* source, ComponentProxyModel* proxy);
35 
36  const map_t& sourceToProxy();
37  const map_t& proxySourceParent();
38 
39  void setRootIndex(const QModelIndex& sourceRootIndex);
40 
41 protected:
42  QModelIndex createProxyIndex(int nrow, int ncol, void* adata);
43  virtual bool processSourceIndex(const QModelIndex& index) = 0;
44 
45  //!< Mapping of proxy model indices to indices in source model
46  QMap<QPersistentModelIndex, QPersistentModelIndex> m_sourceToProxy;
47  //!< Mapping of proxy model indices to indices of parent in source model
48  QMap<QPersistentModelIndex, QPersistentModelIndex> m_proxySourceParent;
49 
50  QPersistentModelIndex m_sourceRootIndex;
53 };
54 
55 //! Strategy for ComponentProxyModel which makes it identical to source model.
56 
58 protected:
59  bool processSourceIndex(const QModelIndex& index);
60 };
61 
62 #endif // BORNAGAIN_GUI_COREGUI_MODELS_PROXYMODELSTRATEGY_H
Proxy model to adjust SessionModel for component editor (right bottom corner of SampleView and simila...
Strategy for ComponentProxyModel which makes it identical to source model.
bool processSourceIndex(const QModelIndex &index)
Builds one-to-one mapping for source and proxy.
Base class for proxy strategies in ComponentProxyModel.
const map_t & proxySourceParent()
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 > map_t
QMap< QPersistentModelIndex, QPersistentModelIndex > m_proxySourceParent
QModelIndex createProxyIndex(int nrow, int ncol, void *adata)
Method to ask proxy to create an index using friendship of ProxyModelStrategy and ComponentProxyModel...
const map_t & sourceToProxy()
void buildModelMap(SessionModel *source, ComponentProxyModel *proxy)
void setRootIndex(const QModelIndex &sourceRootIndex)
virtual ~ProxyModelStrategy()=default
virtual bool processSourceIndex(const QModelIndex &index)=0
Mapping of proxy model indices to indices in source model.
virtual void onDataChanged(SessionModel *source, ComponentProxyModel *proxy)