mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Completion Export : Add option to control export of comments
This commit is contained in:
@@ -106,7 +106,7 @@ void RifCsvDataTableFormatter::outputBuffer()
|
||||
{
|
||||
for ( size_t i = 0; i < m_columnHeaders.size(); i++ )
|
||||
{
|
||||
m_out << m_columnHeaders[i].title;
|
||||
m_out << m_columnHeaders[i].title();
|
||||
|
||||
if ( i < m_columnHeaders.size() - 1 )
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ RifTextDataTableFormatter::RifTextDataTableFormatter( QTextStream& out )
|
||||
, m_headerPrefix( "-- " )
|
||||
, m_maxDataRowWidth( MAX_ECLIPSE_DATA_ROW_WIDTH )
|
||||
, m_defaultMarker( "1*" )
|
||||
, m_isOptionalCommentEnabled( true )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -51,6 +52,7 @@ RifTextDataTableFormatter::RifTextDataTableFormatter( const RifTextDataTableForm
|
||||
, m_headerPrefix( rhs.m_headerPrefix )
|
||||
, m_maxDataRowWidth( rhs.m_maxDataRowWidth )
|
||||
, m_defaultMarker( rhs.m_defaultMarker )
|
||||
, m_isOptionalCommentEnabled( rhs.isOptionalCommentEnabled() )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -175,6 +177,22 @@ QString RifTextDataTableFormatter::defaultMarker() const
|
||||
return m_defaultMarker;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifTextDataTableFormatter::setOptionalComment( bool enable )
|
||||
{
|
||||
m_isOptionalCommentEnabled = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifTextDataTableFormatter::isOptionalCommentEnabled() const
|
||||
{
|
||||
return m_isOptionalCommentEnabled;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -182,12 +200,26 @@ void RifTextDataTableFormatter::outputBuffer()
|
||||
{
|
||||
if ( !m_columns.empty() && !isAllHeadersEmpty( m_columns ) )
|
||||
{
|
||||
m_out << m_headerPrefix;
|
||||
size_t maxSubTitleCount = 0;
|
||||
for ( size_t i = 0u; i < m_columns.size(); ++i )
|
||||
{
|
||||
m_out << formatColumn( m_columns[i].title, i );
|
||||
maxSubTitleCount = std::max( maxSubTitleCount, m_columns[i].titles.size() );
|
||||
}
|
||||
|
||||
for ( size_t subTitleIndex = 0; subTitleIndex < maxSubTitleCount; subTitleIndex++ )
|
||||
{
|
||||
m_out << m_headerPrefix;
|
||||
for ( size_t i = 0u; i < m_columns.size(); ++i )
|
||||
{
|
||||
QString subTitle;
|
||||
if ( subTitleIndex < m_columns[i].titles.size() )
|
||||
{
|
||||
subTitle = m_columns[i].titles[subTitleIndex];
|
||||
}
|
||||
m_out << formatColumn( subTitle, i );
|
||||
}
|
||||
m_out << "\n";
|
||||
}
|
||||
m_out << "\n";
|
||||
}
|
||||
|
||||
for ( auto line : m_buffer )
|
||||
@@ -200,6 +232,10 @@ void RifTextDataTableFormatter::outputBuffer()
|
||||
{
|
||||
outputHorizontalLine( line );
|
||||
}
|
||||
else if ( line.lineType == KEYWORD )
|
||||
{
|
||||
outputKeyword( line );
|
||||
}
|
||||
else if ( line.lineType == CONTENTS )
|
||||
{
|
||||
QString lineText = m_tableRowPrependText;
|
||||
@@ -232,24 +268,38 @@ void RifTextDataTableFormatter::outputBuffer()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifTextDataTableFormatter::outputComment( const RifTextDataTableLine& comment )
|
||||
void RifTextDataTableFormatter::outputKeyword( const RifTextDataTableLine& keyword )
|
||||
{
|
||||
m_out << m_commentPrefix << comment.data[0] << "\n";
|
||||
QString text;
|
||||
if ( !keyword.data.empty() ) text = keyword.data.front();
|
||||
|
||||
m_out << text << "\n";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifTextDataTableFormatter::outputHorizontalLine( RifTextDataTableLine& comment )
|
||||
void RifTextDataTableFormatter::outputComment( const RifTextDataTableLine& comment )
|
||||
{
|
||||
if ( comment.lineType == HORIZONTAL_LINE )
|
||||
QString text;
|
||||
if ( !comment.data.empty() ) text = comment.data.front();
|
||||
|
||||
m_out << m_commentPrefix << text << "\n";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifTextDataTableFormatter::outputHorizontalLine( RifTextDataTableLine& horizontalLine )
|
||||
{
|
||||
if ( horizontalLine.lineType == HORIZONTAL_LINE )
|
||||
{
|
||||
int charCount = tableWidth();
|
||||
|
||||
QChar fillChar = ' ';
|
||||
if ( !comment.data.empty() )
|
||||
if ( !horizontalLine.data.empty() )
|
||||
{
|
||||
QString firstString = comment.data[0];
|
||||
QString firstString = horizontalLine.data[0];
|
||||
if ( !firstString.isEmpty() )
|
||||
{
|
||||
fillChar = firstString[0];
|
||||
@@ -270,7 +320,7 @@ bool RifTextDataTableFormatter::isAllHeadersEmpty( const std::vector<RifTextData
|
||||
{
|
||||
for ( auto& header : headers )
|
||||
{
|
||||
if ( !header.title.isEmpty() ) return false;
|
||||
if ( !header.titles.empty() ) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -305,9 +355,18 @@ void RifTextDataTableFormatter::tableCompleted( const QString& appendText, bool
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifTextDataTableFormatter& RifTextDataTableFormatter::keyword( const QString& keyword )
|
||||
{
|
||||
CVF_ASSERT( m_buffer.empty() );
|
||||
CVF_ASSERT( m_columns.empty() );
|
||||
m_out << keyword << "\n";
|
||||
RifTextDataTableLine line;
|
||||
line.data.push_back( keyword );
|
||||
line.lineType = KEYWORD;
|
||||
if ( m_columns.empty() )
|
||||
{
|
||||
outputKeyword( line );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer.push_back( line );
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -321,7 +380,12 @@ RifTextDataTableFormatter& RifTextDataTableFormatter::header( const std::vector<
|
||||
|
||||
for ( size_t colNumber = 0u; colNumber < m_columns.size(); ++colNumber )
|
||||
{
|
||||
m_columns[colNumber].width = measure( m_columns[colNumber].title );
|
||||
int maxWidth = 0;
|
||||
for ( const auto& subTitle : m_columns[colNumber].titles )
|
||||
{
|
||||
maxWidth = std::max( maxWidth, measure( subTitle ) );
|
||||
}
|
||||
m_columns[colNumber].width = maxWidth;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -346,6 +410,19 @@ RifTextDataTableFormatter& RifTextDataTableFormatter::comment( const QString& co
|
||||
return *this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifTextDataTableFormatter& RifTextDataTableFormatter::addOptionalComment( const QString& str )
|
||||
{
|
||||
if ( m_isOptionalCommentEnabled )
|
||||
{
|
||||
return comment( str );
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -30,7 +30,8 @@ enum RifTextDataTableLineType
|
||||
{
|
||||
COMMENT,
|
||||
CONTENTS,
|
||||
HORIZONTAL_LINE
|
||||
HORIZONTAL_LINE,
|
||||
KEYWORD
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -87,17 +88,52 @@ struct RifTextDataTableColumn
|
||||
RifTextDataTableDoubleFormatting doubleFormat = RifTextDataTableDoubleFormatting(),
|
||||
RifTextDataTableAlignment alignment = LEFT,
|
||||
int width = -1 )
|
||||
: title( title )
|
||||
, doubleFormat( doubleFormat )
|
||||
: doubleFormat( doubleFormat )
|
||||
, alignment( alignment )
|
||||
, width( width )
|
||||
{
|
||||
titles.push_back( title );
|
||||
}
|
||||
|
||||
RifTextDataTableColumn( const QString& title,
|
||||
const QString& subTitle,
|
||||
RifTextDataTableDoubleFormatting doubleFormat = RifTextDataTableDoubleFormatting(),
|
||||
RifTextDataTableAlignment alignment = LEFT,
|
||||
int width = -1 )
|
||||
: doubleFormat( doubleFormat )
|
||||
, alignment( alignment )
|
||||
, width( width )
|
||||
{
|
||||
titles.push_back( title );
|
||||
titles.push_back( subTitle );
|
||||
}
|
||||
|
||||
RifTextDataTableColumn( const QString& title,
|
||||
const QString& subTitle1,
|
||||
const QString& subTitle2,
|
||||
RifTextDataTableDoubleFormatting doubleFormat = RifTextDataTableDoubleFormatting(),
|
||||
RifTextDataTableAlignment alignment = LEFT,
|
||||
int width = -1 )
|
||||
: doubleFormat( doubleFormat )
|
||||
, alignment( alignment )
|
||||
, width( width )
|
||||
{
|
||||
titles.push_back( title );
|
||||
titles.push_back( subTitle1 );
|
||||
titles.push_back( subTitle2 );
|
||||
}
|
||||
|
||||
QString title() const
|
||||
{
|
||||
if ( !titles.empty() ) return titles.front();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
QString title;
|
||||
RifTextDataTableDoubleFormatting doubleFormat;
|
||||
RifTextDataTableAlignment alignment;
|
||||
int width;
|
||||
std::vector<QString> titles;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -126,6 +162,9 @@ public:
|
||||
void setDefaultMarker( const QString& defaultMarker );
|
||||
QString defaultMarker() const;
|
||||
|
||||
void setOptionalComment( bool enable );
|
||||
bool isOptionalCommentEnabled() const;
|
||||
|
||||
RifTextDataTableFormatter& keyword( const QString& keyword );
|
||||
RifTextDataTableFormatter& header( std::vector<RifTextDataTableColumn> tableHeader );
|
||||
RifTextDataTableFormatter& add( const QString& str );
|
||||
@@ -135,6 +174,7 @@ public:
|
||||
RifTextDataTableFormatter& addOneBasedCellIndex( size_t zeroBasedIndex );
|
||||
RifTextDataTableFormatter& addValueOrDefaultMarker( double value, double defaultValue );
|
||||
RifTextDataTableFormatter& comment( const QString& str );
|
||||
RifTextDataTableFormatter& addOptionalComment( const QString& str );
|
||||
RifTextDataTableFormatter& addHorizontalLine( const QChar& str );
|
||||
void rowCompleted();
|
||||
void rowCompleted( const QString& appendText );
|
||||
@@ -157,8 +197,9 @@ protected:
|
||||
QString formatColumn( const QString str, size_t columnIndex ) const;
|
||||
|
||||
void outputBuffer();
|
||||
void outputKeyword( const RifTextDataTableLine& keyword );
|
||||
void outputComment( const RifTextDataTableLine& comment );
|
||||
void outputHorizontalLine( RifTextDataTableLine& comment );
|
||||
void outputHorizontalLine( RifTextDataTableLine& horizontalLine );
|
||||
|
||||
bool isAllHeadersEmpty( const std::vector<RifTextDataTableColumn>& headers );
|
||||
|
||||
@@ -174,4 +215,5 @@ private:
|
||||
QString m_headerPrefix;
|
||||
int m_maxDataRowWidth;
|
||||
QString m_defaultMarker;
|
||||
bool m_isOptionalCommentEnabled;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user