# KDChartDatasetProxyModel.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002  ** Copyright (C) 2006 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 index( int row, int column,
    00069                            const QModelIndex &parent = QModelIndex() ) const;
    00070         QModelIndex parent(const QModelIndex &child ) const;
    00071
    00073         QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
    00074
    00076         QModelIndex mapToSource ( const QModelIndex& proxyIndex ) const;
    00077
    00079         QVariant data(const QModelIndex &index, int role) const;
    00080
    00082         QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
    00083
    00085         void setSourceModel(QAbstractItemModel *sourceModel);
    00086
    00089         void setSourceRootIndex(const QModelIndex& rootIdx);
    00090
    00091
    00092     public Q_SLOTS:
    00097         void resetDatasetDescriptions();
    00098
    00103         void setDatasetColumnDescriptionVector ( const DatasetDescriptionVector& columnConfig );
    00104
    00109         void setDatasetRowDescriptionVector ( const DatasetDescriptionVector& rowConfig );
    00110
    00112         void setDatasetDescriptionVectors (
    00113             const DatasetDescriptionVector& rowConfig,
    00114             const DatasetDescriptionVector& columnConfig );
    00115
    00116         // FIXME: add convenience methods to configure common dataset
    00117         // selections (like rectangular areas etc)
    00118
    00119     protected:
    00121         bool filterAcceptsColumn ( int sourceColumn,
    00122                                    const QModelIndex & ) const;
    00123
    00124
    00126         bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const;
    00127
    00128     private:
    00129
    00131         int mapProxyColumnToSource ( const int& proxyColumn ) const;
    00132
    00134         int mapSourceColumnToProxy ( const int& sourceColumn ) const;
    00135
    00137         int mapProxyRowToSource ( const int& proxyRow ) const;
    00138
    00140         int mapSourceRowToProxy ( const int& sourceRow ) const;
    00141
    00165         void initializeDatasetDecriptors (
    00166             const DatasetDescriptionVector& inConfiguration,
    00167             int sourceCount,
    00168             DatasetDescriptionVector& outSourceToProxyMap,
    00169             DatasetDescriptionVector& outProxyToSourceMap );
    00170
    00171         DatasetDescriptionVector mColSrcToProxyMap;
    00172         DatasetDescriptionVector mColProxyToSrcMap;
    00173         DatasetDescriptionVector mRowSrcToProxyMap;
    00174         DatasetDescriptionVector mRowProxyToSrcMap;
    00175
    00176         int mProxyRowCount;
    00177         int mProxyColumnCount;
    00178         QModelIndex mRootIndex;
    00179     };
    00180
    00181 }
    00182
    00183
    00184 #endif