|
|
|
@ -16,11 +16,58 @@ std::string CSVWorld::ReferenceCreator::getId() const
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const
|
|
|
|
|
{
|
|
|
|
|
int index =
|
|
|
|
|
// Set cellID
|
|
|
|
|
int cellIdColumn =
|
|
|
|
|
dynamic_cast<CSMWorld::IdTable&> (*getData().getTableModel (getCollectionId())).
|
|
|
|
|
findColumnIndex (CSMWorld::Columns::ColumnId_Cell);
|
|
|
|
|
|
|
|
|
|
command.addValue (index, mCell->text());
|
|
|
|
|
command.addValue (cellIdColumn, mCell->text());
|
|
|
|
|
|
|
|
|
|
// Set RefNum
|
|
|
|
|
int refNumColumn = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
|
*getData().getTableModel (CSMWorld::UniversalId::Type_References)).
|
|
|
|
|
findColumnIndex (CSMWorld::Columns::ColumnId_RefNum);
|
|
|
|
|
|
|
|
|
|
command.addValue (refNumColumn, getRefNumCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ReferenceCreator::pushCommand (std::auto_ptr<CSMWorld::CreateCommand> command,
|
|
|
|
|
const std::string& id)
|
|
|
|
|
{
|
|
|
|
|
// get the old count
|
|
|
|
|
std::string cellId = mCell->text().toUtf8().constData();
|
|
|
|
|
|
|
|
|
|
CSMWorld::IdTable& cellTable = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
|
*getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
|
|
|
|
|
|
|
|
|
|
int countColumn = cellTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNumCounter);
|
|
|
|
|
|
|
|
|
|
QModelIndex countIndex = cellTable.getModelIndex (cellId, countColumn);
|
|
|
|
|
|
|
|
|
|
int count = cellTable.data (countIndex).toInt();
|
|
|
|
|
|
|
|
|
|
// command for incrementing counter
|
|
|
|
|
std::auto_ptr<CSMWorld::ModifyCommand> increment (new CSMWorld::ModifyCommand
|
|
|
|
|
(cellTable, countIndex, count+1));
|
|
|
|
|
|
|
|
|
|
getUndoStack().beginMacro (command->text());
|
|
|
|
|
GenericCreator::pushCommand (command, id);
|
|
|
|
|
getUndoStack().push (increment.release());
|
|
|
|
|
getUndoStack().endMacro();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CSVWorld::ReferenceCreator::getRefNumCount() const
|
|
|
|
|
{
|
|
|
|
|
std::string cellId = mCell->text().toUtf8().constData();
|
|
|
|
|
|
|
|
|
|
CSMWorld::IdTable& cellTable = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
|
*getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
|
|
|
|
|
|
|
|
|
|
int countColumn = cellTable.findColumnIndex (CSMWorld::Columns::ColumnId_RefNumCounter);
|
|
|
|
|
|
|
|
|
|
QModelIndex countIndex = cellTable.getModelIndex (cellId, countColumn);
|
|
|
|
|
|
|
|
|
|
return cellTable.data (countIndex).toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
|
|
|
@ -47,12 +94,9 @@ void CSVWorld::ReferenceCreator::reset()
|
|
|
|
|
|
|
|
|
|
std::string CSVWorld::ReferenceCreator::getErrors() const
|
|
|
|
|
{
|
|
|
|
|
std::string errors = GenericCreator::getErrors();
|
|
|
|
|
|
|
|
|
|
if (mCloneMode)
|
|
|
|
|
{
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
// We are ignoring errors coming from GenericCreator here, because the ID of the new
|
|
|
|
|
// record is internal and requires neither user input nor verification.
|
|
|
|
|
std::string errors;
|
|
|
|
|
|
|
|
|
|
std::string cell = mCell->text().toUtf8().constData();
|
|
|
|
|
|
|
|
|
@ -79,15 +123,17 @@ void CSVWorld::ReferenceCreator::cellChanged()
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ReferenceCreator::toggleWidgets(bool active)
|
|
|
|
|
{
|
|
|
|
|
CSVWorld::GenericCreator::toggleWidgets(active);
|
|
|
|
|
mCell->setEnabled(active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ReferenceCreator::cloneMode(const std::string& originId,
|
|
|
|
|
const CSMWorld::UniversalId::Type type)
|
|
|
|
|
{
|
|
|
|
|
CSMWorld::IdTable& referenceTable = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
|
*getData().getTableModel (CSMWorld::UniversalId::Type_References));
|
|
|
|
|
|
|
|
|
|
int cellIdColumn = referenceTable.findColumnIndex (CSMWorld::Columns::ColumnId_Cell);
|
|
|
|
|
|
|
|
|
|
mCell->setText (
|
|
|
|
|
referenceTable.data (referenceTable.getModelIndex (originId, cellIdColumn)).toString());
|
|
|
|
|
|
|
|
|
|
CSVWorld::GenericCreator::cloneMode(originId, type);
|
|
|
|
|
cellChanged(); //otherwise ok button will remain disabled
|
|
|
|
|
}
|
|
|
|
|