From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- tests/fute/pieCharts/main.cpp | 12 ++++++++ tests/fute/pieCharts/pieCharts.pro | 29 ++++++++++++++++++ tests/fute/pieCharts/pieCharts_test.cpp | 52 +++++++++++++++++++++++++++++++++ tests/fute/pieCharts/pieCharts_test.h | 34 +++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 tests/fute/pieCharts/main.cpp create mode 100644 tests/fute/pieCharts/pieCharts.pro create mode 100644 tests/fute/pieCharts/pieCharts_test.cpp create mode 100644 tests/fute/pieCharts/pieCharts_test.h (limited to 'tests/fute/pieCharts') diff --git a/tests/fute/pieCharts/main.cpp b/tests/fute/pieCharts/main.cpp new file mode 100644 index 0000000..ed7ce6e --- /dev/null +++ b/tests/fute/pieCharts/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "pieCharts_test.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + PieChartsTest mainWin; + mainWin.show(); + return app.exec(); +} + diff --git a/tests/fute/pieCharts/pieCharts.pro b/tests/fute/pieCharts/pieCharts.pro new file mode 100644 index 0000000..960dd59 --- /dev/null +++ b/tests/fute/pieCharts/pieCharts.pro @@ -0,0 +1,29 @@ +TEMPLATE = app +QT += widgets +TARGET = piecharts_test +DEPENDPATH += . +INCLUDEPATH += . +QMAKE_CXXFLAGS += -std=gnu++11 +DESTDIR = ./ + +win32: { + CONFIG += console + } + +HEADERS = \ + pieCharts_test.h \ + ../../../src/charts/PieChart.h \ + ../../../src/charts/DataPoint.h \ + ../../../src/charts/PieChartScene.h \ + ../../../src/charts/ChartView.h \ + ../../../src/charts/PieRound.h \ + ../../../src/charts/PieLegend.h + +SOURCES = \ + main.cpp \ + pieCharts_test.cpp \ + ../../../src/charts/PieChart.cpp \ + ../../../src/charts/PieChartScene.cpp \ + ../../../src/charts/ChartView.cpp \ + ../../../src/charts/PieRound.cpp \ + ../../../src/charts/PieLegend.cpp diff --git a/tests/fute/pieCharts/pieCharts_test.cpp b/tests/fute/pieCharts/pieCharts_test.cpp new file mode 100644 index 0000000..d88981a --- /dev/null +++ b/tests/fute/pieCharts/pieCharts_test.cpp @@ -0,0 +1,52 @@ +#include "pieCharts_test.h" +#include "../../../src/charts/PieChart.h" + +#include +#include + +const QStringList PieChartsTest::Labels = + {"Studied", "Scheduled for today", "New"}; + +PieChartsTest::PieChartsTest() +{ + srand(time(NULL)); + createUi(); + changeDataSet(); +} + +void PieChartsTest::changeDataSet() +{ + yValuesStr = "Values: "; + dataSet.clear(); + for (int i = 0; i < 3; i++) + addDataPoint(i); + chart->setDataSet(dataSet); + valuesLabel->setText(yValuesStr); +} + +void PieChartsTest::addDataPoint(int index) +{ + int yValue = rand() % 200; + dataSet << DataPoint(Labels[index], yValue, ""); + yValuesStr += QString::number(yValue) + ", "; +} + +void PieChartsTest::createUi() +{ + QPushButton* newBtn = new QPushButton(tr("New chart")); + connect(newBtn, SIGNAL(clicked()), SLOT(changeDataSet())); + + valuesLabel = new QLabel; + chart = new PieChart; + chart->setColors({"#39c900", "#ece900", "#ff0000"}); + + QHBoxLayout* controlLt = new QHBoxLayout; + controlLt->addWidget(valuesLabel); + controlLt->addWidget(newBtn); + + QVBoxLayout* mainLt = new QVBoxLayout; + mainLt->addLayout(controlLt); + mainLt->addWidget(chart); + setLayout(mainLt); + resize(800, 500); +} diff --git a/tests/fute/pieCharts/pieCharts_test.h b/tests/fute/pieCharts/pieCharts_test.h new file mode 100644 index 0000000..835ff72 --- /dev/null +++ b/tests/fute/pieCharts/pieCharts_test.h @@ -0,0 +1,34 @@ +#ifndef PIE_CHARTS_TEST_H +#define PIE_CHARTS_TEST_H + +#include +#include + +#include "../../../src/charts/DataPoint.h" + +class PieChart; + +class PieChartsTest: public QWidget +{ + Q_OBJECT +public: + static const QStringList Labels; + +public: + PieChartsTest(); + +private: + void createUi(); + void addDataPoint(int index); + +private slots: + void changeDataSet(); + +private: + QString yValuesStr; + PieChart* chart; + QList dataSet; + QLabel* valuesLabel; +}; + +#endif -- cgit