forked from teamnwah/openmw-tes3coop
Fix OpenCS crash when drag and drop is used with unexpected data, e.g. plain text (Fixes #1543)
This commit is contained in:
parent
06e89d8bd3
commit
e19bbfd1b5
7 changed files with 43 additions and 8 deletions
|
@ -35,7 +35,11 @@ void CSVFilter::FilterBox::setRecordFilter (const std::string& filter)
|
||||||
|
|
||||||
void CSVFilter::FilterBox::dropEvent (QDropEvent* event)
|
void CSVFilter::FilterBox::dropEvent (QDropEvent* event)
|
||||||
{
|
{
|
||||||
std::vector<CSMWorld::UniversalId> data = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData())->getData();
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::vector<CSMWorld::UniversalId> data = mime->getData();
|
||||||
|
|
||||||
emit recordDropped(data, event->proposedAction());
|
emit recordDropped(data, event->proposedAction());
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
|
||||||
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
|
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
|
||||||
{
|
{
|
||||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
return;
|
||||||
|
|
||||||
if (mime->fromDocument (mDocument))
|
if (mime->fromDocument (mDocument))
|
||||||
{
|
{
|
||||||
|
|
|
@ -382,6 +382,9 @@ void CSVWorld::RegionMap::dropEvent (QDropEvent* event)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
return;
|
||||||
|
|
||||||
if (mime->fromDocument(mDocument) && mime->holdsType(CSMWorld::UniversalId::Type_Region))
|
if (mime->fromDocument(mDocument) && mime->holdsType(CSMWorld::UniversalId::Type_Region))
|
||||||
{
|
{
|
||||||
CSMWorld::UniversalId record (mime->returnMatching (CSMWorld::UniversalId::Type_Region));
|
CSMWorld::UniversalId record (mime->returnMatching (CSMWorld::UniversalId::Type_Region));
|
||||||
|
|
|
@ -44,20 +44,37 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& docum
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event)
|
void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event)
|
||||||
|
{
|
||||||
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime)
|
||||||
|
QTextEdit::dragEnterEvent(event);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
setTextCursor (cursorForPosition (event->pos()));
|
setTextCursor (cursorForPosition (event->pos()));
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event)
|
void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event)
|
||||||
|
{
|
||||||
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime)
|
||||||
|
QTextEdit::dragMoveEvent(event);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
setTextCursor (cursorForPosition (event->pos()));
|
setTextCursor (cursorForPosition (event->pos()));
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event)
|
void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event)
|
||||||
{
|
{
|
||||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
{
|
||||||
|
QTextEdit::dropEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setTextCursor (cursorForPosition (event->pos()));
|
setTextCursor (cursorForPosition (event->pos()));
|
||||||
|
|
||||||
|
|
|
@ -464,6 +464,9 @@ void CSVWorld::Table::dropEvent(QDropEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||||
|
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
return;
|
||||||
|
|
||||||
if (mime->fromDocument (mDocument))
|
if (mime->fromDocument (mDocument))
|
||||||
{
|
{
|
||||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
||||||
|
|
|
@ -131,6 +131,9 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event)
|
||||||
{
|
{
|
||||||
QDropEvent* drop = dynamic_cast<QDropEvent*>(event);
|
QDropEvent* drop = dynamic_cast<QDropEvent*>(event);
|
||||||
const CSMWorld::TableMimeData* data = dynamic_cast<const CSMWorld::TableMimeData*>(drop->mimeData());
|
const CSMWorld::TableMimeData* data = dynamic_cast<const CSMWorld::TableMimeData*>(drop->mimeData());
|
||||||
|
if (!data) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
return false;
|
||||||
|
|
||||||
bool handled = data->holdsType(CSMWorld::UniversalId::Type_Filter);
|
bool handled = data->holdsType(CSMWorld::UniversalId::Type_Filter);
|
||||||
if (handled)
|
if (handled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -255,6 +255,9 @@ void CSVWorld::DropLineEdit::dragMoveEvent(QDragMoveEvent *event)
|
||||||
void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event)
|
void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
const CSMWorld::TableMimeData* data(dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData()));
|
const CSMWorld::TableMimeData* data(dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData()));
|
||||||
|
if (!data) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||||
|
return;
|
||||||
|
|
||||||
emit tableMimeDataDropped(data->getData(), data->getDocumentPtr());
|
emit tableMimeDataDropped(data->getData(), data->getDocumentPtr());
|
||||||
//WIP
|
//WIP
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue