SciDAVis  1.D4
Public Member Functions | Protected Attributes
AbstractSimpleFilter Class Reference

Simplified filter interface for filters with only one output port. More...

#include <AbstractSimpleFilter.h>

Inheritance diagram for AbstractSimpleFilter:
AbstractFilter AbstractAspect DateTime2DoubleFilter DateTime2StringFilter DayOfWeek2DoubleFilter Double2DateTimeFilter Double2DayOfWeekFilter Double2MonthFilter Double2StringFilter Month2DoubleFilter SimpleCopyThroughFilter String2DateTimeFilter String2DayOfWeekFilter String2DoubleFilter String2MonthFilter

List of all members.

Public Member Functions

 AbstractSimpleFilter ()
 Ctor.
virtual SciDAVis::ColumnMode columnMode () const
 Return the column mode.
virtual SciDAVis::ColumnDataType dataType () const
 Return the data type of the input.
virtual QDate dateAt (int row) const
 Return the date part of row 'row'.
virtual QDateTime dateTimeAt (int row) const
 Set the content of row 'row'.
virtual int inputCount () const
 Default to one input port.
virtual QList< Interval< int > > invalidIntervals () const
 Return all intervals of invalid rows.
virtual bool isInvalid (int row) const
 Return whether a certain row contains an invalid value.
virtual bool isInvalid (Interval< int > i) const
 Return whether a certain interval of rows contains only invalid values.
