"Fossies" - the Fresh Open Source Software Archive

Member "scidavis-2.3.0/libscidavis/src/future/core/AbstractColumn.h" (12 Jun 2020, 16127 Bytes) of package /linux/misc/scidavis-2.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractColumn.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.23_vs_1.25.

    1 /***************************************************************************
    2     File                 : AbstractColumn.h
    3     Project              : SciDAVis
    4     Description          : Interface definition for data with column logic
    5     --------------------------------------------------------------------
    6     Copyright            : (C) 2007-2009 Tilman Benkert (thzs*gmx.net)
    7                            (replace * with @ in the email addresses) 
    8 
    9  ***************************************************************************/
   10 
   11 /***************************************************************************
   12  *                                                                         *
   13  *  This program is free software; you can redistribute it and/or modify   *
   14  *  it under the terms of the GNU General Public License as published by   *
   15  *  the Free Software Foundation; either version 2 of the License, or      *
   16  *  (at your option) any later version.                                    *
   17  *                                                                         *
   18  *  This program is distributed in the hope that it will be useful,        *
   19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
   20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
   21  *  GNU General Public License for more details.                           *
   22  *                                                                         *
   23  *   You should have received a copy of the GNU General Public License     *
   24  *   along with this program; if not, write to the Free Software           *
   25  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
   26  *   Boston, MA  02110-1301  USA                                           *
   27  *                                                                         *
   28  ***************************************************************************/
   29 
   30 #ifndef ABSTRACTCOLUMN_H
   31 #define ABSTRACTCOLUMN_H
   32 
   33 #include <QList>
   34 #include <QString>
   35 #include <QDateTime>
   36 #include <QDate>
   37 #include <QTime>
   38 #include "lib/Interval.h"
   39 #include "globals.h"
   40 #include "core/AbstractAspect.h"
   41 
   42 class Column;
   43 class AbstractSimpleFilter;
   44 class QStringList;
   45 class AbstractFilter;
   46 
   47 //! Interface definition for data with column logic
   48 /**
   49   This is an abstract base class for column-based data, 
   50   i.e. mathematically a vector or technically a 1D array or list.
   51   It only defines the interface but has no data members itself. 
   52 
   53   Classes derived from this are typically table columns or outputs
   54   of filters which can be chained between table columns and plots. 
   55   From the point of view of the plot functions there will be no difference 
   56   between a table column and a filter output since both use this interface.
   57 
   58   Classes derived from this will either store a 
   59   vector with entries of one certain data type, e.g. double, QString, 
   60   QDateTime, or generate such values on demand. To determine the data
   61   type of a class derived from this, use the dataType() function. 
   62   AbstractColumn defines all access functions for all supported data 
   63   types but only those corresponding to the return value of dataType() 
   64   will return a meaningful value. Calling functions not belonging to 
   65   the data type of the column is safe, but will do nothing (writing
   66   function) or return some default value (reading functions).
   67 
   68   This class also defines all signals which indicate a data change.
   69   Any class whose output values are subject to change over time must emit
   70   the according signals. These signals notify any object working with the
   71   column before and after a change of the column.
   72   In some cases it will be necessary for a class using 
   73   the column to connect aboutToBeDestroyed(), to react 
   74   to a column's deletion, e.g. a filter's reaction to a 
   75   table deletion.
   76 
   77   All writing functions have a "do nothing" standard implementation to
   78   make deriving a read-only class very easy without bothering about the
   79   writing interface. 
   80   */
   81 class AbstractColumn : public AbstractAspect
   82 {
   83     Q_OBJECT
   84 
   85     public:
   86         //! Ctor
   87         AbstractColumn(const QString& name) : AbstractAspect(name) {}
   88         //! Dtor
   89         virtual ~AbstractColumn() { aboutToBeDestroyed(this);}
   90 
   91         //! Return the data type of the column
   92         virtual SciDAVis::ColumnDataType dataType() const = 0;
   93         //! Return whether the object is read-only
   94         virtual bool isReadOnly() const { return true; };
   95         //! Return the column mode
   96         /*
   97          * This function is most used by tables but can also be used
   98          * by plots. The column mode specifies how to interpret 
   99          * the values in the column additional to the data type.
  100          */ 
  101         virtual SciDAVis::ColumnMode columnMode() const = 0;
  102         //! Set the column mode
  103         /**
  104          * This sets the column mode and, if
  105          * necessary, converts it to another datatype.
  106          */
  107   virtual void setColumnMode(SciDAVis::ColumnMode mode, AbstractFilter *conversion_filter=0)
  108   { Q_UNUSED(mode);  Q_UNUSED(conversion_filter);};
  109         //! Copy another column of the same type
  110         /**
  111          * This function will return false if the data type
  112          * of 'other' is not the same as the type of 'this'.
  113          * The validity information for the rows is also copied.
  114          * Use a filter to convert a column to another type.
  115          */
  116         virtual bool copy(const AbstractColumn * other) { Q_UNUSED(other) return false; };
  117         //! Copies part of another column of the same type
  118         /**
  119          * This function will return false if the data type
  120          * of 'other' is not the same as the type of 'this'.
  121          * The validity information for the rows is also copied.
  122          * \param other pointer to the column to copy
  123          * \param src_start first row to copy in the column to copy
  124          * \param dest_start first row to copy in
  125          * \param num_rows the number of rows to copy
  126          */ 
  127         virtual bool copy(const AbstractColumn * source, int source_start, int dest_start, int num_rows) 
  128         {
  129             Q_UNUSED(source)
  130             Q_UNUSED(source_start)
  131             Q_UNUSED(dest_start)
  132             Q_UNUSED(num_rows)
  133             return false; 
  134         };
  135 
  136         //! Return the data vector size
  137         virtual int rowCount() const = 0;
  138         //! Insert some empty (or initialized with zero) rows
  139         virtual void insertRows(int before, int count) { Q_UNUSED(before) Q_UNUSED(count) };
  140         //! Remove 'count' rows starting from row 'first'
  141         virtual void removeRows(int first, int count) { Q_UNUSED(first) Q_UNUSED(count) };
  142         //! Return the column plot designation
  143         virtual SciDAVis::PlotDesignation plotDesignation() const = 0;
  144         //! Set the column plot designation
  145         //virtual void setPlotDesignation(SciDAVis::PlotDesignation pd) { Q_UNUSED(pd) };
  146         //! Clear the whole column
  147         virtual void clear() {};
  148         //! This must be called before the column is replaced by another
  149         virtual void notifyReplacement(const AbstractColumn *replacement) { aboutToBeReplaced(this, replacement); }
  150 
  151         //! \name IntervalAttribute related functions
  152         //@{
  153         //! Return whether a certain row contains an invalid value   
  154         virtual bool isInvalid(int row) const { return !Interval<int>(0, rowCount()-1).contains(row); }      
  155         //! Return whether a certain interval of rows contains only invalid values   
  156         virtual bool isInvalid(Interval<int> i) const { return !Interval<int>(0, rowCount()-1).contains(i); }    
  157         //! Return all intervals of invalid rows
  158         virtual QList< Interval<int> > invalidIntervals() const { return QList< Interval<int> >(); }     
  159         //! Return whether a certain row is masked   
  160         virtual bool isMasked(int row) const { Q_UNUSED(row); return false; }    
  161         //! Return whether a certain interval of rows rows is fully masked   
  162         virtual bool isMasked(Interval<int> i) const { Q_UNUSED(i); return false; }
  163         //! Return all intervals of masked rows
  164         virtual QList< Interval<int> > maskedIntervals() const { return QList< Interval<int> >(); }      
  165         //! Clear all validity information
  166         virtual void clearValidity() {};
  167         //! Clear all masking information
  168         virtual void clearMasks() {};
  169         //! Set an interval invalid or valid
  170         /**
  171          * \param i the interval
  172          * \param invalid true: set invalid, false: set valid
  173          */ 
  174         //virtual void setInvalid(Interval<int> i, bool invalid = true) { Q_UNUSED(i) Q_UNUSED(invalid) };
  175         //! Overloaded function for convenience
  176         //virtual void setInvalid(int row, bool invalid = true) { Q_UNUSED(row) Q_UNUSED(invalid) };
  177         //! Set an interval masked
  178         /**
  179          * \param i the interval
  180          * \param mask true: mask, false: unmask
  181          */ 
  182         //virtual void setMasked(Interval<int> i, bool mask = true) { Q_UNUSED(i) Q_UNUSED(mask) };
  183         //! Overloaded function for convenience
  184         //virtual void setMasked(int row, bool mask = true) { Q_UNUSED(row) Q_UNUSED(mask) };
  185         //@}
  186 
  187         //! \name Formula related functions
  188         //@{
  189         //! Return the formula associated with row 'row'     
  190         virtual QString formula(int row) const { Q_UNUSED(row); return QString(); }
  191         //! Return the intervals that have associated formulas
  192         /**
  193          * This can be used to make a list of formulas with their intervals.
  194          * Here is some example code:
  195          *
  196          * \code
  197          * QStringList list;
  198          * QList< Interval<int> > intervals = my_column.formulaIntervals();
  199          * foreach(Interval<int> interval, intervals)
  200          *  list << QString(interval.toString() + ": " + my_column.formula(interval.start()));
  201          * \endcode
  202          */
  203         virtual QList< Interval<int> > formulaIntervals() const { return QList< Interval<int> >(); }
  204         //! Set a formula string for an interval of rows
  205         //virtual void setFormula(Interval<int> i, QString formula) { Q_UNUSED(i) Q_UNUSED(formula) };
  206         //! Overloaded function for convenience
  207         //virtual void setFormula(int row, QString formula) { Q_UNUSED(row) Q_UNUSED(formula) };
  208         //! Clear all formulas
  209         virtual void clearFormulas() {};
  210         //@}
  211         
  212         //! \name type specific functions
  213         //@{
  214         //! Return the content of row 'row'.
  215         /**
  216          * Use this only when dataType() is QString
  217          */
  218         virtual QString textAt(int row) const { Q_UNUSED(row); return ""; }
  219         //! Set the content of row 'row'
  220         /**
  221          * Use this only when dataType() is QString
  222          */
  223         //virtual void setTextAt(int row, const QString& new_value) { Q_UNUSED(row) Q_UNUSED(new_value) };
  224         //! Replace a range of values 
  225         /**
  226          * Use this only when dataType() is QString
  227          */
  228         virtual void replaceTexts(int first, const QStringList& new_values) { Q_UNUSED(first) Q_UNUSED(new_values) };
  229         //! Return the date part of row 'row'
  230         /**
  231          * Use this only when dataType() is QDateTime
  232          */
  233         virtual QDate dateAt(int row) const { Q_UNUSED(row); return QDate(); };
  234         //! Set the content of row 'row'
  235         /**
  236          * Use this only when dataType() is QDateTime
  237          */
  238         //virtual void setDateAt(int row, const QDate& new_value) { Q_UNUSED(row) Q_UNUSED(new_value) };
  239         //! Return the time part of row 'row'
  240         /**
  241          * Use this only when dataType() is QDateTime
  242          */
  243         virtual QTime timeAt(int row) const { Q_UNUSED(row); return QTime(); };
  244         //! Set the content of row 'row'
  245         /**
  246          * Use this only when dataType() is QDateTime
  247          */
  248         //virtual void setTimeAt(int row, const QTime& new_value) { Q_UNUSED(row) Q_UNUSED(new_value) };
  249         //! Return the QDateTime in row 'row'
  250         /**
  251          * Use this only when dataType() is QDateTime
  252          */
  253         virtual QDateTime dateTimeAt(int row) const { Q_UNUSED(row); return QDateTime(); };
  254         //! Set the content of row 'row'
  255         /**
  256          * Use this only when dataType() is QDateTime
  257          */
  258         //virtual void setDateTimeAt(int row, const QDateTime& new_value) { Q_UNUSED(row) Q_UNUSED(new_value) };
  259         //! Replace a range of values 
  260         /**
  261          * Use this only when dataType() is QDateTime
  262          */
  263         virtual void replaceDateTimes(int first, const QList<QDateTime>& new_values) { Q_UNUSED(first) Q_UNUSED(new_values) };
  264         //! Return the double value in row 'row'
  265         /**
  266          * Use this only when dataType() is double
  267          */
  268         virtual double valueAt(int row) const { Q_UNUSED(row); return 0; };
  269         //! Set the content of row 'row'
  270         /**
  271          * Use this only when dataType() is double
  272          */
  273         //virtual void setValueAt(int row, double new_value) { Q_UNUSED(row) Q_UNUSED(new_value) };
  274         //! Replace a range of values 
  275         /**
  276          * Use this only when dataType() is double
  277          */
  278         virtual void replaceValues(int first, const QVector<qreal>& new_values) { Q_UNUSED(first) Q_UNUSED(new_values) };
  279         //@}
  280 
  281     signals: 
  282         //! Column plot designation will be changed
  283         /**
  284          * 'source' is always the this pointer of the column that
  285          * emitted this signal. This way it's easier to use
  286          * one handler for lots of columns.
  287          */
  288         void plotDesignationAboutToChange(const AbstractColumn * source); 
  289         //! Column plot designation changed
  290         /**
  291          * 'source' is always the this pointer of the column that
  292          * emitted this signal. This way it's easier to use
  293          * one handler for lots of columns.
  294          */
  295         void plotDesignationChanged(const AbstractColumn * source); 
  296         //! Column mode (possibly also the data type) will be changed
  297         /**
  298          * 'source' is always the this pointer of the column that
  299          * emitted this signal. This way it's easier to use
  300          * one handler for lots of columns.
  301          */
  302         void modeAboutToChange(const AbstractColumn * source); 
  303         //! Column mode (possibly also the data type) changed
  304         /**
  305          * 'source' is always the this pointer of the column that
  306          * emitted this signal. This way it's easier to use
  307          * one handler for lots of columns.
  308          */
  309         void modeChanged(const AbstractColumn * source); 
  310         //! Data (including validity) of the column will be changed
  311         /**
  312          * 'source' is always the this pointer of the column that
  313          * emitted this signal. This way it's easier to use
  314          * one handler for lots of columns.
  315          */
  316         void dataAboutToChange(const AbstractColumn * source); 
  317         //! Data (including validity) of the column has changed
  318         /**
  319          * Important: When data has changed also the number
  320          * of rows in the column may have changed without
  321          * any other signal emission.
  322          * 'source' is always the this pointer of the column that
  323          * emitted this signal. This way it's easier to use
  324          * one handler for lots of columns.
  325          */
  326         void dataChanged(const AbstractColumn * source); 
  327         //! The column will be replaced
  328         /**
  329          * This is used then a column is replaced by another
  330          * column, possibly of another type. 
  331          *
  332          * \param new_col Pointer to the column this one is to be replaced with.
  333          *
  334          * \param source is always a pointer to the column that
  335          * emitted this signal. This way it's easier to use
  336          * one handler for lots of columns.
  337          */
  338         void aboutToBeReplaced(const AbstractColumn * source, const AbstractColumn* new_col); 
  339         //! Rows will be inserted
  340         /**
  341          *  \param source the column that emitted the signal
  342          *  \param before the row to insert before
  343          *  \param count the number of rows to be inserted
  344          */
  345         void rowsAboutToBeInserted(const AbstractColumn * source, int before, int count); 
  346         //! Rows have been inserted
  347         /**
  348          *  \param source the column that emitted the signal
  349          *  \param before the row to insert before
  350          *  \param count the number of rows to be inserted
  351          */
  352         void rowsInserted(const AbstractColumn * source, int before, int count); 
  353         //! Rows will be deleted
  354         /**
  355          *  \param source the column that emitted the signal
  356          *  \param first the first row to be deleted
  357          *  \param count the number of rows to be deleted
  358          */
  359         void rowsAboutToBeRemoved(const AbstractColumn * source, int first, int count); 
  360         //! Rows have been deleted
  361         /**
  362          *  \param source the column that emitted the signal
  363          *  \param first the first row that was deleted
  364          *  \param count the number of deleted rows
  365          */
  366         void rowsRemoved(const AbstractColumn * source, int first, int count); 
  367         //! IntervalAttribute related signal
  368         void maskingAboutToChange(const AbstractColumn * source); 
  369         //! IntervalAttribute related signal
  370         void maskingChanged(const AbstractColumn * source); 
  371         // TODO: Check whether aboutToBeDestroyed is needed 
  372         //! Emitted shortly before this data source is deleted.
  373         /**
  374          * \param source the object emitting this signal
  375          *
  376          * This is needed by AbstractFilter. 
  377          */
  378         void aboutToBeDestroyed(const AbstractColumn * source);
  379 
  380     friend class ColumnPrivate;
  381     friend class AbstractSimpleFilter;
  382     friend class SimpleMappingFilter;
  383     friend class SimpleCopyThroughFilter;
  384 };
  385 
  386 #endif