void TvmBarDataProxy::generate(const QSet<qint64>& rowKeys, int rowCount, int tvmRowIndex) { qDebug() << "qps::TvmBarDataProxy::generate(): tvm=" << _tvm.data(); if ( !getTvm() ) { resetArray(nullptr); return; } if ( tvmRowIndex >= rowCount ) { qWarning() << "qps::TvmBarDataProxy::generate(): Warning: row >= rowCount."; return; } // Generate empty rows for all tvms (ie for rowCount) QBarDataArray* barDataArray = new QBarDataArray{}; barDataArray->reserve(rowCount); for ( int r = 0; r < rowCount; r++ ) barDataArray->append(new QBarDataRow{}); // Generate a row with rowKeys.size() columns for the TVM QBarDataRow* tvmBarDataRow = new QBarDataRow(rowKeys.size()); auto i = _tvm->getMap().constBegin(); while ( i != _tvm->getMap().constEnd() ) { QSet<qint64>::const_iterator rowIndexIter = rowKeys.find(i.key()); if ( rowIndexIter != rowKeys.constEnd()) { int rowIndex = std::distance(rowKeys.cbegin(), rowIndexIter); if ( rowIndex >= 0 && rowIndex < tvmBarDataRow->size() ) (*tvmBarDataRow)[rowIndex].setValue( static_cast<float>(i.value())); } ++i; } barDataArray->replace(tvmRowIndex, tvmBarDataRow); // Finnaly replace empty tvm row with the tvm data row resetArray(barDataArray); }
void CQ3DBarsModifier::loadData(const CDataArray * pData, unsigned int rowIndex, unsigned int colIndex) { bool isOneDimensional = pData->dimensionality() == 1; std::vector<size_t> types = pData->size(); size_t numRows = types.size() > rowIndex ? types[rowIndex] : 0; size_t numCols = isOneDimensional ? 1 : types.size() > colIndex ? types[colIndex] : 0; CArrayInterface::index_type mSelectedCell; mSelectedCell.resize(pData->dimensionality()); QBarDataArray *dataSet = new QBarDataArray; QBarDataRow *dataRow; QStringList rowHeaders; QStringList colheaders; std::vector<std::string> rowdescr = pData->getAnnotationsString(rowIndex); for (auto it : rowdescr) rowHeaders << FROM_UTF8(it); if (!isOneDimensional) { std::vector<std::string> coldescr = pData->getAnnotationsString(colIndex); for (auto it : coldescr) colheaders << FROM_UTF8(it); } double maxValue = std::numeric_limits<double>::min(); double minValue = std::numeric_limits<double>::max(); dataSet->reserve(numRows); for (size_t row = 0; row < numRows; row++) { // Create a data row dataRow = new QBarDataRow(numCols); for (size_t col = 0; col < numCols; col++) { mSelectedCell[rowIndex] = row; if (!isOneDimensional) mSelectedCell[colIndex] = col; double value = (double)(*pData->array())[mSelectedCell]; if (isnan(value) || !finite(value)) { value = 0; } if (value > maxValue) maxValue = value; if (value < minValue) minValue = value; // Add data to the row (*dataRow)[col].setValue(value); } // Add the row to the set dataSet->append(dataRow); } m_valueAxis->setRange(minValue, maxValue); // Add data to the data proxy (the data proxy assumes ownership of it) m_primarySeries->dataProxy()->resetArray(dataSet, rowHeaders, colheaders); mRowHeaders = rowHeaders; mColHeaders = colheaders; }