KD Chart 2 [rev.2.4]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #ifndef __KDCHART_ATTRIBUTES_MODEL_H__ 00024 #define __KDCHART_ATTRIBUTES_MODEL_H__ 00025 00026 #include "KDChartAbstractProxyModel.h" 00027 #include <QMap> 00028 #include <QVariant> 00029 00030 #include "KDChartGlobal.h" 00031 00032 namespace KDChart { 00033 00037 class KDCHART_EXPORT AttributesModel : public AbstractProxyModel 00038 { 00039 Q_OBJECT 00040 00041 friend class AttributesModelSerializer; 00042 00043 public: 00044 enum PaletteType { 00045 PaletteTypeDefault = 0, 00046 PaletteTypeRainbow = 1, 00047 PaletteTypeSubdued = 2 00048 }; 00049 00050 explicit AttributesModel( QAbstractItemModel* model, QObject * parent = 0 ); 00051 ~AttributesModel(); 00052 00056 void initFrom( const AttributesModel* other ); 00057 00061 bool compare( const AttributesModel* other )const; 00062 00063 bool compareAttributes( int role, const QVariant& a, const QVariant& b )const; 00064 00065 /* Attributes Model specific API */ 00066 bool setModelData( const QVariant value, int role ); 00067 QVariant modelData( int role ) const; 00068 00071 bool isKnownAttributesRole( int role ) const; 00072 00074 void setPaletteType( PaletteType type ); 00075 PaletteType paletteType() const; 00076 00080 QVariant data(int role) const; 00081 00085 QVariant data(int column, int role) const; 00086 00088 QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; 00090 int rowCount(const QModelIndex& ) const; 00092 int columnCount(const QModelIndex& ) const; 00094 QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const; 00096 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::DisplayRole); 00098 bool resetData ( const QModelIndex & index, int role = Qt::DisplayRole); 00100 bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, 00101 int role = Qt::DisplayRole); 00103 virtual QVariant defaultHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; 00105 bool resetHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole); 00107 void setSourceModel ( QAbstractItemModel* sourceModel ); 00108 00111 void setDefaultForRole( int role, const QVariant& value ); 00112 00113 Q_SIGNALS: 00114 void attributesChanged( const QModelIndex&, const QModelIndex& ); 00115 00116 protected: 00118 const QMap<int, QMap<int, QMap<int, QVariant> > > dataMap()const; 00120 const QMap<int, QMap<int, QVariant> > horizontalHeaderDataMap()const; 00122 const QMap<int, QMap<int, QVariant> > verticalHeaderDataMap()const; 00124 const QMap<int, QVariant> modelDataMap()const; 00126 void setDataMap( const QMap<int, QMap<int, QMap<int, QVariant> > > map ); 00128 void setHorizontalHeaderDataMap( const QMap<int, QMap<int, QVariant> > map ); 00130 void setVerticalHeaderDataMap( const QMap<int, QMap<int, QVariant> > map ); 00132 void setModelDataMap( const QMap<int, QVariant> map ); 00133 00134 private Q_SLOTS: 00135 void slotRowsAboutToBeInserted( const QModelIndex& parent, int start, int end ); 00136 void slotColumnsAboutToBeInserted( const QModelIndex& parent, int start, int end ); 00137 void slotRowsInserted( const QModelIndex& parent, int start, int end ); 00138 void slotColumnsInserted( const QModelIndex& parent, int start, int end ); 00139 00140 void slotRowsAboutToBeRemoved( const QModelIndex& parent, int start, int end ); 00141 void slotColumnsAboutToBeRemoved( const QModelIndex& parent, int start, int end ); 00142 void slotRowsRemoved( const QModelIndex& parent, int start, int end ); 00143 void slotColumnsRemoved( const QModelIndex& parent, int start, int end ); 00144 00145 void slotDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight ); 00146 00147 private: 00148 // helper 00149 QVariant defaultsForRole( int role ) const; 00150 00151 void removeEntriesFromDataMap( int start, int end ); 00152 void removeEntriesFromDirectionDataMaps( Qt::Orientation dir, int start, int end ); 00153 QMap<int, QMap<int, QMap<int, QVariant> > > mDataMap; 00154 QMap<int, QMap<int, QVariant> > mHorizontalHeaderDataMap; 00155 QMap<int, QMap<int, QVariant> > mVerticalHeaderDataMap; 00156 QMap<int, QVariant> mModelDataMap; 00157 QMap<int, QVariant> mDefaultsMap; 00158 PaletteType mPaletteType; 00159 }; 00160 00161 } 00162 00163 #endif