JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches

Manages one column of data. Data may either be stored internally as double* array or QVector<double> or the object may reference an external array of data. This class also provides basic tools to edit the data, change column size etc. More...

#include <jkqtpdatastorage.h>

Collaboration diagram for JKQTPColumn:
[legend]

Public Types

typedef JKQTPColumnConstIterator const_iterator
enum  DataTransferMode {
  TransferOwnership ,
  ExternallyOwned ,
  CopyData
}
typedef JKQTPColumnIterator iterator
enum class  StorageType {
  External ,
  Internal ,
  Vector
}

Public Member Functions

 JKQTPColumn (const JKQTPColumn &)=delete
 JKQTPColumn (JKQTPColumn &&)
 JKQTPColumn (JKQTPDatastore *datastore_, const QString &name_, const double *data_, size_t datasize_, size_t imageColumns_=1)
 class constructor that creates a column, which is initialized by c copy of the array data_ (size datasize_ ).
 JKQTPColumn (JKQTPDatastore *datastore_, const QString &name_, const QVector< double > &data, size_t imageColumns_=1)
 class constructor that fills the column with data from datavec_ (by copy).
 JKQTPColumn (JKQTPDatastore *datastore_, const QString &name_, DataTransferMode transferMode, double *data_, size_t datasize_, size_t imageColumns_=1)
 class constructor that binds the column to a specific array data_ (size datasize_ ) of externally managed data. Depending on transferMode the data is either copied into the column, managed as internally owned or externally owned array
 JKQTPColumn (JKQTPDatastore *datastore_, const QString &name_, QVector< double > &&data, size_t imageColumns_=1)
 class constructor that fills the column with data from datavec_ (by move).
 JKQTPColumn (JKQTPDatastore *datastore_, const QString &name_, size_t imageColumns_=1)
 class constructor that constructs a new empty vector column
 JKQTPColumn (JKQTPDatastore *datastore_, const QString &name_, size_t rows, double initialVal=0.0, size_t imageColumns_=1)
 class constructor that constructs a new vector column with rows rows that are all equal to initialVal
 JKQTPColumn (JKQTPDatastore *datastore_=nullptr)
 constructs an invalid column
 ~JKQTPColumn ()
void append (double val)
 append value to the column, Possibly converts the column to a vector column, if necessary
double & at (int n)
 returns a reference to the n -th row in this column (possibly throwing an exception if it does not exist!)
const double & at (int n) const
 returns a reference to the n -th row in this column (possibly throwing an exception if it does not exist!)
iterator begin ()
 returns an iterator to the internal data
const_iterator begin () const
 returns an iterator to the internal data
quint16 calculateChecksum () const
 calculates a checksum over the contents of the column (using qChecksum())
void clear ()
 clears the contents, frees any associated memory (if storageType==StorageType::Internal or storageType==StorageType::Vector )
size_t copy (const double *data, size_t N, size_t offset=0)
 copy data from the given array into the column
QVector< double > copyData ()
 returns a QVector with the contained data (as a copy)
void copyData (QVector< double > &copyTo) const
 copies the contained data into a QVector
void decValue (size_t n, double decrement=1.0)
 decrement the n'th value from the column
iterator end ()
 returns an iterator to the internal data
const_iterator end () const
 returns an iterator to the internal data
void exchange (double value, double replace)
 exchange every occurence of a given value by a replace value
size_t getImageColumns () const
 number of image columns, if the data in this column is interpreted as a row-major image (e.g. for display in a JKQTPMathImage )
QString getName () const
 a name describing the column
double getPixelValue (size_t x, size_t y) const
 returns the element at (x,y) in the column, where the data is interpreted as a row-major ordered Matrix of the width imageWidth
double * getPointer (size_t n=0)
 gets a pointer to the n -th value in the column
const double * getPointer (size_t n=0) const
 gets a pointer to the n -th value in the column
size_t getRows () const noexcept
 returns the number of rows in this column (accesses the datastore)
StorageType getStorageType () const
 retrurnsthe storage type of the data in this column
double getValue (int n) const
 reads the n'th value from the column
double getValue (size_t n) const
 reads the n'th value from the column
void incValue (size_t n, double increment=1.0)
 increment the n'th value from the column
bool isValid () const noexcept
 return true if the column is valid i.e. is properly initialized
bool isVectorColumn () const
 returns true if data is managed in a vector, i.e. operations like append are possible without copying the data into a vector
