2021-04-30 20:12:10 +02:00
|
|
|
// Copyright (C) 2019-2021 Jakub Melka
|
2019-07-01 19:53:38 +02:00
|
|
|
//
|
2020-12-20 19:03:58 +01:00
|
|
|
// This file is part of Pdf4Qt.
|
2019-07-01 19:53:38 +02:00
|
|
|
//
|
2020-12-20 19:03:58 +01:00
|
|
|
// Pdf4Qt is free software: you can redistribute it and/or modify
|
2019-07-01 19:53:38 +02:00
|
|
|
// 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
|
2021-04-30 20:12:10 +02:00
|
|
|
// with the written consent of the copyright owner, any later version.
|
2019-07-01 19:53:38 +02:00
|
|
|
//
|
2020-12-20 19:03:58 +01:00
|
|
|
// Pdf4Qt is distributed in the hope that it will be useful,
|
2019-07-01 19:53:38 +02:00
|
|
|
// 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
|
2020-12-20 19:03:58 +01:00
|
|
|
// along with Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
|
2019-07-01 19:53:38 +02:00
|
|
|
|
|
|
|
#ifndef PDFITEMMODELS_H
|
|
|
|
#define PDFITEMMODELS_H
|
|
|
|
|
|
|
|
#include "pdfglobal.h"
|
|
|
|
#include "pdfobject.h"
|
|
|
|
|
2019-11-29 19:10:29 +01:00
|
|
|
#include <QIcon>
|
2019-12-07 17:59:03 +01:00
|
|
|
#include <QPixmapCache>
|
2019-07-01 19:53:38 +02:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
|
2021-08-04 16:43:26 +02:00
|
|
|
#include <set>
|
|
|
|
|
2019-07-01 19:53:38 +02:00
|
|
|
namespace pdf
|
|
|
|
{
|
2019-11-29 19:10:29 +01:00
|
|
|
class PDFAction;
|
2019-07-01 19:53:38 +02:00
|
|
|
class PDFDocument;
|
2019-11-28 18:20:32 +01:00
|
|
|
class PDFOutlineItem;
|
2020-04-25 14:21:06 +02:00
|
|
|
class PDFModifiedDocument;
|
2019-12-01 18:10:11 +01:00
|
|
|
class PDFFileSpecification;
|
2019-07-02 16:20:12 +02:00
|
|
|
class PDFOptionalContentActivity;
|
2019-12-07 17:59:03 +01:00
|
|
|
class PDFDrawWidgetProxy;
|
2019-07-01 19:53:38 +02:00
|
|
|
|
|
|
|
/// Represents tree item in the GUI tree
|
2021-06-06 18:24:09 +02:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFTreeItem
|
2019-07-01 19:53:38 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline explicit PDFTreeItem() = default;
|
|
|
|
inline explicit PDFTreeItem(PDFTreeItem* parent) : m_parent(parent) { }
|
|
|
|
virtual ~PDFTreeItem();
|
|
|
|
|
|
|
|
template<typename T, typename... Arguments>
|
|
|
|
inline T* addChild(Arguments&&... arguments)
|
|
|
|
{
|
|
|
|
T* item = new T(this, std::forward(arguments)...);
|
|
|
|
m_children.push_back(item);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addCreatedChild(PDFTreeItem* item)
|
|
|
|
{
|
|
|
|
item->m_parent = this;
|
|
|
|
m_children.push_back(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int getRow() const { return m_parent->m_children.indexOf(const_cast<PDFTreeItem*>(this)); }
|
|
|
|
int getChildCount() const { return m_children.size(); }
|
|
|
|
const PDFTreeItem* getChild(int index) const { return m_children.at(index); }
|
2021-06-06 18:24:09 +02:00
|
|
|
PDFTreeItem* getChild(int index) { return m_children.at(index); }
|
2019-07-01 19:53:38 +02:00
|
|
|
const PDFTreeItem* getParent() const { return m_parent; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PDFTreeItem* m_parent = nullptr;
|
|
|
|
QList<PDFTreeItem*> m_children;
|
|
|
|
};
|
|
|
|
|
2020-04-25 14:21:06 +02:00
|
|
|
/// Root of all tree item models. Reimplementations of this model
|
|
|
|
/// must handle "soft" document updates, such as only annotations changed etc.
|
|
|
|
/// Model should be rebuilded only, if it is neccessary.
|
2020-12-20 19:03:58 +01:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFTreeItemModel : public QAbstractItemModel
|
2019-07-01 19:53:38 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit PDFTreeItemModel(QObject* parent);
|
|
|
|
|
2020-04-25 14:21:06 +02:00
|
|
|
void setDocument(const PDFModifiedDocument& document);
|
2019-07-01 19:53:38 +02:00
|
|
|
|
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
|
|
|
|
virtual QModelIndex parent(const QModelIndex& child) const override;
|
|
|
|
virtual int rowCount(const QModelIndex& parent) const override;
|
|
|
|
virtual bool hasChildren(const QModelIndex& parent) const override;
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
|
|
|
virtual void update() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const PDFDocument* m_document;
|
|
|
|
std::unique_ptr<PDFTreeItem> m_rootItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PDFOptionalContentTreeItem : public PDFTreeItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline explicit PDFOptionalContentTreeItem(PDFOptionalContentTreeItem* parent, PDFObjectReference reference, QString text, bool locked) :
|
|
|
|
PDFTreeItem(parent),
|
|
|
|
m_reference(reference),
|
|
|
|
m_text(qMove(text)),
|
|
|
|
m_locked(locked)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PDFObjectReference getReference() const { return m_reference; }
|
|
|
|
QString getText() const;
|
|
|
|
bool isLocked() const { return m_locked; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PDFObjectReference m_reference; ///< Reference to optional content group
|
|
|
|
QString m_text; ///< Node display name
|
|
|
|
bool m_locked; ///< Node is locked (user can't change it)
|
|
|
|
};
|
|
|
|
|
2020-12-20 19:03:58 +01:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFOptionalContentTreeItemModel : public PDFTreeItemModel
|
2019-07-01 19:53:38 +02:00
|
|
|
{
|
2019-11-29 19:10:29 +01:00
|
|
|
Q_OBJECT
|
2019-07-01 19:53:38 +02:00
|
|
|
public:
|
|
|
|
inline explicit PDFOptionalContentTreeItemModel(QObject* parent) :
|
2019-07-02 16:20:12 +02:00
|
|
|
PDFTreeItemModel(parent),
|
|
|
|
m_activity(nullptr)
|
2019-07-01 19:53:38 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-02 16:20:12 +02:00
|
|
|
void setActivity(PDFOptionalContentActivity* activity);
|
|
|
|
|
2019-07-01 19:53:38 +02:00
|
|
|
virtual int columnCount(const QModelIndex& parent) const override;
|
|
|
|
virtual QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
virtual void update() override;
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
2019-07-02 16:20:12 +02:00
|
|
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
PDFOptionalContentActivity* m_activity;
|
2019-07-01 19:53:38 +02:00
|
|
|
};
|
|
|
|
|
2019-11-28 18:20:32 +01:00
|
|
|
class PDFOutlineTreeItem : public PDFTreeItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit PDFOutlineTreeItem(PDFOutlineTreeItem* parent, QSharedPointer<PDFOutlineItem> outlineItem);
|
|
|
|
|
|
|
|
const PDFOutlineItem* getOutlineItem() const { return m_outlineItem.data(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
QSharedPointer<PDFOutlineItem> m_outlineItem;
|
|
|
|
};
|
|
|
|
|
2020-12-20 19:03:58 +01:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFOutlineTreeItemModel : public PDFTreeItemModel
|
2019-11-28 18:20:32 +01:00
|
|
|
{
|
2019-11-29 19:10:29 +01:00
|
|
|
Q_OBJECT
|
2019-11-28 18:20:32 +01:00
|
|
|
public:
|
2019-11-29 19:10:29 +01:00
|
|
|
PDFOutlineTreeItemModel(QIcon icon, QObject* parent) :
|
|
|
|
PDFTreeItemModel(parent),
|
|
|
|
m_icon(qMove(icon))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2019-11-28 18:20:32 +01:00
|
|
|
|
|
|
|
virtual int columnCount(const QModelIndex& parent) const override;
|
|
|
|
virtual QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
virtual void update() override;
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
2019-11-29 19:10:29 +01:00
|
|
|
|
|
|
|
/// Returns action assigned to the index. If index is invalid, or
|
|
|
|
/// points to the invalid item, nullptr is returned.
|
|
|
|
/// \param index Index of the outline item
|
|
|
|
const PDFAction* getAction(const QModelIndex& index) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QIcon m_icon;
|
2019-11-28 18:20:32 +01:00
|
|
|
};
|
|
|
|
|
2021-08-04 16:43:26 +02:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFSelectableOutlineTreeItemModel : public PDFOutlineTreeItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFOutlineTreeItemModel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PDFSelectableOutlineTreeItemModel(QIcon icon, QObject* parent) :
|
|
|
|
BaseClass(qMove(icon), parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
virtual void update() override;
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
|
|
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role) override;
|
|
|
|
|
|
|
|
std::vector<const PDFOutlineItem*> getSelectedItems() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::set<const PDFOutlineItem*> m_selectedItems;
|
|
|
|
};
|
|
|
|
|
2019-12-01 18:10:11 +01:00
|
|
|
class PDFAttachmentsTreeItem : public PDFTreeItem
|
|
|
|
{
|
|
|
|
public:
|
2020-04-25 14:21:06 +02:00
|
|
|
explicit PDFAttachmentsTreeItem(PDFAttachmentsTreeItem* parent, QIcon icon, QString title, QString description, const PDFFileSpecification* fileSpecification);
|
|
|
|
virtual ~PDFAttachmentsTreeItem() override;
|
2019-12-01 18:10:11 +01:00
|
|
|
|
|
|
|
const QIcon& getIcon() const { return m_icon; }
|
|
|
|
const QString& getTitle() const { return m_title; }
|
|
|
|
const QString& getDescription() const { return m_description; }
|
2020-04-25 14:21:06 +02:00
|
|
|
const PDFFileSpecification* getFileSpecification() const { return m_fileSpecification.get(); }
|
2019-12-01 18:10:11 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QIcon m_icon;
|
|
|
|
QString m_title;
|
|
|
|
QString m_description;
|
2020-04-25 14:21:06 +02:00
|
|
|
std::unique_ptr<PDFFileSpecification> m_fileSpecification;
|
2019-12-01 18:10:11 +01:00
|
|
|
};
|
|
|
|
|
2020-12-20 19:03:58 +01:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFAttachmentsTreeItemModel : public PDFTreeItemModel
|
2019-12-01 18:10:11 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
PDFAttachmentsTreeItemModel(QObject* parent) :
|
|
|
|
PDFTreeItemModel(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Column
|
|
|
|
{
|
|
|
|
Title,
|
|
|
|
Description,
|
|
|
|
EndColumn
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual int columnCount(const QModelIndex& parent) const override;
|
|
|
|
virtual QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
virtual void update() override;
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
2019-12-03 19:24:43 +01:00
|
|
|
|
|
|
|
const PDFFileSpecification* getFileSpecification(const QModelIndex& index) const;
|
2019-12-01 18:10:11 +01:00
|
|
|
};
|
|
|
|
|
2020-12-20 19:03:58 +01:00
|
|
|
class Pdf4QtLIBSHARED_EXPORT PDFThumbnailsItemModel : public QAbstractItemModel
|
2019-12-07 17:59:03 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit inline PDFThumbnailsItemModel(const PDFDrawWidgetProxy* proxy, QObject* parent);
|
|
|
|
|
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
|
|
|
|
virtual QModelIndex parent(const QModelIndex& child) const override;
|
|
|
|
virtual int rowCount(const QModelIndex& parent) const override;
|
|
|
|
virtual int columnCount(const QModelIndex& parent) const override;
|
|
|
|
virtual QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
|
|
|
|
void setThumbnailsSize(int size);
|
2020-04-25 14:21:06 +02:00
|
|
|
void setDocument(const PDFModifiedDocument& document);
|
2019-12-07 17:59:03 +01:00
|
|
|
|
|
|
|
/// Sets the extra item width/height for size hint. This space will be added to the size hint (pixmap size)
|
|
|
|
void setExtraItemSizeHint(int width, int height) { m_extraItemWidthHint = width; m_extraItemHeighHint = height; }
|
|
|
|
|
2019-12-08 19:20:36 +01:00
|
|
|
PDFInteger getPageIndex(const QModelIndex& index) const;
|
|
|
|
|
2019-12-07 17:59:03 +01:00
|
|
|
private:
|
|
|
|
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
|
|
|
|
|
|
|
/// Returns generated key for page index
|
|
|
|
QString getKey(int pageIndex) const;
|
|
|
|
|
|
|
|
const PDFDrawWidgetProxy* m_proxy;
|
|
|
|
int m_thumbnailSize;
|
|
|
|
int m_extraItemWidthHint;
|
|
|
|
int m_extraItemHeighHint;
|
|
|
|
int m_pageCount;
|
|
|
|
const PDFDocument* m_document;
|
|
|
|
QPixmapCache m_thumbnailCache;
|
|
|
|
};
|
|
|
|
|
2019-07-01 19:53:38 +02:00
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
#endif // PDFITEMMODELS_H
|