| 15 | #include <QWidget> |
| 16 | |
| 17 | void SparkLineRunnable::run() { |
| 18 | if (col->columnMode() != Column::ColumnMode::Text && !col->isPlottable()) { |
| 19 | mPixmap = QPixmap(1, 1); |
| 20 | mPixmap.fill(QColor(49, 54, 59)); |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | static const QString sparklineTheme = QStringLiteral("Sparkline"); |
| 25 | static const QString sparklineText = QStringLiteral("add-sparkline"); |
| 26 | |
| 27 | auto* worksheet = new Worksheet(sparklineText); |
| 28 | worksheet->setUndoAware(false); |
| 29 | worksheet->setUseViewSize(true); |
| 30 | worksheet->setLayoutBottomMargin(0); |
| 31 | worksheet->setLayoutTopMargin(0); |
| 32 | worksheet->setLayoutLeftMargin(0); |
| 33 | worksheet->setLayoutRightMargin(0); |
| 34 | |
| 35 | auto* plot = new CartesianPlot(sparklineText); |
| 36 | plot->setSuppressRetransform(true); |
| 37 | plot->setVerticalPadding(2); |
| 38 | plot->setRightPadding(2); |
| 39 | plot->setBottomPadding(2); |
| 40 | plot->setHorizontalPadding(2); |
| 41 | worksheet->addChild(plot); |
| 42 | |
| 43 | QApplication::processEvents(QEventLoop::AllEvents, 100); |
| 44 | if (col->columnMode() == Column::ColumnMode::Text) { |
| 45 | auto* barPlot = new BarPlot(QString()); |
| 46 | barPlot->setSuppressRetransform(true); |
| 47 | barPlot->setOrientation(BarPlot::Orientation::Vertical); |
| 48 | |
| 49 | // generate columns holding the data and the labels |
| 50 | auto* dataColumn = new Column(QStringLiteral("data")); |
| 51 | dataColumn->setColumnMode(AbstractColumn::ColumnMode::Integer); |
| 52 | |
| 53 | // sort the frequencies and the accompanying labels |
| 54 | const auto& frequencies = col->frequencies(); |
| 55 | auto i = frequencies.constBegin(); |
| 56 | QVector<QPair<QString, int>> pairs; |
| 57 | while (i != frequencies.constEnd()) { |
| 58 | pairs << QPair<QString, int>(i.key(), i.value()); |
| 59 | ++i; |
| 60 | } |
| 61 | |
| 62 | QVector<int> data; |
| 63 | for (const auto& pair : std::as_const(pairs)) |
| 64 | data << pair.second; |
| 65 | dataColumn->replaceInteger(0, data); |
| 66 | const QVector<const AbstractColumn*> columns{dataColumn}; |
| 67 | barPlot->setDataColumns(columns); |
| 68 | plot->addChild(barPlot); |
| 69 | barPlot->setSuppressRetransform(false); |
| 70 | } else { |
| 71 | const int rowCount = col->rowCount(); |
| 72 | QVector<int> xData(rowCount); |
| 73 | xData.resize(rowCount); |
| 74 |
nothing calls this directly
no test coverage detected