- added several new copy/set-functions to JKQTPDatastore

- bugfix: JKQTPColumnConstIterator and JKQTPColumnIterator: getImagePositionX() and getImagePositionY() were switched
This commit is contained in:
jkriege2 2020-09-11 12:39:10 +02:00
parent ff373236d4
commit a1c4f0c0d2
3 changed files with 161 additions and 55 deletions

View File

@ -20,6 +20,7 @@ Changes, compared to \ref page_whatsnew_V2019_11 "v2019.11" include:
<li> fixed issue <a href="https://github.com/jkriege2/JKQtPlotter/pull/41">#41: Build error when JKQtPlotter_BUILD_INCLUDE_XITS_FONTS set to OFF </a>, thanks to <a href="https://github.com/smistad">user:smistad</a></li>
<li> fixed issue <a href="https://github.com/jkriege2/JKQtPlotter/pull/37">#37: CMake installs things into $PREFIX/doc/*.txt </a>, thanks to <a href="https://github.com/certik">user:certik</a></li>
<li> fixed issue <a href="https://github.com/jkriege2/JKQtPlotter/pull/45">#45: Build error on mac jkqtfastplotter.cpp:342:28: Variable has incomplete type 'QPainterPath'</a>, thanks to <a href="https://github.com/abdedixit">user:abdedixit</a></li>
<li>fixed: JKQTPColumnConstIterator and JKQTPColumnIterator: getImagePositionX() and getImagePositionY() were switched</li>
<li>renamed/breaking change: renamed JKQTPColorPaletteStyleAndToolsMixin::setPalette() -> JKQTPColorPaletteStyleAndToolsMixin::setColorPalette()</li>
<li>removed/breaking change: removed the usage of some deprecated functions and objects (e.g. QMatrix)</li>
<li>removed/breaking change: removed the overlay elements (derived from JKQTPOverlayElement), which were not very well set up and are more confusing than useful.</li>
@ -29,6 +30,7 @@ Changes, compared to \ref page_whatsnew_V2019_11 "v2019.11" include:
<li>new: added geometric plot objects JKQTPGeoArrow to draw arrows (aka lines with added line-end decorators, also extended JKQTPGeoLine, JKQTPGeoInfiniteLine, JKQTPGeoPolyLines to draw line-end decorator (aka arrows)</li>
<li>new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves</li>
<li>new: a new graph class JKQTPXYFunctionLineGraph draws parametric 2D curves ( \f$ [x,y] = f(t) \f$ ), see \ref JKQTPlotterEvalCurves for an example</li>
<li>new: added several new copy/set-functions to JKQTPDatastore</li>
</ul>
\subsection page_whatsnew_TRUNK_DOWNLOAD trunk: Download

View File

@ -64,9 +64,9 @@ QString JKQTPColumn::getName() const
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPColumn::setImageColumns(size_t __value)
void JKQTPColumn::setImageColumns(size_t imageWidth)
{
imageColumns=__value;
imageColumns=imageWidth;
}
////////////////////////////////////////////////////////////////////////////////////////////////
@ -116,7 +116,7 @@ double *JKQTPColumn::getPointer(size_t n)
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPColumn::copy(double* data, size_t N, size_t offset) {
void JKQTPColumn::copy(const double *data, size_t N, size_t offset) {
if (!datastore) return ;
JKQTPDatastoreItem* it=datastore->getItem(datastoreItem);
if (!it) return;
@ -480,7 +480,7 @@ void JKQTPDatastore::deleteAllPrefixedColumns(QString prefix, bool removeItems)
////////////////////////////////////////////////////////////////////////////////////////////////
quint16 JKQTPDatastore::getColumnChecksum(int column) const
{
return getColumn(column).calculateChecksum();
return columns.value(column, JKQTPColumn()).calculateChecksum();
}
@ -535,18 +535,6 @@ int JKQTPDatastore::ensureColumnNum(const QString& name) {
return static_cast<int>(addColumn(0, name));
}
////////////////////////////////////////////////////////////////////////////////////////////////
JKQTPColumn JKQTPDatastore::getColumn(size_t i) const
{
return columns.value(i, JKQTPColumn());
}
////////////////////////////////////////////////////////////////////////////////////////////////
JKQTPColumn JKQTPDatastore::getColumn(int i) const
{
if (i<0) return JKQTPColumn();
return getColumn(static_cast<size_t>(i));
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::addCopiedItem(JKQTPDatastoreItemFormat dataformat, double* data, size_t columnsnum, size_t rows) {
@ -676,6 +664,17 @@ size_t JKQTPDatastore::addInternalImageColumn(double *data, size_t width, size_t
return col;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::setColumnImageWidth(size_t column, size_t imageWidth)
{
columns[column].setImageColumns(imageWidth);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::setColumnImageHeight(size_t column, size_t imageHeight)
{
columns[column].setImageColumns(columns[column].getRows()/imageHeight);
}
@ -708,6 +707,14 @@ size_t JKQTPDatastore::copyColumn(size_t old_column, const QString& name)
return copyColumn(old_column, 0, 1, name);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::copyColumnData(size_t toColumn, size_t fromColumn)
{
resizeColumn(toColumn, getRows(fromColumn));
std::copy(begin(fromColumn), end(fromColumn), begin(toColumn));
setColumnImageWidth(toColumn, getColumnImageWidth(fromColumn));
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::addLinearColumn(size_t rows, double start, double end, const QString& name) {
@ -1327,10 +1334,30 @@ int JKQTPDatastore::getNextHigherIndex(int column, size_t row) const {
return getNextHigherIndex(static_cast<size_t>(column), row);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::setColumnData(size_t toColumn, const QVector<double> &data)
{
setColumnCopiedData(toColumn, data.data(), data.size());
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::setColumnCopiedData(size_t toColumn, const double *data, size_t N)
{
resizeColumn(toColumn, N);
columns[toColumn].copy(data, N);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::setColumnCopiedImageData(size_t toColumn, const double *data, size_t width, size_t height)
{
setColumnCopiedData(toColumn, data, width*height);
columns[toColumn].setImageColumns(width);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::appendToColumn(size_t column, double value)
{
bool ok=columns[column].getDatastoreItem()->append(columns[column].getDatastoreOffset(), value);
const bool ok=columns[column].getDatastoreItem()->append(columns[column].getDatastoreOffset(), value);
if (!ok) {
QVector<double> old_data=columns[column].copyData();
size_t itemID=addItem(new JKQTPDatastoreItem(1, static_cast<size_t>(old_data.size()+1)));
@ -1342,6 +1369,29 @@ void JKQTPDatastore::appendToColumn(size_t column, double value)
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::resizeColumn(size_t column, size_t new_rows)
{
if (columns[column].getRows()==new_rows) return;
const bool ok=columns[column].getDatastoreItem()->isVector();
if (!ok) {
QVector<double> old_data=columns[column].copyData();
size_t itemID=addItem(new JKQTPDatastoreItem(1, static_cast<size_t>(old_data.size()+1)));
columns[column]=JKQTPColumn(this, columns[column].getName(), itemID, 0);
for (int i=0; i<old_data.size(); i++) {
columns[column].setValue(static_cast<size_t>(i), old_data[i]);
}
}
columns[column].getDatastoreItem()->resize(new_rows);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::resizeImageColumn(size_t column, size_t new_image_width, size_t new_image_height)
{
resizeColumn(column, new_image_width*new_image_height);
columns[column].setImageColumns(new_image_width);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, double value1, double value2)
{
@ -1380,6 +1430,7 @@ void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, size_t colu
appendToColumn(column3,value3);
appendToColumn(column4,value4);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, size_t column3, size_t column4, size_t column5, double value1, double value2, double value3, double value4, double value5)
{
@ -1389,3 +1440,17 @@ void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, size_t colu
appendToColumn(column4,value4);
appendToColumn(column5,value5);
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::getColumnImageWidth(int column) const
{
if (column<0) return 0;
return columns[static_cast<size_t>(column)].getImageColumns();
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::getColumnImageHeight(int column) const
{
if (column<0) return 0;
return columns[static_cast<size_t>(column)].getRows()/columns[static_cast<size_t>(column)].getImageColumns();
}

View File

@ -351,22 +351,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{
*/
size_t addColumnForItem(size_t itemID, size_t columnInItem, const QString& name=QString(""));
/** \brief returns the JKQTPColumn object for the \a i -th column in the store
*
* \warning This function copies the pointers/references to the internal data into a new object.
* Therefore you should delete it as soon as possible and not store the return value over long durations,
* as the data may get moved in the meantime and then the object gets invalid, but is not informed of this fact!
*/
JKQTPColumn getColumn(size_t i) const;
/** \brief returns the JKQTPColumn object for the \a i -th column in the store
*
* \warning This function copies the pointers/references to the internal data into a new object.
* Therefore you should delete it as soon as possible and not store the return value over long durations,
* as the data may get moved in the meantime and then the object gets invalid, but is not informed of this fact!
*/
JKQTPColumn getColumn(int i) const;
/** \brief mutable iterator for columns in the JKQTPDatastore (\c ColumnIterator::first: column number, \c ColumnIterator::second: column data) */
typedef QMap<size_t, JKQTPColumn>::iterator ColumnIterator;
/** \brief constant iterator for columns in the JKQTPDatastore (\c ColumnIterator::first: column number, \c ColumnIterator::second: column data) */
@ -471,9 +456,14 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{
inline double* getColumnPointer(int column, size_t row=0);
/** \brief returns the width of the image, represented by \a column (in row-major ordering).
* Internally this returns the imageColumns or image width, if set in the column */
inline size_t getColumnImageWidth(int column) const;
size_t getColumnImageWidth(int column) const;
/** \brief returns the height of the image, represented by \a column (in row-major ordering) */
inline size_t getColumnImageHeight(int column) const;
size_t getColumnImageHeight(int column) const;
/** \brief sets the height of the image, represented by \a column (in row-major ordering) to \a imageHeight */
void setColumnImageHeight(size_t column, size_t imageHeight);
/** \brief sets the width of the image, represented by \a column (in row-major ordering) to \a imageWidth */
void setColumnImageWidth(size_t column, size_t imageWidth);
/** \brief returns the data checksum of the given column */
quint16 getColumnChecksum(int column) const;
@ -507,6 +497,36 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{
inline void set(size_t column, size_t row, double value);
/** \brief sets the value at position (\c column, \c row). \c column is the logical column and will be mapped to the according memory block internally!) */
inline void set(int column, size_t row, double value);
/** \brief copies the data from \a data into an existing column \a toColumn
*
* \param toColumn target of the copy operation
* \param data data to copy
*
* \warning If the memory in \a toColumn was externally managed before, it will be
* internally managed afterwards!
*/
void setColumnData(size_t toColumn, const QVector<double>& data);
/** \brief copies the data from \a data into an existing column \a toColumn
*
* \param toColumn target of the copy operation
* \param data data to copy
* \param N entries in \a data
*
* \warning If the memory in \a toColumn was externally managed before, it will be
* internally managed afterwards!
*/
void setColumnCopiedData(size_t toColumn, const double* data, size_t N);
/** \brief copies the image data from \a data into an existing column \a toColumn
*
* \param toColumn target of the copy operation
* \param data data to copy, size is \a width * \a height
* \param width number of columns in \a data
* \param height number of rows in \a data
*
* \warning If the memory in \a toColumn was externally managed before, it will be
* internally managed afterwards!
*/
void setColumnCopiedImageData(size_t toColumn, const double* data, size_t width, size_t height);
/** \brief adds a value \a value to the column \a column. This changes the column length (number of rows).
*
* \warning This changes the column length (number of rows). If the memory was externally managed before, it will be internally managed afterwards .
@ -514,6 +534,20 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{
* \see appendToColumns()
*/
void appendToColumn(size_t column, double value);
/** \brief resizes the column \a column to have \a new_rows rows
*
* \warning This changes the column length (number of rows). If the memory was externally managed before, it will be internally managed afterwards .
*
* \see resizeImageColumn(), appendToColumn()
*/
void resizeColumn(size_t column, size_t new_rows);
/** \brief resizes the column \a column to have enough rows to be interpreted as an image of size \a new_image_width * \a new_image_height pixels, also sets the internally store image size in the column!
*
* \warning This changes the column length (number of rows). If the memory was externally managed before, it will be internally managed afterwards .
*
* \see resizeColumn(), appendToColumn()
*/
void resizeImageColumn(size_t column, size_t new_image_width, size_t new_image_height);
/** \brief adds a value \a value1 to the column \a column1 and a value \a value2 to \a column2.
*
* This is equivalent to
@ -776,6 +810,16 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{
* \see \ref JKQTPlotterBasicJKQTPDatastore
*/
size_t copyColumn(size_t old_column, const QString& name=QString(""));
/** \brief copies the data from \a fromColumn into an existing column \a toColumn
*
* \param toColumn target of the copy operation
* \param fromColumn source of the copy operation
*
* \warning If the memory in \a toColumn was externally managed before, it will be
* internally managed afterwards!
*/
void copyColumnData(size_t toColumn, size_t fromColumn);
/** \brief add one column to the datastore. It will be filled with the values from \a first ... \a last
@ -1387,8 +1431,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{
/** \brief stores information about one data column. See JKQTPDatastore for more information.
/** \brief internally stores information about one data column. See JKQTPDatastore for more information.
* \ingroup jkqtpdatastorage
* \internal
*
* \see JKQTPDatastore
*/
@ -1435,7 +1480,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColumn {
QString getName () const;
/*! \copydoc imageColumns */
void setImageColumns (size_t __value);
void setImageColumns (size_t imageWidth);
/*! \copydoc imageColumns */
inline size_t getImageColumns () const { return imageColumns; }
@ -1538,7 +1583,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPColumn {
* This copies \a N elements from \a data into the column where the first overwritten column
* line is \a offset, so you can shift the location where the copy process starts.
*/
void copy(double* data, size_t N, size_t offset=0);
void copy(const double* data, size_t N, size_t offset=0);
/** \brief exchange every occurence of a given \a value by a \a replace value */
void exchange(double value, double replace);
@ -1826,12 +1871,12 @@ class JKQTPColumnIterator {
/** \brief returns the referenced position/row interpreted as an image pixel, x-component, returns -1 for an invalid operator */
inline int getImagePositionX() const {
if (!isValid()) return -1;
return pos_ % static_cast<int>(col_->getImageColumns());
return pos_ / static_cast<int>(col_->getImageColumns());
}
/** \brief returns the referenced position/row interpreted as an image pixel, y-component, returns -1 for an invalid operator */
inline int getImagePositionY() const {
if (!isValid()) return -1;
return pos_ / static_cast<int>(col_->getImageColumns());
return pos_ % static_cast<int>(col_->getImageColumns());
}
/*! \brief if the data in the column is interpreted as an image, this is the number of columns (x-dimension) of the image
\see JKQTPColumn::imageColumns */
@ -2157,12 +2202,12 @@ class JKQTPColumnConstIterator {
/** \brief returns the referenced position/row interpreted as an image pixel, x-component, returns -1 for an invalid operator */
inline int getImagePositionX() const {
if (!isValid()) return -1;
return pos_ % static_cast<int>(col_->getImageColumns());
return pos_ / static_cast<int>(col_->getImageColumns());
}
/** \brief returns the referenced position/row interpreted as an image pixel, y-component, returns -1 for an invalid operator */
inline int getImagePositionY() const {
if (!isValid()) return -1;
return pos_ / static_cast<int>(col_->getImageColumns());
return pos_ % static_cast<int>(col_->getImageColumns());
}
/*! \brief if the data in the column is interpreted as an image, this is the number of columns (x-dimension) of the image
\see JKQTPColumn::imageColumns */
@ -2257,6 +2302,14 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastoreItem {
return dataformat==JKQTPDatastoreItemFormat::SingleColumn && storageType==StorageType::Vector;
}
/** \brief if \c isValid() : resize the row to have \a rows_new rows */
inline void resize(size_t rows_new) {
JKQTPASSERT(isVector());
datavec.resize(rows_new);
rows=static_cast<size_t>(datavec.size());
data=datavec.data();
}
/** \brief if \c isValid() : erase the row \a row */
inline void erase(size_t row) {
JKQTPASSERT(isVector());
@ -2548,20 +2601,6 @@ double *JKQTPDatastore::getColumnPointer(int column, size_t row)
return columns[static_cast<size_t>(column)].getPointer(row);
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::getColumnImageWidth(int column) const
{
if (column<0) return 0;
return columns[static_cast<size_t>(column)].getImageColumns();
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::getColumnImageHeight(int column) const
{
if (column<0) return 0;
return columns[static_cast<size_t>(column)].getRows()/columns[static_cast<size_t>(column)].getImageColumns();
}
////////////////////////////////////////////////////////////////////////////////////////////////
size_t JKQTPDatastore::getRows(int column) const {
if (column<0) return 0;