KDChartAttributesModel.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2007 Klaralvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KD Chart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KD Chart licenses may use this file in
00016  ** accordance with the KD Chart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.kdab.net/kdchart for
00023  **   information about KD Chart Commercial License Agreements.
00024  **
00025  ** Contact info@kdab.net if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 #ifndef __KDCHART_ATTRIBUTES_MODEL_H__
00030 #define __KDCHART_ATTRIBUTES_MODEL_H__
00031 
00032 #include "KDChartAbstractProxyModel.h"
00033 #include <QMap>
00034 #include <QVariant>
00035 
00036 #include "KDChartGlobal.h"
00037 
00038 namespace KDChart {
00039 
00043 class KDCHART_EXPORT AttributesModel : public AbstractProxyModel
00044 {
00045     Q_OBJECT
00046 
00047     friend class AttributesModelSerializer;
00048 
00049 public:
00050     enum PaletteType {
00051         PaletteTypeDefault = 0,
00052         PaletteTypeRainbow = 1,
00053         PaletteTypeSubdued = 2
00054     };
00055 
00056     explicit AttributesModel( QAbstractItemModel* model, QObject * parent = 0 );
00057     ~AttributesModel();
00058 
00059     /* Copies the internal data (maps and palette) of another
00060        AttributesModel* into this one.
00061     */
00062     void initFrom( const AttributesModel* other );
00063 
00064     /* Returns true if both, all of the attributes set, and
00065      * the palette set is equal in both of the AttributeModels.
00066     */
00067     bool compare( const AttributesModel* other )const;
00068 
00069     bool compareAttributes( int role, const QVariant& a, const QVariant& b )const;
00070 
00071     /* Attributes Model specific API */
00072     bool setModelData( const QVariant value, int role );
00073     QVariant modelData( int role ) const;
00074 
00077     bool isKnownAttributesRole( int role ) const;
00078 
00080     void setPaletteType( PaletteType type );
00081     PaletteType paletteType() const;
00082 
00086     QVariant data(int role) const;
00087 
00091     QVariant data(int column, int role) const;
00092 
00094     QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
00096     int rowCount(const QModelIndex& ) const;
00098     int columnCount(const QModelIndex& ) const;
00100     QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
00102     bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::DisplayRole);
00104     bool resetData ( const QModelIndex & index, int role = Qt::DisplayRole);
00106     bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value,
00107                          int role = Qt::DisplayRole);
00109     bool resetHeaderData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole);
00111     void setSourceModel ( QAbstractItemModel* sourceModel );
00112 
00115     void setDefaultForRole( int role, const QVariant& value );
00116 
00117 Q_SIGNALS:
00118     void attributesChanged( const QModelIndex&, const QModelIndex& );
00119 
00120 protected:
00122     const QMap<int, QMap<int, QMap<int, QVariant> > > dataMap()const;
00124     const QMap<int, QMap<int, QVariant> > horizontalHeaderDataMap()const;
00126     const QMap<int, QMap<int, QVariant> > verticalHeaderDataMap()const;
00128     const QMap<int, QVariant> modelDataMap()const;
00130     void setDataMap( const QMap<int, QMap<int, QMap<int, QVariant> > > map );
00132     void setHorizontalHeaderDataMap( const QMap<int, QMap<int, QVariant> > map );
00134     void setVerticalHeaderDataMap( const QMap<int, QMap<int, QVariant> > map );
00136     void setModelDataMap( const QMap<int, QVariant> map );
00137 
00138 private Q_SLOTS:
00139     void slotRowsAboutToBeInserted( const QModelIndex& parent, int start, int end );
00140     void slotColumnsAboutToBeInserted( const QModelIndex& parent, int start, int end );
00141     void slotRowsInserted( const QModelIndex& parent, int start, int end );
00142     void slotColumnsInserted( const QModelIndex& parent, int start, int end );
00143 
00144     void slotRowsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
00145     void slotColumnsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
00146     void slotRowsRemoved( const QModelIndex& parent, int start, int end );
00147     void slotColumnsRemoved( const QModelIndex& parent, int start, int end );
00148 
00149     void slotDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight );
00150 
00151 private:
00152     // helper
00153     QVariant defaultsForRole( int role ) const;
00154 
00155     QMap<int, QMap<int, QMap<int, QVariant> > > mDataMap;
00156     QMap<int, QMap<int, QVariant> > mHorizontalHeaderDataMap;
00157     QMap<int, QMap<int, QVariant> > mVerticalHeaderDataMap;
00158     QMap<int, QVariant> mModelDataMap;
00159     QMap<int, QVariant> mDefaultsMap;
00160     PaletteType mPaletteType;
00161 };
00162 
00163 }
00164 
00165 #endif

Generated on Thu Mar 4 23:19:10 2010 for KD Chart 2 by  doxygen 1.5.4