Hi,
What I'am trying to do: Overwrite QFileSystemModel's setData and data to implement Caching of pictures in the shown directory.
I use a QListView for testing purpose.
Here is the relevant code:
My Class with QFileSystemModel as parent:
.h-file:
#ifndef QPICSINFILESYSTEMMODEL_H
#define QPICSINFILESYSTEMMODEL_H
#include <QFileSystemModel>
#include <QCache>
#include <QDebug>
/* This Model holds all Picturefiles with a cached QPixmap of
* them.
*/
class PicsInFileSystemModel : public QFileSystemModel
{
public:
PicsInFileSystemModel();
QVariant data (const QModelIndex & index, int role);
private:
QCache<qint64,QPixmap> *cache; //Cache for the pictures
};
#endif // QPICSINFILESYSTEMMODEL_
.cpp-file:
#include "PicsInFileSystemModel.h"
PicsInFileSystemModel::PicsInFileSystemModel()
{
QStringList myFilter;
this->setFilter(QDir::Files | QDir::AllDirs);
this->setRootPath(QDir::rootPath());//QDir::homePath());
myFilter << "jpeg" << "jpg" << "png";
//this->setNameFilters(myFilter);
}
/* Reimplement data to send the pictures to the cache */
QVariant PicsInFileSystemModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) {
qDebug() << "index: " << index << "role: " << role;
return ((QFileSystemModel)this).data(index,role);
}
How I call the object:
pics = new PicsInFileSystemModel;
form->listViewPictures->setModel(pics);
form->listViewPictures->setRootIndex(pics->index(
"mypath"));
So here is the question: In my opinion I should see many debug outputs when the View access the Model. But there is nothing. Has anyone an idea what I'am doing wrong?
Thanks!
EDIT: The answers work. I also had to change this
return ((QFileSystemModel)this).data(index,role);
into
QFileSystemModel::data(index,role))