diff --git a/apps/opencs/view/world/dragdroputils.cpp b/apps/opencs/view/world/dragdroputils.cpp index 2336c14924..63e0a9c1e9 100644 --- a/apps/opencs/view/world/dragdroputils.cpp +++ b/apps/opencs/view/world/dragdroputils.cpp @@ -18,6 +18,14 @@ 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..1db87fef8e 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. diff --git a/apps/opencs/view/world/infocreator.hpp b/apps/opencs/view/world/infocreator.hpp index 2227b5bc9e..2820d101b4 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. 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..47b63e5942 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,26 @@ 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); + + /*Default system of createRequest - TODO: Modify so that user doesn't see the edit box*/ + mCreator->toggleWidgets(true); + mLayout->setCurrentWidget(mCreator); + setVisible(true); + mEditMode = EditMode_Creation; + mCreator->focus(); + } + 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);