Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //My Model
- #include "Model.h"
- #include <QDebug>
- Model::Model(QObject *parent) :
- QAbstractItemModel(parent)
- {
- }
- QModelIndex Model::index(int r, int c, const QModelIndex&) const
- {
- return createIndex(r,c);
- }
- QModelIndex Model::parent(const QModelIndex&) const
- {
- return QModelIndex();
- }
- int Model::rowCount(const QModelIndex&) const
- {
- static int a = 0;
- qDebug() << "Model::rowCount data_.size() " << a++ << ": " << data_.size();
- return data_.size();
- }
- int Model::columnCount(const QModelIndex&) const
- {
- return 1;
- }
- QVariant Model::data(const QModelIndex& index, int role) const
- {
- switch (role)
- {
- case Qt::DisplayRole:
- {
- static int a = 0;
- if (data_.size() > index.row())
- {
- //qDebug() << "Model::data data_[index.row()] " << a++ << ": " << data_.at(index.row());
- return data_.at(index.row());
- }
- else
- {
- return QVariant();
- }
- }
- default:
- return QVariant();
- }
- }
- bool Model::set_data(int data)
- {
- beginInsertRows(QModelIndex(),0,data_.size());
- data_.append(data);
- static int a = 0;
- qDebug() << "Model::set_data data_ " << a++ << ":" << data_;
- endInsertRows();
- emit dataChanged(createIndex(0,0),createIndex(data_.size(),0));
- return true;
- }
- //My Proxy
- #include "Proxy.h"
- #include <QDebug>
- Proxy::Proxy(QAbstractItemModel* source_model,QObject *parent) :
- QAbstractProxyModel(parent)
- {
- }
- QModelIndex Proxy::mapToSource(const QModelIndex & proxyIndex) const
- {
- return sourceModel()->index(proxyIndex.row(),proxyIndex.column());
- }
- QModelIndex Proxy::mapFromSource(const QModelIndex & sourceIndex) const
- {
- return sourceModel()->index(sourceIndex.row(),sourceIndex.column());
- }
- QModelIndex Proxy::index(int row, int column,
- const QModelIndex &parent) const
- {
- return createIndex(row,column);
- }
- QModelIndex Proxy::parent(const QModelIndex &child) const
- {
- return QModelIndex();
- }
- int Proxy::rowCount(const QModelIndex &parent) const
- {
- static int i = 0;
- qDebug() << "Proxy row count " << i++ << ": " << sourceModel()->rowCount();
- return sourceModel()->rowCount();
- }
- int Proxy::columnCount(const QModelIndex &parent) const
- {
- return sourceModel()->columnCount();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement