File indexing completed on 2024-04-21 03:48:03
0001 /* 0002 File : WorksheetTest.cpp 0003 Project : LabPlot 0004 Description : Tests for Worksheets 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2023 Martin Marmsoler <martin.marmsoler@gmail.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "WorksheetTest.h" 0012 0013 #include "backend/core/Project.h" 0014 #include "backend/worksheet/Line.h" 0015 #include "backend/worksheet/TreeModel.h" 0016 #include "backend/worksheet/Worksheet.h" 0017 #include "backend/worksheet/WorksheetPrivate.h" 0018 #include "backend/worksheet/plots/cartesian/CartesianPlot.h" 0019 #include "backend/worksheet/plots/cartesian/XYCurve.h" 0020 0021 #include <QPen> 0022 0023 void WorksheetTest::cursorCurveColor() { 0024 Project project; 0025 0026 auto* worksheet = new Worksheet(QStringLiteral("Worksheet")); 0027 project.addChild(worksheet); 0028 0029 auto* plot = new CartesianPlot(QStringLiteral("plot123")); 0030 worksheet->addChild(plot); 0031 0032 auto* curve1 = new XYCurve(QStringLiteral("Curve1")); 0033 plot->addChild(curve1); 0034 auto* curve2 = new XYCurve(QStringLiteral("Curve2")); 0035 plot->addChild(curve2); 0036 0037 curve2->line()->color(); 0038 QVERIFY(curve1->line()->pen().color() != curve2->line()->pen().color()); 0039 0040 const auto* treemodel = worksheet->cursorModel(); 0041 0042 // Row0: X Value 0043 // Row1: Plot 0044 QCOMPARE(treemodel->rowCount(), 2); 0045 0046 QCOMPARE(treemodel->data(treemodel->index(0, (int)WorksheetPrivate::TreeModelColumn::PLOTNAME), Qt::DisplayRole).toString(), QStringLiteral("X")); 0047 const auto& plotIndex = treemodel->index(1, (int)WorksheetPrivate::TreeModelColumn::PLOTNAME); 0048 0049 // Row2: Curve1 (Plot as parent index) 0050 // Row3: Curve2 (Plot as parent index) 0051 QCOMPARE(treemodel->rowCount(plotIndex), 2); 0052 QCOMPARE(treemodel->data(plotIndex, Qt::DisplayRole).toString(), QStringLiteral("plot123")); 0053 QCOMPARE(treemodel->data(treemodel->index(0, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::DisplayRole).toString(), curve1->name()); 0054 QCOMPARE(treemodel->data(treemodel->index(1, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::DisplayRole).toString(), curve2->name()); 0055 0056 { 0057 QColor color = curve1->line()->pen().color(); 0058 color.setAlpha(worksheet->d_func()->cursorTreeModelCurveBackgroundAlpha); 0059 QCOMPARE(treemodel->data(treemodel->index(0, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::BackgroundRole).value<QColor>(), 0060 color); 0061 } 0062 { 0063 QColor color = curve2->line()->pen().color(); 0064 color.setAlpha(worksheet->d_func()->cursorTreeModelCurveBackgroundAlpha); 0065 QCOMPARE(treemodel->data(treemodel->index(1, (int)WorksheetPrivate::TreeModelColumn::SIGNALNAME, plotIndex), Qt::BackgroundRole).value<QColor>(), 0066 color); 0067 } 0068 } 0069 0070 QTEST_MAIN(WorksheetTest)