caf: Add warnings for deprecated keywords.

This commit is contained in:
Kristian Bendiksen
2025-07-30 13:39:02 +02:00
parent e5d43c74ed
commit aa02440000
11 changed files with 213 additions and 62 deletions
@@ -118,6 +118,7 @@
#include "cafPdmCodeGenerator.h"
#include "cafPdmDataValueField.h"
#include "cafPdmDefaultObjectFactory.h"
#include "cafPdmDeprecation.h"
#include "cafPdmMarkdownBuilder.h"
#include "cafPdmMarkdownGenerator.h"
#include "cafPdmScriptIOMessages.h"
@@ -495,7 +496,12 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
}
m_project->setFileName( fullPathProjectFileName );
m_project->readFile();
std::vector<QString> deprecationMessages = m_project->readFile( defaultDeprecations() );
for ( const QString& deprecationMessage : deprecationMessages )
{
RiaLogging::info( deprecationMessage );
}
m_project->updatesAfterProjectFileIsRead();
// Apply any modifications to the loaded project before we go ahead and load actual data
@@ -1848,3 +1854,11 @@ RiaKeyValueStore<char>* RiaApplication::keyValueStore() const
{
return m_keyValueStore.get();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmDeprecation> RiaApplication::defaultDeprecations()
{
return {};
}
@@ -22,6 +22,7 @@
#include "KeyValueStore/RiaKeyValueStore.h"
#include "RiaDefines.h"
#include "cafPdmDeprecation.h"
#include "cafPdmPointer.h"
#include "cvfObject.h"
@@ -225,6 +226,8 @@ protected:
bool generateCode( const QString& outputPath, gsl::not_null<QString*> errMsg );
static std::vector<caf::PdmDeprecation> defaultDeprecations();
protected:
void initializeDataLoadController();
@@ -60,6 +60,7 @@ set(PROJECT_FILES
cafAsyncWorkerManager.h
cafAsyncWorkerManager.cpp
cafPdmObjectHandleTools.h
cafPdmDeprecation.h
)
add_library(${PROJECT_NAME} ${PROJECT_FILES})
@@ -0,0 +1,50 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QString>
namespace caf
{
struct PdmDeprecation
{
QString objectKeyword;
QString fieldKeyword;
QString lastValidVersion;
QString message;
};
} //namespace caf
@@ -70,21 +70,22 @@ void PdmDocument::setFileName( const QString& fileName )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDocument::readFile()
std::vector<QString> PdmDocument::readFile( const std::vector<PdmDeprecation>& deprecations )
{
QFile xmlFile( m_fileName );
if ( !xmlFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) return;
if ( !xmlFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) return {};
readFile( &xmlFile );
return readFile( &xmlFile, deprecations );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDocument::readFile( QIODevice* xmlFile )
std::vector<QString> PdmDocument::readFile( QIODevice* xmlFile, const std::vector<PdmDeprecation>& deprecations )
{
QXmlStreamReader xmlStream( xmlFile );
std::vector<QString> deprecationMessages;
while ( !xmlStream.atEnd() )
{
xmlStream.readNext();
@@ -92,11 +93,17 @@ void PdmDocument::readFile( QIODevice* xmlFile )
{
if ( !matchesClassKeyword( xmlStream.name().toString() ) )
{
return;
return deprecationMessages;
}
readFields( xmlStream, PdmDefaultObjectFactory::instance(), false );
auto deprecationMessagesForField =
readFields( xmlStream, PdmDefaultObjectFactory::instance(), false, deprecations );
deprecationMessages.insert( deprecationMessages.end(),
deprecationMessagesForField.begin(),
deprecationMessagesForField.end() );
}
}
return deprecationMessages;
}
//--------------------------------------------------------------------------------------------------
@@ -36,6 +36,7 @@
#pragma once
#include "cafPdmDeprecation.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
@@ -57,8 +58,8 @@ public:
QString fileName() const;
void setFileName( const QString& fileName );
void readFile();
bool writeFile();
std::vector<QString> readFile( const std::vector<PdmDeprecation>& deprecations = {} );
bool writeFile();
static void updateUiIconStateRecursively( PdmObjectHandle* root );
@@ -67,9 +68,9 @@ protected:
const PdmFieldHandle* fileNameHandle() const;
private:
void writeDocumentToXmlStream( QXmlStreamWriter& xmlStream );
void readFile( QIODevice* device );
void writeFile( QIODevice* device );
void writeDocumentToXmlStream( QXmlStreamWriter& xmlStream );
std::vector<QString> readFile( QIODevice* device, const std::vector<PdmDeprecation>& deprecations );
void writeFile( QIODevice* device );
private:
PdmField<QString> m_fileName;
@@ -30,9 +30,11 @@ public:
// Xml Serializing
public:
void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
@@ -59,10 +61,12 @@ public:
// Xml Serializing
public:
void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
QString referenceString() const override;
std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactoryconst,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
QString referenceString() const override;
private:
FieldType* m_field;
@@ -90,10 +94,12 @@ public:
// Xml Serializing
public:
void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
private:
FieldType* m_field;
@@ -120,9 +126,11 @@ public:
// Xml Serializing
public:
void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
private:
FieldType* m_field;
@@ -146,10 +154,12 @@ public:
// Xml Serializing
public:
void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
private:
FieldType* m_field;
@@ -174,10 +184,12 @@ public:
// Xml Serializing
public:
void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) override;
void writeFieldData( QXmlStreamWriter& xmlStream ) const override;
bool resolveReferences() override;
bool isVectorField() const override;
private:
FieldType* m_field;
@@ -30,12 +30,15 @@ bool caf::PdmFieldXmlCap<FieldType>::isVectorField() const
///
//--------------------------------------------------------------------------------------------------
template <typename FieldType>
void caf::PdmFieldXmlCap<FieldType>::readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory )
std::vector<QString> caf::PdmFieldXmlCap<FieldType>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations )
{
this->assertValid();
typename FieldType::FieldDataType value;
PdmFieldReader<typename FieldType::FieldDataType>::readFieldData( value, xmlStream, objectFactory );
m_field->setValue( value );
return {};
}
//--------------------------------------------------------------------------------------------------
@@ -66,12 +69,15 @@ bool caf::PdmFieldXmlCap<FieldType>::resolveReferences()
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void caf::PdmFieldXmlCap<caf::PdmPtrField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* )
std::vector<QString>
caf::PdmFieldXmlCap<caf::PdmPtrField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory*,
const std::vector<caf::PdmDeprecation>& deprecations )
{
this->assertValid();
PdmFieldIOHelper::skipComments( xmlStream );
if ( !xmlStream.isCharacters() ) return;
if ( !xmlStream.isCharacters() ) return {};
QString dataString = xmlStream.text().toString();
@@ -92,6 +98,8 @@ void caf::PdmFieldXmlCap<caf::PdmPtrField<DataType*>>::readFieldData( QXmlStream
m_referenceString = dataString;
m_field->setRawPtr( NULL );
return {};
}
//--------------------------------------------------------------------------------------------------
@@ -143,12 +151,15 @@ QString caf::PdmFieldXmlCap<PdmPtrField<DataType*>>::referenceString() const
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void caf::PdmFieldXmlCap<caf::PdmPtrArrayField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* )
std::vector<QString>
caf::PdmFieldXmlCap<caf::PdmPtrArrayField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory*,
const std::vector<caf::PdmDeprecation>& deprecations )
{
this->assertValid();
PdmFieldIOHelper::skipComments( xmlStream );
if ( !xmlStream.isCharacters() ) return;
if ( !xmlStream.isCharacters() ) return {};
QString dataString = xmlStream.text().toString();
@@ -163,6 +174,8 @@ void caf::PdmFieldXmlCap<caf::PdmPtrArrayField<DataType*>>::readFieldData( QXmlS
m_referenceString = dataString;
m_field->clearWithoutDelete();
return {};
}
//--------------------------------------------------------------------------------------------------
@@ -228,13 +241,15 @@ bool caf::PdmFieldXmlCap<caf::PdmPtrArrayField<DataType*>>::isVectorField() cons
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void caf::PdmFieldXmlCap<caf::PdmChildField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory )
std::vector<QString>
caf::PdmFieldXmlCap<caf::PdmChildField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations )
{
PdmFieldIOHelper::skipCharactersAndComments( xmlStream );
if ( !xmlStream.isStartElement() )
{
return; // This happens when the field is "shortcut" empty (written like: <ElementName/>)
return {}; // This happens when the field is "shortcut" empty (written like: <ElementName/>)
}
QString className = xmlStream.name().toString();
@@ -254,7 +269,7 @@ void caf::PdmFieldXmlCap<caf::PdmChildField<DataType*>>::readFieldData( QXmlStre
xmlStream.skipCurrentElement(); // Skip to the endelement of the object we was supposed to read
xmlStream.skipCurrentElement(); // Skip to the endelement of this field
return;
return {};
}
else
{
@@ -267,7 +282,7 @@ void caf::PdmFieldXmlCap<caf::PdmChildField<DataType*>>::readFieldData( QXmlStre
xmlStream.skipCurrentElement(); // Skip to the endelement of the object we was supposed to read
xmlStream.skipCurrentElement(); // Skip to the endelement of this field
return;
return {};
}
m_field->m_fieldValue.setRawPtr( obj );
@@ -295,18 +310,20 @@ void caf::PdmFieldXmlCap<caf::PdmChildField<DataType*>>::readFieldData( QXmlStre
xmlStream.skipCurrentElement(); // Skip to the endelement of the object we was supposed to read
xmlStream.skipCurrentElement(); // Skip to the endelement of this field
return;
return {};
}
// Everything seems ok, so read the contents of the object:
xmlObject->readFields( xmlStream, objectFactory, false );
std::vector<QString> deprecationMessages = xmlObject->readFields( xmlStream, objectFactory, false, deprecations );
// Make stream point to endElement of this field
QXmlStreamReader::TokenType type = xmlStream.readNext();
Q_UNUSED( type );
PdmFieldIOHelper::skipCharactersAndComments( xmlStream );
return deprecationMessages;
}
//--------------------------------------------------------------------------------------------------
@@ -369,11 +386,14 @@ void caf::PdmFieldXmlCap<caf::PdmChildArrayField<DataType*>>::writeFieldData( QX
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void caf::PdmFieldXmlCap<caf::PdmChildArrayField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory )
std::vector<QString>
caf::PdmFieldXmlCap<caf::PdmChildArrayField<DataType*>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations )
{
m_field->deleteChildren();
PdmFieldIOHelper::skipCharactersAndComments( xmlStream );
std::vector<QString> deprecationMessages;
while ( xmlStream.isStartElement() )
{
QString className = xmlStream.name().toString();
@@ -418,7 +438,11 @@ void caf::PdmFieldXmlCap<caf::PdmChildArrayField<DataType*>>::readFieldData( QXm
continue;
}
xmlObject->readFields( xmlStream, objectFactory, false );
std::vector<QString> deprecationMessagesForField =
xmlObject->readFields( xmlStream, objectFactory, false, deprecations );
deprecationMessages.insert( deprecationMessages.end(),
deprecationMessagesForField.begin(),
deprecationMessagesForField.end() );
m_field->m_pointers.push_back( PdmPointer<DataType>() );
m_field->m_pointers.back().setRawPtr( obj );
@@ -431,6 +455,8 @@ void caf::PdmFieldXmlCap<caf::PdmChildArrayField<DataType*>>::readFieldData( QXm
Q_UNUSED( type );
PdmFieldIOHelper::skipCharactersAndComments( xmlStream );
}
return deprecationMessages;
}
//--------------------------------------------------------------------------------------------------
@@ -469,13 +495,16 @@ bool caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::isVectorField()
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory )
std::vector<QString> caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::readFieldData(
QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations )
{
this->assertValid();
typename FieldType::FieldDataType value;
PdmFieldReader<typename FieldType::FieldDataType>::readFieldData( value, xmlStream, objectFactory );
m_field->setValue( value );
return {};
}
//--------------------------------------------------------------------------------------------------
@@ -1,5 +1,6 @@
#pragma once
#include "cafPdmDeprecation.h"
#include "cafPdmFieldCapability.h"
#include <QString>
@@ -39,8 +40,10 @@ public:
QString dataTypeName() const;
virtual void readFieldData( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory ) = 0;
virtual void writeFieldData( QXmlStreamWriter& xmlStream ) const = 0;
virtual std::vector<QString> readFieldData( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
const std::vector<caf::PdmDeprecation>& deprecations = {} ) = 0;
virtual void writeFieldData( QXmlStreamWriter& xmlStream ) const = 0;
virtual bool resolveReferences() = 0;
@@ -42,8 +42,12 @@ PdmXmlObjectHandle* xmlObj( PdmObjectHandle* obj )
/// This makes attribute based field storage possible.
/// Leaves the xmlStream pointing to the EndElement of the PdmObject.
//--------------------------------------------------------------------------------------------------
void PdmXmlObjectHandle::readFields( QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory, bool isCopyOperation )
std::vector<QString> PdmXmlObjectHandle::readFields( QXmlStreamReader& xmlStream,
PdmObjectFactory* objectFactory,
bool isCopyOperation,
const std::vector<PdmDeprecation>& deprecations )
{
std::vector<QString> deprecationMessages;
bool isObjectFinished = false;
QXmlStreamReader::TokenType type;
while ( !isObjectFinished )
@@ -87,7 +91,11 @@ void PdmXmlObjectHandle::readFields( QXmlStreamReader& xmlStream, PdmObjectFacto
// After reading, the xmlStream is supposed to point to the first token after the field
// content. (typically an "endElement")
xmlStream.readNext();
xmlFieldHandle->readFieldData( xmlStream, objectFactory );
std::vector<QString> deprecationMessagesForField =
xmlFieldHandle->readFieldData( xmlStream, objectFactory, deprecations );
deprecationMessages.insert( deprecationMessages.end(),
deprecationMessagesForField.begin(),
deprecationMessagesForField.end() );
}
else
{
@@ -99,10 +107,28 @@ void PdmXmlObjectHandle::readFields( QXmlStreamReader& xmlStream, PdmObjectFacto
// Debug text is commented out, as this code is relatively often reached. Consider a new logging
// concept to receive this information
//
// std::cout << "Line " << xmlStream.lineNumber() << ": Warning: Could not find a field with
// name "
// << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data()
// << std::endl;
// std::cout << "Line " << xmlStream.lineNumber() << ": Warning: Could not find a field with name "
// << name.toLatin1().data()
// << " in the current object : " << classKeyword().toLatin1().data() << std::endl;
auto findDeprecation = []( const std::vector<PdmDeprecation>& deprecations,
const QString& objectKeyword,
const QString& fieldKeyword ) -> std::optional<PdmDeprecation>
{
for ( const PdmDeprecation& deprecation : deprecations )
{
if ( deprecation.fieldKeyword == fieldKeyword && deprecation.objectKeyword == objectKeyword )
return deprecation;
}
return {};
};
auto deprecation = findDeprecation( deprecations, classKeyword(), name );
if ( deprecation )
{
deprecationMessages.push_back( deprecation.value().message );
}
xmlStream.skipCurrentElement();
}
@@ -112,7 +138,6 @@ void PdmXmlObjectHandle::readFields( QXmlStreamReader& xmlStream, PdmObjectFacto
case QXmlStreamReader::EndElement:
{
// End of object.
QString name = xmlStream.name().toString(); // For debugging
isObjectFinished = true;
}
break;
@@ -130,6 +155,8 @@ void PdmXmlObjectHandle::readFields( QXmlStreamReader& xmlStream, PdmObjectFacto
break;
}
}
return deprecationMessages;
}
//--------------------------------------------------------------------------------------------------
///
@@ -1,5 +1,6 @@
#pragma once
#include "cafPdmDeprecation.h"
#include "cafPdmObjectCapability.h"
#include <QString>
@@ -45,8 +46,11 @@ public:
// Main XML serialization methods that is used internally by the document serialization system
// Not supposed to be used directly.
void readFields( QXmlStreamReader& inputStream, PdmObjectFactory* objectFactory, bool isCopyOperation );
void writeFields( QXmlStreamWriter& outputStream ) const;
std::vector<QString> readFields( QXmlStreamReader& inputStream,
PdmObjectFactory* objectFactory,
bool isCopyOperation,
const std::vector<PdmDeprecation>& deprecations = {} );
void writeFields( QXmlStreamWriter& outputStream ) const;
/// Check if a string is a valid Xml element name
static bool isValidXmlElementName( const QString& name );