2017-05-15 08:46:28 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-05-16 05:49:36 -05:00
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2018-03-21 01:43:54 -05:00
|
|
|
//
|
2017-05-15 08:46:28 -05:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-03-21 01:43:54 -05:00
|
|
|
//
|
2017-05-15 08:46:28 -05:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2018-03-21 01:43:54 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-05-15 08:46:28 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
enum RifEclipseOutputTableLineType
|
|
|
|
{
|
|
|
|
COMMENT,
|
2018-06-29 04:21:31 -05:00
|
|
|
CONTENTS,
|
|
|
|
HORIZONTAL_LINE
|
2017-05-15 08:46:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
enum RifEclipseOutputTableAlignment
|
|
|
|
{
|
|
|
|
LEFT,
|
|
|
|
RIGHT
|
|
|
|
};
|
|
|
|
|
2017-06-21 09:25:41 -05:00
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
enum RifEclipseOutputTableDoubleFormat
|
|
|
|
{
|
2017-08-10 08:07:56 -05:00
|
|
|
RIF_SCIENTIFIC,
|
|
|
|
RIF_FLOAT,
|
2018-12-12 06:09:09 -06:00
|
|
|
RIF_CONSISE
|
2017-06-21 09:25:41 -05:00
|
|
|
};
|
|
|
|
|
2017-05-15 08:46:28 -05:00
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
struct RifEclipseOutputTableLine
|
|
|
|
{
|
|
|
|
RifEclipseOutputTableLineType lineType;
|
2018-03-21 01:43:54 -05:00
|
|
|
std::vector<QString> data;
|
2018-10-08 08:52:33 -05:00
|
|
|
bool appendTextSet;
|
|
|
|
QString appendText;
|
2017-05-15 08:46:28 -05:00
|
|
|
};
|
|
|
|
|
2017-06-21 09:25:41 -05:00
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
struct RifEclipseOutputTableDoubleFormatting
|
|
|
|
{
|
2018-12-18 03:22:22 -06:00
|
|
|
RifEclipseOutputTableDoubleFormatting(RifEclipseOutputTableDoubleFormat format = RIF_FLOAT, int precision = 5)
|
2018-03-21 01:43:54 -05:00
|
|
|
: format(format)
|
2018-12-18 03:22:22 -06:00
|
|
|
, precision(precision)
|
2018-03-21 01:43:54 -05:00
|
|
|
{
|
|
|
|
}
|
2017-06-21 09:25:41 -05:00
|
|
|
|
|
|
|
RifEclipseOutputTableDoubleFormat format;
|
2018-12-18 03:22:22 -06:00
|
|
|
int precision;
|
2017-06-21 09:25:41 -05:00
|
|
|
};
|
|
|
|
|
2017-05-15 08:46:28 -05:00
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
struct RifEclipseOutputTableColumn
|
|
|
|
{
|
2018-03-21 01:43:54 -05:00
|
|
|
RifEclipseOutputTableColumn(const QString& title,
|
2017-06-21 09:25:41 -05:00
|
|
|
RifEclipseOutputTableDoubleFormatting doubleFormat = RifEclipseOutputTableDoubleFormatting(),
|
2018-03-21 01:43:54 -05:00
|
|
|
RifEclipseOutputTableAlignment alignment = LEFT,
|
|
|
|
int width = -1)
|
|
|
|
: title(title)
|
|
|
|
, doubleFormat(doubleFormat)
|
|
|
|
, alignment(alignment)
|
|
|
|
, width(width)
|
2017-05-16 06:36:14 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-21 09:25:41 -05:00
|
|
|
QString title;
|
|
|
|
RifEclipseOutputTableDoubleFormatting doubleFormat;
|
|
|
|
RifEclipseOutputTableAlignment alignment;
|
|
|
|
int width;
|
2017-05-15 08:46:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
2017-05-30 08:00:14 -05:00
|
|
|
class RifEclipseDataTableFormatter
|
2017-05-15 08:46:28 -05:00
|
|
|
{
|
|
|
|
public:
|
2017-05-30 08:00:14 -05:00
|
|
|
RifEclipseDataTableFormatter(QTextStream& out);
|
2018-12-18 03:22:22 -06:00
|
|
|
RifEclipseDataTableFormatter(const RifEclipseDataTableFormatter& rhs);
|
|
|
|
|
2017-05-30 08:00:14 -05:00
|
|
|
virtual ~RifEclipseDataTableFormatter();
|
2017-05-15 08:46:28 -05:00
|
|
|
|
2018-12-11 09:57:05 -06:00
|
|
|
int columnSpacing() const;
|
2018-03-21 01:41:55 -05:00
|
|
|
void setColumnSpacing(int spacing);
|
2018-12-12 06:09:09 -06:00
|
|
|
QString tableRowPrependText() const;
|
2018-12-19 08:06:14 -06:00
|
|
|
QString tableRowAppendText() const;
|
2018-06-29 04:21:31 -05:00
|
|
|
void setTableRowPrependText(const QString& text);
|
|
|
|
void setTableRowLineAppendText(const QString& text);
|
2018-12-19 08:06:14 -06:00
|
|
|
QString commentPrefix() const;
|
2018-11-01 04:02:30 -05:00
|
|
|
void setCommentPrefix(const QString& commentPrefix);
|
2019-01-18 07:55:12 -06:00
|
|
|
void setUnlimitedDataRowWidth();
|
|
|
|
int maxDataRowWidth() const;
|
2018-03-21 01:41:55 -05:00
|
|
|
|
2018-06-29 04:21:31 -05:00
|
|
|
RifEclipseDataTableFormatter& keyword(const QString& keyword);
|
2018-03-21 01:43:54 -05:00
|
|
|
RifEclipseDataTableFormatter& header(std::vector<RifEclipseOutputTableColumn> tableHeader);
|
2018-06-29 04:21:31 -05:00
|
|
|
RifEclipseDataTableFormatter& add(const QString& str);
|
2018-08-13 05:59:45 -05:00
|
|
|
RifEclipseDataTableFormatter& add(double num);
|
2018-03-21 01:43:54 -05:00
|
|
|
RifEclipseDataTableFormatter& add(int num);
|
|
|
|
RifEclipseDataTableFormatter& add(size_t num);
|
2018-08-29 01:41:06 -05:00
|
|
|
RifEclipseDataTableFormatter& addOneBasedCellIndex(size_t zeroBasedIndex);
|
2018-08-13 05:59:45 -05:00
|
|
|
RifEclipseDataTableFormatter& addValueOrDefaultMarker(double value, double defaultValue);
|
2018-06-29 04:21:31 -05:00
|
|
|
RifEclipseDataTableFormatter& comment(const QString& str);
|
|
|
|
RifEclipseDataTableFormatter& addHorizontalLine(const QChar& str);
|
2018-03-21 01:43:54 -05:00
|
|
|
void rowCompleted();
|
2018-10-08 08:52:33 -05:00
|
|
|
void rowCompleted(const QString& appendText);
|
2018-03-21 01:43:54 -05:00
|
|
|
void tableCompleted();
|
2018-10-08 08:52:33 -05:00
|
|
|
void tableCompleted(const QString& appendText, bool appendNewline);
|
|
|
|
|
2018-12-19 08:06:14 -06:00
|
|
|
int tableWidth() const;
|
2018-12-18 03:22:22 -06:00
|
|
|
|
2017-05-15 08:46:28 -05:00
|
|
|
private:
|
2018-03-21 01:43:54 -05:00
|
|
|
int measure(const QString str);
|
|
|
|
int measure(double num, RifEclipseOutputTableDoubleFormatting doubleFormat);
|
|
|
|
int measure(int num);
|
|
|
|
int measure(size_t num);
|
2017-05-15 08:46:28 -05:00
|
|
|
|
2018-03-21 01:43:54 -05:00
|
|
|
QString format(double num, RifEclipseOutputTableDoubleFormatting doubleFormat);
|
|
|
|
QString format(int num);
|
|
|
|
QString format(size_t num);
|
2018-12-12 06:09:09 -06:00
|
|
|
QString formatColumn(const QString str, size_t columnIndex) const;
|
2017-05-15 08:46:28 -05:00
|
|
|
|
2018-03-21 01:43:54 -05:00
|
|
|
void outputBuffer();
|
|
|
|
void outputComment(RifEclipseOutputTableLine& comment);
|
2018-06-29 04:21:31 -05:00
|
|
|
void outputHorizontalLine(RifEclipseOutputTableLine& comment);
|
2017-05-15 08:46:28 -05:00
|
|
|
|
2018-10-08 08:52:33 -05:00
|
|
|
bool isAllHeadersEmpty(const std::vector<RifEclipseOutputTableColumn>& headers);
|
|
|
|
|
2017-05-15 08:46:28 -05:00
|
|
|
private:
|
|
|
|
std::vector<RifEclipseOutputTableColumn> m_columns;
|
|
|
|
std::vector<RifEclipseOutputTableLine> m_buffer;
|
|
|
|
std::vector<QString> m_lineBuffer;
|
|
|
|
QTextStream& m_out;
|
2018-03-21 01:43:54 -05:00
|
|
|
int m_colSpacing;
|
2018-06-29 04:21:31 -05:00
|
|
|
QString m_tableRowPrependText;
|
|
|
|
QString m_tableRowAppendText;
|
2018-11-01 04:02:30 -05:00
|
|
|
QString m_commentPrefix;
|
2019-01-18 07:55:12 -06:00
|
|
|
int m_maxDataRowWidth;
|
2017-05-15 08:46:28 -05:00
|
|
|
};
|