Refactor view id

This commit is contained in:
Gaute Lindkvist
2019-11-14 20:48:11 +01:00
parent d9043db5e0
commit 228810fd05
27 changed files with 237 additions and 59 deletions

View File

@@ -139,7 +139,9 @@ QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summar
QString objectAsText = summaryPlot->writeObjectToXmlString();
caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText, caf::PdmDefaultObjectFactory::instance() );
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText,
caf::PdmDefaultObjectFactory::instance(),
true );
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot )

View File

@@ -64,7 +64,9 @@ RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const Q
QString objectAsText = stream.readAll();
caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText, caf::PdmDefaultObjectFactory::instance() );
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText,
caf::PdmDefaultObjectFactory::instance(),
true );
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot )

View File

@@ -333,7 +333,8 @@ void RicDeleteItemExec::undo()
{
caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( m_commandData->m_deletedObjectAsXml(),
caf::PdmDefaultObjectFactory::instance() );
caf::PdmDefaultObjectFactory::instance(),
false );
listField->insertAt( m_commandData->m_indexToObject, obj );

View File

@@ -123,6 +123,14 @@ RimFlowCharacteristicsPlot::~RimFlowCharacteristicsPlot()
}
}
//--------------------------------------------------------------------------------------------------
/// TODO: implement properly
//--------------------------------------------------------------------------------------------------
int RimFlowCharacteristicsPlot::id() const
{
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -721,6 +729,11 @@ void RimFlowCharacteristicsPlot::onLoadDataAndUpdate()
}
}
//--------------------------------------------------------------------------------------------------
/// TODO: implement properly
//--------------------------------------------------------------------------------------------------
void RimFlowCharacteristicsPlot::assignIdIfNecessary() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -56,6 +56,8 @@ public:
RimFlowCharacteristicsPlot();
~RimFlowCharacteristicsPlot() override;
int id() const final;
void setFromFlowSolution( RimFlowDiagSolution* flowSolution );
void updateCurrentTimeStep();
@@ -97,6 +99,9 @@ protected:
caf::PdmUiEditorAttribute* attribute ) override;
void onLoadDataAndUpdate() override;
private:
void assignIdIfNecessary() final;
private:
caf::PdmPtrField<RimEclipseResultCase*> m_case;
caf::PdmPtrField<RimFlowDiagSolution*> m_flowDiagSolution;

View File

@@ -76,6 +76,14 @@ RimTofAccumulatedPhaseFractionsPlot::~RimTofAccumulatedPhaseFractionsPlot()
}
}
//--------------------------------------------------------------------------------------------------
/// TODO: implement properly
//--------------------------------------------------------------------------------------------------
int RimTofAccumulatedPhaseFractionsPlot::id() const
{
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -190,6 +198,11 @@ QString RimTofAccumulatedPhaseFractionsPlot::description() const
return m_userName();
}
//--------------------------------------------------------------------------------------------------
/// TODO: Implement properly
//--------------------------------------------------------------------------------------------------
void RimTofAccumulatedPhaseFractionsPlot::assignIdIfNecessary() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -55,6 +55,8 @@ public:
RimTofAccumulatedPhaseFractionsPlot();
~RimTofAccumulatedPhaseFractionsPlot() override;
int id() const final;
void setDescription( const QString& description );
QString description() const;
@@ -73,7 +75,7 @@ public:
protected:
// RimViewWindow overrides
void assignIdIfNecessary() final;
void onLoadDataAndUpdate() override;
QImage snapshotWindowContent() override;

View File

@@ -64,6 +64,14 @@ RimTotalWellAllocationPlot::~RimTotalWellAllocationPlot()
}
}
//--------------------------------------------------------------------------------------------------
/// TODO: implement properly
//--------------------------------------------------------------------------------------------------
int RimTotalWellAllocationPlot::id() const
{
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -104,6 +112,11 @@ void RimTotalWellAllocationPlot::fieldChangedByUi( const caf::PdmFieldHandle* ch
}
}
//--------------------------------------------------------------------------------------------------
/// TODO: Implement properly
//--------------------------------------------------------------------------------------------------
void RimTotalWellAllocationPlot::assignIdIfNecessary() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -54,6 +54,8 @@ public:
RimTotalWellAllocationPlot();
~RimTotalWellAllocationPlot() override;
int id() const final;
void setDescription( const QString& description );
QString description() const;
QString totalAllocationAsText() const;
@@ -82,6 +84,9 @@ protected:
const QVariant& oldValue,
const QVariant& newValue ) override;
private:
void assignIdIfNecessary() final;
private:
caf::PdmField<bool> m_showPlotTitle;
caf::PdmField<QString> m_userName;

