2013-07-30 10:53:03 +00:00
|
|
|
|
|
|
|
#include "referencecreator.hpp"
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
2015-06-19 08:50:02 +00:00
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
|
2013-07-30 10:53:03 +00:00
|
|
|
#include "../../model/world/data.hpp"
|
|
|
|
#include "../../model/world/commands.hpp"
|
2013-08-08 10:49:30 +00:00
|
|
|
#include "../../model/world/columns.hpp"
|
|
|
|
#include "../../model/world/idtable.hpp"
|
2015-06-19 08:50:02 +00:00
|
|
|
#include "../../model/world/idcompletionmanager.hpp"
|
2013-07-30 10:53:03 +00:00
|
|
|
|
2015-06-25 08:20:35 +00:00
|
|
|
#include "../widget/droplineedit.hpp"
|
|
|
|
|
2013-07-30 10:53:03 +00:00
|
|
|
std::string CSVWorld::ReferenceCreator::getId() const
|
|
|
|
{
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const
|
|
|
|
{
|
2014-09-18 11:41:29 +00:00
|
|
|
// Set cellID
|
|
|
|
int cellIdColumn =
|
2013-08-08 10:49:30 +00:00
|
|
|
dynamic_cast<CSMWorld::IdTable&> (*getData().getTableModel (getCollectionId())).
|
|
|
|
findColumnIndex (CSMWorld::Columns::ColumnId_Cell);
|
|
|
|
|
2014-09-18 11:41:29 +00:00
|
|
|
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());
|
2013-07-30 10:53:03 +00:00
|
|
|
}
|
|
|
|
|
2014-09-20 10:37:25 +00:00
|
|
|
void CSVWorld::ReferenceCreator::pushCommand (std::auto_ptr<CSMWorld::CreateCommand> command,
|
2014-09-18 10:25:17 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-09-18 11:41:29 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-07-30 10:53:03 +00:00
|
|
|
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
2015-06-19 08:50:02 +00:00
|
|
|
const CSMWorld::UniversalId& id, CSMWorld::IdCompletionManager &completionManager)
|
2013-07-30 10:53:03 +00:00
|
|
|
: GenericCreator (data, undoStack, id)
|
|
|
|
{
|
|
|
|
QLabel *label = new QLabel ("Cell", this);
|
|
|
|
insertBeforeButtons (label, false);
|
|
|
|
|
2015-06-25 08:20:35 +00:00
|
|
|
mCell = new CSVWidget::DropLineEdit(CSMWorld::ColumnBase::Display_Cell, this);
|
2015-06-19 08:50:02 +00:00
|
|
|
mCell->setCompleter(completionManager.getCompleter(CSMWorld::ColumnBase::Display_Cell).get());
|
2013-07-30 10:53:03 +00:00
|
|
|
insertBeforeButtons (mCell, true);
|
|
|
|
|
|
|
|
setManualEditing (false);
|
|
|
|
|
|
|
|
connect (mCell, SIGNAL (textChanged (const QString&)), this, SLOT (cellChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVWorld::ReferenceCreator::reset()
|
|
|
|
{
|
2014-01-23 08:40:32 +00:00
|
|
|
GenericCreator::reset();
|
2013-07-30 10:53:03 +00:00
|
|
|
mCell->setText ("");
|
|
|
|
mId = getData().getReferences().getNewId();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSVWorld::ReferenceCreator::getErrors() const
|
|
|
|
{
|
2014-09-18 10:39:29 +00:00
|
|
|
// 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;
|
2013-07-30 10:53:03 +00:00
|
|
|
|
|
|
|
std::string cell = mCell->text().toUtf8().constData();
|
2014-01-27 18:40:05 +00:00
|
|
|
|
2013-07-30 10:53:03 +00:00
|
|
|
if (cell.empty())
|
|
|
|
{
|
|
|
|
if (!errors.empty())
|
|
|
|
errors += "<br>";
|
|
|
|
|
|
|
|
errors += "Missing Cell ID";
|
|
|
|
}
|
|
|
|
else if (getData().getCells().searchId (cell)==-1)
|
|
|
|
{
|
|
|
|
if (!errors.empty())
|
|
|
|
errors += "<br>";
|
|
|
|
|
|
|
|
errors += "Invalid Cell ID";
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2015-05-02 11:20:42 +00:00
|
|
|
void CSVWorld::ReferenceCreator::focus()
|
|
|
|
{
|
|
|
|
mCell->setFocus();
|
|
|
|
}
|
|
|
|
|
2013-07-30 10:53:03 +00:00
|
|
|
void CSVWorld::ReferenceCreator::cellChanged()
|
|
|
|
{
|
|
|
|
update();
|
2014-01-23 15:17:04 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 12:13:39 +00:00
|
|
|
void CSVWorld::ReferenceCreator::cloneMode(const std::string& originId,
|
2014-01-27 12:08:14 +00:00
|
|
|
const CSMWorld::UniversalId::Type type)
|
2014-01-23 15:17:04 +00:00
|
|
|
{
|
2014-09-20 10:54:25 +00:00
|
|
|
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());
|
|
|
|
|
2014-01-27 12:13:39 +00:00
|
|
|
CSVWorld::GenericCreator::cloneMode(originId, type);
|
2014-01-23 15:17:04 +00:00
|
|
|
cellChanged(); //otherwise ok button will remain disabled
|
|
|
|
}
|
2015-06-19 08:50:02 +00:00
|
|
|
|
|
|
|
CSVWorld::Creator *CSVWorld::ReferenceCreatorFactory::makeCreator (CSMDoc::Document& document,
|
|
|
|
const CSMWorld::UniversalId& id) const
|
|
|
|
{
|
|
|
|
return new ReferenceCreator(document.getData(),
|
|
|
|
document.getUndoStack(),
|
|
|
|
id,
|
|
|
|
document.getIdCompletionManager());
|
|
|
|
}
|