2013-11-08 10:51:59 +00:00
|
|
|
#include "infocreator.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <memory>
|
2013-11-08 10:51:59 +00:00
|
|
|
|
|
|
|
#include <QLabel>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <QString>
|
2013-11-08 10:51:59 +00:00
|
|
|
#include <QUuid>
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <apps/opencs/model/world/columnbase.hpp>
|
|
|
|
#include <apps/opencs/model/world/idcollection.hpp>
|
|
|
|
#include <apps/opencs/view/world/genericcreator.hpp>
|
|
|
|
|
2022-08-02 22:00:54 +00:00
|
|
|
#include <components/misc/strings/lower.hpp>
|
2013-11-08 11:03:03 +00:00
|
|
|
|
2015-06-19 09:51:50 +00:00
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
|
2013-11-08 10:51:59 +00:00
|
|
|
#include "../../model/world/columns.hpp"
|
|
|
|
#include "../../model/world/commands.hpp"
|
|
|
|
#include "../../model/world/data.hpp"
|
2015-06-19 09:51:50 +00:00
|
|
|
#include "../../model/world/idcompletionmanager.hpp"
|
|
|
|
#include "../../model/world/idtable.hpp"
|
2013-11-08 10:51:59 +00:00
|
|
|
|
2015-06-25 08:24:19 +00:00
|
|
|
#include "../widget/droplineedit.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
class QUndoStack;
|
|
|
|
|
2013-11-08 10:51:59 +00:00
|
|
|
std::string CSVWorld::InfoCreator::getId() const
|
|
|
|
{
|
2023-03-08 01:17:15 +00:00
|
|
|
const std::string topic = mTopic->text().toStdString();
|
2013-11-08 10:51:59 +00:00
|
|
|
|
|
|
|
std::string unique = QUuid::createUuid().toByteArray().data();
|
|
|
|
|
|
|
|
unique.erase(std::remove(unique.begin(), unique.end(), '-'), unique.end());
|
|
|
|
|
|
|
|
unique = unique.substr(1, unique.size() - 2);
|
|
|
|
|
2023-03-08 01:17:15 +00:00
|
|
|
return topic + '#' + unique;
|
2013-11-08 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVWorld::InfoCreator::configureCreateCommand(CSMWorld::CreateCommand& command) const
|
|
|
|
{
|
2017-08-24 17:51:53 +00:00
|
|
|
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*getData().getTableModel(getCollectionId()));
|
2013-11-08 10:51:59 +00:00
|
|
|
|
2021-01-11 10:53:34 +00:00
|
|
|
CSMWorld::CloneCommand* cloneCommand = dynamic_cast<CSMWorld::CloneCommand*>(&command);
|
2017-08-24 17:51:53 +00:00
|
|
|
if (getCollectionId() == CSMWorld::UniversalId::Type_TopicInfos)
|
|
|
|
{
|
2021-01-11 10:53:34 +00:00
|
|
|
if (!cloneCommand)
|
|
|
|
{
|
|
|
|
command.addValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Topic), mTopic->text());
|
|
|
|
command.addValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Rank), -1);
|
|
|
|
command.addValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Gender), -1);
|
|
|
|
command.addValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_PcRank), -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cloneCommand->setOverrideValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Topic), mTopic->text());
|
|
|
|
}
|
2017-08-24 17:51:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-11 10:53:34 +00:00
|
|
|
if (!cloneCommand)
|
|
|
|
{
|
|
|
|
command.addValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Journal), mTopic->text());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cloneCommand->setOverrideValue(table.findColumnIndex(CSMWorld::Columns::ColumnId_Journal), mTopic->text());
|
2017-08-24 17:51:53 +00:00
|
|
|
}
|
2013-11-08 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSVWorld::InfoCreator::InfoCreator(CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id,
|
2015-06-19 09:51:50 +00:00
|
|
|
CSMWorld::IdCompletionManager& completionManager)
|
2013-11-08 10:51:59 +00:00
|
|
|
: GenericCreator(data, undoStack, id)
|
|
|
|
{
|
2017-03-26 13:14:32 +00:00
|
|
|
// Determine if we're dealing with topics or journals.
|
2015-06-19 09:51:50 +00:00
|
|
|
CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Topic;
|
2017-03-26 13:14:32 +00:00
|
|
|
QString labelText = "Topic";
|
2015-06-19 10:48:58 +00:00
|
|
|
if (getCollectionId().getType() == CSMWorld::UniversalId::Type_JournalInfos)
|
2015-06-19 09:51:50 +00:00
|
|
|
{
|
|
|
|
displayType = CSMWorld::ColumnBase::Display_Journal;
|
2017-03-26 13:14:32 +00:00
|
|
|
labelText = "Journal";
|
2015-06-19 09:51:50 +00:00
|
|
|
}
|
2017-03-26 13:14:32 +00:00
|
|
|
|
|
|
|
QLabel* label = new QLabel(labelText, this);
|
|
|
|
insertBeforeButtons(label, false);
|
|
|
|
|
|
|
|
// Add topic/journal ID input with auto-completion.
|
|
|
|
// Only existing topic/journal IDs are accepted so no ID validation is performed.
|
2015-06-25 08:24:19 +00:00
|
|
|
mTopic = new CSVWidget::DropLineEdit(displayType, this);
|
2015-06-19 09:51:50 +00:00
|
|
|
mTopic->setCompleter(completionManager.getCompleter(displayType).get());
|
2013-11-08 10:51:59 +00:00
|
|
|
insertBeforeButtons(mTopic, true);
|
|
|
|
|
|
|
|
setManualEditing(false);
|
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mTopic, &CSVWidget::DropLineEdit::textChanged, this, &InfoCreator::topicChanged);
|
2022-08-23 02:53:19 +00:00
|
|
|
connect(mTopic, &CSVWidget::DropLineEdit::returnPressed, this, &InfoCreator::inputReturnPressed);
|
2013-11-08 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
2014-09-20 11:30:36 +00:00
|
|
|
void CSVWorld::InfoCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type)
|
|
|
|
{
|
|
|
|
CSMWorld::IdTable& infoTable = dynamic_cast<CSMWorld::IdTable&>(*getData().getTableModel(getCollectionId()));
|
|
|
|
|
|
|
|
int topicColumn = infoTable.findColumnIndex(getCollectionId().getType() == CSMWorld::UniversalId::Type_TopicInfos
|
|
|
|
? CSMWorld::Columns::ColumnId_Topic
|
|
|
|
: CSMWorld::Columns::ColumnId_Journal);
|
|
|
|
|
|
|
|
mTopic->setText(infoTable.data(infoTable.getModelIndex(originId, topicColumn)).toString());
|
|
|
|
|
|
|
|
GenericCreator::cloneMode(originId, type);
|
|
|
|
}
|
|
|
|
|
2013-11-08 10:51:59 +00:00
|
|
|
void CSVWorld::InfoCreator::reset()
|
|
|
|
{
|
|
|
|
mTopic->setText("");
|
|
|
|
GenericCreator::reset();
|
|
|
|
}
|
|
|
|
|
2023-01-14 18:36:49 +00:00
|
|
|
void CSVWorld::InfoCreator::setText(const std::string& text)
|
|
|
|
{
|
|
|
|
QString qText = QString::fromStdString(text);
|
|
|
|
mTopic->setText(qText);
|
|
|
|
}
|
|
|
|
|
2013-11-08 10:51:59 +00:00
|
|
|
std::string CSVWorld::InfoCreator::getErrors() const
|
|
|
|
{
|
|
|
|
// We ignore errors from GenericCreator here, because they can never happen in an InfoCreator.
|
|
|
|
std::string errors;
|
|
|
|
|
2023-02-16 20:37:33 +00:00
|
|
|
const ESM::RefId topic = ESM::RefId::stringRefId(mTopic->text().toStdString());
|
2013-11-08 10:51:59 +00:00
|
|
|
|
|
|
|
if ((getCollectionId().getType() == CSMWorld::UniversalId::Type_TopicInfos ? getData().getTopics()
|
|
|
|
: getData().getJournals())
|
|
|
|
.searchId(topic)
|
|
|
|
== -1)
|
|
|
|
{
|
|
|
|
errors += "Invalid Topic ID";
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2015-05-02 11:20:42 +00:00
|
|
|
void CSVWorld::InfoCreator::focus()
|
|
|
|
{
|
|
|
|
mTopic->setFocus();
|
|
|
|
}
|
|
|
|
|
2023-01-14 19:30:25 +00:00
|
|
|
void CSVWorld::InfoCreator::callReturnPressed()
|
|
|
|
{
|
|
|
|
emit inputReturnPressed();
|
|
|
|
}
|
|
|
|
|
2013-11-08 10:51:59 +00:00
|
|
|
void CSVWorld::InfoCreator::topicChanged()
|
|
|
|
{
|
|
|
|
update();
|
2015-03-11 14:54:45 +00:00
|
|
|
}
|
2015-06-19 09:51:50 +00:00
|
|
|
|
2016-03-25 16:13:55 +00:00
|
|
|
CSVWorld::Creator* CSVWorld::InfoCreatorFactory::makeCreator(
|
2015-06-19 09:51:50 +00:00
|
|
|
CSMDoc::Document& document, const CSMWorld::UniversalId& id) const
|
|
|
|
{
|
|
|
|
return new InfoCreator(document.getData(), document.getUndoStack(), id, document.getIdCompletionManager());
|
|
|
|
}
|