Hi everybody

I am trying to create a little treeview based on a QFileSystem. The folders will be selected to perform several analysis with the files inside.
I would like to provide more information in the treeview columns such as the number of files in the subfolder, some values extracted from path name etc.

I spent several hours on google, this forum and others Qt resources and I still have difficulties to understand how it works.
I found different solutions. The one I investigated is to create a subclass of the QFileSystemModel class and overwriting flags, data, setdata methods.
I succeed to did it with this very basic code:


Qt Code:
  1. TreeModel::TreeModel(const QString &path, const QStringList &headers, const MainAnalysis &data, QObject *parent)
  2. : QFileSystemModel(parent)
  3. {
  4. this->setReadOnly(true);
  5. this->setFilter(QDir::Dirs| QDir::NoDotAndDotDot);
  6. this->setRootPath(path);
  7. headerList = headers;
  8.  
  9. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. int TreeModel::columnCount(const QModelIndex& parent = QModelIndex()) const
  2. {
  3. int sup;
  4. sup = headerList.size()-QFileSystemModel::columnCount();
  5.  
  6. return QFileSystemModel::columnCount();//+sup;
  7. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
  2. {
  3. for(uint i = 0; i<headerList.size(); i++){
  4. if (section == i && orientation == Qt::Horizontal && role == Qt::DisplayRole)
  5. return headerList.at(i);
  6. }
  7. return QFileSystemModel::headerData(section, orientation, role);
  8. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QVariant TreeModel::data(const QModelIndex& index,int role) const
  2. {
  3.  
  4. QString test;
  5. qDebug() << "index: " << index << "role: " << role;
  6. if(!index.isValid()){
  7. return QFileSystemModel::data(index,role);}
  8. if(index.column()==0){
  9. if (role == Qt::CheckStateRole) return checklist.contains(index) ? Qt::Checked : Qt::Unchecked;
  10. }
  11. if(index.column()== 2)
  12. {
  13. switch(role)
  14. {
  15. case(Qt::DisplayRole):
  16. {return QString("Your text");}
  17. case(Qt::TextAlignmentRole):
  18. {return Qt::AlignHCenter;}
  19. default:{}
  20. }
  21. }
  22.  
  23.  
  24. return QFileSystemModel::data(index,role);
  25. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. Qt::ItemFlags TreeModel::flags(const QModelIndex& index) const {
  2. return QFileSystemModel::flags(index) | Qt::ItemIsUserCheckable;
  3.  
  4. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. bool TreeModel::setData(const QModelIndex& index, const QVariant& value, int role) {
  2. if (role == Qt::CheckStateRole) {
  3. if (value == Qt::Checked) checklist.insert(index);
  4. else checklist.remove(index);
  5. emit dataChanged(index, index);
  6. return true;
  7. }
  8. return QFileSystemModel::setData(index, value, role);
  9. }
To copy to clipboard, switch view to plain text mode 

Parts of these codes are extracted from different wokrs found on forums... may be here.
I understood how to create a column (done in headerData and columnCount...
I understood -- partially-- how to add a checkbox (done in data) and handle if it is checked or not in setData

But I don't understand how to modify item and index values... Is there a clever person to explain how to do that with in a newbie language ?

With these functions, How I can add in the column 2 (for example) the number of subdirectories of the item ?
How I can add the results of the operation on the item path name (a double) ?

Thanks a lot