Newer
Older
namespace routing {
class GeneratorBase : public QObject {
Q_OBJECT
public:
using Generator = std::function<bool(snake::Transects &)>;
explicit GeneratorBase(QObject *parent = nullptr);
explicit GeneratorBase(Data d, QObject *parent = nullptr);
~GeneratorBase();
Q_PROPERTY(QString editorQml READ editorQml CONSTANT)
Q_PROPERTY(QString mapVisualQml READ mapVisualQml CONSTANT)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
virtual QString editorQml() const = 0;
virtual QString mapVisualQml() const = 0;
virtual bool save(QJsonObject &obj) const; // must be called if overridden
virtual bool load(const QJsonObject &obj,
QString &errorString); // must be called if overridden
QString name() const;
virtual QString abbreviation() const = 0;
virtual QString type() const = 0;
virtual bool get(Generator &generator) = 0;
Data data() const;
void setData(Data d);
static const char *nameKey;
Valentin Platzgummer
committed
void dataChanged();
protected:
virtual void establishConnections();
virtual void deleteConnections();
Data _d;
QString _name;
private:
};
class GeneratorFactory {
GeneratorFactory();
GeneratorFactory(GeneratorFactory &other) = delete;
static GeneratorFactory *createInstance();
public:
typedef std::function<GeneratorBase *(QObject *)> Creator;
~GeneratorFactory();
static GeneratorFactory *instance();
bool registerGenerator(const QString &type,
Creator creator); // use REGISTER_GENERATOR to register
// a generator befor main()
bool registered(const QString &type);
void unregisterGenerator(const QString &type);
GeneratorBase *create(const QString &type, QObject *parent = nullptr);
GeneratorBase *create(const QJsonObject &jsonGenerator, QString &errorMessage,
QObject *parent = nullptr);
#define REGISTER_GENERATOR(type, creator) \
namespace { \
auto registered_##type = \
GeneratorFactory::instance() -> registerGenerator(type, creator); \
}