JKQTPColumnoperator= (const JKQTPColumn &)=delete
JKQTPColumnoperator= (JKQTPColumn &&)
bool operator== (const JKQTPColumn &other) const
 two columns are equal, if the same memory in the same datastore is referenced
double & operator[] (int n)
 returns a reference to the n -th row in this column
const double & operator[] (int n) const
 returns a reference to the n -th row in this column (possibly throwing an exception if it does not exist!)
void push_back (double val)
 append value to the column, Possibly converts the column to a vector column, if necessary
void resize (size_t new_size, double added_vala=0.0)
 resize the column to new_size (possibly filling with added_vala ), Possibly converts the column to a vector column, if necessary
void scale (double factor)
 scales all members of the column with the given factor
void setAll (double value)
 set all values in the column to a specific value
void setImageColumns (size_t imageWidth)
 number of image columns, if the data in this column is interpreted as a row-major image (e.g. for display in a JKQTPMathImage )
void setName (const QString &__value)
 a name describing the column
void setPixelValue (size_t x, size_t y, double val)
 sets the element at (x,y) in the column, where the data is interpreted as a row-major ordered Matrix of the width imageWidth
void setPixelValue (size_t x, size_t y, size_t width, double val)
 sets the element at (x,y) in the column, where the data is interpreted as a row-major ordered Matrix of the given width
void setValue (size_t n, double val)
 sets the n'th value from the column
void subtract (double value)
 subtracts a given value from all members of the column

Protected Member Functions

bool convertToVectorColumn ()
 if the column's data is \u not stored in an internal vector , this copies the data into a vector This does copies all data.
void convertToVectorColumnFromRange (size_t start1, size_t end1)
 if the column's data is \u not stored in an internal vector , this copies the data into a vector This does not copy all data, but only the inclusive row range [start1..end1].
void convertToVectorColumnFromRanges (size_t start1, size_t end1, size_t start2, size_t end2)
 if the column's data is \u not stored in an internal vector, this copies the data into a vector This does not copy all data, but only the inclusive row ranges [start1..end1] and [start2..end2].
void eraseFromVectorColumn (size_t row)
 removes the entry row
void eraseFromVectorColumn (size_t row, size_t rowEnd)
 removes the entries row to rowEnd (inclusive)
JKQTPDatastoregetDatastore ()
const JKQTPDatastoregetDatastore () const

Private Attributes

double * data
 how data is represented in this JKQTPColumn
JKQTPDatastoredatastore
 pointer to the datastore object used to manage the data of the plot
QVector< double > datavec
 iif storageType is StorageType::Vector, the data is actually save here
size_t imageColumns
 number of image columns, if the data in this column is interpreted as a row-major image (e.g. for display in a JKQTPMathImage )
QString name
 a name describing the column
size_t rows
 number of rows in data
StorageType storageType
 specifies whether the datastore manages the memory (true , i.e. may also free the data) or whether the user application does this (false , i.e. the datastore never frees the data) .
bool valid
 is this item valid/usable?

Friends

class JKQTPColumnConstIterator
class JKQTPColumnIterator
class JKQTPDatastore

Detailed Description

Manages one column of data. Data may either be stored internally as double* array or QVector<double> or the object may reference an external array of data. This class also provides basic tools to edit the data, change column size etc.

See also
JKQTPDatastore

Member Typedef Documentation

◆ const_iterator

◆ iterator

Member Enumeration Documentation

◆ DataTransferMode

Enumerator
TransferOwnership 

