1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 07:23:51 +00:00

Cloning works for single record type tables. Well, kinda.

This commit is contained in:
Marek Kochanowicz 2014-01-20 13:59:00 +01:00
parent 0ea2bb7c4c
commit 33620a001b
15 changed files with 150 additions and 78 deletions

View file

@ -98,6 +98,11 @@ namespace CSMWorld
UniversalId::Type type = UniversalId::Type_None);
///< \param type Will be ignored, unless the collection supports multiple record types
virtual void cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type,
const UniversalId::ArgumentType argumentType);
virtual int searchId (const std::string& id) const;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
@ -193,6 +198,26 @@ namespace CSMWorld
return true;
}
template<typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type,
const UniversalId::ArgumentType argumentType)
{
Record<ESXRecordT> copy = getRecord(origin);
if (copy.isDeleted())
{
return;
}
if (argumentType == UniversalId::ArgumentType_Id)
{
copy.get().mId = Misc::StringUtils::lowerCase(destination);
}
insertRecord(copy, getAppendIndex(destination, type));
}
template<typename ESXRecordT, typename IdAccessorT>
Collection<ESXRecordT, IdAccessorT>::Collection()
{}

View file

@ -74,6 +74,11 @@ namespace CSMWorld
UniversalId::Type type = UniversalId::Type_None) = 0;
///< If the record type does not match, an exception is thrown.
virtual void cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type,
const UniversalId::ArgumentType argumentType) = 0;
virtual const RecordBase& getRecord (const std::string& id) const = 0;
virtual const RecordBase& getRecord (int index) const = 0;

View file

@ -28,12 +28,14 @@ void CSMWorld::ModifyCommand::undo()
CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model,
const std::string& idOrigin,
const std::string& IdDestination,
CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::ArgumentType argumentType,
QUndoCommand* parent) :
QUndoCommand(parent),
mModel(model),
mIdOrigin(idOrigin),
mIdDestination(IdDestination),
mArgumentType(argumentType),
mType(type)
{
setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str());
@ -42,7 +44,12 @@ CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model,
void CSMWorld::CloneCommand::redo()
{
mModel.cloneRecord(mIdOrigin, mIdDestination, mType);
mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType);
}
void CSMWorld::CloneCommand::undo()
{
mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row());
}
@ -166,3 +173,4 @@ void CSMWorld::ReorderRowsCommand::undo()
mModel.reorderRows(mBaseIndex, reverse);
}
// kate: indent-mode cstyle; indent-width 4; replace-tabs on;

View file

@ -45,18 +45,20 @@ namespace CSMWorld
std::string mIdOrigin;
std::string mIdDestination;
UniversalId::Type mType;
UniversalId::ArgumentType mArgumentType;
std::map<int, QVariant> mValues;
public:
CloneCommand (IdTable& model, const std::string& idOrigin,
const std::string& IdDestination,
UniversalId::Type type,
const UniversalId::Type type,
const UniversalId::ArgumentType argumentType,
QUndoCommand* parent = 0);
virtual void redo();
// virtual void undo();
virtual void undo();
};
class CreateCommand : public QUndoCommand

View file

@ -126,9 +126,10 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type
void CSMWorld::IdTable::cloneRecord(const std::string& origin,
const std::string& destination,
CSMWorld::UniversalId::ArgumentType argumentType,
CSMWorld::UniversalId::Type type)
{
mIdCollection->cloneRecord(origin, destination, type, argumentType);
}

View file

@ -63,7 +63,10 @@ namespace CSMWorld
void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None);
///< \param type Will be ignored, unless the collection supports multiple record types
void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None);
void cloneRecord(const std::string& origin,
const std::string& destination,
UniversalId::ArgumentType argumentType,
UniversalId::Type type = UniversalId::Type_None);
QModelIndex getModelIndex (const std::string& id, int column) const;

View file

