CheckDirTree::CheckDirTree( QWidget* parent ) : QTreeView( parent ) { m_dirModel.setFilter( QDir::Dirs | QDir::NoDotAndDotDot ); m_dirModel.setRootPath( "/" ); m_dirModel.setNameFilters( QStringList() << "[^\\.]*" ); setModel( &m_dirModel ); setColumnHidden( 1, true ); setColumnHidden( 2, true ); setColumnHidden( 3, true ); //header()->hide(); connect( &m_dirModel, SIGNAL( dataChangedByUser( QModelIndex ) ), SLOT( updateNode( QModelIndex ) ) ); connect( &m_dirModel, SIGNAL( dataChangedByUser( const QModelIndex& ) ), SIGNAL( changed() ) ); connect( &m_dirModel, SIGNAL( modelReset() ), SLOT( modelReset() ) ); connect( this, SIGNAL( collapsed( QModelIndex ) ), SLOT( onCollapse( QModelIndex ) ) ); connect( this, SIGNAL( expanded( QModelIndex ) ), SLOT( onExpand( QModelIndex ) ) ); }
bool CheckDirModel::setData( const QModelIndex& index, const QVariant& value, int role ) { bool b = QFileSystemModel::setData( index, value, role ); if ( role == Qt::CheckStateRole ) { m_checkTable.insert( index, (Qt::CheckState)value.toInt() ); emit dataChanged( index, index ); emit dataChangedByUser( index ); } return b; }
/****************************************************************************** CheckDirModel::setData Gets called when the user checks/unchecks through the GUI. ******************************************************************************/ bool CheckDirModel::setData( const QModelIndex& index, const QVariant& value, int role) { if (role == Qt::CheckStateRole) { m_checkTable.insert(index.internalId(), (Qt::CheckState)value.toInt()); emit dataChanged(index, index); emit dataChangedByUser(index); return true; } else { return QDirModel::setData(index, value, role); } }