From 7f8a84f2f2e682805ccfd5864746e098e7a9da60 Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 14 Jan 2023 16:19:37 +0200 Subject: [PATCH 1/4] Move Response column earlier --- apps/opencs/model/world/data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)); From 0310b1cddfb2eab977ae02311fae843fc2c5e7b7 Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 14 Jan 2023 20:36:49 +0200 Subject: [PATCH 2/4] Dragging Topics to TopicInfo window opens create TopicInfo BottomBox with the correct id --- apps/opencs/view/world/dragdroputils.cpp | 8 ++++++++ apps/opencs/view/world/dragdroputils.hpp | 2 ++ apps/opencs/view/world/dragrecordtable.cpp | 11 ++++++++++- apps/opencs/view/world/dragrecordtable.hpp | 1 + apps/opencs/view/world/infocreator.cpp | 6 ++++++ apps/opencs/view/world/infocreator.hpp | 2 ++ apps/opencs/view/world/table.cpp | 2 ++ apps/opencs/view/world/table.hpp | 2 ++ apps/opencs/view/world/tablebottombox.cpp | 23 ++++++++++++++++++++++ apps/opencs/view/world/tablebottombox.hpp | 1 + apps/opencs/view/world/tablesubview.cpp | 2 ++ 11 files changed, 59 insertions(+), 1 deletion(-) 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); From 7fce4bc8c46575a09a229e1402e0f28aaf793eec Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 14 Jan 2023 21:30:25 +0200 Subject: [PATCH 3/4] Issue command passing through QLineInput --- apps/opencs/view/world/infocreator.cpp | 5 +++++ apps/opencs/view/world/infocreator.hpp | 4 ++++ apps/opencs/view/world/tablebottombox.cpp | 8 +------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index 1db87fef8e..cdea2b27f9 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -144,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 2820d101b4..0c4a9fd4d3 100644 --- a/apps/opencs/view/world/infocreator.hpp +++ b/apps/opencs/view/world/infocreator.hpp @@ -56,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/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index 47b63e5942..a7460bbcd1 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -264,13 +264,7 @@ void CSVWorld::TableBottomBox::createRecordsDirectlyRequest(const std::string& i { 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(); + creator->callReturnPressed(); } else { From 50726636ba46e1e26f85e3ff3cb8fba5b8a6f5dd Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 14 Jan 2023 21:42:33 +0200 Subject: [PATCH 4/4] clang-format --- apps/opencs/view/world/dragdroputils.cpp | 3 +-- apps/opencs/view/world/tablebottombox.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/dragdroputils.cpp b/apps/opencs/view/world/dragdroputils.cpp index 63e0a9c1e9..e6c68fa12e 100644 --- a/apps/opencs/view/world/dragdroputils.cpp +++ b/apps/opencs/view/world/dragdroputils.cpp @@ -22,8 +22,7 @@ bool CSVWorld::DragDropUtils::isTopicOrJournal(const QDropEvent& event, CSMWorld { const CSMWorld::TableMimeData* data = getTableMimeData(event); return data != nullptr - && (data->holdsType(CSMWorld::UniversalId::Type_Topic) - || data->holdsType(CSMWorld::UniversalId::Type_Journal)); + && (data->holdsType(CSMWorld::UniversalId::Type_Topic) || data->holdsType(CSMWorld::UniversalId::Type_Journal)); } bool CSVWorld::DragDropUtils::isInfo(const QDropEvent& event, CSMWorld::ColumnBase::Display type) diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index a7460bbcd1..72b70b8109 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -260,7 +260,7 @@ void CSVWorld::TableBottomBox::createRequest() void CSVWorld::TableBottomBox::createRecordsDirectlyRequest(const std::string& id) { - if (InfoCreator* creator = dynamic_cast (mCreator)) + if (InfoCreator* creator = dynamic_cast(mCreator)) { creator->reset(); creator->setText(id);