@ -449,6 +449,14 @@ void CSMWorld::RefIdCollection::replace (int index, const RecordBase& record)
mData.getRecord (mData.globalToLocalIndex (index)).assign (record);
}
void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin,
const std::string& destination,
const CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::ArgumentType argumentType)
{
}
void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record,
UniversalId::Type type)
{

View file

@ -69,6 +69,11 @@ namespace CSMWorld
virtual void removeRows (int index, int count);
virtual void cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type,
const UniversalId::ArgumentType argumentType);
virtual void appendBlankRecord (const std::string& id, UniversalId::Type type);
///< \param type Will be ignored, unless the collection supports multiple record types

View file

@ -25,7 +25,7 @@ namespace CSVWorld
virtual void reset() = 0;
virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) = 0;
virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0;
virtual void setEditLock (bool locked) = 0;

View file

@ -59,7 +59,8 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
const CSMWorld::UniversalId& id, bool relaxedIdRules)
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None)
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None),
mArgumentType(CSMWorld::UniversalId::ArgumentType_None)
{
mLayout = new QHBoxLayout;
mLayout->setContentsMargins (0, 0, 0, 0);
@ -126,7 +127,12 @@ void CSVWorld::GenericCreator::create()
{
std::string id = getId();
std::auto_ptr<CSMWorld::CloneCommand> command (new CSMWorld::CloneCommand (
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel(mListId)), mClonedId, id, mClonedType));
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType));
mUndoStack.push(command.release());
emit done();
emit requestFocus(id);
} else {
std::string id = getId();
@ -143,11 +149,14 @@ void CSVWorld::GenericCreator::create()
}
}
void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type)
void CSVWorld::GenericCreator::cloneMode(const std::string& originid,
const CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::ArgumentType argumentType)
{
mCloneMode = true;
mClonedId = originid;
mClonedType = type;
mArgumentType = argumentType;
mId->setText(QString::fromStdString(mClonedId));
}

View file

@ -32,6 +32,7 @@ namespace CSVWorld
bool mCloneMode;
std::string mClonedId;
CSMWorld::UniversalId::Type mClonedType;
CSMWorld::UniversalId::ArgumentType mArgumentType;
protected:
@ -61,13 +62,14 @@ namespace CSVWorld
virtual void reset();
virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type);
virtual void cloneMode(const std::string& originid,
const CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::ArgumentType argumentType);
virtual std::string getErrors() const;
///< Return formatted error descriptions for the current state of the creator. if an empty
/// string is returned, there is no error.
private slots:
void textChanged (const QString& text);

View file

@ -158,10 +158,12 @@ void CSVWorld::TableBottomBox::createRequest()
mCreating = true;
}
void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type)
void CSVWorld::TableBottomBox::cloneRequest(const std::string& id,
const CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::ArgumentType argumnetType)
{
mCreator->reset();
mCreator->cloneMode(id, type);
mCreator->cloneMode(id, type, argumnetType);
mLayout->setCurrentWidget(mCreator);
setVisible (true);
mCreating = true;

View file

@ -77,7 +77,7 @@ namespace CSVWorld
/// \param modified Number of added and modified records
void createRequest();
void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type);
void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType);
};
}

View file

@ -50,8 +50,8 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest()));
connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int)));
connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)),
mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)));
connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)),
mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)));
}
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
mTable, SLOT (requestFocus (const std::string&)));
@ -85,5 +85,5 @@ void CSVWorld::TableSubView::setStatusBar (bool show)
void CSVWorld::TableSubView::cloneRequest(int row)
{
const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row));
emit cloneRequest(toClone.getId(), toClone.getType());
emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType());
}

View file

@ -35,7 +35,9 @@ namespace CSVWorld
virtual void setStatusBar (bool show);
signals:
void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type);
void cloneRequest(const std::string& id,
const CSMWorld::UniversalId::Type type,
const CSMWorld::UniversalId::ArgumentType argumentType);
private slots: