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

Method print

src/frontend/spreadsheet/SpreadsheetView.cpp:3855–3972  ·  view source on GitHub ↗

! prints the complete spreadsheet to \c printer. */

Source from the content-addressed store, hash-verified

3853 prints the complete spreadsheet to \c printer.
3854 */
3855void SpreadsheetView::print(QPrinter* printer) const {
3856 WAIT_CURSOR;
3857 QPainter painter(printer);
3858
3859 const int dpiy = printer->logicalDpiY();
3860 const int margin = (int)((1 / GSL_CONST_CGS_INCH) * dpiy); // 1 cm margins
3861
3862 QHeaderView* hHeader = m_tableView->horizontalHeader();
3863 QHeaderView* vHeader = m_tableView->verticalHeader();
3864
3865 const int rows = m_spreadsheet->rowCount();
3866 const int cols = m_spreadsheet->columnCount();
3867 int height = margin;
3868 const int vertHeaderWidth = vHeader->width();
3869 const int width = printer->pageLayout().paintRectPixels(printer->resolution()).width() - 2 * margin;
3870
3871 int columnsPerTable = 0;
3872 int headerStringWidth = 0;
3873 int firstRowStringWidth = 0;
3874 bool tablesNeeded = false;
3875 for (int col = 0; col < cols; ++col) {
3876 headerStringWidth += m_tableView->columnWidth(col);
3877 firstRowStringWidth += m_spreadsheet->column(col)->asStringColumn()->textAt(0).length();
3878 if ((headerStringWidth >= width) || (firstRowStringWidth >= width)) {
3879 tablesNeeded = true;
3880 break;
3881 }
3882 columnsPerTable++;
3883 }
3884
3885 int tablesCount = (columnsPerTable != 0) ? cols / columnsPerTable : 0;
3886 const int remainingColumns = (columnsPerTable != 0) ? cols % columnsPerTable : cols;
3887
3888 if (!tablesNeeded) {
3889 tablesCount = 1;
3890 columnsPerTable = cols;
3891 }
3892
3893 if (remainingColumns > 0)
3894 tablesCount++;
3895 // Paint the horizontal header first
3896 for (int table = 0; table < tablesCount; ++table) {
3897 int right = margin + vertHeaderWidth;
3898
3899 painter.setFont(hHeader->font());
3900 QString headerString = m_tableView->model()->headerData(0, Qt::Horizontal).toString();
3901 QRect br;
3902 br = painter.boundingRect(br, Qt::AlignCenter, headerString);
3903 QRect tr(br);
3904 if (table != 0)
3905 height += tr.height();
3906 painter.drawLine(right, height, right, height + br.height());
3907
3908 int i = table * columnsPerTable;
3909 int toI = table * columnsPerTable + columnsPerTable;
3910 if ((remainingColumns > 0) && (table == tablesCount - 1)) {
3911 i = (tablesCount - 1) * columnsPerTable;
3912 toI = (tablesCount - 1) * columnsPerTable + remainingColumns;

Callers

nothing calls this directly

Calls 15

lengthMethod · 0.80
asStringColumnMethod · 0.80
fontMethod · 0.80
heightMethod · 0.80
setHeightMethod · 0.80
rowCountMethod · 0.45
columnCountMethod · 0.45
widthMethod · 0.45
columnWidthMethod · 0.45
textAtMethod · 0.45
columnMethod · 0.45
setFontMethod · 0.45

Tested by

no test coverage detected