2015-07-11 18:56:02 +08:00
|
|
|
/*
|
2020-08-26 18:58:23 +08:00
|
|
|
Copyright (c) 2008-2020 Jan W. Krieger (<jan@jkrieger.de>)
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2015-07-12 22:34:27 +08:00
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
2019-02-08 00:24:46 +08:00
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
2015-07-11 18:56:02 +08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License (LGPL) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-26 03:25:44 +08:00
|
|
|
#include "jkqtplotter/jkqtpdatastorage.h"
|
2015-07-11 18:56:02 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QtGlobal>
|
2019-05-30 04:47:26 +08:00
|
|
|
#include <limits>
|
2019-05-13 04:22:48 +08:00
|
|
|
#include <cmath>
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
/**************************************************************************************************************************
|
2019-01-20 17:49:29 +08:00
|
|
|
* JKQTPColumn
|
2015-07-11 18:56:02 +08:00
|
|
|
**************************************************************************************************************************/
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPColumn::JKQTPColumn()
|
2018-11-18 18:59:30 +08:00
|
|
|
{
|
|
|
|
datastore=nullptr;
|
|
|
|
name="";
|
|
|
|
datastoreItem=0;
|
|
|
|
datastoreOffset=0;
|
2019-05-13 04:22:48 +08:00
|
|
|
imageColumns=1;
|
2018-11-18 18:59:30 +08:00
|
|
|
valid=false;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-13 04:22:48 +08:00
|
|
|
JKQTPColumn::JKQTPColumn(JKQTPDatastore *datastore, const QString &name, size_t datastoreItem, size_t datastoreOffset, size_t imageColumns)
|
2018-11-18 18:59:30 +08:00
|
|
|
{
|
|
|
|
this->datastore=datastore;
|
|
|
|
this->datastoreItem=datastoreItem;
|
|
|
|
this->datastoreOffset=datastoreOffset;
|
2019-05-13 04:22:48 +08:00
|
|
|
this->imageColumns=imageColumns;
|
2018-11-18 18:59:30 +08:00
|
|
|
this->name=name;
|
|
|
|
valid=true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-13 04:22:48 +08:00
|
|
|
void JKQTPColumn::setName(const QString &__value)
|
|
|
|
{
|
|
|
|
this->name = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
QString JKQTPColumn::getName() const
|
|
|
|
{
|
|
|
|
return this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPColumn::setImageColumns(size_t __value)
|
|
|
|
{
|
|
|
|
imageColumns=__value;
|
|
|
|
}
|
2018-11-18 18:59:30 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPColumn::getRows() const {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!valid || !datastore) return 0;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem* i=datastore->getItem(datastoreItem);
|
2019-01-26 20:00:40 +08:00
|
|
|
if (i) return i->getRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPColumn::copyData(QVector<double> ©To) const
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2018-12-28 22:17:40 +08:00
|
|
|
const double* d=getPointer(0);
|
2015-07-11 18:56:02 +08:00
|
|
|
copyTo.clear();
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t i, cnt=getRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
if (cnt>0) {
|
2018-12-28 22:17:40 +08:00
|
|
|
copyTo.resize(static_cast<int>(cnt));
|
2015-07-11 18:56:02 +08:00
|
|
|
for (i=0; i<cnt; i++) {
|
2019-05-17 14:32:50 +08:00
|
|
|
copyTo[static_cast<int>(i)]=d[i];
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
QVector<double> JKQTPColumn::copyData()
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
QVector<double> d;
|
|
|
|
copyData(d);
|
|
|
|
return d;
|
2015-08-21 19:49:11 +08:00
|
|
|
}
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
const double *JKQTPColumn::getPointer(size_t n) const
|
2018-12-28 22:17:40 +08:00
|
|
|
{
|
|
|
|
if (!datastore) return nullptr;
|
|
|
|
if (!datastore->getItem(datastoreItem)) return nullptr;
|
|
|
|
return datastore->getItem(datastoreItem)->getPointer(datastoreOffset, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
double *JKQTPColumn::getPointer(size_t n)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2018-11-27 05:14:41 +08:00
|
|
|
if (!datastore) return nullptr;
|
|
|
|
if (!datastore->getItem(datastoreItem)) return nullptr;
|
2015-07-11 18:56:02 +08:00
|
|
|
return datastore->getItem(datastoreItem)->getPointer(datastoreOffset, n);
|
2015-08-21 19:49:11 +08:00
|
|
|
}
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2015-08-21 19:49:11 +08:00
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPColumn::copy(double* data, size_t N, size_t offset) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!datastore) return ;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem* it=datastore->getItem(datastoreItem);
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!it) return;
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<N; i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
it->set(datastoreOffset, i+offset, data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPColumn::exchange(double value, double replace)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
if (!datastore) return ;
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<getRows(); i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
double v=getValue(i);
|
|
|
|
if (v==value) v=replace;
|
|
|
|
setValue(i, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPColumn::subtract(double value)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
if (!datastore) return ;
|
|
|
|
double* data=getPointer();
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t N=getRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
if (data){
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<N; i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
data[i]=data[i]-value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPColumn::scale(double factor)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
if (!datastore) return ;
|
|
|
|
double* data=getPointer();
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t N=getRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
if (data){
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<N; i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
data[i]=data[i]*factor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:57:20 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPColumn::setAll(double value)
|
2018-12-11 06:57:20 +08:00
|
|
|
{
|
|
|
|
if (!datastore) return ;
|
|
|
|
double* data=getPointer();
|
|
|
|
size_t N=getRows();
|
|
|
|
if (data){
|
|
|
|
for (size_t i=0; i<N; i++) {
|
|
|
|
data[i]=value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
/**************************************************************************************************************************
|
2019-01-20 17:49:29 +08:00
|
|
|
* JKQTPDatastoreItem
|
2015-07-11 18:56:02 +08:00
|
|
|
**************************************************************************************************************************/
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem::JKQTPDatastoreItem(){
|
2019-05-17 14:32:50 +08:00
|
|
|
this->dataformat=JKQTPDatastoreItemFormat::SingleColumn;
|
2015-07-11 18:56:02 +08:00
|
|
|
this->allocated=false;
|
2018-11-18 18:59:30 +08:00
|
|
|
this->data=nullptr;
|
2015-07-11 18:56:02 +08:00
|
|
|
this->columns=0;
|
|
|
|
this->rows=0;
|
2019-05-17 14:32:50 +08:00
|
|
|
this->storageType=StorageType::Internal;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem::JKQTPDatastoreItem(size_t columns, size_t rows){
|
2019-05-17 14:32:50 +08:00
|
|
|
this->storageType=StorageType::Internal;
|
2015-07-11 18:56:02 +08:00
|
|
|
this->allocated=false;
|
|
|
|
if (columns>1) {
|
2019-05-17 14:32:50 +08:00
|
|
|
this->dataformat=JKQTPDatastoreItemFormat::MatrixRow;
|
2019-01-26 20:00:40 +08:00
|
|
|
this->data=static_cast<double*>(calloc(columns*rows, sizeof(double)));
|
2015-07-11 18:56:02 +08:00
|
|
|
} else {
|
2019-05-17 14:32:50 +08:00
|
|
|
this->dataformat=JKQTPDatastoreItemFormat::SingleColumn;
|
|
|
|
this->storageType=StorageType::Vector;
|
|
|
|
datavec.resize(static_cast<int>(columns*rows));
|
|
|
|
for( double& d: datavec) { d=0.0; }
|
|
|
|
this->data=datavec.data();
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
this->columns=columns;
|
|
|
|
this->rows=rows;
|
|
|
|
this->allocated=true;
|
|
|
|
}
|
|
|
|
|
2019-05-31 20:01:49 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPDatastoreItem::JKQTPDatastoreItem(const QVector<double>& data_)
|
|
|
|
{
|
|
|
|
this->storageType=StorageType::Internal;
|
|
|
|
this->allocated=false;
|
|
|
|
this->dataformat=JKQTPDatastoreItemFormat::SingleColumn;
|
|
|
|
this->storageType=StorageType::Vector;
|
|
|
|
this->datavec=data_;
|
|
|
|
this->data=datavec.data();
|
|
|
|
this->columns=1;
|
|
|
|
this->rows=static_cast<int>(data_.size());
|
|
|
|
this->allocated=true;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
bool JKQTPDatastoreItem::resizeColumns(size_t new_rows) {
|
|
|
|
bool dataRetained=false;
|
|
|
|
if (storageType==StorageType::Internal && allocated && data!=nullptr) {
|
2015-07-11 18:56:02 +08:00
|
|
|
free(data);
|
2018-11-18 18:59:30 +08:00
|
|
|
data=nullptr;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
2019-05-17 14:32:50 +08:00
|
|
|
if (columns>1) {
|
|
|
|
this->dataformat=JKQTPDatastoreItemFormat::MatrixRow;
|
|
|
|
this->data=static_cast<double*>(calloc(columns*new_rows, sizeof(double)));
|
|
|
|
storageType=StorageType::Internal;
|
|
|
|
} else {
|
|
|
|
this->dataformat=JKQTPDatastoreItemFormat::SingleColumn;
|
|
|
|
this->storageType=StorageType::Vector;
|
|
|
|
datavec.resize(static_cast<int>(columns*new_rows));
|
|
|
|
if (new_rows>rows) {
|
|
|
|
for( size_t i=rows; i<new_rows; i++) { datavec[static_cast<int>(i)]=0.0; }
|
|
|
|
}
|
|
|
|
this->data=datavec.data();
|
|
|
|
dataRetained=true;
|
|
|
|
}
|
2015-07-11 18:56:02 +08:00
|
|
|
rows=new_rows;
|
|
|
|
allocated=true;
|
2019-05-17 14:32:50 +08:00
|
|
|
return dataRetained;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem::JKQTPDatastoreItem(JKQTPDatastoreItemFormat dataformat, double* data, size_t columns, size_t rows){
|
2015-07-11 18:56:02 +08:00
|
|
|
this->dataformat=dataformat;
|
|
|
|
this->allocated=true;
|
|
|
|
this->data=data;
|
|
|
|
this->columns=columns;
|
|
|
|
this->rows=rows;
|
2019-05-17 14:32:50 +08:00
|
|
|
this->storageType=StorageType::External;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem::JKQTPDatastoreItem(JKQTPDatastoreItemFormat dataformat, double *data, size_t columns, size_t rows, bool internal)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
this->dataformat=dataformat;
|
|
|
|
this->allocated=true;
|
|
|
|
this->data=data;
|
|
|
|
this->columns=columns;
|
|
|
|
this->rows=rows;
|
2019-05-17 14:32:50 +08:00
|
|
|
this->storageType=internal?StorageType::Internal:StorageType::External;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem::~JKQTPDatastoreItem(){
|
2019-05-17 14:32:50 +08:00
|
|
|
if (storageType==StorageType::Internal && allocated && data!=nullptr) {
|
2015-07-11 18:56:02 +08:00
|
|
|
free(data);
|
2018-11-18 18:59:30 +08:00
|
|
|
data=nullptr;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************************************
|
2019-01-20 17:49:29 +08:00
|
|
|
* JKQTPDatastore
|
2015-07-11 18:56:02 +08:00
|
|
|
**************************************************************************************************************************/
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addItem(JKQTPDatastoreItem* item) {
|
2015-07-11 18:56:02 +08:00
|
|
|
/*items.push_back(item);
|
|
|
|
return items.size()-1;*/
|
|
|
|
items.insert(maxItemID, item);
|
|
|
|
maxItemID++;
|
|
|
|
return maxItemID-1;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addColumn(JKQTPColumn col) {
|
2015-07-11 18:56:02 +08:00
|
|
|
columns.insert(maxColumnsID, col);
|
|
|
|
maxColumnsID++;
|
|
|
|
return maxColumnsID-1;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-30 04:40:02 +08:00
|
|
|
JKQTPDatastore::JKQTPDatastore():
|
|
|
|
m_invalidColumn(new JKQTPColumn)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
maxItemID=0;
|
|
|
|
maxColumnsID=0;
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:22:48 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPDatastore::~JKQTPDatastore() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2019-06-16 18:54:56 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool JKQTPDatastore::hasColumn(size_t i) const
|
|
|
|
{
|
|
|
|
return columns.find(i)!=columns.end();
|
|
|
|
}
|
|
|
|
|
2019-05-30 04:40:02 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPDatastore::ColumnIterator JKQTPDatastore::begin()
|
|
|
|
{
|
|
|
|
return columns.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPDatastore::ColumnIterator JKQTPDatastore::end()
|
|
|
|
{
|
|
|
|
return columns.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPDatastore::ConstColumnIterator JKQTPDatastore::begin() const
|
|
|
|
{
|
|
|
|
return columns.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPDatastore::ConstColumnIterator JKQTPDatastore::end() const
|
|
|
|
{
|
|
|
|
return columns.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnIterator JKQTPDatastore::begin(int i)
|
|
|
|
{
|
|
|
|
if (i<0) return m_invalidColumn->end();
|
|
|
|
auto it=columns.find(static_cast<size_t>(i));
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnIterator JKQTPDatastore::end(int i)
|
|
|
|
{
|
|
|
|
if (i<0) return m_invalidColumn->end();
|
|
|
|
auto it=columns.find(static_cast<size_t>(i));
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnConstIterator JKQTPDatastore::begin(int i) const
|
|
|
|
{
|
|
|
|
if (i<0) return m_invalidColumn->end();
|
|
|
|
auto it=columns.find(static_cast<size_t>(i));
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnConstIterator JKQTPDatastore::end(int i) const
|
|
|
|
{
|
|
|
|
if (i<0) return m_invalidColumn->end();
|
|
|
|
auto it=columns.find(static_cast<size_t>(i));
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnIterator JKQTPDatastore::begin(size_t i)
|
|
|
|
{
|
|
|
|
auto it=columns.find(i);
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnIterator JKQTPDatastore::end(size_t i)
|
|
|
|
{
|
|
|
|
auto it=columns.find(i);
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnConstIterator JKQTPDatastore::begin(size_t i) const
|
|
|
|
{
|
|
|
|
auto it=columns.find(i);
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnConstIterator JKQTPDatastore::end(size_t i) const
|
|
|
|
{
|
|
|
|
auto it=columns.find(i);
|
|
|
|
if (it==columns.end()) return m_invalidColumn->end();
|
|
|
|
else return it->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnBackInserter JKQTPDatastore::backInserter(int i)
|
|
|
|
{
|
2019-05-30 04:47:26 +08:00
|
|
|
if (i<0) return JKQTPColumnBackInserter(this, std::numeric_limits<size_t>::max());
|
|
|
|
auto it=columns.find(static_cast<size_t>(i));
|
|
|
|
if (it==columns.end()) return JKQTPColumnBackInserter(this, std::numeric_limits<size_t>::max());
|
2019-05-30 04:40:02 +08:00
|
|
|
else return JKQTPColumnBackInserter(this, static_cast<size_t>(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JKQTPColumnBackInserter JKQTPDatastore::backInserter(size_t i)
|
|
|
|
{
|
|
|
|
auto it=columns.find(i);
|
|
|
|
if (it==columns.end()) return JKQTPColumnBackInserter(this, std::numeric_limits<size_t>::max());
|
|
|
|
else return JKQTPColumnBackInserter(this, static_cast<size_t>(i));
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPDatastore::clear(){
|
2015-07-11 18:56:02 +08:00
|
|
|
maxItemID=0;
|
|
|
|
maxColumnsID=0;
|
|
|
|
/*if (items.size()>0) {
|
|
|
|
for (size_t i=0; i<items.size(); i++) {
|
|
|
|
delete items[i];
|
|
|
|
}
|
|
|
|
}*/
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPDatastoreItem*> it(items);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
delete it.value();
|
|
|
|
}
|
|
|
|
items.clear();
|
|
|
|
columns.clear();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPDatastore::deleteAllColumns(const QString& name, bool removeItems) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QList<size_t> ids;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-01-26 20:00:40 +08:00
|
|
|
if (it.value().getName()==name) {
|
2015-07-11 18:56:02 +08:00
|
|
|
ids.append(it.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i=0; i<ids.size(); i++) {
|
|
|
|
deleteColumn(ids[i], removeItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPDatastore::deleteAllPrefixedColumns(QString prefix, bool removeItems) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QList<size_t> ids;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-01-26 20:00:40 +08:00
|
|
|
if (it.value().getName().startsWith(prefix)) {
|
2015-07-11 18:56:02 +08:00
|
|
|
ids.append(it.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i=0; i<ids.size(); i++) {
|
|
|
|
deleteColumn(ids[i], removeItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-19 04:41:38 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
quint16 JKQTPDatastore::getColumnChecksum(int column) const
|
|
|
|
{
|
|
|
|
return getColumn(column).calculateChecksum();
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:22:48 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPDatastore::deleteColumn(size_t column, bool removeItems) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (removeItems) {
|
2019-01-26 20:00:40 +08:00
|
|
|
size_t dsitem=columns[column].getDatastoreItemNum();
|
2015-07-11 18:56:02 +08:00
|
|
|
int cnt=0;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-01-26 20:00:40 +08:00
|
|
|
if (it.value().getDatastoreItemNum()==dsitem) {
|
2015-07-11 18:56:02 +08:00
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cnt<=1) {
|
|
|
|
delete items[dsitem];
|
|
|
|
items.remove(dsitem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
columns.remove(column);
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getColumnNum(const QString& name) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (columns.size()<=0) return -1;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-05-11 21:56:11 +08:00
|
|
|
if (it.value().getName()==name) return static_cast<int>(it.key());
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-30 04:40:02 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
QString JKQTPDatastore::getColumnName(size_t column)
|
|
|
|
{
|
|
|
|
auto it=columns.find(column);
|
|
|
|
|
|
|
|
if (it==columns.end()) return "";
|
|
|
|
else return it->getName();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-26 20:00:40 +08:00
|
|
|
int JKQTPDatastore::ensureColumnNum(const QString& name) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (columns.size()<=0) return -1;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-05-11 21:56:11 +08:00
|
|
|
if (it.value().getName()==name) return static_cast<int>(it.key());
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
2019-05-11 21:56:11 +08:00
|
|
|
return static_cast<int>(addColumn(0, name));
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPColumn JKQTPDatastore::getColumn(size_t i) const
|
2015-08-21 19:49:11 +08:00
|
|
|
{
|
2019-05-11 21:56:11 +08:00
|
|
|
return columns.value(i, JKQTPColumn());
|
2015-08-21 19:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPColumn JKQTPDatastore::getColumn(int i) const
|
2018-12-16 21:59:39 +08:00
|
|
|
{
|
2019-05-11 21:56:11 +08:00
|
|
|
if (i<0) return JKQTPColumn();
|
|
|
|
return getColumn(static_cast<size_t>(i));
|
2018-12-16 21:59:39 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addCopiedItem(JKQTPDatastoreItemFormat dataformat, double* data, size_t columnsnum, size_t rows) {
|
|
|
|
JKQTPDatastoreItem* it=nullptr;
|
2019-05-17 14:32:50 +08:00
|
|
|
if ((dataformat==JKQTPDatastoreItemFormat::SingleColumn)||(columnsnum==1)) {
|
2015-07-11 18:56:02 +08:00
|
|
|
return addCopiedItem(data, rows);
|
2019-05-17 14:32:50 +08:00
|
|
|
} else if (dataformat==JKQTPDatastoreItemFormat::MatrixColumn) {
|
2019-01-20 17:49:29 +08:00
|
|
|
it=new JKQTPDatastoreItem(columnsnum, rows);
|
2015-07-11 18:56:02 +08:00
|
|
|
for (size_t c=0; c<columnsnum; c++) {
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t r=0; r<rows; r++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
it->set(c, r, data[c*rows+r]);
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 14:32:50 +08:00
|
|
|
} else if (dataformat==JKQTPDatastoreItemFormat::MatrixColumn) {
|
2019-01-20 17:49:29 +08:00
|
|
|
it=new JKQTPDatastoreItem(columnsnum, rows);
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t r=0; r<rows; r++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
for (size_t c=0; c<columnsnum; c++) {
|
|
|
|
it->set(c, r, data[r*columnsnum+c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*items.push_back(it);
|
|
|
|
return items.size()-1;*/
|
|
|
|
return addItem(it);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addItem(size_t rows) {
|
|
|
|
/*items.push_back(new JKQTPDatastoreItem(1, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
return items.size()-1;*/
|
2019-01-20 17:49:29 +08:00
|
|
|
return addItem(new JKQTPDatastoreItem(1, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
};
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addItem(size_t columnsnum, size_t rows) {
|
|
|
|
/*items.push_back(new JKQTPDatastoreItem(columnsnum, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
return items.size()-1;*/
|
2019-01-20 17:49:29 +08:00
|
|
|
return addItem(new JKQTPDatastoreItem(columnsnum, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief add one external column to the datastore. It contains \a rows rows.*/
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addItem(double* data, size_t rows) {
|
|
|
|
/*items.push_back(new JKQTPDatastoreItem(JKQTPSingleColumn, data, 1, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
return items.size()-1;*/
|
2019-05-17 14:32:50 +08:00
|
|
|
return addItem(new JKQTPDatastoreItem(JKQTPDatastoreItemFormat::SingleColumn, data, 1, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addInternalItem(double *data, size_t rows)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2019-05-17 14:32:50 +08:00
|
|
|
JKQTPDatastoreItem* dsi=new JKQTPDatastoreItem(JKQTPDatastoreItemFormat::SingleColumn, data, 1, rows, true);
|
2015-07-11 18:56:02 +08:00
|
|
|
return addItem(dsi);
|
|
|
|
};
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addItem(JKQTPDatastoreItemFormat dataformat, double* data, size_t columnsnum, size_t rows) {
|
|
|
|
/*items.push_back(new JKQTPDatastoreItem(dataformat, data, columnsnum, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
return items.size()-1;*/
|
2019-01-20 17:49:29 +08:00
|
|
|
return addItem(new JKQTPDatastoreItem(dataformat, data, columnsnum, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
};
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addCopiedItem(const double* data, size_t rows) {
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows);
|
2015-07-11 18:56:02 +08:00
|
|
|
if (data) {
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<rows; i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
it->set(0, i, data[i]);
|
|
|
|
//std::cout<<"copy@"<<i<<" = "<<data[i]<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*items.push_back(it);
|
|
|
|
return items.size()-1;*/
|
|
|
|
return addItem(it);
|
|
|
|
};
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addColumnForItem(size_t itemID, size_t columnInItem, const QString& name) {
|
|
|
|
return addColumn(JKQTPColumn(this, name, itemID, columnInItem));
|
2015-07-11 18:56:02 +08:00
|
|
|
};
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addColumn(size_t rows, const QString& name) {
|
|
|
|
size_t item= addItem(new JKQTPDatastoreItem(1, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
return addColumnForItem(item, 0, name);
|
|
|
|
};
|
|
|
|
|
2019-05-30 04:40:02 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addColumn(const QString& name) {
|
|
|
|
return addColumn(0, name);
|
|
|
|
};
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addColumn(double* data, size_t rows, const QString& name) {
|
2019-05-17 14:32:50 +08:00
|
|
|
size_t it=addItem(new JKQTPDatastoreItem(JKQTPDatastoreItemFormat::SingleColumn, data, 1, rows));
|
2015-07-11 18:56:02 +08:00
|
|
|
return addColumnForItem(it, 0, name);
|
|
|
|
};
|
2018-12-28 22:17:40 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addInternalColumn(double* data, size_t rows, const QString& name) {
|
2019-05-17 14:32:50 +08:00
|
|
|
size_t it=addItem(new JKQTPDatastoreItem(JKQTPDatastoreItemFormat::SingleColumn, data, 1, rows,true));
|
2015-07-11 18:56:02 +08:00
|
|
|
return addColumnForItem(it, 0, name);
|
2019-05-13 04:22:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addImageColumn(size_t width, size_t height, const QString &name)
|
|
|
|
{
|
|
|
|
size_t col= addColumn(width*height, name);
|
|
|
|
columns[col].setImageColumns(width);
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addImageColumn(double *data, size_t width, size_t height, const QString &name)
|
|
|
|
{
|
|
|
|
size_t col= addColumn(data, width*height, name);
|
|
|
|
columns[col].setImageColumns(width);
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addInternalImageColumn(double *data, size_t width, size_t height, const QString &name)
|
|
|
|
{
|
|
|
|
size_t col= addInternalColumn(data, width*height, name);
|
|
|
|
columns[col].setImageColumns(width);
|
|
|
|
return col;
|
|
|
|
}
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-02 19:36:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::copyColumn(size_t old_column, size_t start, size_t stride, const QString& name)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPColumn old=columns[old_column];
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t rows=old.getRows();
|
2019-01-26 20:00:40 +08:00
|
|
|
double* d=static_cast<double*>(malloc(rows*sizeof(double)));
|
2015-07-11 18:56:02 +08:00
|
|
|
double* dd=old.getPointer(0);
|
2019-05-17 14:32:50 +08:00
|
|
|
size_t j=0;
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=start; i<rows; i+=stride) {
|
2015-07-11 18:56:02 +08:00
|
|
|
d[j]=dd[i];
|
|
|
|
//qDebug()<<old_column<<name<<": "<<j<<i<<d[j];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
size_t n=addCopiedColumn(d, j, name);
|
|
|
|
free(d);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::copyColumn(size_t old_column, const QString& name)
|
2015-08-02 19:36:54 +08:00
|
|
|
{
|
|
|
|
return copyColumn(old_column, 0, 1, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
size_t JKQTPDatastore::addLinearColumn(size_t rows, double start, double end, const QString& name) {
|
2019-01-26 20:00:40 +08:00
|
|
|
double delta=(end-start)/static_cast<double>(rows-1);
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows);
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<rows; i++) {
|
2019-01-26 19:28:44 +08:00
|
|
|
it->set(0, i, start+static_cast<double>(i) * delta);
|
2015-07-11 18:56:02 +08:00
|
|
|
//std::cout<<"copy@"<<i<<" = "<<data[i]<<std::endl;
|
|
|
|
}
|
|
|
|
/*items.push_back(it);
|
|
|
|
size_t itemid=items.size()-1;*/
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:22:48 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addLogColumn(size_t rows, double start, double end, const QString &name)
|
|
|
|
{
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows);
|
2020-08-26 17:43:44 +08:00
|
|
|
const double x0=log(start)/JKQTPSTATISTICS_LN10;
|
|
|
|
const double x1=log(end)/JKQTPSTATISTICS_LN10;
|
2019-05-13 04:22:48 +08:00
|
|
|
for (size_t i=0; i<rows; i++) {
|
|
|
|
it->set(0, i, pow(10.0, x0+static_cast<double>(i)/static_cast<double>(rows-1)*(x1-x0)));
|
|
|
|
}
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addDecadeLogColumn(size_t rows, double startDecade, double endDecade, const QString &name)
|
|
|
|
{
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows);
|
|
|
|
const double x0=startDecade;
|
|
|
|
const double x1=endDecade;
|
|
|
|
for (size_t i=0; i<rows; i++) {
|
|
|
|
it->set(0, i, pow(10.0, x0+static_cast<double>(i)/static_cast<double>(rows-1)*(x1-x0)));
|
|
|
|
}
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
std::pair<size_t, size_t> JKQTPDatastore::addLinearGridColumns(size_t width, double startX, double endX, size_t height, double startY, double endY, const QString &nameX, const QString &nameY)
|
|
|
|
{
|
|
|
|
const double decX=(endX-startX)/static_cast<double>(width-1);
|
|
|
|
const double decY=(endY-startY)/static_cast<double>(height-1);
|
|
|
|
double y=startY;
|
|
|
|
size_t cx=addColumn(width*height, nameX);
|
|
|
|
size_t cy=addColumn(width*height, nameY);
|
|
|
|
size_t i=0;
|
|
|
|
for (size_t iy=0; iy<height; iy++) {
|
|
|
|
double x=startX;
|
|
|
|
for (size_t ix=0; ix<width; ix++) {
|
|
|
|
set(cx, i, x);
|
|
|
|
set(cy, i, y);
|
|
|
|
x+=decX;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
y+=decY;
|
|
|
|
}
|
|
|
|
return std::make_pair(cx,cy);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addCalculatedColumn(size_t rows, const std::function<double (size_t, JKQTPDatastore *)> &f, const QString &name)
|
|
|
|
{
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows);
|
|
|
|
for (size_t i=0; i<rows; i++) {
|
|
|
|
it->set(0, i, f(i, this));
|
|
|
|
}
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addCalculatedColumn(size_t rows, const std::function<double (size_t)> &f, const QString &name)
|
|
|
|
{
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows);
|
|
|
|
for (size_t i=0; i<rows; i++) {
|
|
|
|
it->set(0, i, f(i));
|
|
|
|
}
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
* reworked color-palette-system:
1. added several new (JKQTPMathImageBone, JKQTPMathImageCool, JKQTPMathImageCopper, JKQTPMathImageAutumn, JKQTPMathImageSeismic, JKQTPMathImageTerrain, JKQTPMathImageViridis, JKQTPMathImageMagma, JKQTPMathImageInferno, JKQTPMathImagePlasma)
2. reworked LUT-types (now a QVector, instead of a C-array, suing malloc)
3. reworked available functions to build LUTs (cleanup, more options, clearer names)
4. added functions to load palettes from files
5. Improved documentation
* added example for user-controlled color palettes
2019-07-28 20:59:09 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addCalculatedImageColumn(size_t cols, size_t rows, const std::function<double (size_t, size_t)> &f, const QString &name)
|
|
|
|
{
|
|
|
|
size_t col=addImageColumn(cols, rows, name);
|
|
|
|
JKQTPColumn& colref = columns[col];
|
|
|
|
for (size_t y=0; y<rows; y++) {
|
|
|
|
for (size_t x=0; x<cols; x++) {
|
|
|
|
colref.setPixelValue(x, y, f(x,y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return col;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:22:48 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addColumnCalculatedFromColumn(size_t otherColumn, const std::function<double (double)> &f, const QString &name)
|
|
|
|
{
|
|
|
|
const JKQTPColumn& oc=columns.value(otherColumn);
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, oc.getRows());
|
|
|
|
for (size_t i=0; i<oc.getRows(); i++) {
|
|
|
|
it->set(0, i, f(oc.getValue(i)));
|
|
|
|
}
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t JKQTPDatastore::addColumnCalculatedFromColumn(size_t otherColumnX, size_t otherColumnY, const std::function<double (double, double)> &f, const QString &name)
|
|
|
|
{
|
|
|
|
const JKQTPColumn& ocx=columns.value(otherColumnX);
|
|
|
|
const JKQTPColumn& ocy=columns.value(otherColumnY);
|
|
|
|
const size_t N= qMin(ocx.getRows(), ocy.getRows());
|
|
|
|
JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, N);
|
|
|
|
for (size_t i=0; i<N; i++) {
|
|
|
|
it->set(0, i, f(ocx.getValue(i), ocy.getValue(i)));
|
|
|
|
}
|
|
|
|
size_t itemid= addItem(it);
|
|
|
|
return addColumnForItem(itemid, 0, name);
|
|
|
|
}
|
|
|
|
|
2019-05-17 14:32:50 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
QVector<int> JKQTPDatastore::getColumnIDsIntVec() const {
|
|
|
|
QVector<int> ks;
|
|
|
|
for (const size_t& k: columns.keys()) {
|
|
|
|
ks<<static_cast<int>(k);
|
|
|
|
}
|
|
|
|
return ks;
|
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextLowerIndex(size_t column, size_t row, int start, int end) const
|
2015-08-21 19:49:11 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
const JKQTPColumn& col=columns[column];
|
2015-08-21 19:49:11 +08:00
|
|
|
if (start<0 && end>=0) return getNextLowerIndex(column, row, 0, end);
|
2019-05-17 14:32:50 +08:00
|
|
|
else if (start>=0 && end<0) return getNextLowerIndex(column, row, start, static_cast<int>(col.getRows())-1);
|
|
|
|
else if (start<0 && end<0) return getNextLowerIndex(column, row, 0, static_cast<int>(col.getRows())-1);
|
2015-08-21 19:49:11 +08:00
|
|
|
else {
|
|
|
|
double d=0;
|
|
|
|
const double v=col.getValue(row);
|
2018-12-16 21:59:39 +08:00
|
|
|
int res=-1;
|
|
|
|
for ( int i=start; i<=end; i++) {
|
2019-01-26 20:00:40 +08:00
|
|
|
if (i!=static_cast<int>(row)) {
|
2015-08-21 19:49:11 +08:00
|
|
|
const double v1=col.getValue(i);
|
|
|
|
const double dd=v1-v;
|
|
|
|
if ((dd<0) && ((fabs(dd)<d)||(d==0.0))) {
|
|
|
|
res=i;
|
|
|
|
d=fabs(dd);
|
|
|
|
//std::cout<<" getNextLowerIndex("<<column<<", "<<row<<", "<<start<<", "<<end<<"): i="<<i<<": OK res="<<res<<" d="<<d<<"\n";
|
|
|
|
} /*else {
|
|
|
|
std::cout<<" getNextLowerIndex("<<column<<", "<<row<<", "<<start<<", "<<end<<"): i="<<i<<": FAIL res="<<res<<" dd="<<dd<<" v1="<<v1<<" v="<<v<<"\n";
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextLowerIndex(size_t column, size_t row) const
|
2015-08-21 19:49:11 +08:00
|
|
|
{
|
2019-05-17 14:32:50 +08:00
|
|
|
return getNextLowerIndex(column, row, 0, static_cast<int>(columns[column].getRows())-1);
|
2015-08-21 19:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextHigherIndex(size_t column, size_t row, int start, int end) const
|
2015-08-21 19:49:11 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
const JKQTPColumn& col=columns[column];
|
2015-08-21 19:49:11 +08:00
|
|
|
if (start<0 && end>=0) return getNextHigherIndex(column, row, 0, end);
|
2019-05-17 14:32:50 +08:00
|
|
|
else if (start>=0 && end<0) return getNextHigherIndex(column, row, start, static_cast<int>(col.getRows())-1);
|
|
|
|
else if (start<0 && end<0) return getNextHigherIndex(column, row, 0, static_cast<int>(col.getRows())-1);
|
2015-08-21 19:49:11 +08:00
|
|
|
else {
|
|
|
|
double d=0;
|
|
|
|
const double v=col.getValue(row);
|
2018-12-16 21:59:39 +08:00
|
|
|
int res=-1;
|
|
|
|
for ( int i=start; i<=end; i++) {
|
2019-01-26 20:00:40 +08:00
|
|
|
if (i!=static_cast<int>(row)) {
|
2015-08-21 19:49:11 +08:00
|
|
|
const double v1=col.getValue(i);
|
|
|
|
const double dd=v1-v;
|
|
|
|
if ((dd>0) && ((fabs(dd)<d)||(d==0.0))) {
|
|
|
|
res=i;
|
|
|
|
d=fabs(dd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextHigherIndex(size_t column, size_t row) const
|
2015-08-21 19:49:11 +08:00
|
|
|
{
|
2019-05-17 14:32:50 +08:00
|
|
|
return getNextHigherIndex(column, row, 0, static_cast<int>(columns[column].getRows())-1);
|
2015-08-21 19:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextLowerIndex(int column, size_t row, int start, int end) const {
|
2018-12-16 21:59:39 +08:00
|
|
|
return getNextLowerIndex(static_cast<size_t>(column), row, start, end);
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextLowerIndex(int column, size_t row) const {
|
2018-12-16 21:59:39 +08:00
|
|
|
return getNextLowerIndex(static_cast<size_t>(column), row);
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextHigherIndex(int column, size_t row, int start, int end) const {
|
2018-12-16 21:59:39 +08:00
|
|
|
return getNextHigherIndex(static_cast<size_t>(column), row, start, end);
|
2015-08-21 19:49:11 +08:00
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
|
2018-12-16 21:59:39 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
size_t JKQTPDatastore::getMaxRows() const {
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t res=0;
|
2015-07-11 18:56:02 +08:00
|
|
|
/*for (size_t i=0; i<columns.size(); i++) {
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t r=columns[i].getRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
if (r>res) res=r;
|
|
|
|
}*/
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t r=it.value().getRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
if (r>res) res=r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
void JKQTPDatastore::saveCSV(const QString& filename, const QSet<int>& userColumns, const QString& separator, const QString& decimal_separator, const QString& comment, const QString& aroundStrings, char floatformat) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
//std::cout<<filename<<"\n";
|
|
|
|
|
|
|
|
// find out the decimal and the thousand separator
|
|
|
|
QLocale loc=QLocale::c();
|
|
|
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
2015-08-02 19:36:54 +08:00
|
|
|
//QChar dsep=loc.decimalPoint();
|
2015-07-11 18:56:02 +08:00
|
|
|
QFile f(filename);
|
|
|
|
if (!f.open(QIODevice::WriteOnly|QIODevice::Text)) return;
|
|
|
|
QTextStream txt(&f);
|
|
|
|
saveCSV(txt, userColumns, separator, decimal_separator, comment, aroundStrings, floatformat);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
void JKQTPDatastore::saveMatlab(const QString& filename, const QSet<int>& userColumns) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
//std::cout<<filename<<"\n";
|
|
|
|
|
|
|
|
// find out the decimal and the thousand separator
|
|
|
|
QLocale loc=QLocale::c();
|
|
|
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
2015-08-02 19:36:54 +08:00
|
|
|
//QChar dsep=loc.decimalPoint();
|
2015-07-11 18:56:02 +08:00
|
|
|
QFile f(filename);
|
|
|
|
if (!f.open(QIODevice::WriteOnly|QIODevice::Text)) return;
|
|
|
|
QTextStream txt(&f);
|
|
|
|
saveMatlab(txt, userColumns);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
QStringList JKQTPDatastore::getColumnNames() const {
|
2015-07-11 18:56:02 +08:00
|
|
|
QStringList names;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
int col=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-01-26 20:00:40 +08:00
|
|
|
names.append(it.value().getName());
|
2015-07-11 18:56:02 +08:00
|
|
|
col++;
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
void JKQTPDatastore::saveMatlab(QTextStream &txt, const QSet<int>& userColumns) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
//std::cout<<filename<<"\n";
|
|
|
|
|
|
|
|
// find out the decimal and the thousand separator
|
|
|
|
QLocale loc=QLocale::c();
|
|
|
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
|
|
|
QSet<QString> varnames;
|
|
|
|
|
|
|
|
|
|
|
|
txt.setLocale(loc);
|
|
|
|
/* if (comment.size()>0) {
|
|
|
|
txt<<comment<<" ";
|
|
|
|
bool first=true;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (!first) txt<<separator;
|
2019-01-26 20:00:40 +08:00
|
|
|
txt<<aroundStrings<<it.value().getName()<<aroundStrings;
|
2015-07-11 18:56:02 +08:00
|
|
|
first=false;
|
|
|
|
}
|
|
|
|
txt<<"\n";
|
|
|
|
}*/
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
int col=0;
|
|
|
|
int i=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(i)) {
|
|
|
|
|
|
|
|
// convert the column name into a variable name (name cleanup!) If the column name is empty, we use a default name ("column")
|
2019-01-26 20:00:40 +08:00
|
|
|
QString newvarbase=jkqtp_to_valid_variable_name(it.value().getName().toStdString()).c_str();
|
2015-07-11 18:56:02 +08:00
|
|
|
if (newvarbase.isEmpty()) newvarbase="column";
|
|
|
|
int cnt=1;
|
|
|
|
QString newvar=newvarbase;
|
|
|
|
// now we make sure that the name is not already used, i.e. we compare it to all variable names used so far and if it has already been used,
|
|
|
|
// an increasing number is added to the name.
|
|
|
|
while (varnames.contains(newvar)) {
|
|
|
|
newvar=newvarbase+QString::number(cnt);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
varnames.insert(newvar);
|
2019-01-26 20:00:40 +08:00
|
|
|
txt<<QString("% data from columne %1 ('%2')\n").arg(col+1).arg(it.value().getName());
|
2015-07-11 18:56:02 +08:00
|
|
|
txt<<QString("%1 = [ ").arg(newvar);
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<it.value().getRows(); i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
txt<<loc.toString(get(it.key(), i))<<" ";
|
|
|
|
|
|
|
|
}
|
|
|
|
txt<<"];\n\n";
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
void JKQTPDatastore::saveCSV(QTextStream& txt, const QSet<int>& userColumns, const QString& separator, const QString& decimal_separator, const QString& comment, const QString& aroundStrings, char floatformat) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
//std::cout<<filename<<"\n";
|
|
|
|
|
|
|
|
// find out the decimal and the thousand separator
|
|
|
|
QLocale loc=QLocale::c();
|
|
|
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
|
|
|
QChar dsep=loc.decimalPoint();
|
|
|
|
|
|
|
|
|
|
|
|
txt.setLocale(loc);
|
|
|
|
if (comment.size()>0) {
|
|
|
|
txt<<comment<<" ";
|
|
|
|
bool first=true;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
int i=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(i)) {
|
|
|
|
if (!first) txt<<separator;
|
2019-01-26 20:00:40 +08:00
|
|
|
txt<<aroundStrings<<it.value().getName()<<aroundStrings;
|
2015-07-11 18:56:02 +08:00
|
|
|
first=false;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
txt<<"\n";
|
|
|
|
}
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t rows=getMaxRows();
|
|
|
|
for (size_t i=0; i<rows; i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
bool first=true;
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
int j=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(j)) {
|
|
|
|
if (!first) txt<<separator;
|
|
|
|
first=false;
|
|
|
|
if (it.value().getRows()>i) {
|
|
|
|
QString num=QString("%1").arg(get(it.key(), i), 0, floatformat);
|
|
|
|
num=num.replace(dsep, decimal_separator);
|
|
|
|
txt<<num;
|
|
|
|
}
|
|
|
|
//std::cout<<"("<<i<<", "<<c<<")\n";
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
txt<<"\n";
|
|
|
|
}
|
|
|
|
txt<<"\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
void JKQTPDatastore::saveSYLK(const QString& filename, const QSet<int>& userColumns, const QString& floatformat) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
Q_UNUSED(floatformat)
|
|
|
|
// find out the decimal and the thousand separator
|
|
|
|
QLocale loc=QLocale::c();
|
|
|
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
2015-08-02 19:36:54 +08:00
|
|
|
//QChar dsep=loc.decimalPoint();
|
2015-07-11 18:56:02 +08:00
|
|
|
QFile f(filename);
|
|
|
|
if (!f.open(QIODevice::WriteOnly|QIODevice::Text)) return;
|
|
|
|
QTextStream txt(&f);
|
|
|
|
txt.setLocale(loc);
|
|
|
|
// write SYLK header
|
|
|
|
txt<<"ID;P\n";
|
|
|
|
|
|
|
|
// write column headers
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
size_t c=1;
|
|
|
|
int i=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(i)) {
|
2019-01-26 20:00:40 +08:00
|
|
|
txt<<"C;Y1;X"<<c<<";K\""<<it.value().getName()<<"\"\n";
|
2015-07-11 18:56:02 +08:00
|
|
|
txt<<"F;Y1;X"<<c<<";SDB\n";
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t rows=getMaxRows();
|
|
|
|
for (size_t i=0; i<rows; i++) {
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
c=1;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2019-05-17 14:32:50 +08:00
|
|
|
if (userColumns.isEmpty() || userColumns.contains(static_cast<int>(i))) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (it.value().getRows()>i) {
|
|
|
|
txt<<QString("C;X%1;Y%2;N;K%3\n").arg(c).arg(i+2).arg(get(it.key(), i));
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
txt<<"E\n\n";
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
QList<QVector<double> > JKQTPDatastore::getData(QStringList *columnNames, const QSet<int>& userColumns) const
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
QStringList cl;
|
|
|
|
QList<QVector<double> > res;
|
|
|
|
|
|
|
|
// write column headers
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
size_t c=1;
|
|
|
|
int i=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(i)) {
|
|
|
|
QVector<double> dat;
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<it.value().getRows(); i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
dat<<it.value().getValue(i);
|
|
|
|
}
|
|
|
|
|
2019-01-26 20:00:40 +08:00
|
|
|
cl<<it.value().getName();
|
2015-07-11 18:56:02 +08:00
|
|
|
res<<dat;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (columnNames) *columnNames=cl;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-06-16 18:54:56 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
QVector<double> JKQTPDatastore::getData(size_t column, QString *columnName) const
|
|
|
|
{
|
|
|
|
QVector<double> res;
|
|
|
|
if (hasColumn(column)) {
|
|
|
|
if (columnName) *columnName=columns.value(column).getName();
|
|
|
|
columns.value(column).copyData(res);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-05-17 14:32:50 +08:00
|
|
|
void JKQTPDatastore::saveDIF(const QString& filename, const QSet<int>& userColumns, const QString& floatformat) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
Q_UNUSED(floatformat)
|
|
|
|
// find out the decimal and the thousand separator
|
|
|
|
QLocale loc=QLocale::c();
|
|
|
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
2015-08-02 19:36:54 +08:00
|
|
|
//QChar dsep=loc.decimalPoint();
|
2015-07-11 18:56:02 +08:00
|
|
|
QFile f(filename);
|
|
|
|
if (!f.open(QIODevice::WriteOnly|QIODevice::Text)) return;
|
|
|
|
QTextStream txt(&f);
|
|
|
|
txt.setLocale(loc);
|
2018-11-18 18:59:30 +08:00
|
|
|
size_t rows=getMaxRows();
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
// write DIF header
|
|
|
|
txt<<QString("TABLE\n0,1\n\"\"\n");
|
|
|
|
if (userColumns.isEmpty()) txt<<QString("VECTORS\n0,%1\n\"\"\n").arg(columns.size());
|
|
|
|
else txt<<QString("VECTORS\n0,%1\n\"\"\n").arg(userColumns.size());
|
|
|
|
txt<<QString("TUPLES\n0,%1\n\"\"\n").arg(rows);
|
|
|
|
|
|
|
|
txt<<QString("-1,0\nBOT\n");
|
|
|
|
|
|
|
|
// write column headers
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
size_t c=1;
|
|
|
|
int i=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(i)) {
|
2019-01-26 20:00:40 +08:00
|
|
|
txt<<QString("1,0\n\"%1\"\n").arg(columns[c].getName());
|
2015-07-11 18:56:02 +08:00
|
|
|
c++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-18 18:59:30 +08:00
|
|
|
for (size_t i=0; i<rows; i++) {
|
2015-07-11 18:56:02 +08:00
|
|
|
txt<<QString("-1,0\nBOT\n");
|
2019-01-20 17:49:29 +08:00
|
|
|
QMapIterator<size_t, JKQTPColumn> it(columns);
|
2015-07-11 18:56:02 +08:00
|
|
|
c=1;
|
|
|
|
int j=0;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (userColumns.isEmpty() || userColumns.contains(j)) {
|
|
|
|
//qDebug()<<i<<"/"<<rows<<", "<<c;
|
|
|
|
if (i<it.value().getRows()) {
|
|
|
|
txt<<QString("0,%1\nV\n").arg(get(it.key(), i));
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
txt<<"-1,0\nEOT\n";
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreModel::JKQTPDatastoreModel(JKQTPDatastore *datastore, QObject *parent):
|
2015-07-11 18:56:02 +08:00
|
|
|
QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
this->datastore=datastore;
|
|
|
|
reloadModel();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastoreModel::~JKQTPDatastoreModel()
|
2019-01-26 19:28:44 +08:00
|
|
|
= default;
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
QVariant JKQTPDatastoreModel::data(const QModelIndex &index, int role) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
int row=index.row();
|
|
|
|
int column=index.column();
|
|
|
|
if (datastore) {
|
|
|
|
if (role==Qt::DisplayRole || role==Qt::EditRole) {
|
2019-05-17 14:32:50 +08:00
|
|
|
int col=static_cast<int>(datastore->getColumnIDsIntVec().value(column, -1));
|
2019-05-13 04:22:48 +08:00
|
|
|
if (col>-1 && row>=0 && row<static_cast<int>(datastore->getRows(col))) {
|
2018-12-28 22:17:40 +08:00
|
|
|
return datastore->get(col, static_cast<size_t>(row));
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
Qt::ItemFlags JKQTPDatastoreModel::flags(const QModelIndex &/*index*/) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
QVariant JKQTPDatastoreModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (datastore) {
|
|
|
|
if (role==Qt::DisplayRole) {
|
|
|
|
if (orientation==Qt::Horizontal) {
|
2019-01-26 20:00:40 +08:00
|
|
|
if (section>=0 && section<static_cast<int64_t>(datastore->getColumnCount())) {
|
2015-07-11 18:56:02 +08:00
|
|
|
//qDebug()<<"columns: "<<datastore->getColumnNames().size()<<datastore->getColumnIDs().size()<<": "<<datastore->getColumnNames();
|
|
|
|
return datastore->getColumnNames().value(section);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return QString::number(section+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastoreModel::rowCount(const QModelIndex &/*parent*/) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (datastore) {
|
2018-12-28 22:17:40 +08:00
|
|
|
return static_cast<int>(datastore->getMaxRows());
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastoreModel::columnCount(const QModelIndex &/*parent*/) const {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (datastore) {
|
2018-12-28 22:17:40 +08:00
|
|
|
return static_cast<int>(datastore->getColumnCount());
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPDatastoreModel::reloadModel()
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
|
|
|
#else
|
|
|
|
reset();
|
|
|
|
#endif
|
|
|
|
}
|
2018-12-16 21:59:39 +08:00
|
|
|
|
2018-12-28 22:17:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-01-20 17:49:29 +08:00
|
|
|
int JKQTPDatastore::getNextHigherIndex(int column, size_t row) const {
|
2018-12-16 21:59:39 +08:00
|
|
|
return getNextHigherIndex(static_cast<size_t>(column), row);
|
|
|
|
}
|
2019-06-12 19:06:53 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPDatastore::appendToColumn(size_t column, double value)
|
|
|
|
{
|
|
|
|
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)));
|
|
|
|
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].setValue(static_cast<size_t>(old_data.size()), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, double value1, double value2)
|
|
|
|
{
|
|
|
|
appendToColumn(column1,value1);
|
|
|
|
appendToColumn(column2,value2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPDatastore::appendToColumns(size_t columnX, size_t columnY, const QPointF& value)
|
|
|
|
{
|
|
|
|
appendToColumn(columnX,value.x());
|
|
|
|
appendToColumn(columnY,value.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPDatastore::appendToColumns(size_t columnX, size_t columnY, const QPoint& value)
|
|
|
|
{
|
|
|
|
appendToColumn(columnX,value.x());
|
|
|
|
appendToColumn(columnY,value.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, size_t column3, double value1, double value2, double value3)
|
|
|
|
{
|
|
|
|
appendToColumn(column1,value1);
|
|
|
|
appendToColumn(column2,value2);
|
|
|
|
appendToColumn(column3,value3);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void JKQTPDatastore::appendToColumns(size_t column1, size_t column2, size_t column3, size_t column4, double value1, double value2, double value3, double value4)
|
|
|
|
{
|
|
|
|
appendToColumn(column1,value1);
|
|
|
|
appendToColumn(column2,value2);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
appendToColumn(column1,value1);
|
|
|
|
appendToColumn(column2,value2);
|
|
|
|
appendToColumn(column3,value3);
|
|
|
|
appendToColumn(column4,value4);
|
|
|
|
appendToColumn(column5,value5);
|
|
|
|
}
|