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

Method exportToLaTeX

src/frontend/spreadsheet/SpreadsheetView.cpp:4063–4399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4061}
4062
4063void SpreadsheetView::exportToLaTeX(const QString& path,
4064 const bool exportHeaders,
4065 const bool gridLines,
4066 const bool captions,
4067 const bool latexHeaders,
4068 const bool skipEmptyRows,
4069 const bool exportEntire) const {
4070 QFile file(path);
4071 if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
4072 RESET_CURSOR;
4073 QMessageBox::critical(nullptr, i18n("Failed to export"), i18n("Failed to write to '%1'. Please check the path.", path));
4074 return;
4075 }
4076
4077 QList<Column*> toExport;
4078 int cols;
4079 int totalRowCount = 0;
4080 if (exportEntire) {
4081 cols = const_cast<SpreadsheetView*>(this)->m_spreadsheet->columnCount();
4082 totalRowCount = m_spreadsheet->rowCount();
4083 for (int col = 0; col < cols; ++col)
4084 toExport << m_spreadsheet->column(col);
4085 } else {
4086 cols = const_cast<SpreadsheetView*>(this)->selectedColumnCount(false /* partial selection */);
4087 const int firtsSelectedCol = const_cast<SpreadsheetView*>(this)->firstSelectedColumn();
4088 bool rowsCalculated = false;
4089 for (int col = firtsSelectedCol; col < firtsSelectedCol + cols; ++col) {
4090 QVector<QString> textData;
4091 for (int row = 0; row < m_spreadsheet->rowCount(); ++row) {
4092 if (const_cast<SpreadsheetView*>(this)->isRowSelected(row)) {
4093 textData << m_spreadsheet->column(col)->asStringColumn()->textAt(row);
4094 if (!rowsCalculated)
4095 totalRowCount++;
4096 }
4097 }
4098 if (!rowsCalculated)
4099 rowsCalculated = true;
4100 Column* column = new Column(m_spreadsheet->column(col)->name(), textData);
4101 toExport << column;
4102 }
4103 }
4104 int columnsStringSize = 0;
4105 int columnsPerTable = 0;
4106
4107 for (int i = 0; i < cols; ++i) {
4108 int maxSize = -1;
4109 for (int j = 0; j < toExport.at(i)->asStringColumn()->rowCount(); ++j) {
4110 if (toExport.at(i)->asStringColumn()->textAt(j).size() > maxSize)
4111 maxSize = toExport.at(i)->asStringColumn()->textAt(j).size();
4112 }
4113 columnsStringSize += maxSize;
4114 if (!toExport.at(i)->isValid(0))
4115 columnsStringSize += 3;
4116 if (columnsStringSize > 65)
4117 break;
4118 ++columnsPerTable;
4119 }
4120

Callers

nothing calls this directly

Calls 15

safeExecutableNameFunction · 0.85
startHostProcessFunction · 0.85
asStringColumnMethod · 0.80
splitMethod · 0.80
QStringClass · 0.50
openMethod · 0.45
columnCountMethod · 0.45
rowCountMethod · 0.45
columnMethod · 0.45
selectedColumnCountMethod · 0.45
firstSelectedColumnMethod · 0.45
isRowSelectedMethod · 0.45

Tested by

no test coverage detected