Qt::ItemFlags ProjectDirModel::flags(const QModelIndex &index) const { Qt::ItemFlags flags = QAbstractItemModel::flags(index); if (index.isValid()) { DvDirModelNode *node = getNode(index); if (node && node->isRenameEnabled()) flags |= Qt::ItemIsEditable; } return flags; }
bool ProjectDirModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid()) return false; DvDirModelNode *node = getNode(index); if (!node || !node->isRenameEnabled()) return false; QString newName = value.toString(); if (newName == "") return false; if (!node->setName(newName.toStdWString())) return false; emit dataChanged(index, index); return true; }
QVariant ProjectDirModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); DvDirModelNode *node = getNode(index); if (role == Qt::DisplayRole || role == Qt::EditRole) return QString::fromStdWString(node->getName()); else if (role == Qt::DecorationRole) { return QVariant(); } else if (role == Qt::ForegroundRole) { if (!node || !node->isRenameEnabled()) return QBrush(Qt::blue); else return QVariant(); } else return QVariant(); }