| 562 | } |
| 563 | |
| 564 | QVariant SpreadsheetModel::color(const AbstractColumn* column, int row, AbstractColumn::Formatting type) const { |
| 565 | if (!column->hasHeatmapFormat() || (!column->isNumeric() && column->columnMode() != AbstractColumn::ColumnMode::Text) || !column->isValid(row)) |
| 566 | return {}; |
| 567 | |
| 568 | const auto& format = column->heatmapFormat(); |
| 569 | if (format.type != type || format.colors.isEmpty()) |
| 570 | return {}; |
| 571 | |
| 572 | int index = 0; |
| 573 | if (column->isNumeric()) { |
| 574 | double value = column->valueAt(row); |
| 575 | double range = (format.max - format.min) / format.colors.count(); |
| 576 | |
| 577 | if (value > format.max) |
| 578 | index = format.colors.count() - 1; |
| 579 | else { |
| 580 | for (int i = 0; i < format.colors.count(); ++i) { |
| 581 | if (value <= format.min + (i + 1) * range) { |
| 582 | index = i; |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } else { |
| 588 | index = column->dictionaryIndex(row); |
| 589 | } |
| 590 | |
| 591 | if (index < format.colors.count()) |
| 592 | return {QColor(format.colors.at(index))}; |
| 593 | else |
| 594 | return {QColor(format.colors.constLast())}; |
| 595 | } |