summaryrefslogtreecommitdiff
path: root/src/csvbuilder.h
diff options
context:
space:
mode:
authorTannin <Tannin@Miranda>2013-02-16 19:09:57 +0100
committerTannin <Tannin@Miranda>2013-02-16 19:09:57 +0100
commit5d1154c24e2475ed2b7ac248de27ab7b501a1e5e (patch)
tree265341b9c8d057da46b56ad9fde40c9b39963ebb /src/csvbuilder.h
parent44b96e6fb5f484e9a60fe03b99021a1c5f78488d (diff)
- hooks for CreateHardLink
- createprocess hook will now reroute the cwd (fixes SUM, may break other tools?) - profile code moved to separate file - executables can now be linked to toolbar - category filters are now represented as a tree - csv export of mod list - ModInfoDialog is now "window modal" instead of "application modal" - nexus dialog now updates the mod-id field while browsing - right-click in nexus browser allows to open in external browser - ini viewer is no longer modal - bugfix: another attempt to fix processing of invalid header lines in fomod xmls (bom now handled) - bugfix: integrated fomod installer will no longer overwrite detected mod name by the one from the xml - bugfix: "hide file" from conflicted files list now updates that list - bugfix: conflicted files list no longer offers to hide files in BSAs - bugfix: pressing delete on the mod list with multiplie files selected offered to delete the wrong files - regression: mod name guessing with the old regular expression was less likely to lead to an empty mod name. Now both are tried
Diffstat (limited to 'src/csvbuilder.h')
-rw-r--r--src/csvbuilder.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/csvbuilder.h b/src/csvbuilder.h
new file mode 100644
index 00000000..f2e0e987
--- /dev/null
+++ b/src/csvbuilder.h
@@ -0,0 +1,93 @@
+#ifndef CSVBUILDER_H
+#define CSVBUILDER_H
+
+
+#include <vector>
+#include <QString>
+#include <QVariant>
+#include <QTextStream>
+
+
+class CSVException : public std::exception {
+
+public:
+ CSVException(const QString &text)
+ : std::exception(), m_Message(text.toLocal8Bit()) {}
+
+ virtual const char* what() const throw()
+ { return m_Message.constData(); }
+private:
+ QByteArray m_Message;
+
+};
+
+
+class CSVBuilder
+{
+
+public:
+
+ enum EFieldType {
+ TYPE_INTEGER,
+ TYPE_STRING,
+ TYPE_FLOAT
+ };
+
+ enum EQuoteMode {
+ QUOTE_NEVER,
+ QUOTE_ONDEMAND,
+ QUOTE_ALWAYS
+ };
+
+ enum ELineBreak {
+ BREAK_LF,
+ BREAK_CRLF,
+ BREAK_CR
+ };
+
+public:
+
+ CSVBuilder(QIODevice *target);
+ ~CSVBuilder();
+
+ void setFieldSeparator(char sep);
+ void setLineBreak(ELineBreak lineBreak);
+ void setEscapeMode(EFieldType type, EQuoteMode mode);
+ void setFields(const std::vector<std::pair<QString, EFieldType> > &fields);
+ void setDefault(const QString &field, const QVariant &value);
+
+ void writeHeader();
+
+ void setRowField(const QString &field, const QVariant &value);
+ void writeRow();
+
+ void addRow(const std::map<QString, QVariant> &data);
+
+private:
+
+ const char *lineBreak();
+ const char separator();
+
+ void fieldValid();
+ void checkFields(const std::vector<QString> &fields);
+ void checkValue(const QString &field, const QVariant &value);
+ void writeData(const std::map<QString, QVariant> &data, bool check);
+
+ void quoteInsert(QTextStream &stream, int value);
+ void quoteInsert(QTextStream &stream, float value);
+ void quoteInsert(QTextStream &stream, const QString &value);
+
+private:
+
+ QTextStream m_Out;
+ char m_Separator;
+ ELineBreak m_LineBreak;
+ std::map<EFieldType, EQuoteMode> m_QuoteMode;
+ std::vector<QString> m_Fields;
+ std::map<QString, EFieldType> m_FieldTypes;
+ std::map<QString, QVariant> m_Defaults;
+ std::map<QString, QVariant> m_RowBuffer;
+
+};
+
+#endif // CSVBUILDER_H