KD Chart 2  [rev.2.6]
KDChartDatasetProxyModel.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2019 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDCHARTDATASETPROXYMODEL_H
24 #define KDCHARTDATASETPROXYMODEL_H
25 
26 #include <QVector>
27 #include <QSortFilterProxyModel>
28 
29 #include "kdchart_export.h"
30 
31 namespace KDChart {
32 
33  class IndexOutOfBoundsException;
34 
36 
55  class KDCHART_EXPORT DatasetProxyModel : public QSortFilterProxyModel
56  {
57  Q_OBJECT
58  public:
63  explicit DatasetProxyModel ( QObject* parent = 0 );
64 
65  QModelIndex buddy( const QModelIndex& index ) const;
66 
67  Qt::ItemFlags flags( const QModelIndex& index ) const;
68 
69  QModelIndex index( int row, int column,
70  const QModelIndex &parent = QModelIndex() ) const;
71  QModelIndex parent(const QModelIndex &child ) const;
72 
74  QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
75 
77  QModelIndex mapToSource ( const QModelIndex& proxyIndex ) const;
78 
80  QVariant data(const QModelIndex &index, int role) const;
81 
83  bool setData( const QModelIndex& index, const QVariant& value, int role );
84 
86  QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
87 
89  void setSourceModel(QAbstractItemModel *sourceModel);
90 
93  void setSourceRootIndex(const QModelIndex& rootIdx);
94 
95 
96  public Q_SLOTS:
101  void resetDatasetDescriptions();
102 
107  void setDatasetColumnDescriptionVector ( const DatasetDescriptionVector& columnConfig );
108 
113  void setDatasetRowDescriptionVector ( const DatasetDescriptionVector& rowConfig );
114 
116  void setDatasetDescriptionVectors (
117  const DatasetDescriptionVector& rowConfig,
118  const DatasetDescriptionVector& columnConfig );
119 
120  // FIXME: add convenience methods to configure common dataset
121  // selections (like rectangular areas etc)
122 
123  protected:
125  bool filterAcceptsColumn ( int sourceColumn,
126  const QModelIndex & ) const;
127 
128 
130  bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const;
131 
132  private:
133 
135  int mapProxyColumnToSource ( const int& proxyColumn ) const;
136 
138  int mapSourceColumnToProxy ( const int& sourceColumn ) const;
139 
141  int mapProxyRowToSource ( const int& proxyRow ) const;
142 
144  int mapSourceRowToProxy ( const int& sourceRow ) const;
145 
169  void initializeDatasetDecriptors (
170  const DatasetDescriptionVector& inConfiguration,
171  int sourceCount,
172  DatasetDescriptionVector& outSourceToProxyMap,
173  DatasetDescriptionVector& outProxyToSourceMap );
174 
175  DatasetDescriptionVector mColSrcToProxyMap;
176  DatasetDescriptionVector mColProxyToSrcMap;
177  DatasetDescriptionVector mRowSrcToProxyMap;
178  DatasetDescriptionVector mRowProxyToSrcMap;
179 
180  int mProxyRowCount;
181  int mProxyColumnCount;
182  QModelIndex mRootIndex;
183  };
184 
185 }
186 
187 
188 #endif
DatasetProxyModel takes a KDChart dataset configuration and translates it into a filtering proxy mode...
QVector< int > DatasetDescriptionVector
Class only listed here to document inheritance of some KDChart classes.
Class only listed here to document inheritance of some KDChart classes.

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
https://www.kdab.com/
https://www.kdab.com/products/kd-chart/