mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
Fix mxe map editor drag'n'drop
This commit is contained in:
parent
26985600b2
commit
4674e240d8
@ -358,12 +358,10 @@ void MapView::dragEnterEvent(QDragEnterEvent * event)
|
|||||||
if(!sc)
|
if(!sc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(event->mimeData()->hasFormat("application/vcmi.object"))
|
if(event->mimeData()->hasImage())
|
||||||
{
|
{
|
||||||
auto encodedData = event->mimeData()->data("application/vcmi.object");
|
logGlobal->info("Drag'n'drop: dispatching object");
|
||||||
QDataStream stream(&encodedData, QIODevice::ReadOnly);
|
QVariant vdata = event->mimeData()->imageData();
|
||||||
QVariant vdata;
|
|
||||||
stream >> vdata;
|
|
||||||
auto data = vdata.toJsonObject();
|
auto data = vdata.toJsonObject();
|
||||||
if(!data.empty())
|
if(!data.empty())
|
||||||
{
|
{
|
||||||
|
@ -86,13 +86,6 @@ Qt::ItemFlags ObjectBrowserProxyModel::flags(const QModelIndex & index) const
|
|||||||
return defaultFlags;
|
return defaultFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ObjectBrowserProxyModel::mimeTypes() const
|
|
||||||
{
|
|
||||||
QStringList types;
|
|
||||||
types << "application/vcmi.object";
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) const
|
QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) const
|
||||||
{
|
{
|
||||||
assert(indexes.size() == 1);
|
assert(indexes.size() == 1);
|
||||||
@ -101,18 +94,12 @@ QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) c
|
|||||||
assert(standardModel);
|
assert(standardModel);
|
||||||
|
|
||||||
QModelIndex index = indexes.front();
|
QModelIndex index = indexes.front();
|
||||||
QByteArray encodedData;
|
|
||||||
|
|
||||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
if(!index.isValid())
|
if(!index.isValid())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto text = standardModel->itemFromIndex(mapToSource(index))->data();
|
|
||||||
stream << text;
|
|
||||||
|
|
||||||
QMimeData * mimeData = new QMimeData;
|
QMimeData * mimeData = new QMimeData;
|
||||||
mimeData->setData("application/vcmi.object", encodedData);
|
mimeData->setImageData(standardModel->itemFromIndex(mapToSource(index))->data());
|
||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +111,7 @@ ObjectBrowser::ObjectBrowser(QWidget * parent):
|
|||||||
|
|
||||||
void ObjectBrowser::startDrag(Qt::DropActions supportedActions)
|
void ObjectBrowser::startDrag(Qt::DropActions supportedActions)
|
||||||
{
|
{
|
||||||
|
logGlobal->info("Drag'n'drop: Start dragging object from ObjectBrowser");
|
||||||
QDrag *drag = new QDrag(this);
|
QDrag *drag = new QDrag(this);
|
||||||
auto indexes = selectedIndexes();
|
auto indexes = selectedIndexes();
|
||||||
if(indexes.isEmpty())
|
if(indexes.isEmpty())
|
||||||
@ -135,5 +123,5 @@ void ObjectBrowser::startDrag(Qt::DropActions supportedActions)
|
|||||||
|
|
||||||
drag->setMimeData(mimeData);
|
drag->setMimeData(mimeData);
|
||||||
|
|
||||||
Qt::DropAction dropAction = drag->exec();
|
Qt::DropAction dropAction = drag->exec(supportedActions);
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,7 @@ public:
|
|||||||
explicit ObjectBrowserProxyModel(QObject *parent = nullptr);
|
explicit ObjectBrowserProxyModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
QStringList mimeTypes() const override;
|
|
||||||
|
|
||||||
QMimeData * mimeData(const QModelIndexList & indexes) const override;
|
QMimeData * mimeData(const QModelIndexList & indexes) const override;
|
||||||
|
|
||||||
TerrainId terrain;
|
TerrainId terrain;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user