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

Method headerData

src/backend/matrix/MatrixModel.cpp:101–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101QVariant 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 }

Callers

nothing calls this directly

Calls 4

numericFormatMethod · 0.80
columnCountMethod · 0.45
toStringMethod · 0.45
rowCountMethod · 0.45

Tested by

no test coverage detected