Skip to content

Commit

Permalink
Qt6: Adjustments (#11804)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
magnesj authored Oct 28, 2024
1 parent bb047e8 commit 2814b92
Show file tree
Hide file tree
Showing 59 changed files with 195 additions and 392 deletions.
1 change: 0 additions & 1 deletion ApplicationLibCode/Application/RiaPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <QDate>
#include <QDir>
#include <QLocale>
#include <QRegExp>
#include <QStandardPaths>
#include <QValidator>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void RiaSumoConnector::parseEnsembleNames( QNetworkReply* reply, const SumoCaseI
QJsonObject aggregationColumnsObject = aggregationsObject["iteration_names"].toObject();

QJsonArray bucketsArray = aggregationColumnsObject["buckets"].toArray();
foreach ( const QJsonValue& bucket, bucketsArray )
for ( const QJsonValue& bucket : bucketsArray )
{
QJsonObject bucketObj = bucket.toObject();
auto ensembleName = bucketObj["key"].toString();
Expand Down Expand Up @@ -825,7 +825,7 @@ void RiaSumoConnector::parseCases( QNetworkReply* reply )

m_cases.clear();

foreach ( const QJsonValue& value, hitsObjects )
for ( const QJsonValue& value : hitsObjects )
{
QJsonObject resultObj = value.toObject();
QJsonObject sourceObj = resultObj["_source"].toObject();
Expand Down Expand Up @@ -931,7 +931,7 @@ void RiaSumoConnector::parseBlobIds( QNetworkReply* reply,
QJsonObject rootHits = jsonObj["hits"].toObject();
QJsonArray hitsObjects = rootHits["hits"].toArray();

foreach ( const QJsonValue& value, hitsObjects )
for ( const QJsonValue& value : hitsObjects )
{
QJsonObject resultObj = value.toObject();
QJsonObject sourceObj = resultObj["_source"].toObject();
Expand Down
4 changes: 0 additions & 4 deletions ApplicationLibCode/Application/Tools/RiaQDateTimeTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,7 @@ QDateTime RiaQDateTimeTools::subtractPeriod( const QDateTime& dt, RiaDefines::Da
//--------------------------------------------------------------------------------------------------
QDateTime RiaQDateTimeTools::createDateTime( const QDate& date, Qt::TimeSpec timeSpec /*= Qt::LocalTime*/ )
{
#if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
return date.startOfDay( timeSpec );
#else
return QDateTime( date, QTime( 0, 0 ), timeSpec );
#endif
}

//--------------------------------------------------------------------------------------------------
Expand Down
23 changes: 11 additions & 12 deletions ApplicationLibCode/Application/Tools/RiaTextStringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ QStringList RiaTextStringTools::splitSkipEmptyParts( const QString& text, const
return splitString( text, sep, skipEmptyParts );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RiaTextStringTools::splitSkipEmptyParts( const QString& text, const QRegularExpression& regularExpression )
{
bool skipEmptyParts = true;
return splitString( text, regularExpression, skipEmptyParts );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -144,9 +153,9 @@ QStringList RiaTextStringTools::splitString( const QString& text, const QString&
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RiaTextStringTools::splitString( const QString& text, const QRegExp& regExp, bool skipEmptyParts )
QStringList RiaTextStringTools::splitString( const QString& text, const QRegularExpression& regularExpression, bool skipEmptyParts )
{
return regExp.splitString( text, skipEmptyParts ? Qt::SkipEmptyParts : Qt::KeepEmptyParts );
return text.split( regularExpression, skipEmptyParts ? Qt::SkipEmptyParts : Qt::KeepEmptyParts );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -197,16 +206,6 @@ bool RiaTextStringTools::isNumber( const QString& text, const QString& decimalPo
return RiaStdStringTools::isNumber( stdString, decimalChar );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RiaTextStringTools::splitSkipEmptyParts( const QString& text, const QRegExp& regExp )
{
bool skipEmptyParts = true;

return splitString( text, regExp, skipEmptyParts );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions ApplicationLibCode/Application/Tools/RiaTextStringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#pragma once

#include <QRegExp>
#include <QRegularExpression>
#include <QString>
#include <QStringList>

Expand All @@ -36,10 +36,10 @@ QString commonSuffix( const QStringList& stringList );
QString trimNonAlphaNumericCharacters( const QString& s );

QStringList splitSkipEmptyParts( const QString& text, const QString& sep = " " );
QStringList splitSkipEmptyParts( const QString& text, const QRegExp& regExp );
QStringList splitSkipEmptyParts( const QString& text, const QRegularExpression& regularExpression );

QStringList splitString( const QString& text, const QString& sep, bool skipEmptyParts );
QStringList splitString( const QString& text, const QRegExp& regExp, bool skipEmptyParts );
QStringList splitString( const QString& text, const QRegularExpression& regularExpression, bool skipEmptyParts );

QString replaceTemplateTextWithValues( const QString& templateText, const std::map<QString, QString>& valueMap );
bool isTextEqual( QStringView text, QStringView compareText );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ bool RiaValidRegExpValidator::isValidCharacter( const QChar& character )
//--------------------------------------------------------------------------------------------------
QValidator::State RiaValidRegExpValidator::validate( QString& inputString, int& position ) const
{
QRegExp inputRe( inputString, Qt::CaseInsensitive, QRegExp::Wildcard );
if ( inputRe.isValid() ) // A valid wildcard pattern is always acceptable
QString regexPattern = QRegularExpression::wildcardToRegularExpression( inputString );
QRegularExpression regex( regexPattern, QRegularExpression::CaseInsensitiveOption );

if ( regex.isValid() )
{
return QValidator::Acceptable;
}
Expand Down Expand Up @@ -70,4 +72,4 @@ QValidator::State RiaValidRegExpValidator::validate( QString& inputString, int&
void RiaValidRegExpValidator::fixup( QString& inputString ) const
{
inputString = m_defaultPattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once

#include <QRegExp>
#include <QString>
#include <QValidator>

Expand All @@ -36,4 +35,4 @@ class RiaValidRegExpValidator : public QValidator

private:
QString m_defaultPattern;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ void RiaSummaryStringTools::splitUsingDataSourceNames( const QStringList& filter

bool foundDataSource = false;

QRegExp searcher( pureDataSourceCandidate, Qt::CaseInsensitive, QRegExp::WildcardUnix );
QString regexPattern = QRegularExpression::wildcardToRegularExpression( pureDataSourceCandidate );
QRegularExpression searcher( regexPattern, QRegularExpression::CaseInsensitiveOption );

for ( const auto& ds : dataSourceNames )
{
if ( !foundDataSource && searcher.exactMatch( ds ) )
if ( !foundDataSource && searcher.match( ds ).hasMatch() )
{
dataSourceFilters.push_back( s );
foundDataSource = true;
Expand Down Expand Up @@ -166,13 +167,14 @@ std::pair<std::vector<RimSummaryCase*>, std::vector<RimSummaryEnsemble*>>

for ( const auto& dsFilter : dataSourceFilters )
{
QString searchString = dsFilter.left( dsFilter.indexOf( ':' ) );
QRegExp searcher( searchString, Qt::CaseInsensitive, QRegExp::WildcardUnix );
QString searchString = dsFilter.left( dsFilter.indexOf( ':' ) );
QString regexPattern = QRegularExpression::wildcardToRegularExpression( searchString );
QRegularExpression searcher( regexPattern, QRegularExpression::CaseInsensitiveOption );

for ( const auto& ensemble : allEnsembles )
{
auto ensembleName = ensemble->name();
if ( searcher.exactMatch( ensembleName ) )
if ( searcher.match( ensembleName ).hasMatch() )
{
if ( searchString == dsFilter )
{
Expand All @@ -184,13 +186,14 @@ std::pair<std::vector<RimSummaryCase*>, std::vector<RimSummaryEnsemble*>>
{
// Match on subset of realisations in ensemble

QString realizationSearchString = dsFilter.right( dsFilter.size() - dsFilter.indexOf( ':' ) - 1 );
QRegExp realizationSearcher( realizationSearchString, Qt::CaseInsensitive, QRegExp::WildcardUnix );
QString realizationSearchString = dsFilter.right( dsFilter.size() - dsFilter.indexOf( ':' ) - 1 );
QString regexPattern = QRegularExpression::wildcardToRegularExpression( realizationSearchString );
QRegularExpression realizationSearcher( regexPattern, QRegularExpression::CaseInsensitiveOption );

for ( const auto& summaryCase : ensemble->allSummaryCases() )
{
auto realizationName = summaryCase->displayCaseName();
if ( realizationSearcher.exactMatch( realizationName ) )
if ( realizationSearcher.match( realizationName ).hasMatch() )
{
matchingSummaryCases.push_back( summaryCase );
}
Expand All @@ -202,7 +205,7 @@ std::pair<std::vector<RimSummaryCase*>, std::vector<RimSummaryEnsemble*>>
for ( const auto& summaryCase : allSummaryCases )
{
auto summaryCaseName = summaryCase->displayCaseName();
if ( searcher.exactMatch( summaryCaseName ) )
if ( searcher.match( summaryCaseName ).hasMatch() )
{
matchingSummaryCases.push_back( summaryCase );
}
Expand All @@ -217,7 +220,7 @@ std::pair<std::vector<RimSummaryCase*>, std::vector<RimSummaryEnsemble*>>
//--------------------------------------------------------------------------------------------------
QStringList RiaSummaryStringTools::splitIntoWords( const QString& text )
{
return RiaTextStringTools::splitSkipEmptyParts( text, QRegExp( "\\s+" ) );
return RiaTextStringTools::splitSkipEmptyParts( text );
}

//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions ApplicationLibCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ find_package(
PrintSupport
Svg
Sql
Core5Compat
OPTIONAL_COMPONENTS Charts
)
set(QT_LIBRARIES
Expand All @@ -51,7 +50,6 @@ set(QT_LIBRARIES
Qt6::PrintSupport
Qt6::Svg
Qt6::Sql
Qt6::Core5Compat
Qt6::Charts
)
qt_standard_project_setup()
Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/Commands/RicCalculatorWidgetCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ QWidget* RicCalculatorWidgetCreator::createWidget( QWidget* parent )
rowSplitter->setContentsMargins( 0, 0, 0, 0 );
rowSplitter->setHandleWidth( 6 );
rowSplitter->setStyleSheet( "QSplitter::handle { image: url(:/SplitterV.png); }" );
rowSplitter->insertWidget( 0, firstRowLeftFrame );
rowSplitter->insertWidget( 1, firstRowRightFrame );
rowSplitter->addWidget( firstRowLeftFrame );
rowSplitter->addWidget( firstRowRightFrame );
rowSplitter->setSizes( QList<int>() << 1 << 1 );
firstRowLayout->addWidget( rowSplitter );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ void RicSummaryPlotEditorWidgetCreator::recursivelyConfigureAndUpdateTopLevelUiO

caf::PdmUiGroup* appearanceGroup = findGroupByKeyword( topLevelUiItems, RiuSummaryCurveDefinitionKeywords::appearance(), uiConfigName );
auto appearanceGroupBox = createGroupBoxWithContent( appearanceGroup, uiConfigName );
m_lowerLeftLayout->insertWidget( 0, appearanceGroupBox );
m_lowerLeftLayout->addWidget( appearanceGroupBox );

caf::PdmUiGroup* nameConfigGroup = findGroupByKeyword( topLevelUiItems, RiuSummaryCurveDefinitionKeywords::nameConfig(), uiConfigName );
auto nameConfigGroupBox = createGroupBoxWithContent( nameConfigGroup, uiConfigName );
m_lowerLeftLayout->insertWidget( 1, nameConfigGroupBox );
m_lowerLeftLayout->addWidget( nameConfigGroupBox );

QMinimizePanel* curveGroup = getOrCreateCurveTreeGroup();
m_lowerLeftLayout->insertWidget( 2, curveGroup, 1 );
m_lowerLeftLayout->addWidget( curveGroup, 1 );
m_lowerLeftLayout->addStretch( 0 );
m_lowerRightLayout->insertWidget( 0, getOrCreatePlotWidget() );
m_lowerRightLayout->addWidget( getOrCreatePlotWidget() );

// Fields at bottom of dialog
configureAndUpdateFields( 1, m_bottomFieldLayout, topLevelUiItems, uiConfigName );
Expand Down Expand Up @@ -155,8 +155,8 @@ QWidget* RicSummaryPlotEditorWidgetCreator::createWidget( QWidget* parent )
m_firstColumnSplitter->setHandleWidth( 6 );
m_firstColumnSplitter->setStyleSheet( "QSplitter::handle { image: url(:/SplitterH.png); }" );

m_firstColumnSplitter->insertWidget( 0, firstRowFrame );
m_firstColumnSplitter->insertWidget( 1, secondRowFrame );
m_firstColumnSplitter->addWidget( firstRowFrame );
m_firstColumnSplitter->addWidget( secondRowFrame );

const int firstRowPixelHeight = 500;
const int secondRowPixelHeight = 300;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifColorLegendData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 10 additions & 8 deletions ApplicationLibCode/FileInterface/RifCsvUserDataParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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 ) );
Expand Down
Loading

0 comments on commit 2814b92

Please sign in to comment.