mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Code generator - objects
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QObjectList>
|
||||
#include <QComboBox>
|
||||
|
||||
namespace codegen
|
||||
{
|
||||
@ -33,6 +34,7 @@ class Serializer
|
||||
public:
|
||||
static QObject* load(const QDomElement& element, QObject* parent);
|
||||
static void store(QObject* object, QDomElement& element);
|
||||
static QObject* clone(QObject* object, QObject* parent);
|
||||
|
||||
template<typename T>
|
||||
static inline QString convertEnumToString(T enumValue)
|
||||
@ -55,6 +57,23 @@ public:
|
||||
value = T();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline void fillComboBox(QComboBox* comboBox, T value)
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
|
||||
Q_ASSERT(metaEnum.isValid());
|
||||
|
||||
const int keyCount = metaEnum.keyCount();
|
||||
comboBox->setUpdatesEnabled(false);
|
||||
comboBox->clear();
|
||||
for (int i = 0; i < keyCount; ++i)
|
||||
{
|
||||
comboBox->addItem(metaEnum.key(i), metaEnum.value(i));
|
||||
}
|
||||
comboBox->setCurrentIndex(comboBox->findData(int(value)));
|
||||
comboBox->setUpdatesEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
class GeneratedFunction;
|
||||
@ -75,18 +94,200 @@ public:
|
||||
void setFunctions(const QObjectList& functions);
|
||||
|
||||
GeneratedFunction* addFunction(const QString& name);
|
||||
GeneratedFunction* addFunction(GeneratedFunction* function);
|
||||
void removeFunction(GeneratedFunction* function);
|
||||
|
||||
private:
|
||||
QObjectList m_functions;
|
||||
};
|
||||
|
||||
class GeneratedFunction : public QObject
|
||||
class GeneratedBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
|
||||
enum class FieldType
|
||||
{
|
||||
Name,
|
||||
ItemType,
|
||||
DataType,
|
||||
Value,
|
||||
Description
|
||||
};
|
||||
|
||||
enum DataType
|
||||
{
|
||||
_void,
|
||||
_PDFNull,
|
||||
_bool,
|
||||
_PDFInteger,
|
||||
_PDFReal,
|
||||
_PDFObjectReference,
|
||||
_QString,
|
||||
_QPointF,
|
||||
_QRectF,
|
||||
_QVariant
|
||||
};
|
||||
Q_ENUM(DataType)
|
||||
|
||||
Q_PROPERTY(QObjectList items READ getItems WRITE setItems)
|
||||
|
||||
virtual bool hasField(FieldType fieldType) const = 0;
|
||||
virtual QVariant readField(FieldType fieldType) const = 0;
|
||||
virtual void writeField(FieldType fieldType, QVariant value) = 0;
|
||||
virtual void fillComboBox(QComboBox* comboBox, FieldType fieldType) = 0;
|
||||
virtual bool canHaveSubitems() const = 0;
|
||||
|
||||
QObjectList getItems() const;
|
||||
void setItems(const QObjectList& items);
|
||||
void addItem(QObject* object);
|
||||
void removeItem(QObject* object);
|
||||
void clearItems();
|
||||
|
||||
private:
|
||||
QObjectList m_items;
|
||||
};
|
||||
|
||||
class GeneratedParameter : public GeneratedBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = GeneratedBase;
|
||||
|
||||
public:
|
||||
Q_INVOKABLE GeneratedParameter(QObject* parent);
|
||||
Q_PROPERTY(QString parameterName READ getParameterName WRITE setParameterName)
|
||||
Q_PROPERTY(DataType parameterType READ getParameterDataType WRITE setParameterDataType)
|
||||
Q_PROPERTY(QString parameterDescription READ getParameterDescription WRITE setParameterDescription)
|
||||
|
||||
virtual bool hasField(FieldType fieldType) const override;
|
||||
virtual QVariant readField(FieldType fieldType) const override;
|
||||
virtual void writeField(FieldType fieldType, QVariant value) override;
|
||||
virtual void fillComboBox(QComboBox* comboBox, FieldType fieldType) override;
|
||||
virtual bool canHaveSubitems() const override;
|
||||
|
||||
QString getParameterName() const;
|
||||
void setParameterName(const QString& parameterName);
|
||||
|
||||
DataType getParameterDataType() const;
|
||||
void setParameterDataType(const DataType& parameterDataType);
|
||||
|
||||
QString getParameterDescription() const;
|
||||
void setParameterDescription(const QString& parameterDescription);
|
||||
|
||||
private:
|
||||
QString m_parameterName;
|
||||
DataType m_parameterDataType = _void;
|
||||
QString m_parameterDescription;
|
||||
};
|
||||
|
||||
class GeneratedPDFObject : public GeneratedBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = GeneratedBase;
|
||||
|
||||
public:
|
||||
|
||||
enum ObjectType
|
||||
{
|
||||
Object,
|
||||
ArraySimple,
|
||||
ArrayComplex,
|
||||
Dictionary,
|
||||
DictionaryItemSimple,
|
||||
DictionaryItemComplex
|
||||
};
|
||||
Q_ENUM(ObjectType)
|
||||
|
||||
Q_INVOKABLE GeneratedPDFObject(QObject* parent);
|
||||
Q_PROPERTY(QString dictionaryItemName READ getDictionaryItemName WRITE setDictionaryItemName)
|
||||
Q_PROPERTY(ObjectType objectType READ getObjectType WRITE setObjectType)
|
||||
Q_PROPERTY(QString value READ getValue WRITE setValue)
|
||||
|
||||
virtual bool hasField(FieldType fieldType) const override;
|
||||
virtual QVariant readField(FieldType fieldType) const override;
|
||||
virtual void writeField(FieldType fieldType, QVariant value) override;
|
||||
virtual void fillComboBox(QComboBox* comboBox, FieldType fieldType) override;
|
||||
virtual bool canHaveSubitems() const override;
|
||||
|
||||
QString getValue() const;
|
||||
void setValue(const QString& value);
|
||||
|
||||
ObjectType getObjectType() const;
|
||||
void setObjectType(ObjectType objectType);
|
||||
|
||||
QString getDictionaryItemName() const;
|
||||
void setDictionaryItemName(const QString& dictionaryItemName);
|
||||
|
||||
private:
|
||||
QString m_dictionaryItemName;
|
||||
ObjectType m_objectType = Object;
|
||||
QString m_value;
|
||||
};
|
||||
|
||||
class GeneratedAction : public GeneratedBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = GeneratedBase;
|
||||
|
||||
public:
|
||||
|
||||
enum ActionType
|
||||
{
|
||||
Parameters,
|
||||
CreateObject,
|
||||
Code
|
||||
};
|
||||
Q_ENUM(ActionType)
|
||||
|
||||
Q_INVOKABLE GeneratedAction(QObject* parent);
|
||||
Q_PROPERTY(ActionType actionType READ getActionType WRITE setActionType)
|
||||
Q_PROPERTY(QString variableName READ getVariableName WRITE setVariableName)
|
||||
Q_PROPERTY(DataType variableType READ getVariableType WRITE setVariableType)
|
||||
Q_PROPERTY(QString code READ getCode WRITE setCode)
|
||||
|
||||
virtual bool hasField(FieldType fieldType) const override;
|
||||
virtual QVariant readField(FieldType fieldType) const override;
|
||||
virtual void writeField(FieldType fieldType, QVariant value) override;
|
||||
virtual void fillComboBox(QComboBox* comboBox, FieldType fieldType) override;
|
||||
virtual bool canHaveSubitems() const override;
|
||||
|
||||
ActionType getActionType() const;
|
||||
void setActionType(ActionType actionType);
|
||||
|
||||
QString getVariableName() const;
|
||||
void setVariableName(const QString& variableName);
|
||||
|
||||
DataType getVariableType() const;
|
||||
void setVariableType(DataType variableType);
|
||||
|
||||
QString getCode() const;
|
||||
void setCode(const QString& code);
|
||||
|
||||
private:
|
||||
ActionType m_actionType;
|
||||
QString m_variableName;
|
||||
DataType m_variableType = _void;
|
||||
QString m_code;
|
||||
};
|
||||
|
||||
class GeneratedFunction : public GeneratedBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = GeneratedBase;
|
||||
|
||||
public:
|
||||
|
||||
enum FunctionType
|
||||
@ -99,9 +300,16 @@ public:
|
||||
|
||||
Q_INVOKABLE GeneratedFunction(QObject* parent);
|
||||
|
||||
Q_PROPERTY(QString functionType READ getFunctionTypeString WRITE setFunctionTypeString)
|
||||
Q_PROPERTY(FunctionType functionType READ getFunctionType WRITE setFunctionType)
|
||||
Q_PROPERTY(QString functionName READ getFunctionName WRITE setFunctionName)
|
||||
Q_PROPERTY(QString functionDescription READ getFunctionDescription WRITE setFunctionDescription)
|
||||
Q_PROPERTY(DataType returnType READ getReturnType WRITE setReturnType)
|
||||
|
||||
virtual bool hasField(FieldType fieldType) const override;
|
||||
virtual QVariant readField(FieldType fieldType) const override;
|
||||
virtual void writeField(FieldType fieldType, QVariant value) override;
|
||||
virtual void fillComboBox(QComboBox* comboBox, FieldType fieldType) override;
|
||||
virtual bool canHaveSubitems() const override;
|
||||
|
||||
QString getFunctionTypeString() const;
|
||||
void setFunctionTypeString(const QString& string);
|
||||
@ -115,10 +323,17 @@ public:
|
||||
QString getFunctionDescription() const;
|
||||
void setFunctionDescription(const QString& functionDescription);
|
||||
|
||||
DataType getReturnType() const;
|
||||
void setReturnType(DataType returnType);
|
||||
|
||||
/// Create a clone of this function
|
||||
GeneratedFunction* clone(QObject* parent);
|
||||
|
||||
private:
|
||||
FunctionType m_functionType = FunctionType::Annotations;
|
||||
QString m_functionName;
|
||||
QString m_functionDescription;
|
||||
DataType m_returnType = _void;
|
||||
};
|
||||
|
||||
class CodeGenerator : public QObject
|
||||
@ -133,7 +348,10 @@ public:
|
||||
|
||||
void initialize();
|
||||
|
||||
QObjectList getFunctions() const { return m_storage->getFunctions(); }
|
||||
GeneratedFunction* addFunction(const QString& name) { return m_storage->addFunction(name); }
|
||||
GeneratedFunction* addFunction(GeneratedFunction* function) { return m_storage->addFunction(function); }
|
||||
void removeFunction(GeneratedFunction* function) { m_storage->removeFunction(function); }
|
||||
|
||||
void load(const QDomDocument& document);
|
||||
void store(QDomDocument& document);
|
||||
|
Reference in New Issue
Block a user