QMimeData *JSONModel::mimeData(const QModelIndexList &indexes) const { // Only 1 index for now QMimeData *mimeData = new QMimeData; const auto& index = indexes.first(); const auto& elt = elements.at(index.row()); QJsonDocument doc{elt.obj}; auto text = doc.toJson(QJsonDocument::Indented); mimeData->setData(categoryMimeTypeMap()[elt.category], text); return mimeData; }
bool JSONModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { beginInsertRows(parent, elements.size(), elements.size()); elements.push_back( LibraryElement {"Name me!", categoryMimeTypeMap().key(data->formats().first(), Category(-1)), {"no tags"}, QJsonObject{}}); endInsertRows(); return false; }
bool JSONModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { // TODO : How to handle the drops that have multiple values ? like messagelist + node... auto doc = QJsonDocument::fromJson(data->data(data->formats().first())); beginInsertRows(parent, elements.size(), elements.size()); elements.push_back( LibraryElement {"Name me!", categoryMimeTypeMap().key(data->formats().first(), Category(-1)), {"no tags"}, doc.object()}); endInsertRows(); return true; }