2013-07-26 12:34:30 +02:00
|
|
|
#ifndef CSV_WORLD_CREATOR_H
|
|
|
|
#define CSV_WORLD_CREATOR_H
|
|
|
|
|
2014-08-07 09:32:49 +02:00
|
|
|
#include <memory>
|
2022-10-19 19:02:00 +02:00
|
|
|
#include <string>
|
2014-08-07 09:32:49 +02:00
|
|
|
|
2013-07-26 18:22:31 +02:00
|
|
|
#include <QWidget>
|
2014-08-07 09:32:49 +02:00
|
|
|
|
2018-12-01 21:27:43 +01:00
|
|
|
#ifndef Q_MOC_RUN
|
2015-06-20 11:34:32 +02:00
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
|
2014-08-07 09:32:49 +02:00
|
|
|
#include "../../model/world/scope.hpp"
|
2015-06-18 22:59:40 +03:00
|
|
|
#include "../../model/world/universalid.hpp"
|
2018-12-01 21:27:43 +01:00
|
|
|
#endif
|
2014-08-07 09:32:49 +02:00
|
|
|
|
2013-07-26 12:34:30 +02:00
|
|
|
namespace CSVWorld
|
|
|
|
{
|
|
|
|
/// \brief Record creator UI base class
|
2013-07-26 18:22:31 +02:00
|
|
|
class Creator : public QWidget
|
2013-07-26 12:34:30 +02:00
|
|
|
{
|
2013-07-26 21:09:23 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2013-07-26 12:34:30 +02:00
|
|
|
public:
|
|
|
|
virtual ~Creator();
|
|
|
|
|
|
|
|
virtual void reset() = 0;
|
2013-07-26 21:09:23 +02:00
|
|
|
|
|
|
|
virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) = 0;
|
2014-01-27 19:40:05 +01:00
|
|
|
|
2014-01-27 13:13:39 +01:00
|
|
|
/// Touches a record, if the creator supports it.
|
2014-01-27 13:08:14 +01:00
|
|
|
virtual void touch(const std::vector<CSMWorld::UniversalId>& ids) = 0;
|
2013-07-26 21:09:23 +02:00
|
|
|
|
2017-09-03 16:41:54 -04:00
|
|
|
virtual void setEditLock(bool locked) = 0;
|
|
|
|
|
2013-07-28 14:51:47 +02:00
|
|
|
virtual void toggleWidgets(bool active = true) = 0;
|
2014-01-27 19:40:05 +01:00
|
|
|
|
2014-01-23 16:00:44 +01:00
|
|
|
/// Default implementation: Throw an exception if scope!=Scope_Content.
|
|
|
|
virtual void setScope(unsigned int scope);
|
2013-07-28 14:51:47 +02:00
|
|
|
|
2014-08-07 09:32:49 +02:00
|
|
|
/// Focus main input widget
|
|
|
|
virtual void focus() = 0;
|
|
|
|
|
2015-05-02 13:20:42 +02:00
|
|
|
signals:
|
|
|
|
|
2013-07-26 21:09:23 +02:00
|
|
|
void done();
|
|
|
|
|
2013-07-29 15:00:41 +02:00
|
|
|
void requestFocus(const std::string& id);
|
|
|
|
///< Request owner of this creator to focus the just created \a id. The owner may
|
|
|
|
/// ignore this request.
|
2013-07-26 12:34:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Base class for Creator factory
|
|
|
|
class CreatorFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~CreatorFactoryBase();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-06-18 22:59:40 +03:00
|
|
|
virtual Creator* makeCreator(CSMDoc::Document& document, const CSMWorld::UniversalId& id) const = 0;
|
2013-07-26 12:34:30 +02:00
|
|
|
///< 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:
|
2020-10-16 22:18:54 +04:00
|
|
|
Creator* makeCreator(CSMDoc::Document& document, const CSMWorld::UniversalId& id) const override;
|
2013-07-26 12:34:30 +02:00
|
|
|
///< The ownership of the returned Creator is transferred to the caller.
|
|
|
|
///
|
|
|
|
/// \note The function always returns 0.
|
|
|
|
};
|
|
|
|
|
2014-08-07 09:32:49 +02:00
|
|
|
template <class CreatorT, unsigned int scope = CSMWorld::Scope_Content>
|
2013-07-26 12:34:30 +02:00
|
|
|
class CreatorFactory : public CreatorFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
Creator* makeCreator(CSMDoc::Document& document, const CSMWorld::UniversalId& id) const override;
|
2013-07-26 12:34:30 +02:00
|
|
|
///< 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.
|
|
|
|
};
|
|
|
|
|
2014-08-07 09:32:49 +02:00
|
|
|
template <class CreatorT, unsigned int scope>
|
2015-06-18 22:59:40 +03:00
|
|
|
Creator* CreatorFactory<CreatorT, scope>::makeCreator(
|
|
|
|
CSMDoc::Document& document, const CSMWorld::UniversalId& id) const
|
2013-07-26 12:34:30 +02:00
|
|
|
{
|
2022-05-29 13:25:17 +02:00
|
|
|
auto creator = std::make_unique<CreatorT>(document.getData(), document.getUndoStack(), id);
|
2014-08-07 09:32:49 +02:00
|
|
|
|
|
|
|
creator->setScope(scope);
|
|
|
|
|
|
|
|
return creator.release();
|
2013-07-26 12:34:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 10:54:45 -04:00
|
|
|
#endif
|