| 1039 | */ |
| 1040 | |
| 1041 | void MatrixView::print(QPrinter* printer) const { |
| 1042 | WAIT_CURSOR; |
| 1043 | QPainter painter(printer); |
| 1044 | |
| 1045 | const int dpiy = printer->logicalDpiY(); |
| 1046 | const int margin = (int)((1 / GSL_CONST_CGS_INCH) * dpiy); // 1 cm margins |
| 1047 | |
| 1048 | QHeaderView* hHeader = m_tableView->horizontalHeader(); |
| 1049 | QHeaderView* vHeader = m_tableView->verticalHeader(); |
| 1050 | auto* data = static_cast<QVector<QVector<double>>*>(m_matrix->data()); |
| 1051 | |
| 1052 | const int rows = m_matrix->rowCount(); |
| 1053 | const int cols = m_matrix->columnCount(); |
| 1054 | int height = margin; |
| 1055 | const int vertHeaderWidth = vHeader->width(); |
| 1056 | int right = margin + vertHeaderWidth; |
| 1057 | |
| 1058 | int columnsPerTable = 0; |
| 1059 | int headerStringWidth = 0; |
| 1060 | int firstRowStringWidth = vertHeaderWidth; |
| 1061 | bool tablesNeeded = false; |
| 1062 | QVector<int> firstRowCeilSizes; |
| 1063 | firstRowCeilSizes.reserve(data[0].size()); |
| 1064 | firstRowCeilSizes.resize(data[0].size()); |
| 1065 | QRect br; |
| 1066 | |
| 1067 | for (int i = 0; i < data->size(); ++i) { |
| 1068 | br = painter.boundingRect(br, Qt::AlignCenter, QString::number(data->at(i)[0]) + QLatin1Char('\t')); |
| 1069 | firstRowCeilSizes[i] = br.width() > m_tableView->columnWidth(i) ? br.width() : m_tableView->columnWidth(i); |
| 1070 | } |
| 1071 | const int width = printer->pageLayout().paintRectPixels(printer->resolution()).width() - 2 * margin; |
| 1072 | for (int col = 0; col < cols; ++col) { |
| 1073 | headerStringWidth += m_tableView->columnWidth(col); |
| 1074 | br = painter.boundingRect(br, Qt::AlignCenter, QString::number(data->at(col)[0]) + QLatin1Char('\t')); |
| 1075 | firstRowStringWidth += br.width(); |
| 1076 | if ((headerStringWidth >= width) || (firstRowStringWidth >= width)) { |
| 1077 | tablesNeeded = true; |
| 1078 | break; |
| 1079 | } |
| 1080 | columnsPerTable++; |
| 1081 | } |
| 1082 | |
| 1083 | int tablesCount = (columnsPerTable != 0) ? cols / columnsPerTable : 0; |
| 1084 | const int remainingColumns = (columnsPerTable != 0) ? cols % columnsPerTable : cols; |
| 1085 | |
| 1086 | if (!tablesNeeded) { |
| 1087 | tablesCount = 1; |
| 1088 | columnsPerTable = cols; |
| 1089 | } |
| 1090 | if (remainingColumns > 0) |
| 1091 | tablesCount++; |
| 1092 | for (int table = 0; table < tablesCount; ++table) { |
| 1093 | // Paint the horizontal header first |
| 1094 | painter.setFont(hHeader->font()); |
| 1095 | QString headerString = m_tableView->model()->headerData(0, Qt::Horizontal).toString(); |
| 1096 | QRect br; |
| 1097 | br = painter.boundingRect(br, Qt::AlignCenter, headerString); |
| 1098 | QRect tr(br); |
nothing calls this directly
no test coverage detected