KD Chart 2: KDChart::DatasetProxyModel class Reference

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# KDChart::DatasetProxyModel Class Reference

`#include <KDChartDatasetProxyModel.h>`

Inheritance diagram for KDChart::DatasetProxyModel:

[legend]
Collaboration diagram for KDChart::DatasetProxyModel:
[legend]
List of all members.

## Detailed Description

DatasetProxyModel takes a KDChart dataset configuration and translates it into a filtering proxy model.

The resulting model will only contain the part of the model that is selected by the dataset, and the according row and column header data.

Currently, this model is implemented for table models only. The way it would work with models representing a tree is to be decided.

The column selection is configured by passing a dataset description vector to the model. This vector (of integers) is supposed to have one value for each column of the original model. If the value at position x is -1, column x of the original model is not included in the dataset. If it is between 0 and (columnCount() -1), it is the column the source column is mapped to in the resulting model. Any other value is an error.

Definition at line 58 of file KDChartDatasetProxyModel.h.

## Public Member Functions
QVariant | data (const QModelIndex &index, int role) const
| Overloaded from base class.
| DatasetProxyModel (QObject *parent=0)
| Create a DatasetProxyModel.
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
| Overloaded from base class.
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const
QModelIndex | mapFromSource (const QModelIndex &sourceIndex) const
| Implements the mapping from the source to the proxy indexes.
QModelIndex | mapToSource (const QModelIndex &proxyIndex) const
| Implements the mapping from the proxy to the source indexes.
QModelIndex | parent (const QModelIndex &child) const
void | setDatasetColumnDescriptionVector (const DatasetDescriptionVector &columnConfig)
| Configure the dataset selection for the columns.
void | setDatasetDescriptionVectors (const DatasetDescriptionVector &rowConfig, const DatasetDescriptionVector &columnConfig)
| Convenience method to configure rows and columns in one step.
void | setDatasetRowDescriptionVector (const DatasetDescriptionVector &rowConfig)
| Configure the dataset selection for the rows.
void | setSourceModel (QAbstractItemModel *sourceModel)
| Overloaded from base class.
void | setSourceRootIndex (const QModelIndex &rootIdx)
| Set the root index of the table in the source model.
## Public Attributes
public | Q_SLOTS: void resetDatasetDescriptions()
## Protected Member Functions
bool | filterAcceptsColumn (int sourceColumn, const QModelIndex &) const
| Decide whether the column is accepted.
bool | filterAcceptsRow (int source_row, const QModelIndex &source_parent) const
| Decide whether the row is accepted.

## Constructor & Destructor Documentation

DatasetProxyModel::DatasetProxyModel | ( | QObject * | parent = 0 | ) | `[explicit]`

| Create a DatasetProxyModel. Without further configuration, this model is invalid. See also: setDatasetDescriptionVector Definition at line 35 of file KDChartDatasetProxyModel.cpp.
    00036     : QSortFilterProxyModel ( parent )
    00037 {
    00038 }

## Member Function Documentation

QVariant DatasetProxyModel::data | ( | const QModelIndex & | index,
|  | int | role
| ) | const

| Overloaded from base class. Definition at line 208 of file KDChartDatasetProxyModel.cpp.
    00209 {
    00210    return sourceModel()->data( mapToSource ( index ), role );
    00211 }

bool DatasetProxyModel::filterAcceptsColumn | ( | int | sourceColumn,
|  | const QModelIndex & |
| ) | const`[protected]`

| Decide whether the column is accepted. Definition at line 135 of file KDChartDatasetProxyModel.cpp.
    00137 {
    00138     if ( mColSrcToProxyMap.isEmpty() )
    00139     {   // no column mapping set up yet, all columns are passed down:
    00140         return true;
    00141     } else {
    00142         Q_ASSERT ( sourceModel() );
    00143         Q_ASSERT ( mColSrcToProxyMap.size() == sourceModel()->columnCount(mRootIndex) );
    00144         if ( mColSrcToProxyMap[sourceColumn] == -1 )
    00145         {   // this column is explicitly not accepted:
    00146             return false;
    00147         } else {
    00148             Q_ASSERT ( mColSrcToProxyMap[sourceColumn] >= 0
    00149                        && mColSrcToProxyMap[sourceColumn] < mColSrcToProxyMap.size() );
    00150             return true;
    00151         }
    00152     }
    00153 }

