Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
rootindexproxymodel.h
1 /****************************************************************************\
2  Copyright 2021 Luca Beldi
3  Licensed under the Apache License, Version 2.0 (the "License");
4  you may not use this file except in compliance with the License.
5  You may obtain a copy of the License at
6  http://www.apache.org/licenses/LICENSE-2.0
7  Unless required by applicable law or agreed to in writing, software
8  distributed under the License is distributed on an "AS IS" BASIS,
9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  See the License for the specific language governing permissions and
11  limitations under the License.
12 \****************************************************************************/
13 
14 #ifndef ROOTINDEXPROXY_H
15 #define ROOTINDEXPROXY_H
16 #include <modelutilities_global.h>
17 #include <QIdentityProxyModel>
18 class RootIndexProxyModelPrivate;
19 class MODELUTILITIES_EXPORT RootIndexProxyModel : public QIdentityProxyModel
20 {
21  Q_OBJECT
22  Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
23  Q_DISABLE_COPY(RootIndexProxyModel)
24  Q_DECLARE_PRIVATE_D(m_dptr, RootIndexProxyModel)
25 public:
26  explicit RootIndexProxyModel(QObject *parent = Q_NULLPTR);
28  QModelIndex rootIndex() const;
29  void setRootIndex(const QModelIndex &root);
30  QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
31  QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
32  void setSourceModel(QAbstractItemModel *sourceModel) override;
33  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
34  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
35  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
36  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
37  bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
38  bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
39  bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
40  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
41  bool hasChildren(const QModelIndex &parent) const override;
42  bool canFetchMore(const QModelIndex &parent) const override;
43  void fetchMore(const QModelIndex &parent) override;
44  bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent,
45  int destinationChild) override;
46  bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
47 Q_SIGNALS:
48  void rootIndexChanged();
49 
50 protected:
51  RootIndexProxyModel(RootIndexProxyModelPrivate &dptr, QObject *parent);
52  RootIndexProxyModelPrivate *m_dptr;
53 };
54 #endif // ROOTINDEXPROXY_H
This proxy model will display only the portion of a tree model with the common ancestor rootIndex.
Definition: rootindexproxymodel.h:20