| 1 |
/* This file is part of the KDE project |
| 2 |
SPDX-FileCopyrightText: 2017 Dag Andersen <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef REPORTGENERATORODT_H |
| 8 |
#define REPORTGENERATORODT_H |
| 9 |
|
| 10 |
#include "ReportGenerator.h" |
| 11 |
|
| 12 |
#include <QModelIndexList> |
| 13 |
|
| 14 |
#include <KoXmlReaderForward.h> |
| 15 |
|
| 16 |
#include <QDomDocument> |
| 17 |
#include <QSortFilterProxyModel> |
| 18 |
|
| 19 |
class QIODevice; |
| 20 |
class QString; |
| 21 |
class QBuffer; |
| 22 |
|
| 23 |
class KoXmlWriter; |
| 24 |
class KoStore; |
| 25 |
class KoOdfWriteStore; |
| 26 |
class KoOdfReadStore; |
| 27 |
|
| 28 |
#define USERFIELD_TRANSLATION -3 |
| 29 |
#define USERFIELD_VARIABLE -2 |
| 30 |
#define USERFIELD_NONE -1 |
| 31 |
#define USERFIELD_HEADER 0 |
| 32 |
#define USERFIELD_DATA 1 |
| 33 |
|
| 34 |
namespace KPlato |
| 35 |
{ |
| 36 |
|
| 37 |
class Project; |
| 38 |
class ScheduleManager; |
| 39 |
class ItemModelBase; |
| 40 |
|
| 41 |
|
| 42 |
class PLANMODELS_EXPORT ReportGeneratorOdt : public ReportGenerator |
| 43 |
{ |
| 44 |
public: |
| 45 |
explicit ReportGeneratorOdt(); |
| 46 |
~ReportGeneratorOdt() override; |
| 47 |
|
| 48 |
bool createReport() override; |
| 49 |
|
| 50 |
protected: |
| 51 |
bool initiateInternal() override; |
| 52 |
bool createReportOdt(); |
| 53 |
bool handleTextP(KoXmlWriter &writer, const KoXmlElement &textp); |
| 54 |
void handleDrawFrame(KoXmlWriter &writer, const KoXmlElement &frame); |
| 55 |
void treatText(KoXmlWriter &writer, const KoXmlText &text); |
| 56 |
void treatTable(KoXmlWriter &writer, const KoXmlElement &tableElement); |
| 57 |
bool treatTableHeaderRows(KoXmlWriter &writer, const KoXmlElement &headerRowElement); |
| 58 |
bool treatTableRow(KoXmlWriter &writer, const KoXmlElement &rowElement); |
| 59 |
void treatUserFieldGet(KoXmlWriter &writer, const KoXmlElement &e); |
| 60 |
void writeElementAttributes(KoXmlWriter &writer, const KoXmlElement &element, const QStringList &exclude = QStringList()); |
| 61 |
void writeChildElements(KoXmlWriter &writer, const KoXmlElement &parent); |
| 62 |
bool copyFile(KoStore &from, KoStore &to, const QString &file); |
| 63 |
bool copyFile(KoStore &from, KoStore &to, const char *file); |
| 64 |
KoStore *copyStore(KoOdfReadStore &reader, const QString &outfile); |
| 65 |
KoXmlWriter *createOasisXmlWriter(KoOdfReadStore &reader, QBuffer *buffer, const QString fileName, const char *rootElementName); |
| 66 |
|
| 67 |
void treatEmbededObjects(KoOdfReadStore &reader, KoStore &outStore); |
| 68 |
void treatChart(KoOdfReadStore &reader, KoStore &outStore, const QString &name, const QString &file); |
| 69 |
void treatGantt(KoOdfReadStore &reader, KoStore &outStore, const QString &name, const QString &file); |
| 70 |
void writeChartElements(KoXmlWriter &writer, const KoXmlElement &parent); |
| 71 |
|
| 72 |
void listChildNodes(const QDomNode &parent); |
| 73 |
|
| 74 |
void handleUserFieldDecls(KoXmlWriter &writer, const KoXmlElement &decls); |
| 75 |
QAbstractItemModel *dataModel(const QString &name) const; |
| 76 |
|
| 77 |
QAbstractItemModel *projectsModel(ItemModelBase *base) const; |
| 78 |
|
| 79 |
public: |
| 80 |
class UserField { |
| 81 |
public: |
| 82 |
enum Variant { None, Header, Rows, Variable, Translation }; |
| 83 |
UserField() : seqNr(USERFIELD_NONE), serieNr(0) {} |
| 84 |
int variant() const; |
| 85 |
void begin(); |
| 86 |
bool next(); |
| 87 |
void finish(); |
| 88 |
QString headerData(const QString &columnName) const; |
| 89 |
QString data(const QString &columnName) const; |
| 90 |
|
| 91 |
int rowCount(); |
| 92 |
int columnCount() const {return columns.count();} |
| 93 |
void setModel(QAbstractItemModel *model, int role); |
| 94 |
int column(const QString &columnName) const; |
| 95 |
|
| 96 |
QString name; // Name of this field (eg: table1) |
| 97 |
QString type; // Type of field (eg: table) |
| 98 |
QString dataName; // Name associated with the data (eg: tasks) |
| 99 |
QStringList properties; // Info on how to handle the data (eg: values=bcws,bcwp,acwp) |
| 100 |
QStringList headerNames; // Lowercase list of all header names |
| 101 |
QStringList columns; // Lowercase list of headernames that shall be used |
| 102 |
QSortFilterProxyModel model; |
| 103 |
int seqNr; // A sequence number used to tabulate column names (eg: seqNr=2: table1.name2) |
| 104 |
int serieNr; // A chart needs to know which data series it works with |
| 105 |
QString hasLabels; // A chart needs to know if data shall contain legends/labels |
| 106 |
|
| 107 |
QModelIndex currentIndex; |
| 108 |
}; |
| 109 |
|
| 110 |
UserField *findUserField(const KoXmlElement &decl) const; |
| 111 |
|
| 112 |
private: |
| 113 |
KoStore *m_templateStore; |
| 114 |
QStringList m_manifestfiles; |
| 115 |
|
| 116 |
QList<QString> m_sortedfields; |
| 117 |
QList<QString> m_activefields; |
| 118 |
|
| 119 |
QMap<QString, UserField*> m_userfields; |
| 120 |
|
| 121 |
QMap<QString, QString> m_embededcharts; |
| 122 |
QMap<QString, QString> m_embededgantts; |
| 123 |
|
| 124 |
QList<QByteArray> m_tags; // cache tags for survival |
| 125 |
}; |
| 126 |
|
| 127 |
QDebug operator<<(QDebug dbg, ReportGeneratorOdt::UserField *f); |
| 128 |
QDebug operator<<(QDebug dbg, ReportGeneratorOdt::UserField &f); |
| 129 |
|
| 130 |
} //namespace KPlato |
| 131 |
|
| 132 |
#endif // REPORTGENERATOR_H |