KDChartDatasetProxyModel.h

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2007 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Chart library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
00012  ** accordance with the KD Chart Commercial License Agreement provided with
00013  ** the Software.
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  ** See http://www.kdab.net/kdchart for
00019  **   information about KDChart Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
00023  **
00024  **********************************************************************/
00025 
00026 #ifndef KDCHARTDATASETPROXYMODEL_H
00027 #define KDCHARTDATASETPROXYMODEL_H
00028 
00029 #include <QVector>
00030 #include <QSortFilterProxyModel>
00031 
00032 #include "kdchart_export.h"
00033 
00034 namespace KDChart {
00035 
00036     class IndexOutOfBoundsException;
00037 
00038     typedef QVector<int> DatasetDescriptionVector;
00039 
00058     class KDCHART_EXPORT DatasetProxyModel : public QSortFilterProxyModel
00059     {
00060         Q_OBJECT
00061     public:
00066         explicit DatasetProxyModel ( QObject* parent = 0 );
00067 
00068         QModelIndex buddy( const QModelIndex& index ) const;
00069 
00070         Qt::ItemFlags flags( const QModelIndex& index ) const;
00071 
00072         QModelIndex index( int row, int column,
00073                            const QModelIndex &parent = QModelIndex() ) const;
00074         QModelIndex parent(const QModelIndex &child ) const;
00075 
00077         QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
00078 
00080         QModelIndex mapToSource ( const QModelIndex& proxyIndex ) const;
00081 
00083         QVariant data(const QModelIndex &index, int role) const;
00084 
00086         bool setData( const QModelIndex& index, const QVariant& value, int role );
00087 
00089         QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
00090 
00092         void setSourceModel(QAbstractItemModel *sourceModel);
00093 
00096         void setSourceRootIndex(const QModelIndex& rootIdx);
00097 
00098 
00099     public Q_SLOTS:
00104         void resetDatasetDescriptions();
00105 
00110         void setDatasetColumnDescriptionVector ( const DatasetDescriptionVector& columnConfig );
00111 
00116         void setDatasetRowDescriptionVector ( const DatasetDescriptionVector& rowConfig );
00117 
00119         void setDatasetDescriptionVectors (
00120             const DatasetDescriptionVector& rowConfig,
00121             const DatasetDescriptionVector& columnConfig );
00122 
00123         // FIXME: add convenience methods to configure common dataset
00124         // selections (like rectangular areas etc)
00125 
00126     protected:
00128         bool filterAcceptsColumn ( int sourceColumn,
00129                                    const QModelIndex & ) const;
00130 
00131 
00133         bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const;
00134 
00135     private:
00136 
00138         int mapProxyColumnToSource ( const int& proxyColumn ) const;
00139 
00141         int mapSourceColumnToProxy ( const int& sourceColumn ) const;
00142 
00144         int mapProxyRowToSource ( const int& proxyRow ) const;
00145 
00147         int mapSourceRowToProxy ( const int& sourceRow ) const;
00148 
00172         void initializeDatasetDecriptors (
00173             const DatasetDescriptionVector& inConfiguration,
00174             int sourceCount,
00175             DatasetDescriptionVector& outSourceToProxyMap,
00176             DatasetDescriptionVector& outProxyToSourceMap );
00177 
00178         DatasetDescriptionVector mColSrcToProxyMap;
00179         DatasetDescriptionVector mColProxyToSrcMap;
00180         DatasetDescriptionVector mRowSrcToProxyMap;
00181         DatasetDescriptionVector mRowProxyToSrcMap;
00182 
00183         int mProxyRowCount;
00184         int mProxyColumnCount;
00185         QModelIndex mRootIndex;
00186     };
00187 
00188 }
00189 
00190 
00191 #endif

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