KDChartDatasetProxyModel.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2011 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 KDCHARTDATASETPROXYMODEL_H
00024 #define KDCHARTDATASETPROXYMODEL_H
00025 
00026 #include <QVector>
00027 #include <QSortFilterProxyModel>
00028 
00029 #include "kdchart_export.h"
00030 
00031 namespace KDChart {
00032 
00033     class IndexOutOfBoundsException;
00034 
00035     typedef QVector<int> DatasetDescriptionVector;
00036 
00055     class KDCHART_EXPORT DatasetProxyModel : public QSortFilterProxyModel
00056     {
00057         Q_OBJECT
00058     public:
00063         explicit DatasetProxyModel ( QObject* parent = 0 );
00064 
00065         QModelIndex buddy( const QModelIndex& index ) const;
00066 
00067         Qt::ItemFlags flags( const QModelIndex& index ) const;
00068 
00069         QModelIndex index( int row, int column,
00070                            const QModelIndex &parent = QModelIndex() ) const;
00071         QModelIndex parent(const QModelIndex &child ) const;
00072 
00074         QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
00075 
00077         QModelIndex mapToSource ( const QModelIndex& proxyIndex ) const;
00078 
00080         QVariant data(const QModelIndex &index, int role) const;
00081 
00083         bool setData( const QModelIndex& index, const QVariant& value, int role );
00084 
00086         QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
00087 
00089         void setSourceModel(QAbstractItemModel *sourceModel);
00090 
00093         void setSourceRootIndex(const QModelIndex& rootIdx);
00094 
00095 
00096     public Q_SLOTS:
00101         void resetDatasetDescriptions();
00102 
00107         void setDatasetColumnDescriptionVector ( const DatasetDescriptionVector& columnConfig );
00108 
00113         void setDatasetRowDescriptionVector ( const DatasetDescriptionVector& rowConfig );
00114 
00116         void setDatasetDescriptionVectors (
00117             const DatasetDescriptionVector& rowConfig,
00118             const DatasetDescriptionVector& columnConfig );
00119 
00120         // FIXME: add convenience methods to configure common dataset
00121         // selections (like rectangular areas etc)
00122 
00123     protected:
00125         bool filterAcceptsColumn ( int sourceColumn,
00126                                    const QModelIndex & ) const;
00127 
00128 
00130         bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const;
00131 
00132     private:
00133 
00135         int mapProxyColumnToSource ( const int& proxyColumn ) const;
00136 
00138         int mapSourceColumnToProxy ( const int& sourceColumn ) const;
00139 
00141         int mapProxyRowToSource ( const int& proxyRow ) const;
00142 
00144         int mapSourceRowToProxy ( const int& sourceRow ) const;
00145 
00169         void initializeDatasetDecriptors (
00170             const DatasetDescriptionVector& inConfiguration,
00171             int sourceCount,
00172             DatasetDescriptionVector& outSourceToProxyMap,
00173             DatasetDescriptionVector& outProxyToSourceMap );
00174 
00175         DatasetDescriptionVector mColSrcToProxyMap;
00176         DatasetDescriptionVector mColProxyToSrcMap;
00177         DatasetDescriptionVector mRowSrcToProxyMap;
00178         DatasetDescriptionVector mRowProxyToSrcMap;
00179 
00180         int mProxyRowCount;
00181         int mProxyColumnCount;
00182         QModelIndex mRootIndex;
00183     };
00184 
00185 }
00186 
00187 
00188 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/