KDeclarative

columnproxymodel.h
1 /*
2  SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef COLUMNPROXYMODEL_H
8 #define COLUMNPROXYMODEL_H
9 
10 #include <QAbstractListModel>
11 
12 class ColumnProxyModel : public QAbstractListModel
13 {
14  Q_OBJECT
15  Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
16 // Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel) //rootIndex sets the model
17  Q_PROPERTY(int column READ column WRITE setColumn)
18  public:
19  explicit ColumnProxyModel(QObject* parent = nullptr);
20 
21  void setRootIndex(const QModelIndex& idx);
22  QModelIndex rootIndex() const;
23 
24  void setSourceModel(QAbstractItemModel* sourceModel);
25  QAbstractItemModel* sourceModel() const { return m_sourceModel; }
26 
27  int column() const;
28  void setColumn(int col);
29 
30  Q_SCRIPTABLE static QModelIndex indexFromModel(QAbstractItemModel* model, int row, int column=0, const QModelIndex& parent=QModelIndex());
31  Q_SCRIPTABLE QModelIndex indexAt(int row, const QModelIndex& parent = QModelIndex()) const;
32 
33  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
34  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
35  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
36  QHash<int, QByteArray> roleNames() const override;
37 
38  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
39 
40  Q_SIGNALS:
41  void rootIndexChanged();
42 
43  private:
44  QModelIndex proxyIndex(const QModelIndex& sourceIndex) const;
45  QModelIndex sourceIndex(const QModelIndex& proxyIndex) const;
46 
47  int m_column;
48  QModelIndex m_index;
49  QAbstractItemModel* m_sourceModel;
50 
51  private Q_SLOTS:
52  void considerRowsAboutToBeInserted(const QModelIndex&,int,int);
53  void considerRowsAboutToBeMoved(const QModelIndex& sourceParent, int rA, int rB, const QModelIndex& destParent, int rD);
54  void considerRowsAboutToBeRemoved(const QModelIndex&,int,int);
55  void considerRowsRemoved(const QModelIndex&,int,int);
56  void considerRowsMoved(const QModelIndex&,int,int,const QModelIndex&,int);
57  void considerRowsInserted(const QModelIndex&,int,int);
58  void considerDataChanged(const QModelIndex& idxA, const QModelIndex& idxB);
59  void sourceDestroyed(QObject* source);
60 };
61 
62 #endif
virtual int rowCount(const QModelIndex &parent) const const =0
virtual QHash< int, QByteArray > roleNames() const const
Q_SIGNALSQ_SIGNALS
Q_OBJECTQ_OBJECT
DisplayRole
virtual QVariant data(const QModelIndex &index, int role) const const =0
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const const
Q_PROPERTY(...)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Orientation
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.