Workspace 6.21.5
Public Member Functions | List of all members
TypeAdaptor Class Referenceabstract

Provides a way to adapt one type to another. More...

#include <Workspace/DataExecution/DataObjects/typeadaptor.h>

Inheritance diagram for TypeAdaptor:
[legend]

Public Member Functions

 ~TypeAdaptor () override=default
 
virtual bool adapt (DataObject &src, DataObject &dest, bool copy)=0
 
bool canSerialize () const override
 
virtual bool connectConversionAction (QAction &action)
 
virtual const TypeAdaptorFactorygetFactory () const =0
 
bool load (const SerializedItem &item) override
 
bool save (SerializedItem &item) const override
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Detailed Description

TypeAdaptors provide a way for Connections to pass DataObjects that are not the same type from the source (ie an Output) to the destination (ie an InputScalar) of a connection. The main thing subclasses must do is implement the adapt() member function to perform the actual adaption from the source to the destination.

Subclasses would generally be creating new underlying data for the DataObject at the destination of the connection. The main exception to this is when the adaptor is converting between a derived class and its base class.

TypeAdaptors may be used outside of connections, but special care must be taken to ensure that the data objects can be converted and that the TypeAdaptor is deleted appropriately.

Constructor & Destructor Documentation

◆ ~TypeAdaptor()

~TypeAdaptor ( )
overridedefault

Member Function Documentation

◆ adapt()

virtual bool adapt ( DataObject src,
DataObject dest,
bool  copy 
)
pure virtual

Performs the conversion between DataObjects.

Parameters
srcThe DataObject that will be converted and stored in dest.
destThe destination of the converted DataObject
copyWhether a copy should occur regardless of whether or not a copy can be avoided.

Some adapt() calls will always effectively make a copy, since they create a different data type from the source. Some, however, are able to make the destination data object re-use the source, such as when the destination is a base class of the source' data type.

Returns
true if the conversion was successful, false if the conversion was unsuccessful.

All TypeAdaptor subclasses are required to override this function and must respect the copy flag.

Implemented in Array3dAdaptor< From, To >, ArrayNdDimensionLabelsToStringListAdaptor, DataSeriesAdaptor< T >, DataSeriesToQVariantAdaptor, QVariantToDataSeriesAdaptor, ImageToOverlayAdaptor, QVariantToQImageAdaptor, MeshModelInterfaceToMeshModelAdaptor, MeshModelToMeshModelInterfaceAdaptor, TypedNullOperationMeshModelFilterAdaptor, TypedScalarNodeStateFilterAdaptor, TransformGroupAdaptor, NumPyToArray3dScalarAdaptor, ImageToSceneOverlayAdaptor, TransformToTransformGroupAdaptor, DateTimeToStringAdaptor, DependencyDateTimeAdaptor, QVariantToQVectorDoubleAdaptor, QVariantToQVectorIntAdaptor, QVariantToQVectorDateTimeAdaptor, TimeToStringAdaptor, AssignmentAdaptor< From, To >, DerivedToBaseAdaptor< D, B >, DoubleToStringAdaptor, EnumToIntAdaptor< T >, IntToStringAdaptor, JsonObjectGroupAdaptorBase< From, To >, JsonObjectGroupAdaptorBase< From, QJsonDocument >, JsonObjectGroupAdaptorBase< QJsonDocument, To >, JsonObjectGroupAdaptor< QJsonDocument, To >, JsonObjectGroupAdaptor< From, QJsonDocument >, SimpleAdaptor< From, To >, SimpleDataObjectAdaptor< From, To >, AdaptFromQVariant< T >, and AdaptToQVariant< T >.

◆ canSerialize()

bool canSerialize ( ) const
overridevirtual

The TypeAdaptor implementation of this function always returns true. Subclasses must not ever override this function, or more precisely, all subclasses must be serializable.

See also
load(), save()

Implements Serialize.

◆ connectConversionAction()

bool connectConversionAction ( QAction &  action)
virtual
Parameters
actionA QAction that will be used in things like a context menu.

Subclasses should only reimplement this function if they need to provide some degree of configurability for their type adaptor. If the subclass does reimplement the function, it must do at least two things:

  • Connect the action to a slot so that the type adaptor will handle the action being triggered.
  • Return true to indicate that the action will be handled.

In addition, the subclass would not normally change the text, icon or shortcut of the action. In fact, the only thing a subclass should do is make a signal/slot connection to it. When the user triggers this action, they would expect to be presented with a dialog box through which they could configure any relevant settings specific to this type adaptor. For example, an adaptor that converts from double to QString would add a signal/slot connection to action, with that slot opening a dialog box with settings for things like the precision, field width, floating point format, etc.

Returns
True if the action will be handled, or false if the action is not needed. If the return value is false, the caller will typically end up deleting the action again.

Reimplemented in ArrayNdDimensionLabelsToStringListAdaptor, ImageToOverlayAdaptor, ImageToSceneOverlayAdaptor, DoubleToStringAdaptor, and IntToStringAdaptor.

◆ getFactory()

virtual const TypeAdaptorFactory & getFactory ( ) const
pure virtual

◆ load()

bool load ( const SerializedItem item)
overridevirtual

The default implementation does nothing and always returns true. Unless subclasses maintain configurable options, they should not need to override load() or save().

Implements Serialize.

◆ save()

bool save ( SerializedItem item) const
overridevirtual

The default implementation does nothing and always returns true. Unless subclasses maintain configurable options, they should not need to override load() or save(). If the subclass does override save(), do not change the tag name of item.

Implements Serialize.