BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ComponentProxyModel.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ComponentProxyModel.h
6 //! @brief Defines class ComponentProxyModel
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_COMPONENTPROXYMODEL_H
16 #define BORNAGAIN_GUI_COREGUI_MODELS_COMPONENTPROXYMODEL_H
17 
19 #include <QAbstractProxyModel>
20 #include <QMap>
21 #include <QPersistentModelIndex>
22 #include <memory>
23 
24 class SessionModel;
25 class ProxyModelStrategy;
26 
27 //! Proxy model to adjust SessionModel for component editor (right bottom corner of SampleView
28 //! and similar).
29 //! The model hides all SessionItems which are not PropertyItems.
30 //! The model hides GroupPropertyItem children and shows grand-children of currently selected item
31 //! one level up.
32 
33 class ComponentProxyModel : public QAbstractProxyModel {
34  Q_OBJECT
35 
36  friend class ProxyModelStrategy;
37 
38 public:
39  ComponentProxyModel(QObject* parent = nullptr);
40 
41  void setSessionModel(SessionModel* model);
42 
43  void setRootIndex(const QModelIndex& sourceRootIndex);
44 
45  void setProxyStrategy(ProxyModelStrategy* strategy);
46 
47  QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
48  QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
49 
50  QModelIndex index(int row, int column, const QModelIndex& parent = {}) const;
51  QModelIndex parent(const QModelIndex& child) const;
52  int rowCount(const QModelIndex& parent = {}) const;
53  int columnCount(const QModelIndex& parent = {}) const;
54 
55  bool hasChildren(const QModelIndex& parent) const;
56 
57 private slots:
58  void sourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
59  const QVector<int>& roles = {});
60  void sourceRowsInserted(const QModelIndex& parent, int start, int end);
61  void sourceRowsRemoved(const QModelIndex& parent, int start, int end);
62 
63 private:
64  void buildModelMap();
65  void updateModelMap();
66 
68  std::unique_ptr<ProxyModelStrategy> m_proxyStrategy;
69 };
70 
71 #endif // BORNAGAIN_GUI_COREGUI_MODELS_COMPONENTPROXYMODEL_H
Defines class ProxyModelStrategy.
Proxy model to adjust SessionModel for component editor (right bottom corner of SampleView and simila...
ComponentProxyModel(QObject *parent=nullptr)
std::unique_ptr< ProxyModelStrategy > m_proxyStrategy
int rowCount(const QModelIndex &parent={}) const
QModelIndex index(int row, int column, const QModelIndex &parent={}) const
void setRootIndex(const QModelIndex &sourceRootIndex)
void setProxyStrategy(ProxyModelStrategy *strategy)
QModelIndex parent(const QModelIndex &child) const
bool hasChildren(const QModelIndex &parent) const
void buildModelMap()
Main method to build the map of persistent indeses.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
void sourceRowsRemoved(const QModelIndex &parent, int start, int end)
int columnCount(const QModelIndex &parent={}) const
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
void setSessionModel(SessionModel *model)
void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles={})
void sourceRowsInserted(const QModelIndex &parent, int start, int end)
Base class for proxy strategies in ComponentProxyModel.