bool DatasetProxyModel::filterAcceptsRow | ( | int | source_row,
|  | const QModelIndex & | source_parent
| ) | const`[protected]`

| Decide whether the row is accepted. Definition at line 115 of file KDChartDatasetProxyModel.cpp.
    00117 {
    00118     if ( mRowSrcToProxyMap.isEmpty() )
    00119     {   // no row mapping set, all rows are passed down:
    00120         return true;
    00121     } else {
    00122         Q_ASSERT ( sourceModel() );
    00123         Q_ASSERT ( mRowSrcToProxyMap.size() == sourceModel()->rowCount(mRootIndex) );
    00124         if ( mRowSrcToProxyMap[sourceRow] == -1 )
    00125         {   // this row is explicitly not accepted:
    00126             return false;
    00127         } else {
    00128             Q_ASSERT ( mRowSrcToProxyMap[sourceRow] >= 0
    00129                        && mRowSrcToProxyMap[sourceRow] < mRowSrcToProxyMap.size() );
    00130             return true;
    00131         }
    00132     }
    00133 }

QVariant DatasetProxyModel::headerData | ( | int | section,
|  | Qt::Orientation | orientation,
|  | int | role = Qt::DisplayRole
| ) | const

| Overloaded from base class. Definition at line 213 of file KDChartDatasetProxyModel.cpp.
    00214 {
    00215     if ( orientation == Qt::Horizontal )
    00216     {
    00217         if ( mapProxyColumnToSource ( section ) == -1 )
    00218         {
    00219             return QVariant();
    00220         } else {
    00221             return sourceModel()->headerData ( mapProxyColumnToSource ( section ),
    00222                                                        orientation,  role );
    00223         }
    00224     } else {
    00225         if ( mapProxyRowToSource ( section ) == -1 )
    00226         {
    00227             return QVariant();
    00228         } else {
    00229             return sourceModel()->headerData ( mapProxyRowToSource ( section ),
    00230                                                        orientation, role );
    00231         }
    00232     }
    00233 }

QModelIndex DatasetProxyModel::index | ( | int | row,
|  | int | column,
|  | const QModelIndex & | parent = QModelIndex()
| ) | const

| Definition at line 68 of file KDChartDatasetProxyModel.cpp. References mapFromSource().
    00070 {
    00071     return mapFromSource( sourceModel()->index( mapProxyRowToSource(row),
    00072                                                 mapProxyColumnToSource(column),
    00073                                                 parent ) );
    00074 }

QModelIndex DatasetProxyModel::mapFromSource | ( | const QModelIndex & | sourceIndex | ) | const

| Implements the mapping from the source to the proxy indexes. Definition at line 81 of file KDChartDatasetProxyModel.cpp. Referenced by index(), and parent().
    00082 {
    00083     Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::mapFromSource", "A source "
    00084                  "model must be set before the selection can be configured." );
    00085
    00086     if ( !sourceIndex.isValid() ) return sourceIndex;
    00087
    00088     if ( mRowSrcToProxyMap.isEmpty() && mColSrcToProxyMap.isEmpty() )
    00089     {
    00090         return createIndex ( sourceIndex.row(), sourceIndex.column(),
    00091                              sourceIndex.internalPointer() );
    00092     } else {
    00093         int row = mapSourceRowToProxy ( sourceIndex.row() );
    00094         int column = mapSourceColumnToProxy ( sourceIndex.column() );
    00095         return createIndex ( row, column, sourceIndex.internalPointer() );
    00096     }
    00097 }

QModelIndex DatasetProxyModel::mapToSource | ( | const QModelIndex & | proxyIndex | ) | const

