| 121 | } |
| 122 | |
| 123 | QVariant SpreadsheetModel::data(const QModelIndex& index, int role) const { |
| 124 | if (!index.isValid()) |
| 125 | return {}; |
| 126 | |
| 127 | const int row = index.row(); |
| 128 | const int col = index.column(); |
| 129 | const Column* col_ptr = m_spreadsheet->column(col); |
| 130 | |
| 131 | if (!col_ptr) |
| 132 | return {}; |
| 133 | |
| 134 | switch (role) { |
| 135 | case Qt::ToolTipRole: |
| 136 | if (col_ptr->isValid(row)) { |
| 137 | if (col_ptr->isMasked(row)) |
| 138 | return {i18n("%1, masked (ignored in all operations)", col_ptr->asStringColumn()->textAt(row))}; |
| 139 | else |
| 140 | return {col_ptr->asStringColumn()->textAt(row)}; |
| 141 | } else { |
| 142 | if (col_ptr->isMasked(row)) |
| 143 | return {i18n("invalid cell, masked (ignored in all operations)")}; |
| 144 | else |
| 145 | return {i18n("invalid cell (ignored in all operations)")}; |
| 146 | } |
| 147 | case Qt::EditRole: |
| 148 | if (col_ptr->columnMode() == AbstractColumn::ColumnMode::Double) { |
| 149 | double value = col_ptr->valueAt(row); |
| 150 | if (std::isnan(value)) |
| 151 | return {QStringLiteral("-")}; |
| 152 | else if (std::isinf(value)) |
| 153 | return {QStringLiteral("inf")}; |
| 154 | else |
| 155 | return {col_ptr->asStringColumn()->textAt(row)}; |
| 156 | } |
| 157 | |
| 158 | if (col_ptr->isValid(row)) |
| 159 | return {col_ptr->asStringColumn()->textAt(row)}; |
| 160 | |
| 161 | // m_formula_mode is not used at the moment |
| 162 | // if (m_formula_mode) |
| 163 | // return QVariant(col_ptr->formula(row)); |
| 164 | |
| 165 | break; |
| 166 | case Qt::DisplayRole: |
| 167 | if (col_ptr->columnMode() == AbstractColumn::ColumnMode::Double) { |
| 168 | double value = col_ptr->valueAt(row); |
| 169 | if (std::isnan(value)) |
| 170 | return {QStringLiteral("-")}; |
| 171 | else if (std::isinf(value)) |
| 172 | return {UTF8_QSTRING("∞")}; |
| 173 | else |
| 174 | return {col_ptr->asStringColumn()->textAt(row)}; |
| 175 | } |
| 176 | |
| 177 | if (!col_ptr->isValid(row)) |
| 178 | return {QStringLiteral("-")}; |
| 179 | |
| 180 | // m_formula_mode is not used at the moment |
no test coverage detected