GH-4164 Assign instances to groups using drag & drop
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include <QUuid>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QMimeData>
|
||||
|
||||
#include "InstanceList.h"
|
||||
#include "BaseInstance.h"
|
||||
@ -63,6 +64,50 @@ InstanceList::~InstanceList()
|
||||
{
|
||||
}
|
||||
|
||||
Qt::DropActions InstanceList::supportedDragActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
Qt::DropActions InstanceList::supportedDropActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
bool InstanceList::canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if(data && data->hasFormat("application/x-instanceid")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstanceList::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
|
||||
{
|
||||
if(data && data->hasFormat("application/x-instanceid")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList InstanceList::mimeTypes() const
|
||||
{
|
||||
auto types = QAbstractListModel::mimeTypes();
|
||||
types.push_back("application/x-instanceid");
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData * InstanceList::mimeData(const QModelIndexList& indexes) const
|
||||
{
|
||||
auto mimeData = QAbstractListModel::mimeData(indexes);
|
||||
if(indexes.size() == 1) {
|
||||
auto instanceId = data(indexes[0], InstanceIDRole).toString();
|
||||
mimeData->setData("application/x-instanceid", instanceId.toUtf8());
|
||||
}
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
|
||||
int InstanceList::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
@ -112,7 +157,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
return pdata->iconKey();
|
||||
}
|
||||
// HACK: see GroupView.h in gui!
|
||||
// HACK: see InstanceView.h in gui!
|
||||
case GroupRole:
|
||||
{
|
||||
return getInstanceGroup(pdata->id());
|
||||
|
Reference in New Issue
Block a user