data is owned by the JKQTPColumn afterwards (and if necessary \C std::free() 's )

ExternallyOwned 

data is referenced, but \u not owned by the JKQTPColumn afterwards

CopyData 

data is owned by the JKQTPColumn and internally managed as a QVector<double> which makes this data item easily editable (also append/erase operations!)

◆ StorageType

enum class JKQTPColumn::StorageType
strong
Enumerator
External 

data is stored in an externally managed (=not owned) C-array

Internal 

data is stored in an internally managed (=owned) C-array

Vector 

data is stored in the internal QVector<double> datavec

Constructor & Destructor Documentation

◆ JKQTPColumn() [1/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_ = nullptr)

constructs an invalid column

◆ JKQTPColumn() [2/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_,
const QString & name_,
DataTransferMode transferMode,
double * data_,
size_t datasize_,
size_t imageColumns_ = 1 )

class constructor that binds the column to a specific array data_ (size datasize_ ) of externally managed data. Depending on transferMode the data is either copied into the column, managed as internally owned or externally owned array

◆ JKQTPColumn() [3/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_,
const QString & name_,
const double * data_,
size_t datasize_,
size_t imageColumns_ = 1 )

class constructor that creates a column, which is initialized by c copy of the array data_ (size datasize_ ).

◆ JKQTPColumn() [4/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_,
const QString & name_,
const QVector< double > & data,
size_t imageColumns_ = 1 )

class constructor that fills the column with data from datavec_ (by copy).

◆ JKQTPColumn() [5/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_,
const QString & name_,
QVector< double > && data,
size_t imageColumns_ = 1 )

class constructor that fills the column with data from datavec_ (by move).

◆ JKQTPColumn() [6/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_,
const QString & name_,
size_t rows,
double initialVal = 0.0,
size_t imageColumns_ = 1 )

class constructor that constructs a new vector column with rows rows that are all equal to initialVal

◆ JKQTPColumn() [7/9]

JKQTPColumn::JKQTPColumn ( JKQTPDatastore * datastore_,
const QString & name_,
size_t imageColumns_ = 1 )

class constructor that constructs a new empty vector column

◆ ~JKQTPColumn()

JKQTPColumn::~JKQTPColumn ( )

◆ JKQTPColumn() [8/9]

JKQTPColumn::JKQTPColumn ( const JKQTPColumn & )
inlinedelete

◆ JKQTPColumn() [9/9]

JKQTPColumn::JKQTPColumn ( JKQTPColumn && )
inline

Member Function Documentation

◆ append()

void JKQTPColumn::append ( double val)
inline

append value to the column, Possibly converts the column to a vector column, if necessary

◆ at() [1/2]

double & JKQTPColumn::at ( int n)
inline

returns a reference to the n -th row in this column (possibly throwing an exception if it does not exist!)

See also
iterator, operator[]()

◆ at() [2/2]

const double & JKQTPColumn::at ( int n) const
inline

returns a reference to the n -th row in this column (possibly throwing an exception if it does not exist!)

See also
const_iterator, operator[]()

◆ begin() [1/2]

JKQTPColumn::iterator JKQTPColumn::begin ( )
inline

returns an iterator to the internal data

See also
JKQTPColumnIterator

◆ begin() [2/2]

JKQTPColumn::const_iterator JKQTPColumn::begin ( ) const
inline

returns an iterator to the internal data

See also
JKQTPColumnIterator

◆ calculateChecksum()

quint16 JKQTPColumn::calculateChecksum ( ) const
inline

calculates a checksum over the contents of the column (using qChecksum())

◆ clear()

void JKQTPColumn::clear ( )

clears the contents, frees any associated memory (if storageType==StorageType::Internal or storageType==StorageType::Vector )

Afterwards the column has storageType==StorageType::Vector and is valid!

◆ convertToVectorColumn()

bool JKQTPColumn::convertToVectorColumn ( )
protected

if the column's data is \u not stored in an internal vector , this copies the data into a vector This does copies all data.

Returns
true if a conversion was performed, or false if the column already linked to a vector item. Especially this returns false if isVectorColumn()==true!!!

◆ convertToVectorColumnFromRange()

void JKQTPColumn::convertToVectorColumnFromRange ( size_t start1,
size_t end1 )
protected

if the column's data is \u not stored in an internal vector , this copies the data into a vector This does not copy all data, but only the inclusive row range [start1..end1].

Parameters
start1start of first range. If start1>getRows() or end1<start1 the range [start1..end1] is ignored. If start1==end1==getRows() all data is copied.
end1end of first range
Returns
true if a conversion was performed, or false if the column already linked to a vector item. In the latter case the range [start1..end1] are ignored (i.e. a vector column is not modified!!!)!!! Especially this returns false if isVectorColumn()==true!!!
Note
If start1==end1==getRows() all data is copied.

◆ convertToVectorColumnFromRanges()

void JKQTPColumn::convertToVectorColumnFromRanges ( size_t start1,
size_t end1,
size_t start2,
size_t end2 )
protected

if the column's data is \u not stored in an internal vector, this copies the data into a vector This does not copy all data, but only the inclusive row ranges [start1..end1] and [start2..end2].

Parameters
start1start of first range. If start1>getRows() or end1<start1 the range [start1..end1] is ignored.
end1end of first range
start2start of second range. If start2>getRows() or end2<start2 the range [start2..end2] is ignored.
end2end of second range
Returns
true if a conversion was performed, or false if the column already linked to a vector item. In the latter case the ranges [start1..end1] and [start2..end2] are ignored (i.e. a vector column is not modified!!!)!!! Especially this returns false if isVectorColumn()==true!!!
Note
If start1==end1==getRows() and start2==end2==getRows() all data is copied.

◆ copy()

size_t JKQTPColumn::copy ( const double * data,
size_t N,
size_t offset = 0 )

copy data from the given array into the column

This copies N elements from data into the column where the first overwritten row is offset, so you can shift the location where the copy process starts.

Warning
Note that the column needs to have enough space to fit the data. This function does not resize the column! If the column contains less rows than required, the data is copied only partially
Returns
the number of entries from data that was actually copied (0 for no copy, N for full copy, in between for partial copy)

◆ copyData() [1/2]

QVector< double > JKQTPColumn::copyData ( )

returns a QVector with the contained data (as a copy)

◆ copyData() [2/2]

void JKQTPColumn::copyData ( QVector< double > & copyTo) const

copies the contained data into a QVector

◆ decValue()

void JKQTPColumn::decValue ( size_t n,
double decrement = 1.0 )
inline

decrement the n'th value from the column

if the referenced entry does not exist for any reason, this function does not throw but simply exits!

◆ end() [1/2]

JKQTPColumn::iterator JKQTPColumn::end ( )
inline

returns an iterator to the internal data

See also
JKQTPColumnIterator

◆ end() [2/2]

JKQTPColumn::const_iterator JKQTPColumn::end ( ) const
inline

returns an iterator to the internal data

See also
JKQTPColumnIterator

◆ eraseFromVectorColumn() [1/2]

void JKQTPColumn::eraseFromVectorColumn ( size_t row)
inlineprotected

removes the entry row

Warning
this function throws an exception if the column is NOT a vector column!

◆ eraseFromVectorColumn() [2/2]

void JKQTPColumn::eraseFromVectorColumn ( size_t row,
size_t rowEnd )
inlineprotected

removes the entries row to rowEnd (inclusive)

Warning
this function throws an exception if the column is NOT a vector column!

◆ exchange()

void JKQTPColumn::exchange ( double value,
double replace )

exchange every occurence of a given value by a replace value

◆ getDatastore() [1/2]

JKQTPDatastore * JKQTPColumn::getDatastore ( )
inlineprotected

◆ getDatastore() [2/2]

const JKQTPDatastore * JKQTPColumn::getDatastore ( ) const
inlineprotected

◆ getImageColumns()

size_t JKQTPColumn::getImageColumns ( ) const
inline

number of image columns, if the data in this column is interpreted as a row-major image (e.g. for display in a JKQTPMathImage )

◆ getName()

QString JKQTPColumn::getName ( ) const
inline

a name describing the column

◆ getPixelValue()

double JKQTPColumn::getPixelValue ( size_t x,
size_t y ) const
inline

returns the element at (x,y) in the column, where the data is interpreted as a row-major ordered Matrix of the width imageWidth

This method accesses the datastore and returns the double value stored in the (y*imageColumns+x)'th row of the according column.

◆ getPointer() [1/2]

double * JKQTPColumn::getPointer ( size_t n = 0)
inline

gets a pointer to the n -th value in the column

◆ getPointer() [2/2]

const double * JKQTPColumn::getPointer ( size_t n = 0) const
inline

gets a pointer to the n -th value in the column

◆ getRows()

size_t JKQTPColumn::getRows ( ) const
inlinenoexcept

returns the number of rows in this column (accesses the datastore)

◆ getStorageType()

StorageType JKQTPColumn::getStorageType ( ) const
inline

retrurnsthe storage type of the data in this column

◆ getValue() [1/2]

double JKQTPColumn::getValue ( int n) const
inline

reads the n'th value from the column

This method accesses the datastore and returns the double value stored in the n'th row of the according column.

See also
at(), operator[]()

◆ getValue() [2/2]

double JKQTPColumn::getValue ( size_t n) const
inline

reads the n'th value from the column

This method accesses the datastore and returns the double value stored in the n'th row of the according column.

If data is not available (e.g. no data in column of n out of range, this function return JKQTP_NAN )

See also
at(), operator[]()

◆ incValue()

void JKQTPColumn::incValue ( size_t n,
double increment = 1.0 )
inline

increment the n'th value from the column

if the referenced entry does not exist for any reason, this function does not throw but simply exits!

◆ isValid()

bool JKQTPColumn::isValid ( ) const
inlinenoexcept

return true if the column is valid i.e. is properly initialized

◆ isVectorColumn()

bool JKQTPColumn::isVectorColumn ( ) const
inline

returns true if data is managed in a vector, i.e. operations like append are possible without copying the data into a vector

◆ operator=() [1/2]

JKQTPColumn & JKQTPColumn::operator= ( const JKQTPColumn & )
inlinedelete

◆ operator=() [2/2]

JKQTPColumn & JKQTPColumn::operator= ( JKQTPColumn && )
inline

◆ operator==()

bool JKQTPColumn::operator== ( const JKQTPColumn & other) const

two columns are equal, if the same memory in the same datastore is referenced

◆ operator[]() [1/2]

double & JKQTPColumn::operator[] ( int n)
inline

returns a reference to the n -th row in this column

This may cause an access violation if the data is not present or referenced correctly. It does not throw explicit exceptions as at() does! On the other side, this function is faster that at().

See also
iterator, at(), getValue()

◆ operator[]() [2/2]

const double & JKQTPColumn::operator[] ( int n) const
inline

returns a reference to the n -th row in this column (possibly throwing an exception if it does not exist!)

This may cause an access violation if the data is not present or referenced correctly. It does not throw explicit exceptions as at() does! On the other side, this function is faster that at().

See also
const_iterator, at(), getValue()

◆ push_back()

void JKQTPColumn::push_back ( double val)
inline

append value to the column, Possibly converts the column to a vector column, if necessary

◆ resize()

void JKQTPColumn::resize ( size_t new_size,
double added_vala = 0.0 )
inline

resize the column to new_size (possibly filling with added_vala ), Possibly converts the column to a vector column, if necessary

◆ scale()

void JKQTPColumn::scale ( double factor)

scales all members of the column with the given factor

◆ setAll()

void JKQTPColumn::setAll ( double value)

set all values in the column to a specific value

◆ setImageColumns()

void JKQTPColumn::setImageColumns ( size_t imageWidth)

number of image columns, if the data in this column is interpreted as a row-major image (e.g. for display in a JKQTPMathImage )

◆ setName()

void JKQTPColumn::setName ( const QString & __value)

a name describing the column

◆ setPixelValue() [1/2]

void JKQTPColumn::setPixelValue ( size_t x,
size_t y,
double val )
inline

sets the element at (x,y) in the column, where the data is interpreted as a row-major ordered Matrix of the width imageWidth

This method accesses the datastore and returns the double value stored in the (y*imageColumns+x)'th row of the according column.

◆ setPixelValue() [2/2]

void JKQTPColumn::setPixelValue ( size_t x,
size_t y,
size_t width,
double val )
inline

sets the element at (x,y) in the column, where the data is interpreted as a row-major ordered Matrix of the given width

This method accesses the datastore and returns the double value stored in the (y*width+x)'th row of the according column.

◆ setValue()

void JKQTPColumn::setValue ( size_t n,
double val )
inline

sets the n'th value from the column

if the referenced entry does not exist for any reason, this function does not throw but simply exits!

◆ subtract()

void JKQTPColumn::subtract ( double value)

subtracts a given value from all members of the column

◆ JKQTPColumnConstIterator

friend class JKQTPColumnConstIterator
friend

◆ JKQTPColumnIterator

friend class JKQTPColumnIterator
friend

◆ JKQTPDatastore

friend class JKQTPDatastore
friend

Member Data Documentation

◆ data

double* JKQTPColumn::data
private

how data is represented in this JKQTPColumn

a pointer to the actual data (if storageType==StorageType::External )

◆ datastore

JKQTPDatastore* JKQTPColumn::datastore
private

pointer to the datastore object used to manage the data of the plot

◆ datavec

QVector<double> JKQTPColumn::datavec
private

iif storageType is StorageType::Vector, the data is actually save here

◆ imageColumns

size_t JKQTPColumn::imageColumns
private

number of image columns, if the data in this column is interpreted as a row-major image (e.g. for display in a JKQTPMathImage )

◆ name

QString JKQTPColumn::name
private

a name describing the column

◆ rows

size_t JKQTPColumn::rows
private

number of rows in data

◆ storageType

StorageType JKQTPColumn::storageType
private

specifies whether the datastore manages the memory (true , i.e. may also free the data) or whether the user application does this (false , i.e. the datastore never frees the data) .

◆ valid

bool JKQTPColumn::valid
private

is this item valid/usable?


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