Skip to content

Instantly share code, notes, and snippets.

@pamaury
Created December 16, 2013 15:54
Show Gist options
  • Save pamaury/7989316 to your computer and use it in GitHub Desktop.
Save pamaury/7989316 to your computer and use it in GitHub Desktop.
#ifndef __MY_VIEW__
#define __MY_VIEW__
#include <QAbstractItemModel>
#include <QFileSystemModel>
#include <QPersistentModelIndex>
#include <QMap>
//#define USE_PERSISTENT
class MyFileSystemView : public QFileSystemModel
{
Q_OBJECT
MyFileSystemView();
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role) const;
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role);
private:
void propagateCheckState(const QModelIndex& index, Qt::CheckState state, bool down);
#ifdef USE_PERSISTENT
/* FIXME using QPersistentModelIndex breaks QFileSystemModel: see QTBUG-12413
* for some reason it prevents the view for hidings items thus the hidden
* filter doesn't work */
mutable QMap<QPersistentModelIndex, Qt::CheckState> m_checkstate;
#else
/* BUG HACK this is an ugly hack which rely on QModelIndex.internalPointer()
* to never change */
mutable QMap<void*, Qt::CheckState> m_checkstate;
#endif
Qt::CheckState getState(const QModelIndex& index) const;
void setState(const QModelIndex& index, Qt::CheckState state);
};
#endif /* __MY_VIEW__ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment