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

Method run

src/frontend/spreadsheet/SparklineRunnable.cpp:17–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <QWidget>
16
17void 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

Callers

nothing calls this directly

Calls 15

isPlottableMethod · 0.80
setUndoAwareMethod · 0.80
setUseViewSizeMethod · 0.80
setVerticalPaddingMethod · 0.80
setRightPaddingMethod · 0.80
setBottomPaddingMethod · 0.80
setHorizontalPaddingMethod · 0.80
setIntegersMethod · 0.80
setYColumnMethod · 0.80
setFirstColorMethod · 0.80
QPixmapClass · 0.50
QColorClass · 0.50

Tested by

no test coverage detected