mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Use LF instead of CRLF
This commit is contained in:
@@ -1,53 +1,53 @@
|
||||
# Copyright (C) 2018-2021 Jakub Melka
|
||||
#
|
||||
# This file is part of PDF4QT.
|
||||
#
|
||||
# PDF4QT is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# with the written consent of the copyright owner, any later version.
|
||||
#
|
||||
# PDF4QT is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
QT += core gui xml
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
QMAKE_CXXFLAGS += /std:c++latest /utf-8
|
||||
|
||||
DESTDIR = $$OUT_PWD/..
|
||||
|
||||
LIBS += -L$$OUT_PWD/..
|
||||
|
||||
|
||||
SOURCES += \
|
||||
codegenerator.cpp \
|
||||
main.cpp \
|
||||
generatormainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
codegenerator.h \
|
||||
generatormainwindow.h
|
||||
|
||||
FORMS += \
|
||||
generatormainwindow.ui
|
||||
|
||||
# Copyright (C) 2018-2021 Jakub Melka
|
||||
#
|
||||
# This file is part of PDF4QT.
|
||||
#
|
||||
# PDF4QT is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# with the written consent of the copyright owner, any later version.
|
||||
#
|
||||
# PDF4QT is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
QT += core gui xml
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
QMAKE_CXXFLAGS += /std:c++latest /utf-8
|
||||
|
||||
DESTDIR = $$OUT_PWD/..
|
||||
|
||||
LIBS += -L$$OUT_PWD/..
|
||||
|
||||
|
||||
SOURCES += \
|
||||
codegenerator.cpp \
|
||||
main.cpp \
|
||||
generatormainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
codegenerator.h \
|
||||
generatormainwindow.h
|
||||
|
||||
FORMS += \
|
||||
generatormainwindow.ui
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,454 +1,454 @@
|
||||
// Copyright (C) 2020-2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CODEGENERATOR_H
|
||||
#define CODEGENERATOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaEnum>
|
||||
#include <QMetaObject>
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QObjectList>
|
||||
#include <QComboBox>
|
||||
|
||||
namespace codegen
|
||||
{
|
||||
|
||||
struct CodeGeneratorParameters
|
||||
{
|
||||
bool header = false;
|
||||
int indent = 0;
|
||||
QString className;
|
||||
bool isFirstItem = false;
|
||||
bool isLastItem = false;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
|
||||
Q_ASSERT(metaEnum.isValid());
|
||||
return metaEnum.valueToKey(enumValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline void convertStringToEnum(const QString enumString, T& value)
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
|
||||
Q_ASSERT(metaEnum.isValid());
|
||||
bool ok = false;
|
||||
value = static_cast<T>(metaEnum.keyToValue(enumString.toLatin1().data(), &ok));
|
||||
if (!ok)
|
||||
{
|
||||
// Set default value, if something fails.
|
||||
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;
|
||||
|
||||
class GeneratedCodeStorage : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
public:
|
||||
Q_INVOKABLE GeneratedCodeStorage(QObject* parent);
|
||||
|
||||
Q_PROPERTY(QObjectList functions READ getFunctions WRITE setFunctions)
|
||||
|
||||
QObjectList getFunctions() const;
|
||||
void setFunctions(const QObjectList& functions);
|
||||
|
||||
GeneratedFunction* addFunction(const QString& name);
|
||||
GeneratedFunction* addFunction(GeneratedFunction* function);
|
||||
void removeFunction(GeneratedFunction* function);
|
||||
|
||||
void generateCode(QTextStream& stream, CodeGeneratorParameters& parameters) const;
|
||||
|
||||
private:
|
||||
QObjectList m_functions;
|
||||
};
|
||||
|
||||
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,
|
||||
_PDFObject,
|
||||
_PDFIntegerVector,
|
||||
_PDFObjectReferenceVector,
|
||||
_PDFFormSubmitFlags,
|
||||
_QString,
|
||||
_QPointF,
|
||||
_QRectF,
|
||||
_QColor,
|
||||
_QVariant,
|
||||
_QPolygonF,
|
||||
_QDateTime,
|
||||
_QLocale,
|
||||
_QByteArray,
|
||||
_Polygons,
|
||||
_TextAnnotationIcon,
|
||||
_LinkHighlightMode,
|
||||
_TextAlignment,
|
||||
_AnnotationLineEnding,
|
||||
_AnnotationBorderStyle,
|
||||
_FileAttachmentIcon,
|
||||
_Stamp,
|
||||
_PDFDestination,
|
||||
_PageRotation
|
||||
};
|
||||
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;
|
||||
virtual QStringList getCaptions() const = 0;
|
||||
virtual GeneratedBase* appendItem() = 0;
|
||||
|
||||
enum class Pass
|
||||
{
|
||||
Enter,
|
||||
Leave
|
||||
};
|
||||
|
||||
void generateSourceCode(QTextStream& stream, CodeGeneratorParameters& parameters) const;
|
||||
void applyFunctor(std::function<void(const GeneratedBase*, Pass)>& functor) const;
|
||||
|
||||
enum class Operation
|
||||
{
|
||||
Delete,
|
||||
MoveUp,
|
||||
MoveDown,
|
||||
NewSibling,
|
||||
NewChild
|
||||
};
|
||||
|
||||
GeneratedBase* getParent() { return qobject_cast<GeneratedBase*>(parent()); }
|
||||
const GeneratedBase* getParent() const { return qobject_cast<const GeneratedBase*>(parent()); }
|
||||
bool canPerformOperation(Operation operation) const;
|
||||
void performOperation(Operation operation);
|
||||
|
||||
QObjectList getItems() const;
|
||||
void setItems(const QObjectList& items);
|
||||
void addItem(QObject* object);
|
||||
void removeItem(QObject* object);
|
||||
void clearItems();
|
||||
|
||||
protected:
|
||||
virtual void generateSourceCodeImpl(QTextStream& stream, CodeGeneratorParameters& parameters, Pass pass) const;
|
||||
|
||||
QString getCppType(DataType type) const;
|
||||
QStringList getFormattedTextWithLayout(QString firstPrefix, QString prefix, QString text, int indent) const;
|
||||
QStringList getFormattedTextBlock(QString firstPrefix, QString prefix, QStringList texts, int indent) const;
|
||||
|
||||
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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() 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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() override;
|
||||
|
||||
QString getValue() const;
|
||||
void setValue(const QString& value);
|
||||
|
||||
ObjectType getObjectType() const;
|
||||
void setObjectType(ObjectType objectType);
|
||||
|
||||
QString getDictionaryItemName() const;
|
||||
void setDictionaryItemName(const QString& dictionaryItemName);
|
||||
|
||||
protected:
|
||||
virtual void generateSourceCodeImpl(QTextStream& stream, CodeGeneratorParameters& parameters, Pass pass) const override;
|
||||
|
||||
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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() 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);
|
||||
|
||||
protected:
|
||||
virtual void generateSourceCodeImpl(QTextStream& stream, CodeGeneratorParameters& parameters, Pass pass) const override;
|
||||
|
||||
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
|
||||
{
|
||||
Structure,
|
||||
Annotations,
|
||||
ColorSpace,
|
||||
Actions,
|
||||
Forms
|
||||
};
|
||||
Q_ENUM(FunctionType)
|
||||
|
||||
|
||||
Q_INVOKABLE GeneratedFunction(QObject* parent);
|
||||
|
||||
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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() override;
|
||||
|
||||
QString getFunctionTypeString() const;
|
||||
void setFunctionTypeString(const QString& string);
|
||||
|
||||
FunctionType getFunctionType() const;
|
||||
void setFunctionType(const FunctionType& functionType);
|
||||
|
||||
QString getFunctionName() const;
|
||||
void setFunctionName(const QString& functionName);
|
||||
|
||||
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);
|
||||
|
||||
void generateCode(QTextStream& stream, CodeGeneratorParameters& parameters) const;
|
||||
|
||||
private:
|
||||
FunctionType m_functionType = FunctionType::Annotations;
|
||||
QString m_functionName;
|
||||
QString m_functionDescription;
|
||||
DataType m_returnType = _void;
|
||||
};
|
||||
|
||||
class CodeGenerator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
public:
|
||||
CodeGenerator(QObject* parent = nullptr);
|
||||
|
||||
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);
|
||||
|
||||
void generateCode(QString headerName, QString sourceName) const;
|
||||
|
||||
private:
|
||||
QString generateHeader(int indent) const;
|
||||
QString generateSource(QString className, int indent) const;
|
||||
|
||||
GeneratedCodeStorage* m_storage = nullptr;
|
||||
};
|
||||
|
||||
} // namespace codegen
|
||||
|
||||
Q_DECLARE_METATYPE(codegen::GeneratedCodeStorage*)
|
||||
Q_DECLARE_METATYPE(codegen::GeneratedFunction*)
|
||||
|
||||
#endif // CODEGENERATOR_H
|
||||
// Copyright (C) 2020-2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CODEGENERATOR_H
|
||||
#define CODEGENERATOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaEnum>
|
||||
#include <QMetaObject>
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QObjectList>
|
||||
#include <QComboBox>
|
||||
|
||||
namespace codegen
|
||||
{
|
||||
|
||||
struct CodeGeneratorParameters
|
||||
{
|
||||
bool header = false;
|
||||
int indent = 0;
|
||||
QString className;
|
||||
bool isFirstItem = false;
|
||||
bool isLastItem = false;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
|
||||
Q_ASSERT(metaEnum.isValid());
|
||||
return metaEnum.valueToKey(enumValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline void convertStringToEnum(const QString enumString, T& value)
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
|
||||
Q_ASSERT(metaEnum.isValid());
|
||||
bool ok = false;
|
||||
value = static_cast<T>(metaEnum.keyToValue(enumString.toLatin1().data(), &ok));
|
||||
if (!ok)
|
||||
{
|
||||
// Set default value, if something fails.
|
||||
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;
|
||||
|
||||
class GeneratedCodeStorage : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
public:
|
||||
Q_INVOKABLE GeneratedCodeStorage(QObject* parent);
|
||||
|
||||
Q_PROPERTY(QObjectList functions READ getFunctions WRITE setFunctions)
|
||||
|
||||
QObjectList getFunctions() const;
|
||||
void setFunctions(const QObjectList& functions);
|
||||
|
||||
GeneratedFunction* addFunction(const QString& name);
|
||||
GeneratedFunction* addFunction(GeneratedFunction* function);
|
||||
void removeFunction(GeneratedFunction* function);
|
||||
|
||||
void generateCode(QTextStream& stream, CodeGeneratorParameters& parameters) const;
|
||||
|
||||
private:
|
||||
QObjectList m_functions;
|
||||
};
|
||||
|
||||
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,
|
||||
_PDFObject,
|
||||
_PDFIntegerVector,
|
||||
_PDFObjectReferenceVector,
|
||||
_PDFFormSubmitFlags,
|
||||
_QString,
|
||||
_QPointF,
|
||||
_QRectF,
|
||||
_QColor,
|
||||
_QVariant,
|
||||
_QPolygonF,
|
||||
_QDateTime,
|
||||
_QLocale,
|
||||
_QByteArray,
|
||||
_Polygons,
|
||||
_TextAnnotationIcon,
|
||||
_LinkHighlightMode,
|
||||
_TextAlignment,
|
||||
_AnnotationLineEnding,
|
||||
_AnnotationBorderStyle,
|
||||
_FileAttachmentIcon,
|
||||
_Stamp,
|
||||
_PDFDestination,
|
||||
_PageRotation
|
||||
};
|
||||
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;
|
||||
virtual QStringList getCaptions() const = 0;
|
||||
virtual GeneratedBase* appendItem() = 0;
|
||||
|
||||
enum class Pass
|
||||
{
|
||||
Enter,
|
||||
Leave
|
||||
};
|
||||
|
||||
void generateSourceCode(QTextStream& stream, CodeGeneratorParameters& parameters) const;
|
||||
void applyFunctor(std::function<void(const GeneratedBase*, Pass)>& functor) const;
|
||||
|
||||
enum class Operation
|
||||
{
|
||||
Delete,
|
||||
MoveUp,
|
||||
MoveDown,
|
||||
NewSibling,
|
||||
NewChild
|
||||
};
|
||||
|
||||
GeneratedBase* getParent() { return qobject_cast<GeneratedBase*>(parent()); }
|
||||
const GeneratedBase* getParent() const { return qobject_cast<const GeneratedBase*>(parent()); }
|
||||
bool canPerformOperation(Operation operation) const;
|
||||
void performOperation(Operation operation);
|
||||
|
||||
QObjectList getItems() const;
|
||||
void setItems(const QObjectList& items);
|
||||
void addItem(QObject* object);
|
||||
void removeItem(QObject* object);
|
||||
void clearItems();
|
||||
|
||||
protected:
|
||||
virtual void generateSourceCodeImpl(QTextStream& stream, CodeGeneratorParameters& parameters, Pass pass) const;
|
||||
|
||||
QString getCppType(DataType type) const;
|
||||
QStringList getFormattedTextWithLayout(QString firstPrefix, QString prefix, QString text, int indent) const;
|
||||
QStringList getFormattedTextBlock(QString firstPrefix, QString prefix, QStringList texts, int indent) const;
|
||||
|
||||
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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() 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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() override;
|
||||
|
||||
QString getValue() const;
|
||||
void setValue(const QString& value);
|
||||
|
||||
ObjectType getObjectType() const;
|
||||
void setObjectType(ObjectType objectType);
|
||||
|
||||
QString getDictionaryItemName() const;
|
||||
void setDictionaryItemName(const QString& dictionaryItemName);
|
||||
|
||||
protected:
|
||||
virtual void generateSourceCodeImpl(QTextStream& stream, CodeGeneratorParameters& parameters, Pass pass) const override;
|
||||
|
||||
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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() 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);
|
||||
|
||||
protected:
|
||||
virtual void generateSourceCodeImpl(QTextStream& stream, CodeGeneratorParameters& parameters, Pass pass) const override;
|
||||
|
||||
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
|
||||
{
|
||||
Structure,
|
||||
Annotations,
|
||||
ColorSpace,
|
||||
Actions,
|
||||
Forms
|
||||
};
|
||||
Q_ENUM(FunctionType)
|
||||
|
||||
|
||||
Q_INVOKABLE GeneratedFunction(QObject* parent);
|
||||
|
||||
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;
|
||||
virtual QStringList getCaptions() const override;
|
||||
virtual GeneratedBase* appendItem() override;
|
||||
|
||||
QString getFunctionTypeString() const;
|
||||
void setFunctionTypeString(const QString& string);
|
||||
|
||||
FunctionType getFunctionType() const;
|
||||
void setFunctionType(const FunctionType& functionType);
|
||||
|
||||
QString getFunctionName() const;
|
||||
void setFunctionName(const QString& functionName);
|
||||
|
||||
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);
|
||||
|
||||
void generateCode(QTextStream& stream, CodeGeneratorParameters& parameters) const;
|
||||
|
||||
private:
|
||||
FunctionType m_functionType = FunctionType::Annotations;
|
||||
QString m_functionName;
|
||||
QString m_functionDescription;
|
||||
DataType m_returnType = _void;
|
||||
};
|
||||
|
||||
class CodeGenerator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
public:
|
||||
CodeGenerator(QObject* parent = nullptr);
|
||||
|
||||
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);
|
||||
|
||||
void generateCode(QString headerName, QString sourceName) const;
|
||||
|
||||
private:
|
||||
QString generateHeader(int indent) const;
|
||||
QString generateSource(QString className, int indent) const;
|
||||
|
||||
GeneratedCodeStorage* m_storage = nullptr;
|
||||
};
|
||||
|
||||
} // namespace codegen
|
||||
|
||||
Q_DECLARE_METATYPE(codegen::GeneratedCodeStorage*)
|
||||
Q_DECLARE_METATYPE(codegen::GeneratedFunction*)
|
||||
|
||||
#endif // CODEGENERATOR_H
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,109 +1,109 @@
|
||||
// Copyright (C) 2020-2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef GENERATORMAINWINDOW_H
|
||||
#define GENERATORMAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
namespace codegen
|
||||
{
|
||||
class CodeGenerator;
|
||||
class GeneratedFunction;
|
||||
class GeneratedBase;
|
||||
}
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class GeneratorMainWindow;
|
||||
}
|
||||
|
||||
class BoolGuard
|
||||
{
|
||||
public:
|
||||
explicit inline BoolGuard(bool& value) :
|
||||
m_oldValue(value),
|
||||
m_value(&value)
|
||||
{
|
||||
*m_value = true;
|
||||
}
|
||||
|
||||
inline ~BoolGuard()
|
||||
{
|
||||
*m_value = m_oldValue;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_oldValue;
|
||||
bool* m_value;
|
||||
};
|
||||
|
||||
class GeneratorMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeneratorMainWindow(QWidget* parent = nullptr);
|
||||
virtual ~GeneratorMainWindow() override;
|
||||
|
||||
void load(const QString& fileName);
|
||||
void save(const QString& fileName);
|
||||
|
||||
private slots:
|
||||
void on_actionLoad_triggered();
|
||||
void on_actionSaveAs_triggered();
|
||||
void on_actionSave_triggered();
|
||||
void on_newFunctionButton_clicked();
|
||||
void on_cloneFunctionButton_clicked();
|
||||
void on_removeFunctionButton_clicked();
|
||||
void on_itemDeleteButton_clicked();
|
||||
void on_itemUpButton_clicked();
|
||||
void on_itemDownButton_clicked();
|
||||
void on_itemNewChildButton_clicked();
|
||||
void on_itemNewSiblingButton_clicked();
|
||||
void on_actionSet_code_header_h_triggered();
|
||||
void on_actionSet_code_source_cpp_triggered();
|
||||
void on_actionGenerate_code_triggered();
|
||||
|
||||
private:
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
void loadGeneratedSettings();
|
||||
void saveGeneratedSettings();
|
||||
|
||||
void updateFunctionListUI();
|
||||
void updateGeneratedSettingsTree();
|
||||
void setCurrentFunction(codegen::GeneratedFunction* currentFunction);
|
||||
void setCurrentSettings(codegen::GeneratedBase* currentSettings);
|
||||
void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
|
||||
void onParameterTreeCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
|
||||
|
||||
Ui::GeneratorMainWindow* ui;
|
||||
codegen::CodeGenerator* m_generator;
|
||||
codegen::GeneratedFunction* m_currentFunction;
|
||||
codegen::GeneratedBase* m_currentSettings;
|
||||
QString m_defaultFileName;
|
||||
QString m_headerFileName;
|
||||
QString m_sourceFileName;
|
||||
std::map<codegen::GeneratedFunction*, QTreeWidgetItem*> m_mapFunctionToWidgetItem;
|
||||
bool m_isLoadingData;
|
||||
};
|
||||
|
||||
#endif // GENERATORMAINWINDOW_H
|
||||
// Copyright (C) 2020-2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef GENERATORMAINWINDOW_H
|
||||
#define GENERATORMAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
namespace codegen
|
||||
{
|
||||
class CodeGenerator;
|
||||
class GeneratedFunction;
|
||||
class GeneratedBase;
|
||||
}
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class GeneratorMainWindow;
|
||||
}
|
||||
|
||||
class BoolGuard
|
||||
{
|
||||
public:
|
||||
explicit inline BoolGuard(bool& value) :
|
||||
m_oldValue(value),
|
||||
m_value(&value)
|
||||
{
|
||||
*m_value = true;
|
||||
}
|
||||
|
||||
inline ~BoolGuard()
|
||||
{
|
||||
*m_value = m_oldValue;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_oldValue;
|
||||
bool* m_value;
|
||||
};
|
||||
|
||||
class GeneratorMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeneratorMainWindow(QWidget* parent = nullptr);
|
||||
virtual ~GeneratorMainWindow() override;
|
||||
|
||||
void load(const QString& fileName);
|
||||
void save(const QString& fileName);
|
||||
|
||||
private slots:
|
||||
void on_actionLoad_triggered();
|
||||
void on_actionSaveAs_triggered();
|
||||
void on_actionSave_triggered();
|
||||
void on_newFunctionButton_clicked();
|
||||
void on_cloneFunctionButton_clicked();
|
||||
void on_removeFunctionButton_clicked();
|
||||
void on_itemDeleteButton_clicked();
|
||||
void on_itemUpButton_clicked();
|
||||
void on_itemDownButton_clicked();
|
||||
void on_itemNewChildButton_clicked();
|
||||
void on_itemNewSiblingButton_clicked();
|
||||
void on_actionSet_code_header_h_triggered();
|
||||
void on_actionSet_code_source_cpp_triggered();
|
||||
void on_actionGenerate_code_triggered();
|
||||
|
||||
private:
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
void loadGeneratedSettings();
|
||||
void saveGeneratedSettings();
|
||||
|
||||
void updateFunctionListUI();
|
||||
void updateGeneratedSettingsTree();
|
||||
void setCurrentFunction(codegen::GeneratedFunction* currentFunction);
|
||||
void setCurrentSettings(codegen::GeneratedBase* currentSettings);
|
||||
void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
|
||||
void onParameterTreeCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
|
||||
|
||||
Ui::GeneratorMainWindow* ui;
|
||||
codegen::CodeGenerator* m_generator;
|
||||
codegen::GeneratedFunction* m_currentFunction;
|
||||
codegen::GeneratedBase* m_currentSettings;
|
||||
QString m_defaultFileName;
|
||||
QString m_headerFileName;
|
||||
QString m_sourceFileName;
|
||||
std::map<codegen::GeneratedFunction*, QTreeWidgetItem*> m_mapFunctionToWidgetItem;
|
||||
bool m_isLoadingData;
|
||||
};
|
||||
|
||||
#endif // GENERATORMAINWINDOW_H
|
||||
|
@@ -1,290 +1,290 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GeneratorMainWindow</class>
|
||||
<widget class="QMainWindow" name="GeneratorMainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1121</width>
|
||||
<height>662</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Code Generator</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="centralWidgetLayout" stretch="1,4">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="generatedFunctionsVerticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="generatedFunctionsTreeWidget">
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="generatedFunctionsHorizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeFunctionButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cloneFunctionButton">
|
||||
<property name="text">
|
||||
<string>Clone</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newFunctionButton">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="parametersGroupBox">
|
||||
<property name="title">
|
||||
<string>Parameters</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="parametersGroupBoxLayout" columnstretch="0,0,0,0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="parameterDataTypeLabel">
|
||||
<property name="text">
|
||||
<string>Data type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="parameterValueEdit"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="parameterItemTypeCombo"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="parameterNameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="4">
|
||||
<widget class="QTextBrowser" name="parameterDescriptionEdit">
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="parameterValueLabel">
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="parameterItemTypeLabel">
|
||||
<property name="text">
|
||||
<string>Item type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="parameterNameLabel">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="descriptionLabel">
|
||||
<property name="text">
|
||||
<string>Text description / C++ code</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="parameterDataTypeCombo"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="parameterTreeWidget">
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">2</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemDeleteButton">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemUpButton">
|
||||
<property name="text">
|
||||
<string>Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemDownButton">
|
||||
<property name="text">
|
||||
<string>Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemNewChildButton">
|
||||
<property name="text">
|
||||
<string>New Child</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemNewSiblingButton">
|
||||
<property name="text">
|
||||
<string>New Sibling</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1121</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionLoad"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuCode">
|
||||
<property name="title">
|
||||
<string>Code</string>
|
||||
</property>
|
||||
<addaction name="actionSet_code_header_h"/>
|
||||
<addaction name="actionSet_code_source_cpp"/>
|
||||
<addaction name="actionGenerate_code"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuCode"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionLoad">
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveAs">
|
||||
<property name="text">
|
||||
<string>Save As...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSet_code_header_h">
|
||||
<property name="text">
|
||||
<string>Set code header (*.h)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSet_code_source_cpp">
|
||||
<property name="text">
|
||||
<string>Set code source (*.cpp)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGenerate_code">
|
||||
<property name="text">
|
||||
<string>Generate code</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GeneratorMainWindow</class>
|
||||
<widget class="QMainWindow" name="GeneratorMainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1121</width>
|
||||
<height>662</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Code Generator</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="centralWidgetLayout" stretch="1,4">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="generatedFunctionsVerticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="generatedFunctionsTreeWidget">
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="generatedFunctionsHorizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeFunctionButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cloneFunctionButton">
|
||||
<property name="text">
|
||||
<string>Clone</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newFunctionButton">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="parametersGroupBox">
|
||||
<property name="title">
|
||||
<string>Parameters</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="parametersGroupBoxLayout" columnstretch="0,0,0,0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="parameterDataTypeLabel">
|
||||
<property name="text">
|
||||
<string>Data type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="parameterValueEdit"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="parameterItemTypeCombo"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="parameterNameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="4">
|
||||
<widget class="QTextBrowser" name="parameterDescriptionEdit">
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="parameterValueLabel">
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="parameterItemTypeLabel">
|
||||
<property name="text">
|
||||
<string>Item type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="parameterNameLabel">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="descriptionLabel">
|
||||
<property name="text">
|
||||
<string>Text description / C++ code</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="parameterDataTypeCombo"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="parameterTreeWidget">
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">2</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemDeleteButton">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemUpButton">
|
||||
<property name="text">
|
||||
<string>Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemDownButton">
|
||||
<property name="text">
|
||||
<string>Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemNewChildButton">
|
||||
<property name="text">
|
||||
<string>New Child</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="itemNewSiblingButton">
|
||||
<property name="text">
|
||||
<string>New Sibling</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1121</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionLoad"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuCode">
|
||||
<property name="title">
|
||||
<string>Code</string>
|
||||
</property>
|
||||
<addaction name="actionSet_code_header_h"/>
|
||||
<addaction name="actionSet_code_source_cpp"/>
|
||||
<addaction name="actionGenerate_code"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuCode"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionLoad">
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveAs">
|
||||
<property name="text">
|
||||
<string>Save As...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSet_code_header_h">
|
||||
<property name="text">
|
||||
<string>Set code header (*.h)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSet_code_source_cpp">
|
||||
<property name="text">
|
||||
<string>Set code source (*.cpp)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGenerate_code">
|
||||
<property name="text">
|
||||
<string>Generate code</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@@ -1,30 +1,30 @@
|
||||
// Copyright (C) 2020-2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "generatormainwindow.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0);
|
||||
QApplication a(argc, argv);
|
||||
GeneratorMainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
// Copyright (C) 2020-2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "generatormainwindow.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0);
|
||||
QApplication a(argc, argv);
|
||||
GeneratorMainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
Reference in New Issue
Block a user