26 lines
598 B
C++
26 lines
598 B
C++
#include "util/serializationRegistry.h"
|
|
|
|
#include <QHash>
|
|
#include <QJsonObject>
|
|
|
|
static QHash<QString, ItemFactory> ®istry()
|
|
{
|
|
static QHash<QString, ItemFactory> map;
|
|
return map;
|
|
}
|
|
|
|
void registerItemFactory(const QString &type, ItemFactory factory)
|
|
{
|
|
registry().insert(type, factory);
|
|
}
|
|
|
|
QGraphicsItem *createItemFromJson(const QJsonObject &obj)
|
|
{
|
|
QString type = obj["type"].toString();
|
|
ItemFactory factory = registry().value(type);
|
|
if (factory)
|
|
return factory(obj);
|
|
qWarning("createItemFromJson: unknown type '%s'", qPrintable(type));
|
|
return nullptr;
|
|
}
|