forked from mirror/openmw-tes3mp
replaced createAndDelete flag with a new class hierarhy (Creator)
This commit is contained in:
parent
4327b81bc3
commit
ba5ca5beed
9 changed files with 108 additions and 24 deletions
|
@ -63,7 +63,7 @@ opencs_units (view/world
|
|||
opencs_units_noqt (view/world
|
||||
dialoguesubview subviews
|
||||
enumdelegate vartypedelegate recordstatusdelegate refidtypedelegate datadisplaydelegate
|
||||
scripthighlighter
|
||||
scripthighlighter creator genericcreator
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -22,28 +22,20 @@ namespace CSVDoc
|
|||
return new SubViewT (id, document);
|
||||
}
|
||||
|
||||
template<class SubViewT>
|
||||
class SubViewFactoryWithCreateFlag : public SubViewFactoryBase
|
||||
|
||||
template<class SubViewT, class CreatorFactoryT>
|
||||
class SubViewFactoryWithCreator : public SubViewFactoryBase
|
||||
{
|
||||
bool mCreateAndDelete;
|
||||
|
||||
public:
|
||||
|
||||
SubViewFactoryWithCreateFlag (bool createAndDelete);
|
||||
|
||||
virtual CSVDoc::SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
};
|
||||
|
||||
template<class SubViewT>
|
||||
SubViewFactoryWithCreateFlag<SubViewT>::SubViewFactoryWithCreateFlag (bool createAndDelete)
|
||||
: mCreateAndDelete (createAndDelete)
|
||||
{}
|
||||
|
||||
template<class SubViewT>
|
||||
CSVDoc::SubView *SubViewFactoryWithCreateFlag<SubViewT>::makeSubView (const CSMWorld::UniversalId& id,
|
||||
CSMDoc::Document& document)
|
||||
template<class SubViewT, class CreatorFactoryT>
|
||||
CSVDoc::SubView *SubViewFactoryWithCreator<SubViewT, CreatorFactoryT>::makeSubView (
|
||||
const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
{
|
||||
return new SubViewT (id, document, mCreateAndDelete);
|
||||
return new SubViewT (id, document, CreatorFactoryT().makeCreator());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
apps/opencs/view/world/creator.cpp
Normal file
12
apps/opencs/view/world/creator.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
#include "creator.hpp"
|
||||
|
||||
CSVWorld::Creator:: ~Creator() {}
|
||||
|
||||
CSVWorld::CreatorFactoryBase::~CreatorFactoryBase() {}
|
||||
|
||||
|
||||
CSVWorld::Creator *CSVWorld::NullCreatorFactory::makeCreator() const
|
||||
{
|
||||
return 0;
|
||||
}
|
58
apps/opencs/view/world/creator.hpp
Normal file
58
apps/opencs/view/world/creator.hpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#ifndef CSV_WORLD_CREATOR_H
|
||||
#define CSV_WORLD_CREATOR_H
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
/// \brief Record creator UI base class
|
||||
class Creator
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Creator();
|
||||
};
|
||||
|
||||
/// \brief Base class for Creator factory
|
||||
class CreatorFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~CreatorFactoryBase();
|
||||
|
||||
virtual Creator *makeCreator() const = 0;
|
||||
///< The ownership of the returned Creator is transferred to the caller.
|
||||
///
|
||||
/// \note The function can return a 0-pointer, which means no UI for creating/deleting
|
||||
/// records should be provided.
|
||||
};
|
||||
|
||||
/// \brief Creator factory that does not produces any creator
|
||||
class NullCreatorFactory : public CreatorFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual Creator *makeCreator() const;
|
||||
///< The ownership of the returned Creator is transferred to the caller.
|
||||
///
|
||||
/// \note The function always returns 0.
|
||||
};
|
||||
|
||||
template<class CreatorT>
|
||||
class CreatorFactory : public CreatorFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual Creator *makeCreator() const;
|
||||
///< The ownership of the returned Creator is transferred to the caller.
|
||||
///
|
||||
/// \note The function can return a 0-pointer, which means no UI for creating/deleting
|
||||
/// records should be provided.
|
||||
};
|
||||
|
||||
template<class CreatorT>
|
||||
Creator *CreatorFactory<CreatorT>::makeCreator() const
|
||||
{
|
||||
return new CreatorT;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
2
apps/opencs/view/world/genericcreator.cpp
Normal file
2
apps/opencs/view/world/genericcreator.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
#include "genericcreator.hpp"
|
14
apps/opencs/view/world/genericcreator.hpp
Normal file
14
apps/opencs/view/world/genericcreator.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef CSV_WORLD_GENERICCREATOR_H
|
||||
#define CSV_WORLD_GENERICCREATOR_H
|
||||
|
||||
#include "creator.hpp"
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class GenericCreator : public Creator
|
||||
{
|
||||
public:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -7,14 +7,15 @@
|
|||
#include "dialoguesubview.hpp"
|
||||
#include "scriptsubview.hpp"
|
||||
#include "regionmapsubview.hpp"
|
||||
#include "genericcreator.hpp"
|
||||
|
||||
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||
{
|
||||
manager.add (CSMWorld::UniversalId::Type_Gmsts,
|
||||
new CSVDoc::SubViewFactoryWithCreateFlag<TableSubView> (false));
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, NullCreatorFactory>);
|
||||
|
||||
manager.add (CSMWorld::UniversalId::Type_Skills,
|
||||
new CSVDoc::SubViewFactoryWithCreateFlag<TableSubView> (false));
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, NullCreatorFactory>);
|
||||
|
||||
static const CSMWorld::UniversalId::Type sTableTypes[] =
|
||||
{
|
||||
|
@ -35,12 +36,10 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
|||
};
|
||||
|
||||
for (int i=0; sTableTypes[i]!=CSMWorld::UniversalId::Type_None; ++i)
|
||||
manager.add (sTableTypes[i], new CSVDoc::SubViewFactoryWithCreateFlag<TableSubView> (true));
|
||||
manager.add (sTableTypes[i],
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<GenericCreator> >);
|
||||
|
||||
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_Global,
|
||||
// new CSVDoc::SubViewFactoryWithCreateFlag<DialogueSubView> (true));
|
||||
}
|
|
@ -7,11 +7,15 @@
|
|||
|
||||
#include "table.hpp"
|
||||
#include "tablebottombox.hpp"
|
||||
#include "creator.hpp"
|
||||
|
||||
CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
|
||||
bool createAndDelete)
|
||||
Creator *creator)
|
||||
: SubView (id)
|
||||
{
|
||||
bool createAndDelete = creator!=0;
|
||||
delete creator;
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
|
||||
layout->setContentsMargins (QMargins (0, 0, 0, 0));
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace CSVWorld
|
|||
{
|
||||
class Table;
|
||||
class TableBottomBox;
|
||||
class Creator;
|
||||
|
||||
class TableSubView : public CSVDoc::SubView
|
||||
{
|
||||
|
@ -24,7 +25,9 @@ namespace CSVWorld
|
|||
|
||||
public:
|
||||
|
||||
TableSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete);
|
||||
TableSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
|
||||
Creator *creator = 0);
|
||||
///< The ownership of \a creator is transferred to this.
|
||||
|
||||
virtual void setEditLock (bool locked);
|
||||
|
||||
|
|
Loading…
Reference in a new issue