forked from mirror/openmw-tes3mp
added specialised Creator for referenceable records
This commit is contained in:
parent
34c825ce52
commit
57be764cce
10 changed files with 119 additions and 8 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
|
cellcreator referenceablecreator
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (view/world
|
opencs_units_noqt (view/world
|
||||||
|
|
|
@ -26,14 +26,19 @@ void CSMWorld::ModifyCommand::undo()
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent)
|
CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent)
|
||||||
: QUndoCommand (parent), mModel (model), mId (id)
|
: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None)
|
||||||
{
|
{
|
||||||
setText (("Create record " + id).c_str());
|
setText (("Create record " + id).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::CreateCommand::setType (UniversalId::Type type)
|
||||||
|
{
|
||||||
|
mType = type;
|
||||||
|
}
|
||||||
|
|
||||||
void CSMWorld::CreateCommand::redo()
|
void CSMWorld::CreateCommand::redo()
|
||||||
{
|
{
|
||||||
mModel.addRecord (mId);
|
mModel.addRecord (mId, mType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::CreateCommand::undo()
|
void CSMWorld::CreateCommand::undo()
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
#include "universalid.hpp"
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
|
|
||||||
|
@ -39,11 +41,14 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
std::string mId;
|
std::string mId;
|
||||||
|
UniversalId::Type mType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
||||||
|
|
||||||
|
void setType (UniversalId::Type type);
|
||||||
|
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
|
|
@ -116,13 +116,13 @@ QModelIndex CSMWorld::IdTable::parent (const QModelIndex& index) const
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::IdTable::addRecord (const std::string& id)
|
void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type)
|
||||||
{
|
{
|
||||||
int index = mIdCollection->getAppendIndex();
|
int index = mIdCollection->getAppendIndex();
|
||||||
|
|
||||||
beginInsertRows (QModelIndex(), index, index);
|
beginInsertRows (QModelIndex(), index, index);
|
||||||
|
|
||||||
mIdCollection->appendBlankRecord (id);
|
mIdCollection->appendBlankRecord (id, type);
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
|
#include "universalid.hpp"
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class CollectionBase;
|
class CollectionBase;
|
||||||
|
@ -44,7 +46,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual QModelIndex parent (const QModelIndex& index) const;
|
virtual QModelIndex parent (const QModelIndex& index) const;
|
||||||
|
|
||||||
void addRecord (const std::string& id);
|
void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None);
|
||||||
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||||
|
|
||||||
QModelIndex getModelIndex (const std::string& id, int column) const;
|
QModelIndex getModelIndex (const std::string& id, int column) const;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "genericcreator.hpp"
|
#include "genericcreator.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
@ -32,11 +34,18 @@ void CSVWorld::GenericCreator::insertAtBeginning (QWidget *widget, bool stretche
|
||||||
mLayout->insertWidget (0, widget, stretched ? 1 : 0);
|
mLayout->insertWidget (0, widget, stretched ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWorld::GenericCreator::insertBeforeButtons (QWidget *widget, bool stretched)
|
||||||
|
{
|
||||||
|
mLayout->insertWidget (mLayout->count()-2, widget, stretched ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
std::string CSVWorld::GenericCreator::getId() const
|
std::string CSVWorld::GenericCreator::getId() const
|
||||||
{
|
{
|
||||||
return mId->text().toUtf8().constData();
|
return mId->text().toUtf8().constData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -103,9 +112,13 @@ void CSVWorld::GenericCreator::create()
|
||||||
{
|
{
|
||||||
std::string id = getId();
|
std::string id = getId();
|
||||||
|
|
||||||
mUndoStack.push (new CSMWorld::CreateCommand (
|
std::auto_ptr<CSMWorld::CreateCommand> command (new CSMWorld::CreateCommand (
|
||||||
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel (mListId)), id));
|
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel (mListId)), id));
|
||||||
|
|
||||||
|
configureCreateCommand (*command);
|
||||||
|
|
||||||
|
mUndoStack.push (command.release());
|
||||||
|
|
||||||
emit done();
|
emit done();
|
||||||
emit requestFocus (id);
|
emit requestFocus (id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@ class QHBoxLayout;
|
||||||
|
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
|
namespace CSMWorld
|
||||||
|
{
|
||||||
|
class CreateCommand;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
class GenericCreator : public Creator
|
class GenericCreator : public Creator
|
||||||
|
@ -33,8 +38,12 @@ namespace CSVWorld
|
||||||
|
|
||||||
void insertAtBeginning (QWidget *widget, bool stretched);
|
void insertAtBeginning (QWidget *widget, bool stretched);
|
||||||
|
|
||||||
|
void insertBeforeButtons (QWidget *widget, bool stretched);
|
||||||
|
|
||||||
virtual std::string getId() const;
|
virtual std::string getId() const;
|
||||||
|
|
||||||
|
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
|
43
apps/opencs/view/world/referenceablecreator.cpp
Normal file
43
apps/opencs/view/world/referenceablecreator.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
#include "referenceablecreator.hpp"
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include "../../model/world/universalid.hpp"
|
||||||
|
#include "../../model/world/commands.hpp"
|
||||||
|
|
||||||
|
void CSVWorld::ReferenceableCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const
|
||||||
|
{
|
||||||
|
command.setType (
|
||||||
|
static_cast<CSMWorld::UniversalId::Type> (mType->itemData (mType->currentIndex()).toInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVWorld::ReferenceableCreator::ReferenceableCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id)
|
||||||
|
: GenericCreator (data, undoStack, id)
|
||||||
|
{
|
||||||
|
QLabel *label = new QLabel ("Type", this);
|
||||||
|
insertBeforeButtons (label, false);
|
||||||
|
|
||||||
|
std::vector<CSMWorld::UniversalId::Type> types = CSMWorld::UniversalId::listReferenceableTypes();
|
||||||
|
|
||||||
|
mType = new QComboBox (this);
|
||||||
|
|
||||||
|
for (std::vector<CSMWorld::UniversalId::Type>::const_iterator iter (types.begin());
|
||||||
|
iter!=types.end(); ++iter)
|
||||||
|
{
|
||||||
|
CSMWorld::UniversalId id (*iter, "");
|
||||||
|
|
||||||
|
mType->addItem (QIcon (id.getIcon().c_str()), id.getTypeName().c_str(),
|
||||||
|
static_cast<int> (id.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
insertBeforeButtons (mType, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ReferenceableCreator::reset()
|
||||||
|
{
|
||||||
|
mType->setCurrentIndex (0);
|
||||||
|
GenericCreator::reset();
|
||||||
|
}
|
30
apps/opencs/view/world/referenceablecreator.hpp
Normal file
30
apps/opencs/view/world/referenceablecreator.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef CSV_WORLD_REFERENCEABLECREATOR_H
|
||||||
|
#define CSV_WORLD_REFERENCEABLECREATOR_H
|
||||||
|
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
|
#include "genericcreator.hpp"
|
||||||
|
|
||||||
|
namespace CSVWorld
|
||||||
|
{
|
||||||
|
class ReferenceableCreator : public GenericCreator
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QComboBox *mType;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ReferenceableCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id);
|
||||||
|
|
||||||
|
virtual void reset();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,6 +9,7 @@
|
||||||
#include "regionmapsubview.hpp"
|
#include "regionmapsubview.hpp"
|
||||||
#include "genericcreator.hpp"
|
#include "genericcreator.hpp"
|
||||||
#include "cellcreator.hpp"
|
#include "cellcreator.hpp"
|
||||||
|
#include "referenceablecreator.hpp"
|
||||||
|
|
||||||
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +30,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_Referenceables,
|
|
||||||
CSMWorld::UniversalId::Type_References,
|
CSMWorld::UniversalId::Type_References,
|
||||||
|
|
||||||
CSMWorld::UniversalId::Type_None // end marker
|
CSMWorld::UniversalId::Type_None // end marker
|
||||||
|
@ -42,6 +42,9 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||||
manager.add (CSMWorld::UniversalId::Type_Cells,
|
manager.add (CSMWorld::UniversalId::Type_Cells,
|
||||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<CellCreator> >);
|
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<CellCreator> >);
|
||||||
|
|
||||||
|
manager.add (CSMWorld::UniversalId::Type_Referenceables,
|
||||||
|
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<ReferenceableCreator> >);
|
||||||
|
|
||||||
manager.add (CSMWorld::UniversalId::Type_Script, new CSVDoc::SubViewFactory<ScriptSubView>);
|
manager.add (CSMWorld::UniversalId::Type_Script, new CSVDoc::SubViewFactory<ScriptSubView>);
|
||||||
|
|
||||||
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