Qt6: Adjustments (#11804)

* Qt6: Avoid insertWidget, use addWidget
In Qt6, the insertWidget function checks if the index parameter is valid based on current widgets present in the layout. This is error prone, and use addWidget to avoid manual counting of index.

* Disable use of Qt keyword foreach

* Replace use of QRegExp with QRegularExpression
Replace use of QRegExp with QRegularExpression
Remove dependency on qt5compat module
Simplify an expression based on review

* Remove Qt5 ifdefs

* Guard access out of bounds seen in debug build

* Avoid reuse of string variable

* Disconnect all signals from the QOpenGLContext
The call stack when this assert happens indicates that there are more signals to be disconnected from the object. Crash is fixed by disconnecting all signals.

Assert seen in debug build:

ASSERT failure in caf::Viewer: "Called object is not of the correct type (class destructor may have already run)", file C:\Qt\6.6.3\msvc2019_64\include\QtCore/qobjectdefs_impl.h, line 130

* Fix issue related to delete of a linked view
Guard null pointer use in view linker. Remove complicated cleanup in destructor in Rim3dVew.
This commit is contained in:
Magne Sjaastad
2024-10-28 13:09:18 +01:00
committed by GitHub
parent bb047e82d3
commit 2814b92055
59 changed files with 196 additions and 393 deletions

View File

@@ -121,7 +121,7 @@ void RifCaseRealizationParametersReader::parse()
QString line = dataStream.readLine();
lineNo++;
QStringList cols = RifFileParseTools::splitLineAndTrim( line, QRegExp( "[ \t]" ), true );
QStringList cols = RifFileParseTools::splitLineAndTrim( line, QRegularExpression( "[ \t]" ), true );
if ( cols.size() != 2 )
{
@@ -287,22 +287,22 @@ int RifCaseRealizationParametersFileLocator::realizationNumber( const QString& m
QDir dir( modelPath );
QString absolutePath = dir.absolutePath();
return realizationNumberFromFullPath( absolutePath );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RifCaseRealizationParametersFileLocator::realizationNumberFromFullPath( const QString& path )
{
int resultIndex = -1;
// Use parenthesis to indicate capture of sub string
QString pattern = "(realization-\\d+)";
QRegularExpression pattern( "realization-(\\d+)", QRegularExpression::CaseInsensitiveOption );
QRegularExpressionMatch match = pattern.match( path );
QRegExp regexp( pattern, Qt::CaseInsensitive );
if ( regexp.indexIn( absolutePath ) )
if ( match.hasMatch() )
{
QString tempText = regexp.cap( 1 );
QRegExp rx( "(\\d+)" ); // Find number
int digitPos = rx.indexIn( tempText );
if ( digitPos > -1 )
{
resultIndex = rx.cap( 0 ).toInt();
}
resultIndex = match.captured( 1 ).toInt();
}
return resultIndex;

View File

@@ -94,4 +94,5 @@ class RifCaseRealizationParametersFileLocator
public:
static QString locate( const QString& modelPath );
static int realizationNumber( const QString& modelPath );
static int realizationNumberFromFullPath( const QString& path );
};

View File

@@ -91,7 +91,7 @@ cvf::ref<RigFormationNames> RifColorLegendData::readLyrFormationNameFile( const
if ( QColor::isValidColorName( colorWord ) ) numberString.remove( colorWord ); // remove color if present as last word on line
// extract words containing formation number(s)
QStringList numberWords = RiaTextStringTools::splitSkipEmptyParts( numberString, QRegExp( "-" ) );
QStringList numberWords = RiaTextStringTools::splitSkipEmptyParts( numberString, QRegularExpression( "-" ) );
if ( numberWords.size() == 2 ) // formation range with or without color at end of line
{

View File

@@ -392,11 +392,12 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream*
// "VECTOR_NAME [unit]"
{
// "VECTORNAME (unit)" ==> "(unit)"
QRegExp exp( "[[]([^]]+)[]]" );
if ( exp.indexIn( colName ) >= 0 )
QRegularExpression exp( R"(\[([^\]]+)\])" );
QRegularExpressionMatch match = exp.match( colName );
if ( match.hasMatch() )
{
QString fullCapture = exp.cap( 0 );
QString unitCapture = exp.cap( 1 );
QString fullCapture = match.captured( 0 );
QString unitCapture = match.captured( 1 );
unit = unitCapture;
colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) );
@@ -405,11 +406,12 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream*
{
// "VECTOR_NAME [unit]" ==> "[unit]"
QRegExp exp( "[(]([^)]+)[)]" );
if ( exp.indexIn( colName ) >= 0 )
QRegularExpression exp( R"(\(([^)]+)\))" );
QRegularExpressionMatch match = exp.match( colName );
if ( match.hasMatch() )
{
QString fullCapture = exp.cap( 0 );
QString unitCapture = exp.cap( 1 );
QString fullCapture = match.captured( 0 );
QString unitCapture = match.captured( 1 );
unit = unitCapture;
colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) );

View File

@@ -1419,31 +1419,31 @@ void RifEclipseInputFileTools::readKeywordDataContent( QFile& data, qint64 fileP
QString line = data.readLine();
line = line.trimmed();
if ( line.startsWith( "--", Qt::CaseInsensitive ) )
{
// Skip comment lines
continue;
}
else if ( line.startsWith( "/", Qt::CaseInsensitive ) )
{
// Detected end of keyword data section
return;
}
else if ( line.startsWith( editKeyword, Qt::CaseInsensitive ) )
{
// End parsing when edit keyword is detected
isStopParsingKeywordDetected = true;
return;
}
else if ( line[0].isLetter() )
{
// If a letter is starting the line, this is a new keyword
return;
}
if ( !line.isEmpty() )
{
if ( line.startsWith( "--", Qt::CaseInsensitive ) )
{
// Skip comment lines
continue;
}
else if ( line.startsWith( "/", Qt::CaseInsensitive ) )
{
// Detected end of keyword data section
return;
}
else if ( line.startsWith( editKeyword, Qt::CaseInsensitive ) )
{
// End parsing when edit keyword is detected
isStopParsingKeywordDetected = true;
return;
}
else if ( line[0].isLetter() )
{
// If a letter is starting the line, this is a new keyword
return;
}
textContent.push_back( line );
}

View File

@@ -24,7 +24,6 @@
#include "RifEclEclipseSummary.h"
#include "RiuSummaryQuantityNameInfoProvider.h"
#include <QRegExp>
#include <QStringList>
#include <QTextStream>
@@ -190,8 +189,7 @@ RifEclipseSummaryAddress RifEclipseSummaryAddress::fromEclipseTextAddressParseEr
if ( tokens.size() > 1 )
{
auto firstToken = RiaStdStringTools::trimString( tokens[0] );
firstToken = RiaStdStringTools::toUpper( firstToken );
auto firstToken = RiaStdStringTools::toUpper( RiaStdStringTools::trimString( tokens[0] ) );
if ( ( firstToken == "ER" ) || ( firstToken == "ERR" ) || ( firstToken == "ERROR" ) )
{
@@ -783,9 +781,10 @@ bool RifEclipseSummaryAddress::isUiTextMatchingFilterText( const QString& filter
if ( filterString.isEmpty() ) return true;
if ( filterString.trimmed() == "*" ) return !value.empty();
QRegExp searcher( filterString, Qt::CaseInsensitive, QRegExp::WildcardUnix );
QString qstrValue = QString::fromStdString( value );
return searcher.exactMatch( qstrValue );
QString pattern = QRegularExpression::wildcardToRegularExpression( filterString );
QRegularExpression searcher( pattern, QRegularExpression::CaseInsensitiveOption );
QString qstrValue = QString::fromStdString( value );
return searcher.match( qstrValue ).hasMatch();
}
//--------------------------------------------------------------------------------------------------
@@ -1226,7 +1225,7 @@ std::string RifEclipseSummaryAddress::blockAsString() const
//--------------------------------------------------------------------------------------------------
std::tuple<int, int, int> RifEclipseSummaryAddress::ijkTupleFromUiText( const std::string& s )
{
auto ijk = RiaTextStringTools::splitSkipEmptyParts( QString::fromStdString( s ).trimmed(), QRegExp( "[,]" ) );
auto ijk = RiaTextStringTools::splitSkipEmptyParts( QString::fromStdString( s ).trimmed(), QRegularExpression( "[,]" ) );
if ( ijk.size() != 3 ) return std::make_tuple( -1, -1, -1 );
@@ -1248,7 +1247,7 @@ std::string RifEclipseSummaryAddress::formatUiTextRegionToRegion() const
//--------------------------------------------------------------------------------------------------
std::pair<int, int> RifEclipseSummaryAddress::regionToRegionPairFromUiText( const std::string& s )
{
auto r2r = RiaTextStringTools::splitSkipEmptyParts( QString::fromStdString( s ).trimmed(), QRegExp( "[-]" ) );
auto r2r = RiaTextStringTools::splitSkipEmptyParts( QString::fromStdString( s ).trimmed(), QRegularExpression( "[-]" ) );
if ( r2r.size() != 2 ) return std::make_pair( -1, -1 );

View File

@@ -19,14 +19,6 @@
#include "RifFileParseTools.h"
#include "RiaTextStringTools.h"
// Disable deprecation warning for QString::SkipEmptyParts
#ifdef _MSC_VER
#pragma warning( disable : 4996 )
#endif
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -43,7 +35,7 @@ QStringList RifFileParseTools::splitLineAndTrim( const QString& line, const QStr
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RifFileParseTools::splitLineAndTrim( const QString& line, const QRegExp& regexp, bool skipEmptyParts )
QStringList RifFileParseTools::splitLineAndTrim( const QString& line, const QRegularExpression& regexp, bool skipEmptyParts )
{
auto cols = RiaTextStringTools::splitString( line.trimmed(), regexp, skipEmptyParts );
for ( QString& col : cols )

View File

@@ -18,7 +18,7 @@
#pragma once
#include <QRegExp>
#include <QRegularExpression>
#include <QString>
#include <QStringList>
@@ -29,7 +29,7 @@ class RifFileParseTools
{
public:
static QStringList splitLineAndTrim( const QString& line, const QString& separator, bool skipEmptyParts = false );
static QStringList splitLineAndTrim( const QString& line, const QRegExp& regexp, bool skipEmptyParts = false );
static QStringList splitLineAndTrim( const QString& line, const QRegularExpression& regexp, bool skipEmptyParts = false );
};
//==================================================================================================

View File

@@ -32,7 +32,7 @@ std::map<QString, std::vector<RifPerforationInterval>> RifPerforationIntervalRea
{
std::map<QString, std::vector<RifPerforationInterval>> perforationIntervals;
foreach ( QString filePath, filePaths )
for ( const QString& filePath : filePaths )
{
readFileIntoMap( filePath, &perforationIntervals );
}

View File

@@ -79,7 +79,7 @@ std::vector<std::vector<cvf::Vec3d>> RifPolygonReader::parseText( const QString&
QStringList commentLineSegs = line.split( "#" );
if ( commentLineSegs.empty() ) continue; // Empty line
QStringList lineSegs = RiaTextStringTools::splitSkipEmptyParts( commentLineSegs[0], QRegExp( "\\s+" ) );
QStringList lineSegs = RiaTextStringTools::splitSkipEmptyParts( commentLineSegs[0], QRegularExpression( "\\s+" ) );
if ( lineSegs.empty() ) continue; // No data

View File

@@ -161,7 +161,7 @@ RifWellPathImporter::WellData RifWellPathImporter::readJsonWellData( const QStri
wellData.m_wellPathGeometry->setDatumElevation( datumElevation );
wellData.m_name = jsonMap["name"].toString();
foreach ( QVariant point, pathList )
for ( const QVariant& point : pathList )
{
QMap<QString, QVariant> coordinateMap = point.toMap();
cvf::Vec3d vec3d( coordinateMap["east"].toDouble(),