mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
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
|
||||
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
||||
cellcreator
|
||||
cellcreator referenceablecreator
|
||||
)
|
||||
|
||||
opencs_units_noqt (view/world
|
||||
|
|
|
@ -26,14 +26,19 @@ void CSMWorld::ModifyCommand::undo()
|
|||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
void CSMWorld::CreateCommand::setType (UniversalId::Type type)
|
||||
{
|
||||
mType = type;
|
||||
}
|
||||
|
||||
void CSMWorld::CreateCommand::redo()
|
||||
{
|
||||
mModel.addRecord (mId);
|
||||
mModel.addRecord (mId, mType);
|
||||
}
|
||||
|
||||
void CSMWorld::CreateCommand::undo()
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include <QUndoCommand>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "universalid.hpp"
|
||||
|
||||
class QModelIndex;
|
||||
class QAbstractItemModel;
|
||||
|
||||
|
@ -39,11 +41,14 @@ namespace CSMWorld
|
|||
{
|
||||
IdTable& mModel;
|
||||
std::string mId;
|
||||
UniversalId::Type mType;
|
||||
|
||||
public:
|
||||
|
||||
CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
||||
|
||||
void setType (UniversalId::Type type);
|
||||
|
||||
virtual void redo();
|
||||
|
||||
virtual void undo();
|
||||
|
|
|
@ -116,13 +116,13 @@ QModelIndex CSMWorld::IdTable::parent (const QModelIndex& index) const
|
|||
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();
|
||||
|
||||
beginInsertRows (QModelIndex(), index, index);
|
||||
|
||||
mIdCollection->appendBlankRecord (id);
|
||||
mIdCollection->appendBlankRecord (id, type);
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#include "universalid.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class CollectionBase;
|
||||
|
@ -44,7 +46,8 @@ namespace CSMWorld
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "genericcreator.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
|
@ -32,11 +34,18 @@ void CSVWorld::GenericCreator::insertAtBeginning (QWidget *widget, bool stretche
|
|||
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
|
||||
{
|
||||
return mId->text().toUtf8().constData();
|
||||
}
|
||||
|
||||
void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {}
|
||||
|
||||
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
const CSMWorld::UniversalId& id)
|
||||
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false)
|
||||
|
@ -103,9 +112,13 @@ void CSVWorld::GenericCreator::create()
|
|||
{
|
||||
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));
|
||||
|
||||
configureCreateCommand (*command);
|
||||
|
||||
mUndoStack.push (command.release());
|
||||
|
||||
emit done();
|
||||
emit requestFocus (id);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,11 @@ class QHBoxLayout;
|
|||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class CreateCommand;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class GenericCreator : public Creator
|
||||
|
@ -33,8 +38,12 @@ namespace CSVWorld
|
|||
|
||||
void insertAtBeginning (QWidget *widget, bool stretched);
|
||||
|
||||
void insertBeforeButtons (QWidget *widget, bool stretched);
|
||||
|
||||
virtual std::string getId() const;
|
||||
|
||||
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||
|
||||
public:
|
||||
|
||||
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 "genericcreator.hpp"
|
||||
#include "cellcreator.hpp"
|
||||
#include "referenceablecreator.hpp"
|
||||
|
||||
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||
{
|
||||
|
@ -29,7 +30,6 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
|||
CSMWorld::UniversalId::Type_Regions,
|
||||
CSMWorld::UniversalId::Type_Birthsigns,
|
||||
CSMWorld::UniversalId::Type_Spells,
|
||||
CSMWorld::UniversalId::Type_Referenceables,
|
||||
CSMWorld::UniversalId::Type_References,
|
||||
|
||||
CSMWorld::UniversalId::Type_None // end marker
|
||||
|
@ -42,6 +42,9 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
|||
manager.add (CSMWorld::UniversalId::Type_Cells,
|
||||
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_RegionMap, new CSVDoc::SubViewFactory<RegionMapSubView>);
|
||||
|
|
Loading…
Reference in a new issue