MCPcopy Create free account
hub / github.com/KDE/labplot / loadMatrix

Method loadMatrix

src/backend/datasources/projects/OriginProjectParser.cpp:1180–1234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1178}
1179
1180bool OriginProjectParser::loadMatrix(Matrix* matrix, bool preview, size_t sheetIndex, const QString& mwbName) {
1181 DEBUG(Q_FUNC_INFO)
1182 // import matrix data
1183 const auto& originMatrix = m_originFile->matrix(findMatrixByName(mwbName));
1184
1185 if (preview)
1186 return true;
1187
1188 // in Origin column width is measured in characters, we need to convert to pixels
1189 // TODO: determine the font used in Origin in order to get the same column width as in Origin
1190 QFont font;
1191 QFontMetrics fm(font);
1192 const int scaling_factor = fm.maxWidth();
1193
1194 const auto& layer = originMatrix.sheets.at(sheetIndex);
1195 const int colCount = layer.columnCount;
1196 const int rowCount = layer.rowCount;
1197
1198 matrix->setRowCount(rowCount);
1199 matrix->setColumnCount(colCount);
1200 matrix->setFormula(QString::fromStdString(layer.command));
1201
1202 // TODO: how to handle different widths for different columns?
1203 for (int j = 0; j < colCount; j++)
1204 matrix->setColumnWidth(j, layer.width * scaling_factor);
1205
1206 // TODO: check column major vs. row major to improve the performance here
1207 for (int i = 0; i < rowCount; i++) {
1208 for (int j = 0; j < colCount; j++)
1209 matrix->setCell(i, j, layer.data[j + i * colCount]);
1210 }
1211
1212 char format = 'g';
1213 // TODO: prec not support by Matrix
1214 // int prec = 6;
1215 switch (layer.valueTypeSpecification) {
1216 case 0: // Decimal 1000
1217 format = 'f';
1218 // prec = layer.decimalPlaces;
1219 break;
1220 case 1: // Scientific
1221 format = 'e';
1222 // prec = layer.decimalPlaces;
1223 break;
1224 case 2: // Engineering
1225 case 3: // Decimal 1,000
1226 format = 'g';
1227 // prec = layer.significantDigits;
1228 break;
1229 }
1230
1231 matrix->setNumericFormat(format);
1232
1233 return true;
1234}
1235
1236bool OriginProjectParser::loadWorksheet(Worksheet* worksheet, bool preview) {
1237 DEBUG(Q_FUNC_INFO << ", preview = " << preview)

Callers

nothing calls this directly

Calls 6

setRowCountMethod · 0.45
setColumnCountMethod · 0.45
setFormulaMethod · 0.45
setColumnWidthMethod · 0.45
setCellMethod · 0.45
setNumericFormatMethod · 0.45

Tested by

no test coverage detected