QMimeData *InventoryItemModel::mimeData(const QModelIndexList &indexes) const { QMimeData *mimeData = new QMimeData(); QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); foreach(QModelIndex index, indexes) { if (index.isValid()) { QString info, asset_type, asset_ref; AbstractInventoryItem *item = GetItem(index); InventoryAsset *asset = dynamic_cast<InventoryAsset *>(item); if (asset) { asset_type.append(QString("%1").arg(asset->GetAssetType())); asset_ref = asset->GetAssetReference(); } else { asset_type.append(QString("%1").arg(RexTypes::RexAT_None)); asset_ref = RexUUID().ToString().c_str(); } info.append(asset_type + ";" + item->GetID() + ";" + item->GetName() + ";" + asset_ref); stream << info; } } mimeData->setData("application/vnd.inventory.item", encodedData); return mimeData; }
bool InventoryItemModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role != Qt::EditRole) return false; AbstractInventoryItem *item = GetItem(index); InventoryFolder *folder = dynamic_cast<InventoryFolder *>(item); if (folder && !folder->IsEditable()) return false; if (item->GetName() == value.toString()) return false; QString oldName = item->GetName(); item->SetName(value.toString()); // Is this needed anymore? emit dataChanged(index, index); // Notify server. Give updated item and old name (webdav needs this at least) dataModel_->NotifyServerAboutItemUpdate(item, oldName); return true; }
QVariant InventoryItemModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); AbstractInventoryItem *item = GetItem(index); if (role == Qt::DecorationRole) { if (item->GetItemType() == AbstractInventoryItem::Type_Folder) return QIcon(":images/iconFolderClosed.png"); if (item->GetItemType() == AbstractInventoryItem::Type_Asset) return QIcon(":images/iconResource.png"); } if (role != Qt::DisplayRole) return QVariant(); return QVariant(item->GetName()); }