ModelAggregator.h
Go to the documentation of this file.
00001 #ifndef MODELAGGREGATOR_H
00002 #define MODELAGGREGATOR_H
00003 
00004 #include <QAbstractItemModel>
00005 #include <QAbstractProxyModel>
00006 #include <QModelIndex>
00007 #include <QList>
00008 
00009 namespace Aseba
00010 {
00011         class ModelAggregator : public QAbstractItemModel
00012         {
00013         public:
00014                 ModelAggregator(QObject* parent = 0);
00015 
00016                 // interface for the aggregator
00017                 void addModel(QAbstractItemModel* model, unsigned int column = 0);
00018 
00019                 // interface for QAbstractItemModel
00020                 int columnCount(const QModelIndex &parent = QModelIndex()) const;
00021                 int rowCount(const QModelIndex &parent = QModelIndex()) const;
00022                 QVariant data(const QModelIndex &index, int role) const;
00023                 bool hasIndex(int row, int column, const QModelIndex &parent) const;
00024                 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00025                 QModelIndex parent(const QModelIndex &child) const;
00026 
00027         protected:
00028                 struct ModelDescription
00029                 {
00030                         QAbstractItemModel* model;
00031                         unsigned int column;
00032                 };
00033 
00034                 typedef QList<ModelDescription> ModelList;
00035                 ModelList models;
00036         };
00037 
00038 
00039         // keep only the leaves of a tree, and present them as a table
00040         class TreeChainsawFilter : public QAbstractProxyModel
00041         {
00042                 Q_OBJECT
00043 
00044         public:
00045                 TreeChainsawFilter(QObject* parent = 0) : QAbstractProxyModel(parent) { }
00046 
00047                 // model interface
00048                 int rowCount(const QModelIndex &parent = QModelIndex()) const;
00049                 int columnCount(const QModelIndex &parent = QModelIndex()) const;
00050                 bool hasIndex(int row, int column, const QModelIndex &parent) const;
00051                 QModelIndex index(int row, int column, const QModelIndex &parent) const;
00052                 QModelIndex parent(const QModelIndex &child) const;
00053 
00054                 // proxy interface
00055                 void setSourceModel(QAbstractItemModel *sourceModel);
00056                 QModelIndex mapFromSource(const QModelIndex & sourceIndex) const;
00057                 QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
00058 
00059                 void sort(int column, Qt::SortOrder order);
00060 
00061         protected:
00062                 struct ModelIndexLink
00063                 {
00064                         QModelIndex source;
00065                         QModelIndex proxy;
00066                 };
00067 
00068                 void sortWalkTree(const QModelIndex& parent);
00069 
00070                 typedef QList<ModelIndexLink> IndexLinkList;
00071                 IndexLinkList indexList;
00072         };
00073 };
00074 
00075 #endif // MODELAGGREGATOR_H


aseba
Author(s): Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:17:16