| 23 | #include <QPen> |
| 24 | |
| 25 | void WorksheetTest::cursorCurveColor() { |
| 26 | Project project; |
| 27 | |
| 28 | auto* worksheet = new Worksheet(QStringLiteral("Worksheet")); |
| 29 | project.addChild(worksheet); |
| 30 | |
| 31 | auto* plot = new CartesianPlot(QStringLiteral("plot123")); |
| 32 | worksheet->addChild(plot); |
| 33 | |
| 34 | auto* curve1 = new XYCurve(QStringLiteral("Curve1")); |
| 35 | plot->addChild(curve1); |
| 36 | auto* curve2 = new XYCurve(QStringLiteral("Curve2")); |
| 37 | plot->addChild(curve2); |
| 38 | |
| 39 | curve2->line()->color(); |
| 40 | QVERIFY(curve1->line()->pen().color() != curve2->line()->pen().color()); |
| 41 | |
| 42 | const auto* treemodel = worksheet->cursorModel(); |
| 43 | |
| 44 | // Row0: X Value |
| 45 | // Row1: Plot |
| 46 | QCOMPARE(treemodel->rowCount(), 2); |
| 47 | |
| 48 | QCOMPARE(treemodel->data(treemodel->index(0, (int)WorksheetPrivate::TreeModelColumn::PLOTNAME), Qt::DisplayRole).toString(), QStringLiteral("X")); |
| 49 | const auto& plotIndex = treemodel->index(1, (int)WorksheetPrivate::TreeModelColumn::PLOTNAME); |
| 50 | |
| 51 | // Row2: Curve1 (Plot as parent index) |
| 52 | // Row3: Curve2 (Plot as parent index) |
| 53 | QCOMPARE(treemodel->rowCount(plotIndex), 2); |
| 54 | QCOMPARE(treemodel->data(plotIndex, Qt::DisplayRole).toString(), QStringLiteral("plot123")); |
| 55 | QCOMPARE(treemodel->data(treemodel->index(0, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::DisplayRole).toString(), curve1->name()); |
| 56 | QCOMPARE(treemodel->data(treemodel->index(1, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::DisplayRole).toString(), curve2->name()); |
| 57 | |
| 58 | { |
| 59 | QColor color = curve1->line()->pen().color(); |
| 60 | color.setAlpha(worksheet->d_func()->cursorTreeModelCurveBackgroundAlpha); |
| 61 | QCOMPARE(treemodel->data(treemodel->index(0, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::BackgroundRole).value<QColor>(), |
| 62 | color); |
| 63 | } |
| 64 | { |
| 65 | QColor color = curve2->line()->pen().color(); |
| 66 | color.setAlpha(worksheet->d_func()->cursorTreeModelCurveBackgroundAlpha); |
| 67 | QCOMPARE(treemodel->data(treemodel->index(1, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::BackgroundRole).value<QColor>(), |
| 68 | color); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /*! |
| 73 | * tests the replacement of the file extension when switching between the different formats during the export. |