diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 51ffe52436..ef1c745b4c 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -328,6 +328,7 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, bool fsStrict, const Files::Path mTopicInfos.addColumn(new RecordStateColumn); mTopicInfos.addColumn(new FixedRecordTypeColumn(UniversalId::Type_TopicInfo)); mTopicInfos.addColumn(new TopicColumn(false)); + mTopicInfos.addColumn(new ResponseColumn); mTopicInfos.addColumn(new ActorColumn); mTopicInfos.addColumn(new RaceColumn); mTopicInfos.addColumn(new ClassColumn); @@ -339,7 +340,6 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, bool fsStrict, const Files::Path mTopicInfos.addColumn(new PcFactionColumn); mTopicInfos.addColumn(new PcRankColumn); mTopicInfos.addColumn(new SoundFileColumn); - mTopicInfos.addColumn(new ResponseColumn); // Result script mTopicInfos.addColumn(new NestedParentColumn( Columns::ColumnId_InfoList, ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_List)); diff --git a/apps/opencs/view/world/dragdroputils.cpp b/apps/opencs/view/world/dragdroputils.cpp index 2336c14924..e6c68fa12e 100644 --- a/apps/opencs/view/world/dragdroputils.cpp +++ b/apps/opencs/view/world/dragdroputils.cpp @@ -18,6 +18,13 @@ bool CSVWorld::DragDropUtils::canAcceptData(const QDropEvent& event, CSMWorld::C return data != nullptr && data->holdsType(type); } +bool CSVWorld::DragDropUtils::isTopicOrJournal(const QDropEvent& event, CSMWorld::ColumnBase::Display type) +{ + const CSMWorld::TableMimeData* data = getTableMimeData(event); + return data != nullptr + && (data->holdsType(CSMWorld::UniversalId::Type_Topic) || data->holdsType(CSMWorld::UniversalId::Type_Journal)); +} + bool CSVWorld::DragDropUtils::isInfo(const QDropEvent& event, CSMWorld::ColumnBase::Display type) { const CSMWorld::TableMimeData* data = getTableMimeData(event); diff --git a/apps/opencs/view/world/dragdroputils.hpp b/apps/opencs/view/world/dragdroputils.hpp index ab27198f71..bf822180cd 100644 --- a/apps/opencs/view/world/dragdroputils.hpp +++ b/apps/opencs/view/world/dragdroputils.hpp @@ -20,6 +20,8 @@ namespace CSVWorld bool canAcceptData(const QDropEvent& event, CSMWorld::ColumnBase::Display type); ///< Checks whether the \a event contains a valid CSMWorld::TableMimeData that holds the \a type + bool isTopicOrJournal(const QDropEvent& event, CSMWorld::ColumnBase::Display type); + bool isInfo(const QDropEvent& event, CSMWorld::ColumnBase::Display type); ///< Info types can be dragged to sort the info table diff --git a/apps/opencs/view/world/dragrecordtable.cpp b/apps/opencs/view/world/dragrecordtable.cpp index 1a35e02d79..ed95acea8b 100644 --- a/apps/opencs/view/world/dragrecordtable.cpp +++ b/apps/opencs/view/world/dragrecordtable.cpp @@ -53,7 +53,8 @@ void CSVWorld::DragRecordTable::dragMoveEvent(QDragMoveEvent* event) { QModelIndex index = indexAt(event->pos()); if (CSVWorld::DragDropUtils::canAcceptData(*event, getIndexDisplayType(index)) - || CSVWorld::DragDropUtils::isInfo(*event, getIndexDisplayType(index))) + || CSVWorld::DragDropUtils::isInfo(*event, getIndexDisplayType(index)) + || CSVWorld::DragDropUtils::isTopicOrJournal(*event, getIndexDisplayType(index))) { if (index.flags() & Qt::ItemIsEditable) { @@ -86,6 +87,14 @@ void CSVWorld::DragRecordTable::dropEvent(QDropEvent* event) { emit moveRecordsFromSameTable(event); } + if (CSVWorld::DragDropUtils::isTopicOrJournal(*event, display)) + { + const CSMWorld::TableMimeData* tableMimeData = CSVWorld::DragDropUtils::getTableMimeData(*event); + for (auto universalId : tableMimeData->getData()) + { + emit createNewInfoRecord(universalId.getId()); + } + } } CSMWorld::ColumnBase::Display CSVWorld::DragRecordTable::getIndexDisplayType(const QModelIndex& index) const diff --git a/apps/opencs/view/world/dragrecordtable.hpp b/apps/opencs/view/world/dragrecordtable.hpp index 7634c0e650..bbd3ece7ee 100644 --- a/apps/opencs/view/world/dragrecordtable.hpp +++ b/apps/opencs/view/world/dragrecordtable.hpp @@ -57,6 +57,7 @@ namespace CSVWorld signals: void moveRecordsFromSameTable(QDropEvent* event); + void createNewInfoRecord(const std::string& id); }; } diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index 00e0399f9b..cdea2b27f9 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -115,6 +115,12 @@ void CSVWorld::InfoCreator::reset() GenericCreator::reset(); } +void CSVWorld::InfoCreator::setText(const std::string& text) +{ + QString qText = QString::fromStdString(text); + mTopic->setText(qText); +} + std::string CSVWorld::InfoCreator::getErrors() const { // We ignore errors from GenericCreator here, because they can never happen in an InfoCreator. @@ -138,6 +144,11 @@ void CSVWorld::InfoCreator::focus() mTopic->setFocus(); } +void CSVWorld::InfoCreator::callReturnPressed() +{ + emit inputReturnPressed(); +} + void CSVWorld::InfoCreator::topicChanged() { update(); diff --git a/apps/opencs/view/world/infocreator.hpp b/apps/opencs/view/world/infocreator.hpp index 2227b5bc9e..0c4a9fd4d3 100644 --- a/apps/opencs/view/world/infocreator.hpp +++ b/apps/opencs/view/world/infocreator.hpp @@ -47,6 +47,8 @@ namespace CSVWorld void reset() override; + void setText(const std::string& text); + std::string getErrors() const override; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. @@ -54,6 +56,10 @@ namespace CSVWorld /// Focus main input widget void focus() override; + public slots: + + void callReturnPressed(); + private slots: void topicChanged(); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 12aec5ab92..cff16a85f2 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -269,6 +269,8 @@ CSVWorld::Table::Table(const CSMWorld::UniversalId& id, bool createAndDelete, bo { mProxyModel = new CSMWorld::InfoTableProxyModel(id.getType(), this); connect(this, &CSVWorld::DragRecordTable::moveRecordsFromSameTable, this, &CSVWorld::Table::moveRecords); + connect(this, &CSVWorld::DragRecordTable::createNewInfoRecord, this, + &CSVWorld::Table::createRecordsDirectlyRequest); } else if (isLtexTable) { diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index c5d0e47f53..e7a30f4a28 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -121,6 +121,8 @@ namespace CSVWorld void createRequest(); + void createRecordsDirectlyRequest(const std::string& id); + void cloneRequest(const CSMWorld::UniversalId&); void touchRequest(const std::vector& ids); diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index de84229421..72b70b8109 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -8,9 +8,12 @@ #include #include +#include + #include #include "creator.hpp" +#include "infocreator.hpp" void CSVWorld::TableBottomBox::updateSize() { @@ -255,6 +258,20 @@ void CSVWorld::TableBottomBox::createRequest() mCreator->focus(); } +void CSVWorld::TableBottomBox::createRecordsDirectlyRequest(const std::string& id) +{ + if (InfoCreator* creator = dynamic_cast(mCreator)) + { + creator->reset(); + creator->setText(id); + creator->callReturnPressed(); + } + else + { + Log(Debug::Warning) << "Creating a record directly failed."; + } +} + void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type) { mCreator->reset(); diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 073d0b42e1..7be57066f6 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -107,6 +107,7 @@ namespace CSVWorld void noMorePosition(); void createRequest(); + void createRecordsDirectlyRequest(const std::string& id); void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); void touchRequest(const std::vector&); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 9c5d110c50..9be0afd912 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -104,6 +104,8 @@ CSVWorld::TableSubView::TableSubView( connect(this, qOverload(&TableSubView::cloneRequest), mBottom, &TableBottomBox::cloneRequest); + connect(mTable, &Table::createRecordsDirectlyRequest, mBottom, &TableBottomBox::createRecordsDirectlyRequest); + connect(mTable, &Table::touchRequest, mBottom, &TableBottomBox::touchRequest); connect(mTable, &Table::extendedDeleteConfigRequest, mBottom, &TableBottomBox::extendedDeleteConfigRequest);