KD Chart 2  [rev.2.7]
KDChartAttributesModel.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 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 __KDCHART_ATTRIBUTES_MODEL_H__
24 #define __KDCHART_ATTRIBUTES_MODEL_H__
25 
27 #include <QMap>
28 #include <QVariant>
29 
30 #include "KDChartGlobal.h"
31 
32 namespace KDChart {
33 
46 class KDCHART_EXPORT AttributesModel : public AbstractProxyModel
47 {
48  Q_OBJECT
50 public:
51  enum PaletteType {
52  PaletteTypeDefault = 0,
53  PaletteTypeRainbow = 1,
54  PaletteTypeSubdued = 2
55  };
56 
57  explicit AttributesModel( QAbstractItemModel* model, QObject * parent = 0 );
58  ~AttributesModel() override;
59 
63  void initFrom( const AttributesModel* other );
64 
68  bool compare( const AttributesModel* other ) const;
69 
70  bool compareAttributes( int role, const QVariant& a, const QVariant& b ) const;
71 
72  /* Attributes Model specific API */
73  bool setModelData( const QVariant value, int role );
74  QVariant modelData( int role ) const;
75 
78  bool isKnownAttributesRole( int role ) const;
79 
81  void setPaletteType( PaletteType type );
82  PaletteType paletteType() const;
83 
87  QVariant data(int role) const;
88 
92  QVariant data(int column, int role) const;
93 
95  QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
97  int rowCount(const QModelIndex& ) const override;
99  int columnCount(const QModelIndex& ) const override;
101  QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const override;
103  bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::DisplayRole) override;
105  bool resetData ( const QModelIndex & index, int role = Qt::DisplayRole);
107  bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value,
108  int role = Qt::DisplayRole) override;
110  virtual QVariant defaultHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
112  bool resetHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole);
114  void setSourceModel ( QAbstractItemModel* sourceModel ) override;
115 
118  void setDefaultForRole( int role, const QVariant& value );
119 
121  void setDatasetDimension( int dimension );
122  int datasetDimension() const;
123 
124 Q_SIGNALS:
125  void attributesChanged( const QModelIndex&, const QModelIndex& );
126 
127 private Q_SLOTS:
128  void slotRowsAboutToBeInserted( const QModelIndex& parent, int start, int end );
129  void slotColumnsAboutToBeInserted( const QModelIndex& parent, int start, int end );
130  void slotRowsInserted( const QModelIndex& parent, int start, int end );
131  void slotColumnsInserted( const QModelIndex& parent, int start, int end );
132 
133  void slotRowsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
134  void slotColumnsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
135  void slotRowsRemoved( const QModelIndex& parent, int start, int end );
136  void slotColumnsRemoved( const QModelIndex& parent, int start, int end );
137 
138  void slotDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight );
139 
140 private:
141  // helper
142  QVariant defaultsForRole( int role ) const;
143  bool compareHeaderDataMaps( const QMap< int, QMap< int, QVariant > >& mapA,
144  const QMap< int, QMap< int, QVariant > >& mapB ) const;
145 
146  void removeEntriesFromDataMap( int start, int end );
147  void removeEntriesFromDirectionDataMaps( Qt::Orientation dir, int start, int end );
148 };
149 
150 }
151 
152 #endif
#define KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC(X)
Definition: KDChartGlobal.h:82
A proxy model used for decorating data with attributes.
Base class for all proxy models used inside KD Chart.
Class only listed here to document inheritance of some KDChart classes.

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/