1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Fix mxe map editor drag'n'drop

This commit is contained in:
nordsoft 2022-12-21 04:28:56 +04:00 committed by Nordsoft91
parent 26985600b2
commit 4674e240d8
3 changed files with 7 additions and 23 deletions

@ -358,12 +358,10 @@ void MapView::dragEnterEvent(QDragEnterEvent * event)
if(!sc)
return;
if(event->mimeData()->hasFormat("application/vcmi.object"))
if(event->mimeData()->hasImage())
{
auto encodedData = event->mimeData()->data("application/vcmi.object");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QVariant vdata;
stream >> vdata;
logGlobal->info("Drag'n'drop: dispatching object");
QVariant vdata = event->mimeData()->imageData();
auto data = vdata.toJsonObject();
if(!data.empty())
{

@ -86,13 +86,6 @@ Qt::ItemFlags ObjectBrowserProxyModel::flags(const QModelIndex & index) const
return defaultFlags;
}
QStringList ObjectBrowserProxyModel::mimeTypes() const
{
QStringList types;
types << "application/vcmi.object";
return types;
}
QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) const
{
assert(indexes.size() == 1);
@ -101,18 +94,12 @@ QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) c
assert(standardModel);
QModelIndex index = indexes.front();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
if(!index.isValid())
return nullptr;
auto text = standardModel->itemFromIndex(mapToSource(index))->data();
stream << text;
QMimeData * mimeData = new QMimeData;
mimeData->setData("application/vcmi.object", encodedData);
mimeData->setImageData(standardModel->itemFromIndex(mapToSource(index))->data());
return mimeData;
}
@ -124,6 +111,7 @@ ObjectBrowser::ObjectBrowser(QWidget * parent):
void ObjectBrowser::startDrag(Qt::DropActions supportedActions)
{
logGlobal->info("Drag'n'drop: Start dragging object from ObjectBrowser");
QDrag *drag = new QDrag(this);
auto indexes = selectedIndexes();
if(indexes.isEmpty())
@ -135,5 +123,5 @@ void ObjectBrowser::startDrag(Qt::DropActions supportedActions)
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec();
Qt::DropAction dropAction = drag->exec(supportedActions);
}

@ -19,9 +19,7 @@ public:
explicit ObjectBrowserProxyModel(QObject *parent = nullptr);
Qt::ItemFlags flags(const QModelIndex &index) const override;
QStringList mimeTypes() const override;
QMimeData * mimeData(const QModelIndexList & indexes) const override;
TerrainId terrain;