bool ImportOPJ::importTables(OPJFile opj) { for (int s=0; s<opj.numSpreads(); s++) { int nr_cols = opj.numCols(s); int maxrows = opj.maxRows(s); Table *table = mw->newTable(opj.spreadName(s), maxrows, nr_cols); if (!table) return false; for (int j=0; j<nr_cols; j++) { QString name(opj.colName(s,j)); table->setColName(j, name.replace(QRegExp(".*_"),"")); if (QString(opj.colType(s,j)) == "X") table->setColPlotDesignation(j, Table::X); else if (QString(opj.colType(s,j)) == "Y") table->setColPlotDesignation(j, Table::Y); else if (QString(opj.colType(s,j)) == "Z") table->setColPlotDesignation(j, Table::Z); else table->setColPlotDesignation(j, Table::None); for (int i=0; i<opj.numRows(s,j); i++) { double val = opj.Data(s,j)[i]; if(fabs(val) > 2e-300 || val == 0) table->setText(i, j, QString::number(val)); } } table->showNormal(); } return true; }
bool ImportOPJ::importTables(const OPJFile &opj) { int visible_count = 0; int QtiPlot_scaling_factor = 10; // in Origin width is measured in characters // while in QtiPlot - pixels --- need to be // accurate for (int s = 0; s < opj.numSpreads(); s++) { int nr_cols = opj.numCols(s); int maxrows = opj.maxRows(s); if (!nr_cols) // remove tables without cols continue; Table *table = (opj.spreadHidden(s) || opj.spreadLoose(s)) && opj.Version() == 7.5 ? mw->newHiddenTable(opj.spreadName(s), opj.spreadLabel(s), maxrows, nr_cols) : mw->newTable(opj.spreadName(s), maxrows, nr_cols); if (!table) return false; rect windowRect; if (opj.Version() == 7.5) { windowRect = opj.spreadWindowRect(s); table->resize(windowRect.width() - (table->frameGeometry().width() - table->width()), windowRect.height() - (table->frameGeometry().height() - table->height())); } table->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.spreadTitle(s)); table->setBirthDate(JulianDateTime2String(opj.spreadCreationDate(s))); QLocale locale = mw->locale(); table->setWindowLabel(opj.spreadLabel(s)); for (int j = 0; j < nr_cols; j++) { QString name(opj.colName(s, j)); table->setColName(j, name.replace(QRegExp(".*_"), "")); table->setCommand(j, QString(opj.colCommand(s, j))); table->setColComment(j, QString(opj.colComment(s, j))); table->setColumnWidth(j, opj.colWidth(s, j) * QtiPlot_scaling_factor); switch (opj.colType(s, j)) { case X: table->setColPlotDesignation(j, Table::X); break; case Y: table->setColPlotDesignation(j, Table::Y); break; case Z: table->setColPlotDesignation(j, Table::Z); break; case XErr: table->setColPlotDesignation(j, Table::xErr); break; case YErr: table->setColPlotDesignation(j, Table::yErr); break; case Label: table->setColPlotDesignation(j, Table::Label); break; default: table->setColPlotDesignation(j, Table::None); } table->setHeaderColType(); // update header double **d_cells = new double *[nr_cols]; for (int i = 0; i < nr_cols; ++i) d_cells[i] = new double[table->numRows()]; for (int i = 0; i < opj.numRows(s, j); i++) { if (opj.colType(s, j) != Label && opj.colValueType(s, j) != 1) { // number double *val = (double *)opj.oData(s, j, i, true); if (fabs(*val) > 0 && fabs(*val) < 2.0e-300) // empty entry continue; table->setText(i, j, locale.toString(*val, 'g', 16)); d_cells[j][i] = *val; } else // label? doesn't seem to work table->setText(i, j, QString((char *)opj.oData(s, j, i))); } table->saveToMemory(d_cells); QString format; int f = 0; switch (opj.colValueType(s, j)) { case 0: // Numeric case 6: // Text&Numeric if (opj.colNumDisplayType(s, j) == 0) f = 0; else switch (opj.colValueTypeSpec(s, j)) { case 0: // Decimal 1000 f = 1; break; case 1: // Scientific f = 2; break; case 2: // Engeneering case 3: // Decimal 1,000 f = 0; break; } table->setColNumericFormat(f, opj.colDecPlaces(s, j), j); break; case 1: // Text table->setTextFormat(j); break; case 2: // Date switch (opj.colValueTypeSpec(s, j)) { case -128: format = "dd/MM/yyyy"; break; case -119: format = "dd/MM/yyyy HH:mm"; break; case -118: format = "dd/MM/yyyy HH:mm:ss"; break; case 0: case 9: case 10: format = "dd.MM.yyyy"; break; case 2: format = "MMM d"; break; case 3: format = "M/d"; break; case 4: format = "d"; break; case 5: case 6: format = "ddd"; break; case 7: format = "yyyy"; break; case 8: format = "yy"; break; case 11: case 12: case 13: case 14: case 15: format = "yyMMdd"; break; case 16: case 17: format = "MMM"; break; case 19: format = "M-d-yyyy"; break; default: format = "dd.MM.yyyy"; } table->setDateFormat(format, j); break; case 3: // Time switch (opj.colValueTypeSpec(s, j) + 128) { case 0: format = "hh:mm"; break; case 1: format = "hh"; break; case 2: format = "hh:mm:ss"; break; case 3: format = "hh:mm:ss.zzz"; break; case 4: format = "hh ap"; break; case 5: format = "hh:mm ap"; break; case 6: format = "mm:ss"; break; case 7: format = "mm:ss.zzz"; break; case 8: format = "hhmm"; break; case 9: format = "hhmmss"; break; case 10: format = "hh:mm:ss.zzz"; break; } table->setTimeFormat(format, j); break; case 4: // Month switch (opj.colValueTypeSpec(s, j)) { case 0: format = "MMM"; break; case 1: format = "MMMM"; break; case 2: format = "M"; break; } table->setMonthFormat(format, j); break; case 5: // Day switch (opj.colValueTypeSpec(s, j)) { case 0: format = "ddd"; break; case 1: format = "dddd"; break; case 2: format = "d"; break; } table->setDayFormat(format, j); break; } table->freeMemory(); } if (!(opj.spreadHidden(s) || opj.spreadLoose(s)) || opj.Version() != 7.5) { switch (opj.spreadState(s)) { case originWindow::Minimized: mw->minimizeWindow(table); break; case originWindow::Maximized: mw->maximizeWindow(table); break; default: table->showNormal(); } // cascade the tables if (opj.Version() == 7.5) { table->move(QPoint(windowRect.left, windowRect.top)); } else { int dx = table->verticalHeaderWidth(); int dy = table->frameGeometry().height() - table->height(); table->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET, visible_count * dy)); visible_count++; } } } // Import matrices for (int s = 0; s < opj.numMatrices(); s++) { int nr_cols = opj.numMatrixCols(s); int nr_rows = opj.numMatrixRows(s); Matrix *matrix = mw->newMatrix(opj.matrixName(s), nr_rows, nr_cols); if (!matrix) return false; rect windowRect; if (opj.Version() == 7.5) { windowRect = opj.matrixWindowRect(s); matrix->resize(windowRect.width() - (matrix->frameGeometry().width() - matrix->width()), windowRect.height() - (matrix->frameGeometry().height() - matrix->height())); } matrix->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.matrixTitle(s)); matrix->setBirthDate(JulianDateTime2String(opj.matrixCreationDate(s))); matrix->setWindowLabel(opj.matrixLabel(s)); matrix->setFormula(opj.matrixFormula(s)); matrix->setColumnsWidth(opj.matrixWidth(s) * QtiPlot_scaling_factor); if (opj.matrixViewType(s) == matrix::ImageView) matrix->setViewType(Matrix::ImageView); if (opj.matrixHeaderViewType(s) == matrix::XY) matrix->setHeaderViewType(Matrix::XY); vector<double> data = opj.matrixData(s); double *matrix_data = matrix->matrixModel()->dataVector(); int size = matrix->numRows() * matrix->numCols(); int cell = 0; for (int i = 0; i < size; i++) { double val = data[cell]; if (val < 2.0e-300) val = GSL_NAN; matrix_data[cell] = val; cell++; } QChar format; switch (opj.matrixValueTypeSpec(s)) { case 0: // Decimal 1000 format = 'f'; break; case 1: // Scientific format = 'e'; break; case 2: // Engeneering case 3: // Decimal 1,000 format = 'g'; break; } matrix->setNumericFormat(format, opj.matrixSignificantDigits(s)); if (!opj.matrixHidden(s) || opj.Version() != 7.5) { switch (opj.matrixState(s)) { case originWindow::Minimized: mw->minimizeWindow(matrix); break; case originWindow::Maximized: mw->maximizeWindow(matrix); break; default: matrix->showNormal(); } // cascade the matrices if (opj.Version() == 7.5) matrix->move(QPoint(windowRect.left, windowRect.top)); else { int dx = matrix->verticalHeaderWidth(); int dy = matrix->frameGeometry().height() - matrix->height(); matrix->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET, visible_count * dy)); visible_count++; } } } if (visible_count > 0) xoffset++; return true; }