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

Method exportToFile

src/frontend/matrix/MatrixView.cpp:1169–1196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1167}
1168
1169void MatrixView::exportToFile(const QString& path, const QString& separator, QLocale::Language language) const {
1170 QFile file(path);
1171 if (!file.open(QFile::WriteOnly | QFile::Truncate))
1172 return;
1173
1174 QTextStream out(&file);
1175
1176 QString sep = separator;
1177 sep = sep.replace(QLatin1String("TAB"), QLatin1String("\t"), Qt::CaseInsensitive);
1178 sep = sep.replace(QLatin1String("SPACE"), QLatin1String(" "), Qt::CaseInsensitive);
1179
1180 // export values
1181 const int cols = m_matrix->columnCount();
1182 const int rows = m_matrix->rowCount();
1183 const auto* data = static_cast<QVector<QVector<double>>*>(m_matrix->data());
1184 // TODO: use general setting for number locale?
1185 QLocale locale(language);
1186 for (int row = 0; row < rows; ++row) {
1187 for (int col = 0; col < cols; ++col) {
1188 out << locale.toString(data->at(col)[row], m_matrix->numericFormat(), m_matrix->precision());
1189
1190 out << data->at(col)[row];
1191 if (col != cols - 1)
1192 out << sep;
1193 }
1194 out << QLatin1Char('\n');
1195 }
1196}
1197
1198void MatrixView::exportToLaTeX(const QString& path,
1199 const bool verticalHeaders,

Callers 1

mainFunction · 0.45

Calls 7

replaceMethod · 0.80
numericFormatMethod · 0.80
openMethod · 0.45
columnCountMethod · 0.45
rowCountMethod · 0.45
dataMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected