imagemodel.cpp Example File
itemviews/pixelator/imagemodel.cpp
#include "imagemodel.h"
ImageModel::ImageModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
void ImageModel::setImage(const QImage &image)
{
beginResetModel();
modelImage = image;
endResetModel();
}
int ImageModel::rowCount(const QModelIndex & ) const
{
return modelImage.height();
}
int ImageModel::columnCount(const QModelIndex & ) const
{
return modelImage.width();
}
QVariant ImageModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || role != Qt::DisplayRole)
return QVariant();
return qGray(modelImage.pixel(index.column(), index.row()));
}
QVariant ImageModel::headerData(int ,
Qt::Orientation ,
int role) const
{
if (role == Qt::SizeHintRole)
return QSize(1, 1);
return QVariant();
}