mirror of https://github.com/JakubMelka/PDF4QT.git
Object editor model
This commit is contained in:
parent
7b95507cac
commit
235cb4cbca
|
@ -59,6 +59,7 @@ SOURCES += \
|
|||
sources/pdfjbig2decoder.cpp \
|
||||
sources/pdfmultimedia.cpp \
|
||||
sources/pdfobject.cpp \
|
||||
sources/pdfobjecteditormodel.cpp \
|
||||
sources/pdfobjectutils.cpp \
|
||||
sources/pdfoptimizer.cpp \
|
||||
sources/pdfoptionalcontent.cpp \
|
||||
|
@ -118,6 +119,7 @@ HEADERS += \
|
|||
sources/pdfmultimedia.h \
|
||||
sources/pdfnametreeloader.h \
|
||||
sources/pdfobject.h \
|
||||
sources/pdfobjecteditormodel.h \
|
||||
sources/pdfobjectutils.h \
|
||||
sources/pdfoptimizer.h \
|
||||
sources/pdfoptionalcontent.h \
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
// Copyright (C) 2020 Jakub Melka
|
||||
//
|
||||
// This file is part of PdfForQt.
|
||||
//
|
||||
// PdfForQt 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pdfobjecteditormodel.h"
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
PDFObjectEditorAbstractModel::PDFObjectEditorAbstractModel(QObject* parent) :
|
||||
BaseClass(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PDFObjectEditorAbstractModel::~PDFObjectEditorAbstractModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
size_t PDFObjectEditorAbstractModel::getAttributeCount() const
|
||||
{
|
||||
return m_attributes.size();
|
||||
}
|
||||
|
||||
const QString& PDFObjectEditorAbstractModel::getAttributeCategory(size_t index) const
|
||||
{
|
||||
return m_attributes.at(index).category;
|
||||
}
|
||||
|
||||
const QString& PDFObjectEditorAbstractModel::getAttributeSubcategory(size_t index) const
|
||||
{
|
||||
return m_attributes.at(index).subcategory;
|
||||
}
|
||||
|
||||
const QString& PDFObjectEditorAbstractModel::getAttributeName(size_t index) const
|
||||
{
|
||||
return m_attributes.at(index).name;
|
||||
}
|
||||
|
||||
size_t PDFObjectEditorAbstractModel::createAttribute(ObjectEditorAttributeType type,
|
||||
QString attributeName,
|
||||
QString category,
|
||||
QString subcategory,
|
||||
QString name,
|
||||
PDFObject defaultValue,
|
||||
uint32_t typeFlags,
|
||||
PDFObjectEditorModelAttribute::Flags flags)
|
||||
{
|
||||
size_t index = m_attributes.size();
|
||||
|
||||
PDFObjectEditorModelAttribute attribute;
|
||||
attribute.type = type;
|
||||
attribute.dictionaryAttribute = QStringList(qMove(attributeName));
|
||||
attribute.category = qMove(category);
|
||||
attribute.subcategory = qMove(subcategory);
|
||||
attribute.name = qMove(name);
|
||||
attribute.defaultValue = qMove(defaultValue);
|
||||
attribute.typeFlags = typeFlags;
|
||||
attribute.attributeFlags = flags;
|
||||
m_attributes.emplace_back(qMove(attribute));
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
PDFObjectEditorAnnotationsModel::PDFObjectEditorAnnotationsModel(QObject* parent) :
|
||||
BaseClass(parent)
|
||||
{
|
||||
createAttribute(ObjectEditorAttributeType::Constant, "Type", tr("General"), tr("General"), tr("Type"), PDFObject::createName("Annot"), 0, PDFObjectEditorModelAttribute::Hidden);
|
||||
createAttribute(ObjectEditorAttributeType::Type, "Subtype", tr("General"), tr("General"), tr("Type"));
|
||||
|
||||
PDFObjectEditorModelAttributeEnumItems typeEnumItems;
|
||||
typeEnumItems.emplace_back(tr("Text"), Text, PDFObject::createName("Text"));
|
||||
typeEnumItems.emplace_back(tr("Link"), Link, PDFObject::createName("Link"));
|
||||
typeEnumItems.emplace_back(tr("Free text"), FreeText, PDFObject::createName("FreeText"));
|
||||
typeEnumItems.emplace_back(tr("Line"), Line, PDFObject::createName("Line"));
|
||||
typeEnumItems.emplace_back(tr("Square"), Square, PDFObject::createName("Square"));
|
||||
typeEnumItems.emplace_back(tr("Circle"), Circle, PDFObject::createName("Circle"));
|
||||
typeEnumItems.emplace_back(tr("Polygon"), Polygon, PDFObject::createName("Polygon"));
|
||||
typeEnumItems.emplace_back(tr("Polyline"), PolyLine, PDFObject::createName("PolyLine"));
|
||||
typeEnumItems.emplace_back(tr("Highlight"), Highlight, PDFObject::createName("Highlight"));
|
||||
typeEnumItems.emplace_back(tr("Underline"), Underline, PDFObject::createName("Underline"));
|
||||
typeEnumItems.emplace_back(tr("Squiggly"), Squiggly, PDFObject::createName("Squiggly"));
|
||||
typeEnumItems.emplace_back(tr("Strike Out"), StrikeOut, PDFObject::createName("StrikeOut"));
|
||||
typeEnumItems.emplace_back(tr("Caret"), Caret, PDFObject::createName("Caret"));
|
||||
typeEnumItems.emplace_back(tr("Stamp"), Stamp, PDFObject::createName("Stamp"));
|
||||
typeEnumItems.emplace_back(tr("Ink"), Ink, PDFObject::createName("Ink"));
|
||||
typeEnumItems.emplace_back(tr("File attachment"), FileAttachment, PDFObject::createName("FileAttachment"));
|
||||
typeEnumItems.emplace_back(tr("Redaction"), Redact, PDFObject::createName("Redact"));
|
||||
m_attributes.back().enumItems = qMove(typeEnumItems);
|
||||
|
||||
createAttribute(ObjectEditorAttributeType::Rectangle, "Rect", tr("General"), tr("General"), tr("Rectangle"), PDFObject());
|
||||
createAttribute(ObjectEditorAttributeType::TextLine, "NM", tr("Contents"), tr("Contents"), tr("Name"));
|
||||
createAttribute(ObjectEditorAttributeType::TextBrowser, "Contents", tr("Contents"), tr("Contents"), tr("Contents"));
|
||||
createAttribute(ObjectEditorAttributeType::DateTime, "M", tr("General"), tr("Info"), tr("Modified"), PDFObject(), 0, PDFObjectEditorModelAttribute::Readonly);
|
||||
}
|
||||
|
||||
} // namespace pdf
|
|
@ -0,0 +1,156 @@
|
|||
// Copyright (C) 2020 Jakub Melka
|
||||
//
|
||||
// This file is part of PdfForQt.
|
||||
//
|
||||
// PdfForQt 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef PDFOBJECTEDITORABSTRACTMODEL_H
|
||||
#define PDFOBJECTEDITORABSTRACTMODEL_H
|
||||
|
||||
#include "pdfobject.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
enum ObjectEditorAttributeType
|
||||
{
|
||||
Constant, ///< Constant attribute, which is always written to the object
|
||||
Type, ///< Type attribute, switches between main types of object
|
||||
TextLine, ///< Single line text
|
||||
TextBrowser, ///< Multiple line text
|
||||
Rectangle, ///< Rectangle defined by x,y,width,height
|
||||
DateTime, ///< Date/time
|
||||
Invalid
|
||||
};
|
||||
|
||||
struct PDFObjectEditorModelAttributeEnumItem
|
||||
{
|
||||
QString name;
|
||||
uint32_t flags = 0;
|
||||
PDFObject value;
|
||||
};
|
||||
|
||||
using PDFObjectEditorModelAttributeEnumItems = std::vector<PDFObjectEditorModelAttributeEnumItem>;
|
||||
|
||||
struct PDFObjectEditorModelAttribute
|
||||
{
|
||||
enum Flag
|
||||
{
|
||||
None = 0x0000,
|
||||
Readonly = 0x0001, ///< Attribute is always read only
|
||||
HideInsteadOfDisable = 0x0002, ///< Hide all widgets of this attribute, if it is disabled
|
||||
Hidden = 0x0004, ///< Attribute is always hidden (not viewable in gui)
|
||||
};
|
||||
Q_DECLARE_FLAGS(Flags, Flag)
|
||||
|
||||
/// Attribute type
|
||||
ObjectEditorAttributeType type = ObjectEditorAttributeType::Invalid;
|
||||
|
||||
/// Attribute name in object dictionary. In case of subdictionaries,
|
||||
/// there can be a path of constisting of dictionary names and last
|
||||
/// string in the string list is key in the dictionary. If this attribute
|
||||
/// is empty, then this attribute is not represented in final object.
|
||||
QStringList dictionaryAttribute;
|
||||
|
||||
/// Category
|
||||
QString category;
|
||||
|
||||
/// Subcategory
|
||||
QString subcategory;
|
||||
|
||||
/// Name of the attribute, which is displayed in the gui.
|
||||
QString name;
|
||||
|
||||
/// Default value
|
||||
PDFObject defaultValue;
|
||||
|
||||
/// Type flags, this filters attributes by object type. If set to zero,
|
||||
/// then this attribute doesn't depend on object type.
|
||||
uint32_t typeFlags = 0;
|
||||
|
||||
/// Attribute flags
|
||||
Flags attributeFlags = None;
|
||||
|
||||
/// Enum items
|
||||
PDFObjectEditorModelAttributeEnumItems enumItems;
|
||||
};
|
||||
|
||||
class PDFFORQTLIBSHARED_EXPORT PDFObjectEditorAbstractModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QObject;
|
||||
|
||||
public:
|
||||
explicit PDFObjectEditorAbstractModel(QObject* parent);
|
||||
virtual ~PDFObjectEditorAbstractModel();
|
||||
|
||||
size_t getAttributeCount() const;
|
||||
const QString& getAttributeCategory(size_t index) const;
|
||||
const QString& getAttributeSubcategory(size_t index) const;
|
||||
const QString& getAttributeName(size_t index) const;
|
||||
|
||||
protected:
|
||||
size_t createAttribute(ObjectEditorAttributeType type,
|
||||
QString attributeName,
|
||||
QString category,
|
||||
QString subcategory,
|
||||
QString name,
|
||||
PDFObject defaultValue = PDFObject(),
|
||||
uint32_t typeFlags = 0,
|
||||
PDFObjectEditorModelAttribute::Flags flags = PDFObjectEditorModelAttribute::None);
|
||||
|
||||
std::vector<PDFObjectEditorModelAttribute> m_attributes;
|
||||
};
|
||||
|
||||
class PDFFORQTLIBSHARED_EXPORT PDFObjectEditorAnnotationsModel : public PDFObjectEditorAbstractModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = PDFObjectEditorAbstractModel;
|
||||
|
||||
enum AnnotationTypes : uint32_t
|
||||
{
|
||||
Text = 1 << 0,
|
||||
Link = 1 << 1,
|
||||
FreeText = 1 << 2,
|
||||
Line = 1 << 3,
|
||||
Square = 1 << 4,
|
||||
Circle = 1 << 5,
|
||||
Polygon = 1 << 6,
|
||||
PolyLine = 1 << 7,
|
||||
Highlight = 1 << 8,
|
||||
Underline = 1 << 9,
|
||||
Squiggly = 1 << 10,
|
||||
StrikeOut = 1 << 11,
|
||||
Caret = 1 << 12,
|
||||
Stamp = 1 << 13,
|
||||
Ink = 1 << 14,
|
||||
FileAttachment = 1 << 15,
|
||||
Redact = 1 << 16,
|
||||
|
||||
Markup = Text | FreeText | Line | Square | Circle | Polygon | PolyLine | Highlight | Underline | Squiggly | StrikeOut | Caret | Stamp | Ink | FileAttachment | Redact
|
||||
};
|
||||
|
||||
public:
|
||||
explicit PDFObjectEditorAnnotationsModel(QObject* parent);
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
||||
#endif // PDFOBJECTEDITORABSTRACTMODEL_H
|
Loading…
Reference in New Issue