Warning, file /utilities/skanpage/src/DocumentModel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**
0002  * SPDX-FileCopyrightText: 2015 by Kåre Särs <kare.sars@iki .fi>
0003  * SPDX-FileCopyrightText: 2021 by Alexander Stippich <a.stippich@gmx.net>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #ifndef DOCUMENT_MODEL_H
0009 #define DOCUMENT_MODEL_H
0010 
0011 #include <memory>
0012 
0013 #include <QAbstractListModel>
0014 #include <QString>
0015 #include <QUrl>
0016 
0017 #include "SkanpageUtils.h"
0018 
0019 class DocumentModelPrivate;
0020 
0021 class DocumentModel : public QAbstractListModel
0022 {
0023     Q_OBJECT
0024     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0025     Q_PROPERTY(QString fileName READ fileName NOTIFY nameChanged)
0026     Q_PROPERTY(bool changed READ changed NOTIFY changedChanged)
0027     Q_PROPERTY(int activePageIndex READ activePageIndex WRITE setActivePageIndex NOTIFY activePageChanged)
0028     Q_PROPERTY(QUrl activePageSource READ activePageSource NOTIFY activePageChanged)
0029     Q_PROPERTY(int activePageRotation READ activePageRotation NOTIFY activePageChanged)
0030     Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
0031     
0032 public:
0033     enum DocumentModelRoles { ImageUrlRole = Qt::UserRole + 1,
0034         RotationAngleRole,
0035         AspectRatioRole,
0036         PreviewWidthRole,
0037         PreviewHeightRole,
0038         IsSavedRole};
0039 
0040     enum RotateOption { Rotate90positive,
0041         Rotate90negative,
0042         Flip180};
0043 
0044     Q_ENUM(RotateOption);
0045 
0046     enum ReorderOption { ReorderDuplex,
0047         ReorderDuplexReversed,
0048         Reverse};
0049 
0050     Q_ENUM(ReorderOption);
0051 
0052     explicit DocumentModel(QObject *parent = nullptr);
0053     ~DocumentModel();
0054 
0055     QString name() const;
0056     QString fileName() const;
0057     int activePageIndex() const;
0058     int activePageRotation() const;
0059     QUrl activePageSource() const;
0060     bool changed() const;
0061 
0062     void setActivePageIndex(int);
0063 
0064     void addImage(const QImage &image);
0065 
0066     Q_INVOKABLE void clearData();
0067 
0068     Q_INVOKABLE void moveImage(int from, int to);
0069 
0070     Q_INVOKABLE void removeImage(int row);
0071 
0072     Q_INVOKABLE void rotateImage(int row, RotateOption rotate = RotateOption::Rotate90positive);
0073 
0074     Q_INVOKABLE void reorderPages(ReorderOption reorder);
0075 
0076     Q_INVOKABLE void save(const QUrl &fileUrl, QList<int> pageNumbers = {});
0077 
0078     Q_INVOKABLE void createSharingFile(const QString &suffix, QList<int> pageNumbers = {});
0079 
0080     Q_INVOKABLE void exportPDF(const QUrl &fileUrl, const QString &title, const bool useOCR);
0081 
0082     QHash<int, QByteArray> roleNames() const override;
0083     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0084     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0085 
0086 Q_SIGNALS:
0087     void nameChanged();
0088     void changedChanged();
0089     void activePageChanged();
0090     void countChanged();
0091     void newPageAdded();
0092     void saveDocument(const QUrl &fileUrl, const SkanpageUtils::DocumentPages &document, const SkanpageUtils::FileType type = SkanpageUtils::EntireDocument, const QString &title = QString());
0093     void saveNewPageTemporary(const int pageID, const QImage &image);
0094     void sharingDocumentsCreated(const QVariantList &fileUrls);
0095 
0096 public Q_SLOTS:
0097     void updateFileInformation(const QList<QUrl> &fileUrls, const SkanpageUtils::DocumentPages &document);
0098     void updateSharingFileInformation(const QList<QUrl> &fileUrls);
0099     void updatePageInModel(const int pageID, const SkanpageUtils::PageProperties &page);
0100 
0101 private:
0102 
0103     SkanpageUtils::DocumentPages selectPages(QList<int> pageNumbers);
0104 
0105     std::unique_ptr<DocumentModelPrivate> d;
0106 };
0107 
0108 #endif // DOCUMENT_MODEL_H