mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 10:09:39 +00:00
added specialised Creator for references
This commit is contained in:
parent
57be764cce
commit
102700a498
12 changed files with 169 additions and 6 deletions
|
@ -58,7 +58,7 @@ opencs_hdrs_noqt (view/doc
|
||||||
|
|
||||||
opencs_units (view/world
|
opencs_units (view/world
|
||||||
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
||||||
cellcreator referenceablecreator
|
cellcreator referenceablecreator referencecreator
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (view/world
|
opencs_units_noqt (view/world
|
||||||
|
|
|
@ -31,6 +31,11 @@ CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, Q
|
||||||
setText (("Create record " + id).c_str());
|
setText (("Create record " + id).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::CreateCommand::addValue (int column, const QVariant& value)
|
||||||
|
{
|
||||||
|
mValues[column] = value;
|
||||||
|
}
|
||||||
|
|
||||||
void CSMWorld::CreateCommand::setType (UniversalId::Type type)
|
void CSMWorld::CreateCommand::setType (UniversalId::Type type)
|
||||||
{
|
{
|
||||||
mType = type;
|
mType = type;
|
||||||
|
@ -39,6 +44,9 @@ void CSMWorld::CreateCommand::setType (UniversalId::Type type)
|
||||||
void CSMWorld::CreateCommand::redo()
|
void CSMWorld::CreateCommand::redo()
|
||||||
{
|
{
|
||||||
mModel.addRecord (mId, mType);
|
mModel.addRecord (mId, mType);
|
||||||
|
|
||||||
|
for (std::map<int, QVariant>::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter)
|
||||||
|
mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::CreateCommand::undo()
|
void CSMWorld::CreateCommand::undo()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "record.hpp"
|
#include "record.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
|
@ -42,6 +43,7 @@ namespace CSMWorld
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
std::string mId;
|
std::string mId;
|
||||||
UniversalId::Type mType;
|
UniversalId::Type mType;
|
||||||
|
std::map<int, QVariant> mValues;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -49,6 +51,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
void setType (UniversalId::Type type);
|
void setType (UniversalId::Type type);
|
||||||
|
|
||||||
|
void addValue (int column, const QVariant& value);
|
||||||
|
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
|
|
@ -300,6 +300,16 @@ CSMWorld::RefIdCollection& CSMWorld::Data::getReferenceables()
|
||||||
return mReferenceables;
|
return mReferenceables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CSMWorld::RefCollection& CSMWorld::Data::getReferences() const
|
||||||
|
{
|
||||||
|
return mRefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMWorld::RefCollection& CSMWorld::Data::getReferences()
|
||||||
|
{
|
||||||
|
return mRefs;
|
||||||
|
}
|
||||||
|
|
||||||
QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id)
|
QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id)
|
||||||
{
|
{
|
||||||
std::map<UniversalId::Type, QAbstractItemModel *>::iterator iter = mModelIndex.find (id.getType());
|
std::map<UniversalId::Type, QAbstractItemModel *>::iterator iter = mModelIndex.find (id.getType());
|
||||||
|
|
|
@ -112,6 +112,10 @@ namespace CSMWorld
|
||||||
|
|
||||||
RefIdCollection& getReferenceables();
|
RefIdCollection& getReferenceables();
|
||||||
|
|
||||||
|
const RefCollection& getReferences() const;
|
||||||
|
|
||||||
|
RefCollection& getReferences();
|
||||||
|
|
||||||
QAbstractItemModel *getTableModel (const UniversalId& id);
|
QAbstractItemModel *getTableModel (const UniversalId& id);
|
||||||
///< If no table model is available for \a id, an exception is thrown.
|
///< If no table model is available for \a id, an exception is thrown.
|
||||||
///
|
///
|
||||||
|
|
|
@ -21,10 +21,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
||||||
while (cell2.getNextRef (reader, ref))
|
while (cell2.getNextRef (reader, ref))
|
||||||
{
|
{
|
||||||
/// \todo handle deleted and moved references
|
/// \todo handle deleted and moved references
|
||||||
std::ostringstream stream;
|
ref.load (reader, cell2, getNewId());
|
||||||
stream << "ref#" << mNextId++;
|
|
||||||
|
|
||||||
ref.load (reader, cell2, stream.str());
|
|
||||||
|
|
||||||
Record<CellRef> record2;
|
Record<CellRef> record2;
|
||||||
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
||||||
|
@ -34,4 +31,11 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
mCells.setRecord (cellIndex, cell);
|
mCells.setRecord (cellIndex, cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CSMWorld::RefCollection::getNewId()
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << "ref#" << mNextId++;
|
||||||
|
return stream.str();
|
||||||
}
|
}
|
|
@ -21,6 +21,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
void load (ESM::ESMReader& reader, int cellIndex, bool base);
|
void load (ESM::ESMReader& reader, int cellIndex, bool base);
|
||||||
///< Load a sequence of references.
|
///< Load a sequence of references.
|
||||||
|
|
||||||
|
std::string getNewId();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,16 @@ std::string CSVWorld::GenericCreator::getId() const
|
||||||
|
|
||||||
void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {}
|
void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {}
|
||||||
|
|
||||||
|
const CSMWorld::Data& CSVWorld::GenericCreator::getData() const
|
||||||
|
{
|
||||||
|
return mData;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMWorld::Data& CSVWorld::GenericCreator::getData()
|
||||||
|
{
|
||||||
|
return mData;
|
||||||
|
}
|
||||||
|
|
||||||
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
const CSMWorld::UniversalId& id)
|
const CSMWorld::UniversalId& id)
|
||||||
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false)
|
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false)
|
||||||
|
|
|
@ -44,6 +44,10 @@ namespace CSVWorld
|
||||||
|
|
||||||
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||||
|
|
||||||
|
const CSMWorld::Data& getData() const;
|
||||||
|
|
||||||
|
CSMWorld::Data& getData();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
|
70
apps/opencs/view/world/referencecreator.cpp
Normal file
70
apps/opencs/view/world/referencecreator.cpp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
#include "referencecreator.hpp"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
#include "../../model/world/data.hpp"
|
||||||
|
#include "../../model/world/commands.hpp"
|
||||||
|
|
||||||
|
std::string CSVWorld::ReferenceCreator::getId() const
|
||||||
|
{
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const
|
||||||
|
{
|
||||||
|
/// \todo avoid using hard-coded column numbers
|
||||||
|
command.addValue (2, mCell->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id)
|
||||||
|
: GenericCreator (data, undoStack, id)
|
||||||
|
{
|
||||||
|
QLabel *label = new QLabel ("Cell", this);
|
||||||
|
insertBeforeButtons (label, false);
|
||||||
|
|
||||||
|
mCell = new QLineEdit (this);
|
||||||
|
insertBeforeButtons (mCell, true);
|
||||||
|
|
||||||
|
setManualEditing (false);
|
||||||
|
|
||||||
|
connect (mCell, SIGNAL (textChanged (const QString&)), this, SLOT (cellChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ReferenceCreator::reset()
|
||||||
|
{
|
||||||
|
mCell->setText ("");
|
||||||
|
mId = getData().getReferences().getNewId();
|
||||||
|
GenericCreator::reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CSVWorld::ReferenceCreator::getErrors() const
|
||||||
|
{
|
||||||
|
std::string errors = GenericCreator::getErrors();
|
||||||
|
|
||||||
|
std::string cell = mCell->text().toUtf8().constData();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ReferenceCreator::cellChanged()
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
40
apps/opencs/view/world/referencecreator.hpp
Normal file
40
apps/opencs/view/world/referencecreator.hpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef CSV_WORLD_REFERENCECREATOR_H
|
||||||
|
#define CSV_WORLD_REFERENCECREATOR_H
|
||||||
|
|
||||||
|
#include "genericcreator.hpp"
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
namespace CSVWorld
|
||||||
|
{
|
||||||
|
class ReferenceCreator : public GenericCreator
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QLineEdit *mCell;
|
||||||
|
std::string mId;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
virtual std::string getId() const;
|
||||||
|
|
||||||
|
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id);
|
||||||
|
|
||||||
|
virtual void reset();
|
||||||
|
|
||||||
|
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 cellChanged();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -10,9 +10,12 @@
|
||||||
#include "genericcreator.hpp"
|
#include "genericcreator.hpp"
|
||||||
#include "cellcreator.hpp"
|
#include "cellcreator.hpp"
|
||||||
#include "referenceablecreator.hpp"
|
#include "referenceablecreator.hpp"
|
||||||
|
#include "referencecreator.hpp"
|
||||||
|
|
||||||
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||||
{
|
{
|
||||||
|
// Regular record tables (including references which are actually sub-records, but are promoted
|
||||||
|
// to top-level records within the editor)
|
||||||
manager.add (CSMWorld::UniversalId::Type_Gmsts,
|
manager.add (CSMWorld::UniversalId::Type_Gmsts,
|
||||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, NullCreatorFactory>);
|
new CSVDoc::SubViewFactoryWithCreator<TableSubView, NullCreatorFactory>);
|
||||||
|
|
||||||
|
@ -30,7 +33,6 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||||
CSMWorld::UniversalId::Type_Regions,
|
CSMWorld::UniversalId::Type_Regions,
|
||||||
CSMWorld::UniversalId::Type_Birthsigns,
|
CSMWorld::UniversalId::Type_Birthsigns,
|
||||||
CSMWorld::UniversalId::Type_Spells,
|
CSMWorld::UniversalId::Type_Spells,
|
||||||
CSMWorld::UniversalId::Type_References,
|
|
||||||
|
|
||||||
CSMWorld::UniversalId::Type_None // end marker
|
CSMWorld::UniversalId::Type_None // end marker
|
||||||
};
|
};
|
||||||
|
@ -45,7 +47,12 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||||
manager.add (CSMWorld::UniversalId::Type_Referenceables,
|
manager.add (CSMWorld::UniversalId::Type_Referenceables,
|
||||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<ReferenceableCreator> >);
|
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<ReferenceableCreator> >);
|
||||||
|
|
||||||
|
manager.add (CSMWorld::UniversalId::Type_References,
|
||||||
|
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<ReferenceCreator> >);
|
||||||
|
|
||||||
|
// Subviews for editing/viewing individual records
|
||||||
manager.add (CSMWorld::UniversalId::Type_Script, new CSVDoc::SubViewFactory<ScriptSubView>);
|
manager.add (CSMWorld::UniversalId::Type_Script, new CSVDoc::SubViewFactory<ScriptSubView>);
|
||||||
|
|
||||||
|
// Other stuff (combined record tables)
|
||||||
manager.add (CSMWorld::UniversalId::Type_RegionMap, new CSVDoc::SubViewFactory<RegionMapSubView>);
|
manager.add (CSMWorld::UniversalId::Type_RegionMap, new CSVDoc::SubViewFactory<RegionMapSubView>);
|
||||||
}
|
}
|
Loading…
Reference in a new issue