mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-11 07:56:08 -06:00
#4828 Summary Plot Templates : Use regexp to match case and index
This commit is contained in:
parent
56a5a750f2
commit
5a410ca8be
@ -44,6 +44,7 @@
|
|||||||
#include "cafSelectionManager.h"
|
#include "cafSelectionManager.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@ -102,32 +103,30 @@ void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
|
|||||||
auto fieldHandle = curve->findField( summaryFieldKeyword );
|
auto fieldHandle = curve->findField( summaryFieldKeyword );
|
||||||
if ( fieldHandle )
|
if ( fieldHandle )
|
||||||
{
|
{
|
||||||
|
bool conversionOk = false;
|
||||||
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase();
|
||||||
|
|
||||||
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
||||||
auto stringList = referenceString.split( " " );
|
int indexValue = RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString,
|
||||||
if ( stringList.size() == 2 )
|
referenceString,
|
||||||
|
&conversionOk );
|
||||||
|
|
||||||
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( selectedSummaryCases.size() ) )
|
||||||
{
|
{
|
||||||
QString indexAsString = stringList[1];
|
auto summaryCaseY = selectedSummaryCases[static_cast<int>( indexValue )];
|
||||||
|
curve->setSummaryCaseY( summaryCaseY );
|
||||||
|
|
||||||
bool conversionOk = false;
|
auto currentAddressY = curve->summaryAddressY();
|
||||||
auto index = indexAsString.toUInt( &conversionOk );
|
if ( summaryCaseY->summaryReader() &&
|
||||||
|
!summaryCaseY->summaryReader()->hasAddress( currentAddressY ) )
|
||||||
if ( conversionOk && index < selectedSummaryCases.size() )
|
|
||||||
{
|
{
|
||||||
auto summaryCaseY = selectedSummaryCases[index];
|
auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses();
|
||||||
curve->setSummaryCaseY( summaryCaseY );
|
|
||||||
|
|
||||||
auto currentAddressY = curve->summaryAddressY();
|
auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY,
|
||||||
if ( summaryCaseY->summaryReader() &&
|
allAddresses );
|
||||||
!summaryCaseY->summaryReader()->hasAddress( currentAddressY ) )
|
if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID )
|
||||||
{
|
{
|
||||||
auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses();
|
curve->setSummaryAddressY( candidate );
|
||||||
|
|
||||||
auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY,
|
|
||||||
allAddresses );
|
|
||||||
if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID )
|
|
||||||
{
|
|
||||||
curve->setSummaryAddressY( candidate );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +335,7 @@ QString RicSummaryPlotTemplateTools::summaryGroupFieldName()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCase()
|
QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCase()
|
||||||
{
|
{
|
||||||
return "SUMMARY_CASE";
|
return "CASE_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -364,3 +363,39 @@ RifEclipseSummaryAddress
|
|||||||
|
|
||||||
return RifEclipseSummaryAddress();
|
return RifEclipseSummaryAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
int RicSummaryPlotTemplateTools::findValueForKeyword( const QString& keyword, const QString& valueString, bool* ok )
|
||||||
|
{
|
||||||
|
// Example string : "CASE_NAME 1"
|
||||||
|
// Will match the string specified by keyword, and return the value captured by the regexp
|
||||||
|
|
||||||
|
QString regexpString = QString( "%1 (\\d++)" ).arg( keyword );
|
||||||
|
QRegularExpression rx( regexpString );
|
||||||
|
|
||||||
|
auto match = rx.match( valueString );
|
||||||
|
if ( match.hasMatch() )
|
||||||
|
{
|
||||||
|
QString integerAsText = match.captured( 1 );
|
||||||
|
|
||||||
|
if ( !integerAsText.isEmpty() )
|
||||||
|
{
|
||||||
|
int integerValue = integerAsText.toInt();
|
||||||
|
|
||||||
|
if ( ok )
|
||||||
|
{
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
return integerValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ok )
|
||||||
|
{
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -63,4 +63,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress,
|
static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress,
|
||||||
const std::set<RifEclipseSummaryAddress>& allAddresses );
|
const std::set<RifEclipseSummaryAddress>& allAddresses );
|
||||||
|
|
||||||
|
static int findValueForKeyword( const QString& keyword, const QString& valueString, bool* ok );
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user