Make the demo model work in widgets and qml views
parent
7b862c0c55
commit
1c7271d091
|
@ -35,12 +35,12 @@ ApplicationWindow {
|
|||
//selectionMode: SelectionMode.SingleSelection
|
||||
TableViewColumn {
|
||||
title: "Name"
|
||||
role: "display"
|
||||
role: "FileName"
|
||||
width: 300
|
||||
}
|
||||
TableViewColumn {
|
||||
title: "Permissions"
|
||||
role: "display"
|
||||
role: "FilePermissions"
|
||||
width: 100
|
||||
}
|
||||
itemDelegate: Item {
|
||||
|
|
|
@ -137,12 +137,16 @@ QVariant RItemModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant("Times");
|
||||
}
|
||||
QVariant v;
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (index.column() == 0) {
|
||||
if (index.column() == 0) {
|
||||
if (role == Qt::DisplayRole || role == Qt::UserRole + 2) {
|
||||
QString s;
|
||||
ritemmodel_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||
v = s;
|
||||
} else if (index.column() == 1) {
|
||||
} else if (role == Qt::UserRole + 3) {
|
||||
v.setValue<int>(ritemmodel_data_file_permissions(d, index.row(), index.internalId()));
|
||||
}
|
||||
} else if (index.column() == 1) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
v.setValue<int>(ritemmodel_data_file_permissions(d, index.row(), index.internalId()));
|
||||
}
|
||||
}
|
||||
|
@ -161,3 +165,11 @@ QModelIndex RItemModel::parent(const QModelIndex &index) const
|
|||
const qmodelindex_t parent = ritemmodel_parent(d, index.row(), index.internalId());
|
||||
return parent.id ?createIndex(parent.row, 0, parent.id) :QModelIndex();
|
||||
}
|
||||
QHash<int, QByteArray> RItemModel::roleNames() const {
|
||||
QHash<int, QByteArray> names;
|
||||
names.insert(Qt::DecorationRole, "FileIcon");
|
||||
names.insert(Qt::UserRole + 1, "FilePath");
|
||||
names.insert(Qt::UserRole + 2, "FileName");
|
||||
names.insert(Qt::UserRole + 3, "FilePermissions");
|
||||
return names;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
private slots:
|
||||
void handleNewData();
|
||||
|
|
Loading…
Reference in New Issue