rewrote subview factory system
parent
0ed378dfb2
commit
2db930a5cf
@ -0,0 +1,41 @@
|
||||
#ifndef CSV_DOC_SUBVIEW_H
|
||||
#define CSV_DOC_SUBVIEW_H
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
#include "subviewfactory.hpp"
|
||||
|
||||
#include <QDockWidget>
|
||||
|
||||
class QUndoStack;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Data;
|
||||
}
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class SubView : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMWorld::UniversalId mUniversalId;
|
||||
|
||||
// not implemented
|
||||
SubView (const SubView&);
|
||||
SubView& operator= (SubView&);
|
||||
|
||||
public:
|
||||
|
||||
SubView (const CSMWorld::UniversalId& id);
|
||||
|
||||
CSMWorld::UniversalId getUniversalId() const;
|
||||
|
||||
virtual void setEditLock (bool locked) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,38 @@
|
||||
|
||||
#include "subviewfactory.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
CSVDoc::SubViewFactoryBase::SubViewFactoryBase() {}
|
||||
|
||||
CSVDoc::SubViewFactoryBase::~SubViewFactoryBase() {}
|
||||
|
||||
|
||||
CSVDoc::SubViewFactoryManager::SubViewFactoryManager() {}
|
||||
|
||||
CSVDoc::SubViewFactoryManager::~SubViewFactoryManager()
|
||||
{
|
||||
for (std::map<CSMWorld::UniversalId::Type, SubViewFactoryBase *>::iterator iter (mSubViewFactories.begin());
|
||||
iter!=mSubViewFactories.end(); ++iter)
|
||||
delete iter->second;
|
||||
}
|
||||
|
||||
void CSVDoc::SubViewFactoryManager::add (const CSMWorld::UniversalId::Type& id, SubViewFactoryBase *factory)
|
||||
{
|
||||
assert (mSubViewFactories.find (id)==mSubViewFactories.end());
|
||||
|
||||
mSubViewFactories.insert (std::make_pair (id, factory));
|
||||
}
|
||||
|
||||
CSVDoc::SubView *CSVDoc::SubViewFactoryManager::makeSubView (const CSMWorld::UniversalId& id,
|
||||
CSMDoc::Document& document)
|
||||
{
|
||||
std::map<CSMWorld::UniversalId::Type, SubViewFactoryBase *>::iterator iter = mSubViewFactories.find (id.getType());
|
||||
|
||||
if (iter==mSubViewFactories.end())
|
||||
throw std::runtime_error ("Failed to create a sub view for: " + id.toString());
|
||||
|
||||
return iter->second->makeSubView (id, document);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
#ifndef CSV_DOC_SUBVIEWFACTORY_H
|
||||
#define CSV_DOC_SUBVIEWFACTORY_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class SubView;
|
||||
|
||||
class SubViewFactoryBase
|
||||
{
|
||||
// not implemented
|
||||
SubViewFactoryBase (const SubViewFactoryBase&);
|
||||
SubViewFactoryBase& operator= (const SubViewFactoryBase&);
|
||||
|
||||
public:
|
||||
|
||||
SubViewFactoryBase();
|
||||
|
||||
virtual ~SubViewFactoryBase();
|
||||
|
||||
virtual SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) = 0;
|
||||
///< The ownership of the returned sub view is not transferred.
|
||||
};
|
||||
|
||||
class SubViewFactoryManager
|
||||
{
|
||||
std::map<CSMWorld::UniversalId::Type, SubViewFactoryBase *> mSubViewFactories;
|
||||
|
||||
// not implemented
|
||||
SubViewFactoryManager (const SubViewFactoryManager&);
|
||||
SubViewFactoryManager& operator= (const SubViewFactoryManager&);
|
||||
|
||||
public:
|
||||
|
||||
SubViewFactoryManager();
|
||||
|
||||
~SubViewFactoryManager();
|
||||
|
||||
void add (const CSMWorld::UniversalId::Type& id, SubViewFactoryBase *factory);
|
||||
///< The ownership of \a factory is transferred to this.
|
||||
|
||||
SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
///< The ownership of the returned sub view is not transferred.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,50 @@
|
||||
#ifndef CSV_DOC_SUBVIEWFACTORYIMP_H
|
||||
#define CSV_DOC_SUBVIEWFACTORYIMP_H
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
#include "subviewfactory.hpp"
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
template<class SubViewT>
|
||||
class SubViewFactory : public SubViewFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual CSVDoc::SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
};
|
||||
|
||||
template<class SubViewT>
|
||||
CSVDoc::SubView *SubViewFactory<SubViewT>::makeSubView (const CSMWorld::UniversalId& id,
|
||||
CSMDoc::Document& document)
|
||||
{
|
||||
return new SubViewT (id, document);
|
||||
}
|
||||
|
||||
template<class SubViewT>
|
||||
class SubViewFactoryWithCreateFlag : 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)
|
||||
{
|
||||
return new SubViewT (id, document, mCreateAndDelete);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,79 +0,0 @@
|
||||
#ifndef CSV_WORLD_SUBVIEW_H
|
||||
#define CSV_WORLD_SUBVIEW_H
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
#include <QDockWidget>
|
||||
|
||||
class QUndoStack;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Data;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class SubView : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMWorld::UniversalId mUniversalId;
|
||||
|
||||
// not implemented
|
||||
SubView (const SubView&);
|
||||
SubView& operator= (SubView&);
|
||||
|
||||
public:
|
||||
|
||||
SubView (const CSMWorld::UniversalId& id);
|
||||
|
||||
CSMWorld::UniversalId getUniversalId() const;
|
||||
|
||||
virtual void setEditLock (bool locked) = 0;
|
||||
};
|
||||
|
||||
struct SubViewFactoryBase
|
||||
{
|
||||
virtual SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
= 0;
|
||||
};
|
||||
|
||||
template<class SubViewT>
|
||||
struct SubViewFactory : public SubViewFactoryBase
|
||||
{
|
||||
virtual SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
};
|
||||
|
||||
template<class SubViewT>
|
||||
SubView *SubViewFactory<SubViewT>::makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
{
|
||||
return new SubViewT (id, document.getData(), document.getUndoStack());
|
||||
}
|
||||
|
||||
template<class SubViewT>
|
||||
struct SubViewFactoryWithCreateFlag : public SubViewFactoryBase
|
||||
{
|
||||
bool mCreateAndDelete;
|
||||
|
||||
SubViewFactoryWithCreateFlag (bool createAndDelete);
|
||||
|
||||
virtual SubView *makeSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
};
|
||||
|
||||
template<class SubViewT>
|
||||
SubViewFactoryWithCreateFlag<SubViewT>::SubViewFactoryWithCreateFlag (bool createAndDelete)
|
||||
: mCreateAndDelete (createAndDelete)
|
||||
{}
|
||||
|
||||
template<class SubViewT>
|
||||
SubView *SubViewFactoryWithCreateFlag<SubViewT>::makeSubView (const CSMWorld::UniversalId& id,
|
||||
CSMDoc::Document& document)
|
||||
{
|
||||
return new SubViewT (id, document.getData(), document.getUndoStack(), mCreateAndDelete);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,12 @@
|
||||
|
||||
#include "subviews.hpp"
|
||||
|
||||
#include "../doc/subviewfactoryimp.hpp"
|
||||
|
||||
#include "tablesubview.hpp"
|
||||
|
||||
void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||
{
|
||||
manager.add (CSMWorld::UniversalId::Type_Globals,
|
||||
new CSVDoc::SubViewFactoryWithCreateFlag<TableSubView> (true));
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#ifndef CSV_WORLD_SUBVIEWS_H
|
||||
#define CSV_WORLD_SUBVIEWS_H
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class SubViewFactoryManager;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
void addSubViewFactories (CSVDoc::SubViewFactoryManager& manager);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue