Add some drag'n'drop utils to work with TableMimeData
parent
dc37aea8eb
commit
2565452052
@ -0,0 +1,26 @@
|
||||
#include "dragdroputils.hpp"
|
||||
|
||||
#include <QDropEvent>
|
||||
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
|
||||
const CSMWorld::TableMimeData *CSVWorld::DragDropUtils::getTableMimeData(const QDropEvent &event)
|
||||
{
|
||||
return dynamic_cast<const CSMWorld::TableMimeData *>(event.mimeData());
|
||||
}
|
||||
|
||||
bool CSVWorld::DragDropUtils::canAcceptData(const QDropEvent &event, CSMWorld::ColumnBase::Display type)
|
||||
{
|
||||
const CSMWorld::TableMimeData *data = getTableMimeData(event);
|
||||
return data != NULL && data->holdsType(type);
|
||||
}
|
||||
|
||||
CSMWorld::UniversalId CSVWorld::DragDropUtils::getAcceptedData(const QDropEvent &event,
|
||||
CSMWorld::ColumnBase::Display type)
|
||||
{
|
||||
if (canAcceptData(event, type))
|
||||
{
|
||||
return getTableMimeData(event)->returnMatching(type);
|
||||
}
|
||||
return CSMWorld::UniversalId::Type_None;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#ifndef CSV_WORLD_DRAGDROPUTILS_HPP
|
||||
#define CSV_WORLD_DRAGDROPUTILS_HPP
|
||||
|
||||
#include "../../model/world/columnbase.hpp"
|
||||
|
||||
class QDropEvent;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class TableMimeData;
|
||||
class UniversalId;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class DragDropUtils
|
||||
{
|
||||
public:
|
||||
static const CSMWorld::TableMimeData *getTableMimeData(const QDropEvent &event);
|
||||
|
||||
static bool canAcceptData(const QDropEvent &event, CSMWorld::ColumnBase::Display type);
|
||||
///< Checks whether the \a event contains a valid CSMWorld::TableMimeData that holds the \a type
|
||||
|
||||
static CSMWorld::UniversalId getAcceptedData(const QDropEvent &event, CSMWorld::ColumnBase::Display type);
|
||||
///< Gets the accepted data from the \a event using the \a type
|
||||
///< \return Type_None if the \a event data doesn't holds the \a type
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue