File indexing completed on 2024-05-12 15:26:38
0001 /*************************************************************************** 0002 File : AbstractColumn.h 0003 Project : LabPlot 0004 Description : Interface definition for data with column logic 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2007,2008 Tilman Benkert (thzs@gmx.net) 0007 Copyright : (C) 2013 Alexander Semke (alexander.semke@web.de) 0008 Copyright : (C) 2017-2020 Stefan Gerlach (stefan.gerlach@uni.kn) 0009 0010 ***************************************************************************/ 0011 0012 /*************************************************************************** 0013 * * 0014 * This program is free software; you can redistribute it and/or modify * 0015 * it under the terms of the GNU General Public License as published by * 0016 * the Free Software Foundation; either version 2 of the License, or * 0017 * (at your option) any later version. * 0018 * * 0019 * This program is distributed in the hope that it will be useful, * 0020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0022 * GNU General Public License for more details. * 0023 * * 0024 * You should have received a copy of the GNU General Public License * 0025 * along with this program; if not, write to the Free Software * 0026 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0027 * Boston, MA 02110-1301 USA * 0028 * * 0029 ***************************************************************************/ 0030 0031 #ifndef ABSTRACTCOLUMN_H 0032 #define ABSTRACTCOLUMN_H 0033 0034 #include "backend/core/AbstractAspect.h" 0035 #include <cmath> // NAN 0036 0037 class AbstractColumnPrivate; 0038 class AbstractSimpleFilter; 0039 class QStringList; 0040 class QString; 0041 class QDateTime; 0042 class QDate; 0043 class QTime; 0044 template<class T> class QVector; 0045 template<class T> class Interval; 0046 0047 class AbstractColumn : public AbstractAspect { 0048 Q_OBJECT 0049 Q_ENUMS(PlotDesignation) 0050 Q_ENUMS(ColumnMode) 0051 0052 public: 0053 enum class PlotDesignation {NoDesignation, X, Y, Z, XError, XErrorPlus, XErrorMinus, YError, YErrorMinus, YErrorPlus}; 0054 enum class ColumnMode { 0055 // BASIC FORMATS 0056 Numeric = 0, // double 0057 Text = 1, // QString 0058 // Time = 2 and Date = 3 are skipped to avoid problems with old obsolete values 0059 Month = 4, // month of year: numeric or "Jan", etc. 0060 Day = 5, // day of week: numeric or "Mon", etc. 0061 DateTime = 6, // any date-time format 0062 // Bool = 7, // bool 0063 // FLOATING POINT 0064 // 10 = Half precision 0065 // Float = 11, // float 0066 // 12 = Long double 0067 // 13 = Quad precision 0068 // 14 = decimal 32 0069 // 15 = decimal 64 0070 // 16 = decimal 128 0071 // COMPLEX 0072 // 17 = complex<float> 0073 // 18 = complex<double> 0074 // 19 = complex<long double> 0075 // INTEGER 0076 // Int8 = 20, // qint8 (char) 0077 // UInt8 = 21, // quint8 (unsigned char) 0078 // Int16 = 22, // qint16 (short) 0079 // UInt16 = 23, // quint16 (unsigned short) 0080 Integer = 24, // qint32 (int) 0081 // UInt32 = 25, // quint32 (unsigned int) 0082 BigInt = 26, // qint64 (long) 0083 // UInt64 = 27, // quint64 (unsigned long) 0084 // MISC 0085 // QBrush = 30 0086 // QColor 0087 // QFont 0088 // QPoint 0089 // QQuaternion 0090 // QVector2D, QVector3D, QVector4D 0091 // QMatrix 0092 // etc. 0093 }; 0094 enum class Properties { // TODO: why bit pattern? Aren't they exclusive? 0095 No = 0x00, 0096 Constant = 0x01, 0097 MonotonicIncreasing = 0x02, // prev_value >= value for all values in column 0098 MonotonicDecreasing = 0x04 // prev_value <= value for all values in column 0099 // add new values with next bit set (0x08) 0100 }; 0101 0102 struct ColumnStatistics { 0103 ColumnStatistics() { 0104 size = 0; 0105 minimum = NAN; 0106 maximum = NAN; 0107 arithmeticMean = NAN; 0108 geometricMean = NAN; 0109 harmonicMean = NAN; 0110 contraharmonicMean = NAN; 0111 mode = NAN; 0112 firstQuartile = NAN; 0113 median = NAN; 0114 thirdQuartile = NAN; 0115 iqr = NAN; 0116 trimean = NAN; 0117 variance = NAN; 0118 standardDeviation = NAN; 0119 meanDeviation = NAN; 0120 meanDeviationAroundMedian = NAN; 0121 medianDeviation = NAN; 0122 skewness = NAN; 0123 kurtosis = NAN; 0124 entropy = NAN; 0125 } 0126 int size; 0127 double minimum; 0128 double maximum; 0129 double arithmeticMean; 0130 double geometricMean; 0131 double harmonicMean; 0132 double contraharmonicMean; 0133 double mode; 0134 double firstQuartile; 0135 double median; 0136 double thirdQuartile; 0137 double iqr; 0138 double trimean; 0139 double variance; 0140 double standardDeviation; 0141 double meanDeviation; // mean absolute deviation around mean 0142 double meanDeviationAroundMedian; // mean absolute deviation around median 0143 double medianDeviation; // median absolute deviation 0144 double skewness; 0145 double kurtosis; 0146 double entropy; 0147 }; 0148 0149 AbstractColumn(const QString& name, AspectType type); 0150 ~AbstractColumn() override; 0151 0152 static QStringList dateFormats(); // supported date formats 0153 static QStringList timeFormats(); // supported time formats 0154 static QStringList dateTimeFormats(); // supported datetime formats 0155 static QIcon iconForMode(ColumnMode mode); 0156 0157 virtual bool isReadOnly() const { 0158 return true; 0159 }; 0160 virtual ColumnMode columnMode() const = 0; 0161 virtual void setColumnMode(AbstractColumn::ColumnMode); 0162 virtual PlotDesignation plotDesignation() const = 0; 0163 virtual QString plotDesignationString() const = 0; 0164 virtual void setPlotDesignation(AbstractColumn::PlotDesignation); 0165 bool isNumeric() const; 0166 bool isPlottable() const; 0167 0168 virtual bool copy(const AbstractColumn *source); 0169 virtual bool copy(const AbstractColumn *source, int source_start, int dest_start, int num_rows); 0170 0171 virtual int rowCount() const = 0; 0172 virtual int availableRowCount() const = 0; 0173 void insertRows(int before, int count); 0174 void removeRows(int first, int count); 0175 virtual void clear(); 0176 0177 virtual double maximum(int count = 0) const; 0178 virtual double maximum(int startIndex, int endIndex) const; 0179 virtual double minimum(int count = 0) const; 0180 virtual double minimum(int startIndex, int endIndex) const; 0181 virtual bool indicesMinMax(double v1, double v2, int& start, int& end) const; 0182 virtual int indexForValue(double x) const; 0183 0184 bool isValid(int row) const; 0185 0186 bool isMasked(int row) const; 0187 bool isMasked(const Interval<int>& i) const; 0188 QVector< Interval<int> > maskedIntervals() const; 0189 void clearMasks(); 0190 void setMasked(const Interval<int>& i, bool mask = true); 0191 void setMasked(int row, bool mask = true); 0192 0193 virtual QString formula(int row) const; 0194 virtual QVector< Interval<int> > formulaIntervals() const; 0195 virtual void setFormula(const Interval<int>& i, const QString& formula); 0196 virtual void setFormula(int row, const QString& formula); 0197 virtual void clearFormulas(); 0198 0199 virtual QString textAt(int row) const; 0200 virtual void setTextAt(int row, const QString& new_value); 0201 virtual void replaceTexts(int first, const QVector<QString>& new_values); 0202 virtual QDate dateAt(int row) const; 0203 virtual void setDateAt(int row, QDate new_value); 0204 virtual QTime timeAt(int row) const; 0205 virtual void setTimeAt(int row, QTime new_value); 0206 virtual QDateTime dateTimeAt(int row) const; 0207 virtual void setDateTimeAt(int row, const QDateTime& new_value); 0208 virtual void replaceDateTimes(int first, const QVector<QDateTime>& new_values); 0209 virtual double valueAt(int row) const; 0210 virtual void setValueAt(int row, double new_value); 0211 virtual void replaceValues(int first, const QVector<double>& new_values); 0212 virtual int integerAt(int row) const; 0213 virtual void setIntegerAt(int row, int new_value); 0214 virtual void replaceInteger(int first, const QVector<int>& new_values); 0215 virtual qint64 bigIntAt(int row) const; 0216 virtual void setBigIntAt(int row, qint64 new_value); 0217 virtual void replaceBigInt(int first, const QVector<qint64>& new_values); 0218 virtual Properties properties() const; 0219 0220 signals: 0221 void plotDesignationAboutToChange(const AbstractColumn* source); 0222 void plotDesignationChanged(const AbstractColumn* source); 0223 void modeAboutToChange(const AbstractColumn* source); 0224 void modeChanged(const AbstractColumn* source); 0225 void dataAboutToChange(const AbstractColumn* source); 0226 void dataChanged(const AbstractColumn* source); 0227 void formatChanged(const AbstractColumn* source); 0228 void rowsAboutToBeInserted(const AbstractColumn* source, int before, int count); 0229 void rowsInserted(const AbstractColumn* source, int before, int count); 0230 void rowsAboutToBeRemoved(const AbstractColumn* source, int first, int count); 0231 void rowsRemoved(const AbstractColumn* source, int first, int count); 0232 void maskingAboutToChange(const AbstractColumn* source); 0233 void maskingChanged(const AbstractColumn* source); 0234 void aboutToBeDestroyed(const AbstractColumn* source); 0235 void reset(const AbstractColumn* source); // this signal is emitted when the column is reused for another purpose. The curves must know that and disconnect all connections 0236 0237 protected: 0238 bool XmlReadMask(XmlStreamReader*); 0239 void XmlWriteMask(QXmlStreamWriter*) const; 0240 0241 virtual void handleRowInsertion(int before, int count); 0242 virtual void handleRowRemoval(int first, int count); 0243 0244 private: 0245 AbstractColumnPrivate* d; 0246 0247 friend class AbstractColumnRemoveRowsCmd; 0248 friend class AbstractColumnInsertRowsCmd; 0249 friend class AbstractColumnClearMasksCmd; 0250 friend class AbstractColumnSetMaskedCmd; 0251 }; 0252 0253 #endif