virtual AbstractColumnoutput (int port)
 Return a pointer to d_output_column on port 0 (don't override unless you really know what you are doing).
virtual const AbstractColumnoutput (int port) const
 Overloaded method for const access.
virtual int outputCount () const
 We manage only one output port (don't override unless you really know what you are doing).
virtual SciDAVis::PlotDesignation plotDesignation () const
 Copy plot designation of input port 0.
virtual QString textAt (int row) const
 Return the content of row 'row'.
virtual QTime timeAt (int row) const
 Return the time part of row 'row'.
virtual double valueAt (int row) const
 Return the double value in row 'row'.
assuming a 1:1 correspondence between input and output rows
virtual int rowCount () const
virtual QList< Interval< int > > dependentRows (Interval< int > input_range) const
Masking
virtual bool isMasked (int row) const
 Return whether a certain row is masked.
virtual bool isMasked (Interval< int > i) const
 Return whether a certain interval of rows rows is fully masked.
virtual QList< Interval< int > > maskedIntervals () const
 Return all intervals of masked rows.
virtual void clearMasks ()
 Clear all masking information.
virtual void setMasked (Interval< int > i, bool mask=true)
 Set an interval masked.
virtual void setMasked (int row, bool mask=true)
 Overloaded function for convenience.
XML related functions
virtual void save (QXmlStreamWriter *writer) const
 Save to XML.
virtual bool load (XmlStreamReader *reader)
 Load from XML.
virtual void writeExtraAttributes (QXmlStreamWriter *writer) const
 Override this in derived classes if they have other attributes than filter_name.
- Public Member Functions inherited from AbstractFilter
 AbstractFilter (const QString &name)
 Standard constructor.
int highestConnectedInput () const
 Return the index of the highest input port that is connected.
bool input (int port, const AbstractColumn *source)
 Connect the provided data source to the specified input port.
bool input (const AbstractFilter *sources)
 Connect all outputs of the provided filter to the corresponding inputs of this filter.
const AbstractColumninput (int port) const
 Return the input currently connected to the specified port, or 0.
virtual QString inputLabel (int port) const
 Return the label associated to the given input port.
int portIndexOf (const AbstractColumn *column)
 Return the input port to which the column is connected or -1 if it's not connected.
virtual ~AbstractFilter ()
 Destructor.
- Public Member Functions inherited from AbstractAspect
 AbstractAspect (const QString &name)
void addChild (AbstractAspect *child)
 Add the given Aspect to my list of children.
QString caption () const
QString captionSpec () const
 Return the specification string used for constructing the caption().
AbstractAspectchild (int index) const
 Get a child by its position in my list of children.
int childCount () const
 Return the number of child Aspects.
QString comment () const
virtual QMenu * createContextMenu () const
 Return a new context menu.
QDateTime creationTime () const
QList< AbstractAspect * > descendantsThatInherit (const char *class_name)
 Get all descendents that inherit the given class.
future::Folderfolder ()
 Return the folder the Aspect is contained in or 0 if not.
virtual QIcon icon () const
 Return an icon to be used for decorating my views.
void importV0x0001XXCreationTime (const QString &str)
int index () const
 Return my position in my parent's list of children.
int indexOfChild (const AbstractAspect *child) const
 Return the position of child in my list of children.
void insertChild (AbstractAspect *child, int index)
 Insert the given Aspect at a specific position in my list of children.
bool isDescendantOf (AbstractAspect *other)
 Return whether the there is a path upwards to the given aspect.
void moveChild (int from, int to)
 Change the positon of a child in my list of children.
QString name () const
AbstractAspectparentAspect () const
 Return my parent Aspect or 0 if I currently don't have one.
virtual QString path () const
 Return the path that leads from the top-most Aspect (usually a Project) to me.
virtual const Projectproject () const
 Return the Project this Aspect belongs to, or 0 if it is currently not part of one.
virtual Projectproject ()
 Return the Project this Aspect belongs to, or 0 if it is currently not part of one.
virtual void removeAllChildAspects ()
 Remove all child aspects.
void removeChild (AbstractAspect *child, bool detach=false)
 Remove the given Aspect from my list of children.
void removeChild (int index)
 Remove the Aspect at the given index from my list of children.
void reparentChild (AbstractAspect *new_parent, AbstractAspect *child, int d_new_index)
 Move a child to another aspect and transfer ownership.
void reparentChild (AbstractAspect *new_parent, AbstractAspect *child)
 Move a child to another aspect and transfer ownership.
virtual ~AbstractAspect ()
virtual QUndoStack * undoStack () const
 Return the undo stack of the Project, or 0 if this Aspect is not part of a Project.
void exec (QUndoCommand *command)
 Execute the given command, pushing it on the undoStack() if available.
void beginMacro (const QString &text)
 Begin an undo stack macro (series of commands)
void endMacro ()
 End the undo stack macro.

Protected Member Functions

signal handlers
virtual void inputPlotDesignationAboutToChange (const AbstractColumn *)
 The plot designation of an input is about to change.
virtual void inputPlotDesignationChanged (const AbstractColumn *)
 The plot designation of an input changed.
virtual void inputModeAboutToChange (const AbstractColumn *)
 The display mode and possibly the data type of an input is about to change.
virtual void inputModeChanged (const AbstractColumn *)
 The display mode and possibly the data type has changed.
virtual void inputDataAboutToChange (const AbstractColumn *)
 The data of an input is about to change.
virtual void inputDataChanged (const AbstractColumn *)
 The data of an input has changed.
virtual void inputRowsAboutToBeInserted (const AbstractColumn *source, int before, int count)
virtual void inputRowsInserted (const AbstractColumn *source, int before, int count)
virtual void inputRowsAboutToBeRemoved (const AbstractColumn *source, int first, int count)
virtual void inputRowsRemoved (const AbstractColumn *source, int first, int count)
- Protected Member Functions inherited from AbstractFilter
virtual void inputAboutToBeDisconnected (const AbstractColumn *source)
 Called whenever an input is disconnected or deleted.
virtual bool inputAcceptable (int port, const AbstractColumn *source)
 Give implementations a chance to reject connections to their input ports.
- Protected Member Functions inherited from AbstractAspect
virtual void completeAspectInsertion (AbstractAspect *aspect, int index)
 Called after a new child has been inserted or added.
void info (const QString &text)
 Implementations should call this whenever status information should be given to the user.
virtual void prepareAspectRemoval (AbstractAspect *aspect)
 Called before a child is removed.
void setCreationTime (const QDateTime &time)
 Set the creation time.
bool readBasicAttributes (XmlStreamReader *reader)
 Load name, creation time and caption spec from XML.
void writeBasicAttributes (QXmlStreamWriter *writer) const
 Save name, creation time and caption spec to XML.
void writeCommentElement (QXmlStreamWriter *writer) const
 Save the comment to XML.
bool readCommentElement (XmlStreamReader *reader)
 Load comment from an XML element.

Protected Attributes

IntervalAttribute< bool > d_masking
SimpleFilterColumnd_output_column
- Protected Attributes inherited from AbstractFilter
QVector< const AbstractColumn * > d_inputs
 The data sources connected to my input ports.

Additional Inherited Members

- Protected Slots inherited from AbstractFilter
virtual void inputDescriptionAboutToChange (const AbstractColumn *source)
 Name and/or comment of an input will be changed.
void inputDescriptionAboutToChange (const AbstractAspect *aspect)
virtual void inputDescriptionChanged (const AbstractColumn *source)
 Name and/or comment of an input changed.
void inputDescriptionChanged (const AbstractAspect *aspect)
virtual void inputAboutToBeReplaced (const AbstractColumn *source, const AbstractColumn *replacement)
 An input is about to be replaced.
virtual void inputMaskingAboutToChange (const AbstractColumn *source)
virtual void inputMaskingChanged (const AbstractColumn *source)
void inputAboutToBeDestroyed (const AbstractColumn *source)

Detailed Description

Simplified filter interface for filters with only one output port.

This class is only meant to simplify implementation of a restricted subtype of filter. It should not be instantiated directly. You should always either derive from AbstractFilter or (if necessary) provide an actual (non-abstract) implementation.

The trick here is that, in a sense, the filter is its own output port. This means you can implement a complete filter in only one class and don't have to coordinate data transfer between a filter class and a data source class. Additionaly, AbstractSimpleFilter offers some useful convenience methods which make writing filters as painless as possible.

For the data type of the output, all types supported by AbstractColumn (currently double, QString and QDateTime) are supported.

Tutorial, Step 1

The simplest filter you can write assumes there's also only one input port and rows on the input correspond 1:1 to rows in the output. All you need to specify is what data type you want to have (in this example double) on the input port and how to compute the output values:

01 #include "AbstractSimpleFilter.h"
02 class TutorialFilter1 : public AbstractSimpleFilter
03 {
04 protected:
05 virtual bool inputAcceptable(int, AbstractColumn *source) {
06 return (source->dataType() == SciDAVis::TypeDouble);
07 }
08 public:
10
11 virtual double valueAt(int row) const {
12 if (!d_inputs.value(0)) return 0.0;
13 double input_value = d_inputs.value(0)->valueAt(row);
14 return input_value * input_value;
15 }
16 };

This filter reads an input value (line 13) and returns its square (line 14). Reimplementing inputAcceptable() makes sure that the data source really is of type double (lines 5 to 7). Otherwise, the source will be rejected by AbstractFilter::input(). The output type is repoted by reimplementing dataType() (line 09). Before you actually use d_inputs.value(0), make sure that the input port has been connected to a data source (line 12). Otherwise line 13 would result in a crash. That's it, we've already written a fully-functional filter!

Equivalently, you can write 1:1-filters for QString or QDateTime inputs by checking for SciDAVis::TypeQString or SciDAVis::TypeQDateTime in line 6. You would then use AbstractColumn::textAt(row) or AbstractColumn::dateTimeAt(row) in line 13 to access the input data. For QString output, you need to implement AbstractColumn::textAt(row). For QDateTime output, you have to implement three methods:

virtual QDateTime dateTimeAt(int row) const;
virtual QDate dateAt(int row) const;
virtual QTime timeAt(int row) const;

Tutorial, Step 2

Now for something slightly more interesting: a filter that uses only every second row of its input. We no longer have a 1:1 correspondence between input and output rows, so we'll have to do a bit more work in order to have everything come out as expected. We'll use double-typed input and output again:

01 #include "AbstractSimpleFilter.h"
02 class TutorialFilter2 : public AbstractSimpleFilter
03 {
04 protected:
05 virtual bool inputAcceptable(int, AbstractColumn *source) {
06 return (source->dataType() == SciDAVis::TypeDouble);
07 }
08 public:

Even rows (including row 0) get dropped, odd rows are renumbered:

10 public:
11 virtual double valueAt(int row) const {
12 if (!d_inputs.value(0)) return 0.0;
13 return d_inputs.value(0)->valueAt(2*row + 1);
14 }

Constructor & Destructor Documentation

AbstractSimpleFilter::AbstractSimpleFilter ( )

Member Function Documentation

void AbstractSimpleFilter::clearMasks ( )
virtual
virtual SciDAVis::ColumnMode AbstractSimpleFilter::columnMode ( ) const
inlinevirtual

Return the column mode.

This function is most used by tables but can also be used by plots. The column mode specifies how to interpret the values in the column additional to the data type.

References AbstractFilter::d_inputs, and SciDAVis::Text.

Referenced by SimpleFilterColumn::columnMode().

virtual SciDAVis::ColumnDataType AbstractSimpleFilter::dataType ( ) const
inlinevirtual
virtual QDate AbstractSimpleFilter::dateAt ( int  row) const
inlinevirtual

Return the date part of row 'row'.

Use this only when dataType() is QDateTime

Reimplemented in String2DateTimeFilter, Double2DateTimeFilter, String2DayOfWeekFilter, String2MonthFilter, Double2MonthFilter, and Double2DayOfWeekFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::dateAt().

virtual QDateTime AbstractSimpleFilter::dateTimeAt ( int  row) const
inlinevirtual

Set the content of row 'row'.

Use this only when dataType() is QDateTime

Reimplemented in String2DateTimeFilter, Double2DateTimeFilter, String2DayOfWeekFilter, String2MonthFilter, Double2DayOfWeekFilter, and Double2MonthFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::dateTimeAt().

virtual QList< Interval<int> > AbstractSimpleFilter::dependentRows ( Interval< int >  input_range) const
inlinevirtual
virtual int AbstractSimpleFilter::inputCount ( ) const
inlinevirtual

Default to one input port.

Implements AbstractFilter.

void AbstractSimpleFilter::inputDataAboutToChange ( const AbstractColumn source)
protectedvirtual

The data of an input is about to change.

Parameters:
sourceis always the this pointer of the column that emitted the signal.

Reimplemented from AbstractFilter.

References d_output_column, and AbstractColumn::dataAboutToChange().

void AbstractSimpleFilter::inputDataChanged ( const AbstractColumn source)
protectedvirtual

The data of an input has changed.

Parameters:
sourceis always the this pointer of the column that emitted the signal.

Reimplemented from AbstractFilter.

References d_output_column, and AbstractColumn::dataChanged().

void AbstractSimpleFilter::inputModeAboutToChange ( const AbstractColumn source)
protectedvirtual

The display mode and possibly the data type of an input is about to change.

Parameters:
sourceis always the this pointer of the column that emitted the signal.

Reimplemented from AbstractFilter.

References d_output_column, and AbstractColumn::dataAboutToChange().

void AbstractSimpleFilter::inputModeChanged ( const AbstractColumn source)
protectedvirtual

The display mode and possibly the data type has changed.

Parameters:
sourceis always the this pointer of the column that emitted the signal.

Reimplemented from AbstractFilter.

References d_output_column, and AbstractColumn::dataChanged().

void AbstractSimpleFilter::inputPlotDesignationAboutToChange ( const AbstractColumn source)
protectedvirtual

The plot designation of an input is about to change.

Parameters:
sourceis always the this pointer of the column that emitted the signal.

Reimplemented from AbstractFilter.

References d_output_column, and AbstractColumn::plotDesignationAboutToChange().

void AbstractSimpleFilter::inputPlotDesignationChanged ( const AbstractColumn source)
protectedvirtual

The plot designation of an input changed.

Parameters:
sourceis always the this pointer of the column that emitted the signal.

Reimplemented from AbstractFilter.

References d_output_column, and AbstractColumn::plotDesignationChanged().

void AbstractSimpleFilter::inputRowsAboutToBeInserted ( const AbstractColumn source,
int  before,
int  count 
)
protectedvirtual
void AbstractSimpleFilter::inputRowsAboutToBeRemoved ( const AbstractColumn source,
int  first,
int  count 
)
protectedvirtual
void AbstractSimpleFilter::inputRowsInserted ( const AbstractColumn source,
int  before,
int  count 
)
protectedvirtual
void AbstractSimpleFilter::inputRowsRemoved ( const AbstractColumn source,
int  first,
int  count 
)
protectedvirtual
virtual QList< Interval<int> > AbstractSimpleFilter::invalidIntervals ( ) const
inlinevirtual

Return all intervals of invalid rows.

Reimplemented in String2DayOfWeekFilter, String2DateTimeFilter, String2MonthFilter, and String2DoubleFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::invalidIntervals().

virtual bool AbstractSimpleFilter::isInvalid ( int  row) const
inlinevirtual

Return whether a certain row contains an invalid value.

Reimplemented in String2DayOfWeekFilter, String2DateTimeFilter, String2MonthFilter, and String2DoubleFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::isInvalid().

virtual bool AbstractSimpleFilter::isInvalid ( Interval< int >  i) const
inlinevirtual

Return whether a certain interval of rows contains only invalid values.

Reimplemented in String2DayOfWeekFilter, String2DateTimeFilter, String2MonthFilter, and String2DoubleFilter.

References AbstractFilter::d_inputs.

virtual bool AbstractSimpleFilter::isMasked ( int  row) const
inlinevirtual

Return whether a certain row is masked.

Reimplemented in SimpleCopyThroughFilter.

References d_masking, and IntervalAttribute< bool >::isSet().

Referenced by SimpleFilterColumn::isMasked().

virtual bool AbstractSimpleFilter::isMasked ( Interval< int >  i) const
inlinevirtual

Return whether a certain interval of rows rows is fully masked.

Reimplemented in SimpleCopyThroughFilter.

References d_masking, and IntervalAttribute< bool >::isSet().

bool AbstractSimpleFilter::load ( XmlStreamReader reader)
virtual
virtual QList< Interval<int> > AbstractSimpleFilter::maskedIntervals ( ) const
inlinevirtual

Return all intervals of masked rows.

Reimplemented in SimpleCopyThroughFilter.

References d_masking, and IntervalAttribute< bool >::intervals().

Referenced by SimpleFilterColumn::maskedIntervals().

AbstractColumn * AbstractSimpleFilter::output ( int  port)
virtual

Return a pointer to d_output_column on port 0 (don't override unless you really know what you are doing).

Implements AbstractFilter.

References d_output_column.

Referenced by Table::importASCII(), AsciiTableImportFilter::importAspect(), and future::Table::text().

const AbstractColumn * AbstractSimpleFilter::output ( int  port) const
virtual

Overloaded method for const access.

Implements AbstractFilter.

References d_output_column.

virtual int AbstractSimpleFilter::outputCount ( ) const
inlinevirtual

We manage only one output port (don't override unless you really know what you are doing).

Implements AbstractFilter.

virtual SciDAVis::PlotDesignation AbstractSimpleFilter::plotDesignation ( ) const
inlinevirtual

Copy plot designation of input port 0.

References AbstractFilter::d_inputs, and SciDAVis::noDesignation.

Referenced by SimpleFilterColumn::plotDesignation().

virtual int AbstractSimpleFilter::rowCount ( ) const
inlinevirtual
void AbstractSimpleFilter::save ( QXmlStreamWriter *  writer) const
virtual
void AbstractSimpleFilter::setMasked ( Interval< int >  i,
bool  mask = true 
)
virtual

Set an interval masked.

Parameters:
ithe interval
masktrue: mask, false: unmask

References d_masking, d_output_column, AbstractColumn::maskingAboutToChange(), AbstractColumn::maskingChanged(), and IntervalAttribute< bool >::setValue().

virtual void AbstractSimpleFilter::setMasked ( int  row,
bool  mask = true 
)
inlinevirtual

Overloaded function for convenience.

References setMasked().

Referenced by setMasked().

virtual QString AbstractSimpleFilter::textAt ( int  row) const
inlinevirtual

Return the content of row 'row'.

Use this only when dataType() is QString

Reimplemented in Double2StringFilter, and DateTime2StringFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::textAt().

virtual QTime AbstractSimpleFilter::timeAt ( int  row) const
inlinevirtual

Return the time part of row 'row'.

Use this only when dataType() is QDateTime

Reimplemented in String2DateTimeFilter, Double2DateTimeFilter, String2DayOfWeekFilter, String2MonthFilter, Double2DayOfWeekFilter, and Double2MonthFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::timeAt().

virtual double AbstractSimpleFilter::valueAt ( int  row) const
inlinevirtual

Return the double value in row 'row'.

Use this only when dataType() is double

Reimplemented in Month2DoubleFilter, String2DoubleFilter, DateTime2DoubleFilter, and DayOfWeek2DoubleFilter.

References AbstractFilter::d_inputs.

Referenced by SimpleFilterColumn::valueAt().

virtual void AbstractSimpleFilter::writeExtraAttributes ( QXmlStreamWriter *  writer) const
inlinevirtual

Override this in derived classes if they have other attributes than filter_name.

Reimplemented in DateTime2StringFilter, Double2StringFilter, and String2DateTimeFilter.

Referenced by save().


Member Data Documentation

IntervalAttribute<bool> AbstractSimpleFilter::d_masking
protected
SimpleFilterColumn* AbstractSimpleFilter::d_output_column
protected

The documentation for this class was generated from the following files: