From 7b28a23668f5f01f1c349f04e3ce88e6f0b84c0d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 13 Oct 2023 08:57:01 +0200 Subject: [PATCH] Improve parsing of units in CSV column headers Detect units enclosed by both () and [] Avoid duplicate vector name in UI --- .../FileInterface/RifCsvUserDataParser.cpp | 34 +++++++++++++------ .../RifEclipseSummaryAddress.cpp | 5 --- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifCsvUserDataParser.cpp b/ApplicationLibCode/FileInterface/RifCsvUserDataParser.cpp index 000e1d3e45..9c927c9147 100644 --- a/ApplicationLibCode/FileInterface/RifCsvUserDataParser.cpp +++ b/ApplicationLibCode/FileInterface/RifCsvUserDataParser.cpp @@ -384,19 +384,33 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* QString unit; - // Check if unit is part of the column name in parentheses, e.g. "VECTOR (unit)". - QRegExp exp( "\\((.*)\\)" ); - if ( exp.indexIn( colName ) >= 0 ) + // Find unit from column header text + // "VECTOR_NAME (unit)" + // "VECTOR_NAME [unit]" { - // "VECTOR (unit)" ==> "(unit)" - QString fullCapture = exp.cap( 0 ); - // "VECTOR (unit)" ==> "unit" - QString unitCapture = exp.cap( 1 ); + // "VECTORNAME (unit)" ==> "(unit)" + QRegExp exp( "[[]([^]]+)[]]" ); + if ( exp.indexIn( colName ) >= 0 ) + { + QString fullCapture = exp.cap( 0 ); + QString unitCapture = exp.cap( 1 ); - unit = unitCapture; + unit = unitCapture; + colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) ); + } + } - // Remove unit from name - colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) ); + { + // "VECTOR_NAME [unit]" ==> "[unit]" + QRegExp exp( "[(]([^)]+)[)]" ); + if ( exp.indexIn( colName ) >= 0 ) + { + QString fullCapture = exp.cap( 0 ); + QString unitCapture = exp.cap( 1 ); + + unit = unitCapture; + colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) ); + } } if ( auto it = nameMapping.find( colName ); it != nameMapping.end() ) diff --git a/ApplicationLibCode/FileInterface/RifEclipseSummaryAddress.cpp b/ApplicationLibCode/FileInterface/RifEclipseSummaryAddress.cpp index 9f7d537f61..a9bb8817fb 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseSummaryAddress.cpp +++ b/ApplicationLibCode/FileInterface/RifEclipseSummaryAddress.cpp @@ -722,11 +722,6 @@ std::string RifEclipseSummaryAddress::itemUiText() const text += std::to_string( aquiferNumber() ); } break; - case SummaryCategory::SUMMARY_IMPORTED: - { - text += vectorName(); - } - break; } return text;