View File

@@ -149,6 +149,14 @@ RimWellAllocationPlot::~RimWellAllocationPlot()
}
}
//--------------------------------------------------------------------------------------------------
/// TODO: implement properly
//--------------------------------------------------------------------------------------------------
int RimWellAllocationPlot::id() const
{
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -552,6 +560,11 @@ QString RimWellAllocationPlot::wellStatusTextForTimeStep( const QString&
return statusText;
}
//--------------------------------------------------------------------------------------------------
/// TODO: Implement properly
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::assignIdIfNecessary() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -66,6 +66,7 @@ public:
RimWellAllocationPlot();
~RimWellAllocationPlot() override;
int id() const final;
void setFromSimulationWell( RimSimWellInView* simWell );
void setDescription( const QString& description );
@@ -126,6 +127,7 @@ private:
size_t timeStep );
// RimViewWindow overrides
void assignIdIfNecessary() final;
QWidget* createViewWidget( QWidget* mainWindowParent ) override;
void deleteViewWidget() override;

View File

@@ -86,6 +86,12 @@ Rim3dView::Rim3dView( void )
RiaPreferences* preferences = app->preferences();
CVF_ASSERT( preferences );
RICF_InitField( &m_id, "ViewId", -1, "View ID", "", "", "" );
m_id.uiCapability()->setUiReadOnly( true );
m_id.uiCapability()->setUiHidden( true );
m_id.capability<RicfFieldHandle>()->setIOWriteable( false );
m_id.xmlCapability()->setCopyable( false );
CAF_PDM_InitFieldNoDefault( &m_nameConfig, "NameConfig", "", "", "", "" );
m_nameConfig = new RimViewNameConfig();
@@ -168,6 +174,14 @@ Rim3dView::~Rim3dView( void )
m_viewer = nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int Rim3dView::id() const
{
return m_id;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -306,6 +320,27 @@ void Rim3dView::initAfterRead()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView::setId( int id )
{
m_id = id;
QString viewIdTooltip = QString( "View id: %1" ).arg( m_id );
this->setUiToolTip( viewIdTooltip );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView::assignIdIfNecessary()
{
if ( m_id == -1 )
{
RiaApplication::instance()->project()->assignViewIdToView( this );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -86,6 +86,8 @@ public:
Rim3dView( void );
~Rim3dView( void ) override;
int id() const final;
// Public fields:
caf::PdmField<double> scaleZ;
@@ -250,6 +252,11 @@ protected:
cvf::ref<RivWellPathsPartMgr> m_wellPathsPartManager;
private:
friend class RimProject;
void setId( int id );
void assignIdIfNecessary() final;
void updateMdiWindowTitle() override;
void deleteViewWidget() override;
QWidget* viewWidget() override;
@@ -287,7 +294,7 @@ private:
bool m_isCallingUpdateDisplayModelForCurrentTimestepAndRedraw; // To avoid infinite recursion if comparison views are pointing to each other.
// Fields
caf::PdmField<int> m_id;
caf::PdmField<QString> m_name_OBSOLETE;
caf::PdmChildField<RimViewNameConfig*> m_nameConfig;
caf::PdmField<bool> m_disableLighting;

View File

@@ -20,6 +20,10 @@
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "RicfCommandObject.h"
#include "RimProject.h"
#include "cafPdmUiComboBoxEditor.h"
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotWindow, "RimPlotWindow" ); // Do not use. Abstract class
@@ -31,6 +35,12 @@ RimPlotWindow::RimPlotWindow()
{
CAF_PDM_InitObject( "PlotWindow", "", "", "" );
RICF_InitField( &m_id, "ViewId", -1, "View ID", "", "", "" );
m_id.uiCapability()->setUiReadOnly( true );
m_id.uiCapability()->setUiHidden( true );
m_id.capability<RicfFieldHandle>()->setIOWriteable( false );
m_id.xmlCapability()->setCopyable( false );
CAF_PDM_InitField( &m_showPlotLegends, "ShowTrackLegends", true, "Show Legends", "", "", "" );
CAF_PDM_InitField( &m_plotLegendsHorizontal, "TrackLegendsHorizontal", true, "Legend Orientation", "", "", "" );
m_plotLegendsHorizontal.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
@@ -50,6 +60,14 @@ RimPlotWindow::RimPlotWindow()
//--------------------------------------------------------------------------------------------------
RimPlotWindow::~RimPlotWindow() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimPlotWindow::id() const
{
return m_id;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -199,3 +217,24 @@ void RimPlotWindow::uiOrderingForLegendSettings( QString uiConfigName, caf::PdmU
uiOrdering.add( &m_plotLegendsHorizontal );
uiOrdering.add( &m_legendFontSize );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotWindow::setId( int id )
{
m_id = id;
QString viewIdTooltip = QString( "Plot id: %1" ).arg( m_id );
this->setUiToolTip( viewIdTooltip );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotWindow::assignIdIfNecessary()
{
if ( m_id == -1 )
{
RiaApplication::instance()->project()->assignPlotIdToPlotWindow( this );
}
}

View File

@@ -24,7 +24,9 @@
#include "cafPdmFieldHandle.h"
#include "cafPdmObject.h"
class RimProject;
class QwtPlotCurve;
class QKeyEvent;
class RimPlotWindow : public RimViewWindow
@@ -35,6 +37,8 @@ public:
RimPlotWindow();
~RimPlotWindow() override;
int id() const final;
RimPlotWindow& operator=( RimPlotWindow&& rhs );
virtual QString description() const = 0;
@@ -62,7 +66,14 @@ protected:
private:
virtual void performLayoutUpdate() {}
private:
friend class RimProject;
void setId( int id );
void assignIdIfNecessary() final;
protected:
caf::PdmField<int> m_id;
caf::PdmField<bool> m_showPlotLegends;
caf::PdmField<bool> m_plotLegendsHorizontal;
caf::PdmField<int> m_legendFontSize;

View File

@@ -59,6 +59,7 @@
#include "RimObservedDataCollection.h"
#include "RimObservedSummaryData.h"
#include "RimOilField.h"
#include "RimPlotWindow.h"
#include "RimPltPlotCollection.h"
#include "RimPolylinesFromFileAnnotation.h"
#include "RimRftPlotCollection.h"
@@ -104,6 +105,7 @@ RimProject::RimProject( void )
: m_nextValidCaseId( 1 )
, m_nextValidCaseGroupId( 1 )
, m_nextValidViewId( 1 )
, m_nextValidPlotId( 1 )
{
CAF_PDM_InitObject( "Project", "", "", "" );
@@ -247,9 +249,10 @@ void RimProject::close()
plotWindowCurrentModelIndexPath = "";
plotWindowTreeViewState = "";
m_nextValidCaseId = 0;
m_nextValidCaseGroupId = 0;
m_nextValidViewId = 0;
m_nextValidCaseId = 1;
m_nextValidCaseGroupId = 1;
m_nextValidViewId = 1;
m_nextValidPlotId = 1;
}
//--------------------------------------------------------------------------------------------------
@@ -507,14 +510,14 @@ void RimProject::assignIdToCaseGroup( RimIdenticalGridCaseGroup* caseGroup )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::assignViewIdToView( RimViewWindow* view )
void RimProject::assignViewIdToView( Rim3dView* view )
{
if ( view )
{
std::vector<RimViewWindow*> viewWindows;
this->descendantsIncludingThisOfType( viewWindows );
std::vector<Rim3dView*> views;
this->descendantsIncludingThisOfType( views );
for ( RimViewWindow* existingView : viewWindows )
for ( Rim3dView* existingView : views )
{
m_nextValidViewId = std::max( m_nextValidViewId, existingView->id() + 1 );
}
@@ -523,6 +526,25 @@ void RimProject::assignViewIdToView( RimViewWindow* view )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::assignPlotIdToPlotWindow( RimPlotWindow* plotWindow )
{
if ( plotWindow )
{
std::vector<RimPlotWindow*> plotWindows;
this->descendantsIncludingThisOfType( plotWindows );
for ( RimPlotWindow* existingPlotWindow : plotWindows )
{
m_nextValidPlotId = std::max( m_nextValidPlotId, existingPlotWindow->id() + 1 );
}
plotWindow->setId( m_nextValidPlotId++ );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -57,6 +57,7 @@ class RimSummaryCaseCollection;
class RimSummaryCaseMainCollection;
class Rim3dView;
class RimGridView;
class RimPlotWindow;
class RimViewLinker;
class RimViewLinkerCollection;
class RimViewWindow;
@@ -116,7 +117,8 @@ public:
void assignCaseIdToCase( RimCase* reservoirCase );
void assignIdToCaseGroup( RimIdenticalGridCaseGroup* caseGroup );
void assignViewIdToView( RimViewWindow* view );
void assignViewIdToView( Rim3dView* view );
void assignPlotIdToPlotWindow( RimPlotWindow* plotWindow );
void allCases( std::vector<RimCase*>& cases ) const;
@@ -204,6 +206,7 @@ private:
int m_nextValidCaseId;
int m_nextValidCaseGroupId;
int m_nextValidViewId;
int m_nextValidPlotId;
caf::PdmChildArrayField<RimEclipseCase*> casesObsolete; // obsolete
caf::PdmChildArrayField<RimIdenticalGridCaseGroup*> caseGroupsObsolete; // obsolete

View File

@@ -999,7 +999,8 @@ void RimViewController::updateRangeFilterOverrides( RimCellRangeFilter* changedR
QString xmlRangeFilterCollCopy = sourceFilterCollection->writeObjectToXmlString();
PdmObjectHandle* objectCopy =
PdmXmlObjectHandle::readUnknownObjectFromXmlString( xmlRangeFilterCollCopy,
caf::PdmDefaultObjectFactory::instance() );
caf::PdmDefaultObjectFactory::instance(),
true );
RimCellRangeFilterCollection* overrideRangeFilterColl = dynamic_cast<RimCellRangeFilterCollection*>( objectCopy );
// Convert the range filter to fit in the managed view if needed

View File

@@ -49,21 +49,12 @@ RimViewWindow::RimViewWindow( void )
m_windowController.uiCapability()->setUiHidden( true );
m_windowController.uiCapability()->setUiTreeChildrenHidden( true );
RICF_InitField( &m_viewId, "ViewId", -1, "View ID", "", "", "" );
m_viewId.uiCapability()->setUiReadOnly( true );
m_viewId.uiCapability()->setUiHidden( true );
m_viewId.capability<RicfFieldHandle>()->setIOWriteable( false );
CAF_PDM_InitField( &m_showWindow, "ShowWindow", true, "Show Window", "", "", "" );
m_showWindow.uiCapability()->setUiHidden( true );
// Obsolete field
CAF_PDM_InitFieldNoDefault( &obsoleteField_windowGeometry, "WindowGeometry", "", "", "", "" );
RiaFieldhandleTools::disableWriteAndSetFieldHidden( &obsoleteField_windowGeometry );
RiaApplication::instance()->project()->assignViewIdToView( this );
QString viewIdTooltip = QString( "View id: %1" ).arg( m_viewId );
this->setUiToolTip( viewIdTooltip );
}
//--------------------------------------------------------------------------------------------------
@@ -74,22 +65,6 @@ RimViewWindow::~RimViewWindow( void )
if ( m_windowController() ) delete m_windowController();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimViewWindow::id() const
{
return m_viewId;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewWindow::setId( int id )
{
m_viewId = id;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -111,6 +86,7 @@ void RimViewWindow::setShowWindow( bool showWindow )
//--------------------------------------------------------------------------------------------------
void RimViewWindow::loadDataAndUpdate()
{
assignIdIfNecessary();
onLoadDataAndUpdate();
}
@@ -352,8 +328,8 @@ void RimViewWindow::defineObjectEditorAttribute( QString uiConfigName, caf::PdmU
caf::PdmUiTreeViewItemAttribute* treeItemAttribute = dynamic_cast<caf::PdmUiTreeViewItemAttribute*>( attribute );
if ( treeItemAttribute && RiaApplication::instance()->preferences()->showViewIdInProjectTree() )
{
treeItemAttribute->tag = QString( "%1" ).arg( m_viewId );
cvf::Color3f viewColor = RiaColorTables::contrastCategoryPaletteColors().cycledColor3f( (size_t)m_viewId );
treeItemAttribute->tag = QString( "%1" ).arg( id() );
cvf::Color3f viewColor = RiaColorTables::contrastCategoryPaletteColors().cycledColor3f( (size_t)id() );
cvf::Color3f viewTextColor = RiaColorTools::contrastColor( viewColor );
treeItemAttribute->bgColor = QColor( RiaColorTools::toQColor( viewColor ) );
treeItemAttribute->fgColor = QColor( RiaColorTools::toQColor( viewTextColor ) );

View File

@@ -61,8 +61,7 @@ public:
RimViewWindow( void );
~RimViewWindow( void ) override;
int id() const;
void setId( int id );
virtual int id() const = 0;
bool showWindow() const;
void setShowWindow( bool showWindow );
@@ -111,6 +110,7 @@ protected:
virtual void updateMdiWindowTitle(); // Has real default implementation
virtual void deleteViewWidget() = 0;
virtual void onLoadDataAndUpdate() = 0;
virtual void assignIdIfNecessary() = 0;
virtual void onViewNavigationChanged();
virtual bool isWindowVisible() const; // Virtual To allow special visibility control
//////////
@@ -127,6 +127,8 @@ protected:
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
private:
friend class RimProject;
void setAsMdiWindow( int mainWindowID );
protected:
@@ -134,7 +136,6 @@ protected:
private:
caf::PdmChildField<RimMdiWindowController*> m_windowController;
caf::PdmField<int> m_viewId;
// Obsoleted field
caf::PdmField<std::vector<int>> obsoleteField_windowGeometry;

View File

@@ -111,7 +111,7 @@ void CmdDeleteItemExec::undo()
PdmChildArrayFieldHandle* listField = dynamic_cast<PdmChildArrayFieldHandle*>(field);
if (listField)
{
PdmObjectHandle* obj = PdmXmlObjectHandle::readUnknownObjectFromXmlString(m_commandData->m_deletedObjectAsXml(), PdmDefaultObjectFactory::instance());
PdmObjectHandle* obj = PdmXmlObjectHandle::readUnknownObjectFromXmlString(m_commandData->m_deletedObjectAsXml(), PdmDefaultObjectFactory::instance(), false);
listField->insertAt(m_commandData->m_indexToObject, obj);

View File

@@ -84,7 +84,7 @@ void PdmDocument::readFile(QIODevice* xmlFile)
// Error: This is not a Ceetron Pdm based xml document
return;
}
readFields(xmlStream, PdmDefaultObjectFactory::instance());
readFields(xmlStream, PdmDefaultObjectFactory::instance(), false);
}
}

View File

@@ -281,7 +281,7 @@ void caf::PdmFieldXmlCap< caf::PdmChildField<DataType*> >::readFieldData(QXmlStr
// Everything seems ok, so read the contents of the object:
xmlObject->readFields(xmlStream, objectFactory);
xmlObject->readFields(xmlStream, objectFactory, false);
// Make stream point to endElement of this field
@@ -397,7 +397,7 @@ void caf::PdmFieldXmlCap< caf::PdmChildArrayField<DataType*> >::readFieldData(QX
continue;
}
xmlObject->readFields(xmlStream, objectFactory);
xmlObject->readFields(xmlStream, objectFactory, false);
m_field->m_pointers.push_back(PdmPointer<DataType>());
m_field->m_pointers.back().setRawPtr(obj);

View File

@@ -34,7 +34,8 @@ bool PdmXmlFieldHandle::assertValid() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmXmlFieldHandle::PdmXmlFieldHandle(PdmFieldHandle* owner, bool giveOwnership) : m_isIOReadable(true), m_isIOWritable(true)
PdmXmlFieldHandle::PdmXmlFieldHandle(PdmFieldHandle* owner, bool giveOwnership)
: m_isIOReadable(true), m_isIOWritable(true), m_isCopyable(true)
{
m_owner = owner;
owner->addCapability(this, giveOwnership);
@@ -47,6 +48,7 @@ void PdmXmlFieldHandle::disableIO()
{
setIOReadable(false);
setIOWritable(false);
setCopyable(false);
}
//--------------------------------------------------------------------------------------------------

View File

@@ -30,10 +30,12 @@ public:
bool isIOReadable() const { return m_isIOReadable; }
bool isIOWritable() const { return m_isIOWritable; }
bool isCopyable() const { return m_isCopyable;}
void disableIO();
void setIOWritable(bool isWritable) { m_isIOWritable = isWritable; }
void setIOReadable(bool isReadable) { m_isIOReadable = isReadable; }
void setCopyable(bool isCopyable) { m_isCopyable = isCopyable; }
QString childClassKeyword();
@@ -51,6 +53,7 @@ protected:
private:
bool m_isIOReadable;
bool m_isIOWritable;
bool m_isCopyable;
PdmFieldHandle* m_owner;
};

View File

@@ -42,7 +42,7 @@ 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)
void PdmXmlObjectHandle::readFields(QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory, bool isCopyOperation)
{
bool isObjectFinished = false;
QXmlStreamReader::TokenType type;
@@ -60,7 +60,12 @@ void PdmXmlObjectHandle::readFields(QXmlStreamReader& xmlStream, PdmObjectFactor
if (fieldHandle && fieldHandle->xmlCapability())
{
PdmXmlFieldHandle* xmlFieldHandle = fieldHandle->xmlCapability();
if (xmlFieldHandle->isIOReadable())
bool readable = xmlFieldHandle->isIOReadable();
if (isCopyOperation && !xmlFieldHandle->isCopyable())
{
readable = false;
}
if (readable)
{
// readFieldData assumes that the xmlStream points to first token of field content.
// After reading, the xmlStream is supposed to point to the first token after the field content.
@@ -153,13 +158,13 @@ void PdmXmlObjectHandle::readObjectFromXmlString(const QString& xmlString, PdmO
QString classKeyword = inputStream.name().toString();
CAF_ASSERT(classKeyword == this->classKeyword());
this->readFields(inputStream, objectFactory);
this->readFields(inputStream, objectFactory, false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectHandle* PdmXmlObjectHandle::readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory)
PdmObjectHandle* PdmXmlObjectHandle::readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory, bool isCopyOperation)
{
QXmlStreamReader inputStream(xmlString);
@@ -171,7 +176,7 @@ PdmObjectHandle* PdmXmlObjectHandle::readUnknownObjectFromXmlString(const QStrin
if (!newObject) return nullptr;
xmlObj(newObject)->readFields(inputStream, objectFactory);
xmlObj(newObject)->readFields(inputStream, objectFactory, isCopyOperation);
return newObject;
}
@@ -185,7 +190,7 @@ PdmObjectHandle* PdmXmlObjectHandle::copyByXmlSerialization(PdmObjectFactory* ob
QString xmlString = this->writeObjectToXmlString();
PdmObjectHandle* objectCopy = PdmXmlObjectHandle::readUnknownObjectFromXmlString(xmlString, objectFactory);
PdmObjectHandle* objectCopy = PdmXmlObjectHandle::readUnknownObjectFromXmlString(xmlString, objectFactory, true);
if (!objectCopy) return nullptr;
objectCopy->xmlCapability()->initAfterReadRecursively();
@@ -213,7 +218,9 @@ caf::PdmObjectHandle* PdmXmlObjectHandle::copyAndCastByXmlSerialization(const QS
QString classKeyword = inputStream.name().toString();
CAF_ASSERT(classKeyword == sourceClassKeyword);
xmlObj(upgradedObject)->readFields(inputStream, objectFactory);
xmlObj(upgradedObject)->readFields(inputStream, objectFactory, true);
xmlObj(upgradedObject)->initAfterReadRecursively();
return upgradedObject;
}

View File

@@ -39,7 +39,7 @@ public:
/// Convenience methods to serialize/de-serialize this particular object (with children)
void readObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
QString writeObjectToXmlString() const;
static PdmObjectHandle* readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
static PdmObjectHandle* readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory, bool isCopyOperation);
PdmObjectHandle* copyByXmlSerialization(PdmObjectFactory* objectFactory);
PdmObjectHandle* copyAndCastByXmlSerialization(const QString& destinationClassKeyword,
const QString& sourceClassKeyword,
@@ -47,7 +47,7 @@ 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);
void readFields(QXmlStreamReader& inputStream, PdmObjectFactory* objectFactory, bool isCopyOperation);
void writeFields(QXmlStreamWriter& outputStream) const;
/// Check if a string is a valid Xml element name