| Implements the mapping from the proxy to the source indexes. Definition at line 99 of file KDChartDatasetProxyModel.cpp.
    00100 {
    00101     Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::mapToSource", "A source "
    00102                  "model must be set before the selection can be configured." );
    00103
    00104     if ( !proxyIndex.isValid() ) return proxyIndex;
    00105     if ( mRowSrcToProxyMap.isEmpty() && mColSrcToProxyMap.isEmpty() )
    00106     {
    00107         return sourceModel()->index( proxyIndex.row(),  proxyIndex.column(), mRootIndex );
    00108     } else {
    00109         int row = mapProxyRowToSource ( proxyIndex.row() );
    00110         int column = mapProxyColumnToSource ( proxyIndex.column() );
    00111         return sourceModel()->index( row, column, mRootIndex );
    00112     }
    00113 }

QModelIndex DatasetProxyModel::parent | ( | const QModelIndex & | child | ) | const

| Definition at line 76 of file KDChartDatasetProxyModel.cpp. References mapFromSource().
    00077 {
    00078     return mapFromSource( sourceModel()->parent( child ) );
    00079 }

void DatasetProxyModel::setDatasetColumnDescriptionVector | ( | const DatasetDescriptionVector & | columnConfig | ) |

| Configure the dataset selection for the columns. Every call to this method resets the previous dataset description. Definition at line 50 of file KDChartDatasetProxyModel.cpp. References KDChart::DatasetDescriptionVector. Referenced by setDatasetDescriptionVectors().
    00052 {
    00053     Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::setDatasetColumnDescriptionVector",
    00054                  "A source model must be set before the selection can be configured." );
    00055     initializeDatasetDecriptors ( configuration, sourceModel()->columnCount(mRootIndex),
    00056                                   mColSrcToProxyMap, mColProxyToSrcMap );
    00057     clear(); // clear emits layoutChanged()
    00058 }

void DatasetProxyModel::setDatasetDescriptionVectors | ( | const DatasetDescriptionVector & | rowConfig,
|  | const DatasetDescriptionVector & | columnConfig
| ) |

| Convenience method to configure rows and columns in one step. Definition at line 60 of file KDChartDatasetProxyModel.cpp. References KDChart::DatasetDescriptionVector, setDatasetColumnDescriptionVector(), and setDatasetRowDescriptionVector().
    00063 {
    00064     setDatasetRowDescriptionVector( rowConfig );
    00065     setDatasetColumnDescriptionVector ( columnConfig );
    00066 }

void DatasetProxyModel::setDatasetRowDescriptionVector | ( | const DatasetDescriptionVector & | rowConfig | ) |

| Configure the dataset selection for the rows. Every call to this method resets the previous dataset description. Definition at line 40 of file KDChartDatasetProxyModel.cpp. References KDChart::DatasetDescriptionVector. Referenced by setDatasetDescriptionVectors().
    00042 {
    00043     Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::setDatasetRowDescriptionVector",
    00044                  "A source model must be set before the selection can be configured." );
    00045     initializeDatasetDecriptors ( configuration, sourceModel()->rowCount(mRootIndex),
    00046                                   mRowSrcToProxyMap,  mRowProxyToSrcMap );
    00047     clear(); // clear emits layoutChanged()
    00048 }

void DatasetProxyModel::setSourceModel | ( | QAbstractItemModel * | sourceModel | ) |

| Overloaded from base class. Definition at line 260 of file KDChartDatasetProxyModel.cpp.
    00261 {
    00262     QSortFilterProxyModel::setSourceModel ( sourceModel );
    00263     mRootIndex = QModelIndex();
    00264     connect ( sourceModel,  SIGNAL ( layoutChanged() ),
    00265               SLOT( resetDatasetDescriptions() ) );
    00266
    00267     resetDatasetDescriptions();
    00268 }

void DatasetProxyModel::setSourceRootIndex | ( | const QModelIndex & | rootIdx | ) |

| Set the root index of the table in the source model. Definition at line 270 of file KDChartDatasetProxyModel.cpp.
    00271 {
    00272     mRootIndex = rootIdx;
    00273     resetDatasetDescriptions();
    00274 }

## Member Data Documentation

public KDChart::DatasetProxyModel::Q_SLOTS

| Definition at line 97 of file KDChartDatasetProxyModel.h.

The documentation for this class was generated from the following files:

- KDChartDatasetProxyModel.h
- KDChartDatasetProxyModel.cpp