KChart

KChartAttributesModel.h
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __KCHART_ATTRIBUTES_MODEL_H__
21 #define __KCHART_ATTRIBUTES_MODEL_H__
22 
23 #include "KChartAbstractProxyModel.h"
24 #include <QMap>
25 #include <QVariant>
26 
27 #include "KChartGlobal.h"
28 
29 namespace KChart {
30 
43 class KCHART_EXPORT AttributesModel : public AbstractProxyModel
44 {
45  Q_OBJECT
46  KCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC( AttributesModel )
47 public:
48  enum PaletteType {
49  PaletteTypeDefault = 0,
50  PaletteTypeRainbow = 1,
51  PaletteTypeSubdued = 2
52  };
53 
54  explicit AttributesModel( QAbstractItemModel* model, QObject * parent = nullptr );
55  ~AttributesModel();
56 
60  void initFrom( const AttributesModel* other );
61 
65  bool compare( const AttributesModel* other ) const;
66 
67  bool compareAttributes( int role, const QVariant& a, const QVariant& b ) const;
68 
69  /* Attributes Model specific API */
70  bool setModelData( const QVariant value, int role );
71  QVariant modelData( int role ) const;
72 
75  bool isKnownAttributesRole( int role ) const;
76 
78  void setPaletteType( PaletteType type );
79  PaletteType paletteType() const;
80 
84  QVariant data(int role) const;
85 
89  QVariant data(int column, int role) const;
90 
92  QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
94  int rowCount(const QModelIndex& ) const override;
96  int columnCount(const QModelIndex& ) const override;
98  QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const override;
100  bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::DisplayRole) override;
102  bool resetData ( const QModelIndex & index, int role = Qt::DisplayRole);
104  bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value,
105  int role = Qt::DisplayRole) override;
107  virtual QVariant defaultHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
109  bool resetHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole);
111  void setSourceModel ( QAbstractItemModel* sourceModel ) override;
112 
115  void setDefaultForRole( int role, const QVariant& value );
116 
118  void setDatasetDimension( int dimension );
119  int datasetDimension() const;
120 
121 Q_SIGNALS:
122  void attributesChanged( const QModelIndex&, const QModelIndex& );
123 
124 private Q_SLOTS:
125  void slotRowsAboutToBeInserted( const QModelIndex& parent, int start, int end );
126  void slotColumnsAboutToBeInserted( const QModelIndex& parent, int start, int end );
127  void slotRowsInserted( const QModelIndex& parent, int start, int end );
128  void slotColumnsInserted( const QModelIndex& parent, int start, int end );
129 
130  void slotRowsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
131  void slotColumnsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
132  void slotRowsRemoved( const QModelIndex& parent, int start, int end );
133  void slotColumnsRemoved( const QModelIndex& parent, int start, int end );
134 
135  void slotDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight );
136 
137 private:
138  // helper
139  QVariant defaultsForRole( int role ) const;
140  bool compareHeaderDataMaps( const QMap< int, QMap< int, QVariant > >& mapA,
141  const QMap< int, QMap< int, QVariant > >& mapB ) const;
142 
143  void removeEntriesFromDataMap( int start, int end );
144  void removeEntriesFromDirectionDataMaps( Qt::Orientation dir, int start, int end );
145 };
146 
147 }
148 
149 #endif
Base class for all proxy models used inside KChart.
Class only listed here to document inheritance of some KChart classes.
Contains KChart macros.
DisplayRole
A proxy model used for decorating data with attributes.
Orientation
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 23 2020 22:36:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.