Files
c-evo-evo/common/include/Cevo/Table.h
T

60 lines
1.7 KiB
C++

#pragma once
#include <QStringList>
#include <memory>
#include <vector>
class QTreeWidget;
namespace Cevo {
// Equivalent of Table.pas's TTableFormat/TTableFormats.
enum class TableFormat { Excel, Plain, Csv, Html, ListView, MediaWiki, Xml, Json };
QString tableFormatText(TableFormat format);
QString tableFormatExt(TableFormat format);
// Equivalent of Table.pas's TRow.
struct Row {
QStringList cells;
void addCell(const QString &text) { cells.append(text); }
};
// Equivalent of Table.pas's TTable: a generic string table with multi-format
// export/import. JSON (QJsonDocument) and XML (QDomDocument) use Qt's own
// parsers/serializers instead of the original's hand-rolled, line-based
// ones (the original's JSON "parser" assumes exactly one "key": "value" per
// line and no nesting; its HTML/JSON output also did not escape cell
// content at all, which is fixed here).
class Table {
public:
QString title;
QStringList columns;
std::vector<std::unique_ptr<Row>> rows;
bool firstRowIsHeader = false;
void clear();
Row &addRow();
QString outputTabs() const;
QString outputPlain() const;
QString outputCsv() const;
QString outputXml() const;
QString outputHtml() const;
QString outputMediaWiki() const;
QString outputJson() const;
void populateTreeWidget(QTreeWidget *tree) const;
QString output(TableFormat format) const;
void setInputCsv(const QString &text);
void setInputMediaWiki(const QString &text);
void setInputJson(const QString &text);
void setInputXml(const QString &text);
void setInput(TableFormat format, const QString &text);
static QList<TableFormat> inputFormats();
};
} // namespace Cevo