#include "qvariantedit_custom.h"


QVariantEditorFactories::QVariantEditorFactories() {}


QVariantEditorFactories * QVariantEditorFactories::instance() {
	static QVariantEditorFactories * ret = new QVariantEditorFactories();
	return ret;
}


void QVariantEditorFactories::registerEditorFactory(int meta_id, QVariantEditorFactoryBase * f) {
	QVariantEditorFactories * s = QVariantEditorFactories::instance();
	if (!f) {
		unregisterEditorFactory(meta_id);
		return;
	}
	if (s->factories.contains(meta_id))
		; // qDebug() << "[QVariantEditorFactories] Warning: factory for metaTypeID" << meta_id << "already registered, override";
	s->factories[meta_id] = f;
}


void QVariantEditorFactories::unregisterEditorFactory(int meta_id) {
	QVariantEditorFactories * s = QVariantEditorFactories::instance();
	s->factories.remove(meta_id);
}


bool QVariantEditorFactories::isRegisteredEditorFactory(int meta_id) {
	QVariantEditorFactories * s = QVariantEditorFactories::instance();
	return s->factories.contains(meta_id);
}


QVariantEditorFactoryBase * QVariantEditorFactories::editorFactory(int meta_id) {
	QVariantEditorFactories * s = QVariantEditorFactories::instance();
	return s->factories.value(meta_id, 0);
}
