show sparkLine of respective column
| 50 | |
| 51 | // show sparkLine of respective column |
| 52 | QPixmap SpreadsheetSparkLinesHeaderModel::showSparkLines(Column* col) { |
| 53 | // Create a QThreadPool instance and set the maximum number of threads |
| 54 | QThreadPool threadPool; |
| 55 | threadPool.setMaxThreadCount(QThread::idealThreadCount()); |
| 56 | PERFTRACE(QLatin1String(Q_FUNC_INFO)); |
| 57 | // Create a QFutureWatcher to monitor the task's progress |
| 58 | QFutureWatcher<QPixmap> watcher; |
| 59 | // Create an instance of SparkLineRunnable |
| 60 | auto* runnable = new SparkLineRunnable(col); |
| 61 | |
| 62 | // Connect the finished signal of the runnable to the watcher's setFuture slot |
| 63 | connect(runnable, &SparkLineRunnable::taskFinished, [&]() { |
| 64 | const auto& resultPixmap = runnable->pixmap(); |
| 65 | // Check if the result is valid |
| 66 | if (!resultPixmap.isNull()) { |
| 67 | watcher.setFuture(QtConcurrent::run(&threadPool, [=]() { |
| 68 | return resultPixmap; |
| 69 | })); |
| 70 | } else |
| 71 | watcher.cancel(); |
| 72 | }); |
| 73 | |
| 74 | // Start the runnable in the thread pool |
| 75 | threadPool.start(runnable); |
| 76 | |
| 77 | // Wait for the task to finish |
| 78 | QEventLoop loop; |
| 79 | QObject::connect(runnable, &SparkLineRunnable::taskFinished, &loop, &QEventLoop::quit); |
| 80 | loop.exec(); |
| 81 | |
| 82 | return watcher.result(); |
| 83 | } |
| 84 | |
| 85 | QVariant SpreadsheetSparkLinesHeaderModel::data(const QModelIndex& /*index*/, int /*role*/) const { |
| 86 | return {}; |