diff --git a/apps/opencs/view/filter/filterbox.cpp b/apps/opencs/view/filter/filterbox.cpp index e588770b1..7a42ef0a5 100644 --- a/apps/opencs/view/filter/filterbox.cpp +++ b/apps/opencs/view/filter/filterbox.cpp @@ -35,7 +35,11 @@ void CSVFilter::FilterBox::setRecordFilter (const std::string& filter) void CSVFilter::FilterBox::dropEvent (QDropEvent* event) { - std::vector data = dynamic_cast (event->mimeData())->getData(); + const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped + return; + + std::vector data = mime->getData(); emit recordDropped(data, event->proposedAction()); } @@ -54,4 +58,4 @@ void CSVFilter::FilterBox::createFilterRequest (std::vector< std::pair< std::str Qt::DropAction action) { mRecordFilterBox->createFilterRequest(filterSource, action); -} \ No newline at end of file +} diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 59b82bb67..afc6b4603 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -120,9 +120,11 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event) void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event) { const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped + return; if (mime->fromDocument (mDocument)) { emit dataDropped(mime->getData()); } //not handling drops from different documents at the moment -} \ No newline at end of file +} diff --git a/apps/opencs/view/world/regionmap.cpp b/apps/opencs/view/world/regionmap.cpp index 849a1988a..9497e4054 100644 --- a/apps/opencs/view/world/regionmap.cpp +++ b/apps/opencs/view/world/regionmap.cpp @@ -382,6 +382,9 @@ void CSVWorld::RegionMap::dropEvent (QDropEvent* event) } const CSMWorld::TableMimeData* mime = dynamic_cast (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)) { CSMWorld::UniversalId record (mime->returnMatching (CSMWorld::UniversalId::Type_Region)); @@ -402,4 +405,4 @@ void CSVWorld::RegionMap::dropEvent (QDropEvent* event) mRegionId = record.getId(); } -} \ No newline at end of file +} diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index b1528d525..23bc76000 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -45,19 +45,36 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& docum void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event) { - setTextCursor (cursorForPosition (event->pos())); - event->acceptProposedAction(); + const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + if (!mime) + QTextEdit::dragEnterEvent(event); + else + { + setTextCursor (cursorForPosition (event->pos())); + event->acceptProposedAction(); + } } void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event) { - setTextCursor (cursorForPosition (event->pos())); - event->accept(); + const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + if (!mime) + QTextEdit::dragMoveEvent(event); + else + { + setTextCursor (cursorForPosition (event->pos())); + event->accept(); + } } void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { const CSMWorld::TableMimeData* mime = dynamic_cast (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())); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 877fd51c0..d0849d631 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -464,6 +464,9 @@ void CSVWorld::Table::dropEvent(QDropEvent *event) } const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped + return; + if (mime->fromDocument (mDocument)) { CSMWorld::ColumnBase::Display display = static_cast diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index a0bef366b..327fb1c0e 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -131,6 +131,9 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event) { QDropEvent* drop = dynamic_cast(event); const CSMWorld::TableMimeData* data = dynamic_cast(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); if (handled) { diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index ea8a7c541..6f3999363 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -255,6 +255,9 @@ void CSVWorld::DropLineEdit::dragMoveEvent(QDragMoveEvent *event) void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event) { const CSMWorld::TableMimeData* data(dynamic_cast(event->mimeData())); + if (!data) // May happen when non-records (e.g. plain text) are dragged and dropped + return; + emit tableMimeDataDropped(data->getData(), data->getDocumentPtr()); //WIP }