| 99 | } |
| 100 | |
| 101 | QVariant MatrixModel::headerData(int section, Qt::Orientation orientation, int role) const { |
| 102 | QString result; |
| 103 | auto headerFormat = m_matrix->headerFormat(); |
| 104 | const auto numberLocale = QLocale(); |
| 105 | switch (orientation) { |
| 106 | case Qt::Horizontal: |
| 107 | switch (role) { |
| 108 | case Qt::DisplayRole: |
| 109 | case Qt::ToolTipRole: |
| 110 | if (headerFormat == Matrix::HeaderFormat::HeaderRowsColumns) { |
| 111 | result = QString::number(section + 1); |
| 112 | } else if (headerFormat == Matrix::HeaderFormat::HeaderValues) { |
| 113 | double diff = m_matrix->xEnd() - m_matrix->xStart(); |
| 114 | double step = 0.0; |
| 115 | if (m_matrix->columnCount() > 1) |
| 116 | step = diff / double(m_matrix->columnCount() - 1); |
| 117 | result = numberLocale.toString(m_matrix->xStart() + double(section) * step, m_matrix->numericFormat(), m_matrix->precision()); |
| 118 | } else { |
| 119 | result = QString::number(section + 1) + QLatin1String(" ("); |
| 120 | double diff = m_matrix->xEnd() - m_matrix->xStart(); |
| 121 | double step = 0.0; |
| 122 | if (m_matrix->columnCount() > 1) |
| 123 | step = diff / double(m_matrix->columnCount() - 1); |
| 124 | result += numberLocale.toString(m_matrix->xStart() + double(section) * step, m_matrix->numericFormat(), m_matrix->precision()); |
| 125 | |
| 126 | result += QLatin1Char(')'); |
| 127 | } |
| 128 | return {result}; |
| 129 | } |
| 130 | break; |
| 131 | case Qt::Vertical: |
| 132 | switch (role) { |
| 133 | case Qt::DisplayRole: |
| 134 | case Qt::ToolTipRole: |
| 135 | if (headerFormat == Matrix::HeaderFormat::HeaderRowsColumns) { |
| 136 | result = QString::number(section + 1); |
| 137 | } else if (headerFormat == Matrix::HeaderFormat::HeaderValues) { |
| 138 | double diff = m_matrix->yEnd() - m_matrix->yStart(); |
| 139 | double step = 0.0; |
| 140 | if (m_matrix->rowCount() > 1) |
| 141 | step = diff / double(m_matrix->rowCount() - 1); |
| 142 | // TODO: implement decent double == 0 check |
| 143 | // if (diff < 1e-10) |
| 144 | // result += numberLocale.toString(m_matrix->yStart(), |
| 145 | // m_matrix->numericFormat(), m_matrix->displayedDigits()); |
| 146 | result += numberLocale.toString(m_matrix->yStart() + double(section) * step, m_matrix->numericFormat(), m_matrix->precision()); |
| 147 | } else { |
| 148 | result = QString::number(section + 1) + QStringLiteral(" ("); |
| 149 | double diff = m_matrix->yEnd() - m_matrix->yStart(); |
| 150 | double step = 0.0; |
| 151 | if (m_matrix->rowCount() > 1) |
| 152 | step = diff / double(m_matrix->rowCount() - 1); |
| 153 | |
| 154 | result += numberLocale.toString(m_matrix->yStart() + double(section) * step, m_matrix->numericFormat(), m_matrix->precision()); |
| 155 | result += QLatin1Char(')'); |
| 156 | } |
| 157 | return {result}; |
| 158 | } |
nothing calls this directly
no test coverage detected