##// END OF EJS Templates
Refactored the test app
Tero Ahola -
r110:d11ac5a26e2a
parent child
Show More
@@ -5,7 +5,6 integrated_build:{
5 DESTDIR = $$CHART_BUILD_BIN_DIR
5 DESTDIR = $$CHART_BUILD_BIN_DIR
6 CONFIG(debug, debug|release) {
6 CONFIG(debug, debug|release) {
7 LIBS += -lQtCommercialChartd
7 LIBS += -lQtCommercialChartd
8
9 #this is ugly hack to work around missing rpath, it simply copies lib
8 #this is ugly hack to work around missing rpath, it simply copies lib
10 win32:{
9 win32:{
11 copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll
10 copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll
@@ -14,7 +13,6 integrated_build:{
14 PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll
13 PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll
15 QMAKE_EXTRA_TARGETS +=copylib
14 QMAKE_EXTRA_TARGETS +=copylib
16 }
15 }
17
18 } else {
16 } else {
19 LIBS += -lQtCommercialChart
17 LIBS += -lQtCommercialChart
20
18
@@ -66,7 +66,7 class ChartTheme : public QObject
66 Q_OBJECT
66 Q_OBJECT
67 public:
67 public:
68 explicit ChartTheme(QObject *parent = 0);
68 explicit ChartTheme(QObject *parent = 0);
69 explicit ChartTheme(const ChartTheme &other) : d(other.d) {}
69 explicit ChartTheme(const ChartTheme &other, QObject *parent = 0) : QObject(parent), d(other.d) {}
70 void operator =(const ChartTheme &other) { d = other.d; }
70 void operator =(const ChartTheme &other) { d = other.d; }
71
71
72 void setTheme(int theme);
72 void setTheme(int theme);
@@ -44,7 +44,7 QPainterPath PieSlice::shape() const
44 return path;
44 return path;
45 }
45 }
46
46
47 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
47 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
48 {
48 {
49 painter->setRenderHint(QPainter::Antialiasing);
49 painter->setRenderHint(QPainter::Antialiasing);
50 // TODO: how to map theme settings to a pie slice? Now we
50 // TODO: how to map theme settings to a pie slice? Now we
@@ -29,7 +29,7 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
29 m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
29 m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)),
30 m_plotDataIndex(0),
30 m_plotDataIndex(0),
31 m_marginSize(0),
31 m_marginSize(0),
32 m_chartTheme(new ChartTheme())
32 m_chartTheme(new ChartTheme(this))
33 {
33 {
34 // TODO: the default theme?
34 // TODO: the default theme?
35 setTheme(QChart::ChartThemeDefault);
35 setTheme(QChart::ChartThemeDefault);
@@ -50,7 +50,7 public:
50
50
51 //from QGraphicsItem
51 //from QGraphicsItem
52 QRectF boundingRect() const;
52 QRectF boundingRect() const;
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
53 void paint(QPainter */*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) {}
54
54
55 void addSeries(QChartSeries* series);
55 void addSeries(QChartSeries* series);
56 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
56 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
@@ -34,12 +34,12 public:
34 // Pure virtual
34 // Pure virtual
35 virtual QChartSeriesType type() const = 0;
35 virtual QChartSeriesType type() const = 0;
36
36
37 virtual bool setData(QList<int> data) { return false; }
37 virtual bool setData(QList<int> /*data*/) { return false; }
38 virtual bool setData(QList<qreal> data) { return false; }
38 virtual bool setData(QList<qreal> /*data*/) { return false; }
39 virtual bool setData(QList<qreal> x, QList<qreal> y){ return false; }
39 virtual bool setData(QList<qreal> /*x*/, QList<qreal> /*y*/){ return false; }
40
40
41 // Prototype for data model. TODO: remove the other setData methods and use something like this for now?
41 // Prototype for data model. TODO: remove the other setData methods and use something like this for now?
42 virtual bool setData(QAbstractItemModel* model) { return false; }
42 virtual bool setData(QAbstractItemModel* /*model*/) { return false; }
43
43
44 };
44 };
45
45
@@ -55,7 +55,7 QRectF QScatterSeriesPrivate::boundingRect() const
55 return QRectF(0, 0, 55, 100);
55 return QRectF(0, 0, 55, 100);
56 }
56 }
57
57
58 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
58 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
59 {
59 {
60 // TODO: The opacity should be user definable?
60 // TODO: The opacity should be user definable?
61 //brush.setColor(QColor(255, 82, 0, 100));
61 //brush.setColor(QColor(255, 82, 0, 100));
@@ -25,10 +25,44 MainWidget::MainWidget(QWidget *parent) :
25 {
25 {
26 m_chartWidget = new QChartWidget(this);
26 m_chartWidget = new QChartWidget(this);
27
27
28 // GridLayout for the controls for configuring the chart widget
29 QGridLayout *grid = new QGridLayout();
30 QGridLayout *mainLayout = new QGridLayout();
28 QPushButton *addSeriesButton = new QPushButton("Add series");
31 QPushButton *addSeriesButton = new QPushButton("Add series");
29 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
32 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
33 grid->addWidget(addSeriesButton, 0, 1);
34 initBackroundCombo(grid);
35 initScaleControls(grid);
36 initThemeCombo(grid);
37 QCheckBox *zoomCheckBox = new QCheckBox("Zoom enabled");
38 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
39 zoomCheckBox->setChecked(true);
40 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
41 // add row with empty label to make all the other rows static
42 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
43 grid->setRowStretch(grid->rowCount() - 1, 1);
44 mainLayout->addLayout(grid, 0, 0);
45
46 // Init series type specific controls
47 initPieControls();
48 mainLayout->addLayout(m_pieLayout, 2, 0);
49 // Scatter series specific settings
50 // m_scatterLayout = new QGridLayout();
51 // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
52 // m_scatterLayout->setEnabled(false);
53 // mainLayout->addLayout(m_scatterLayout, 1, 0);
54
55 // Add layouts and the chart widget to the main layout
56 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
57 setLayout(mainLayout);
58
59 // force an update to test data
60 testDataChanged(0);
61 }
30
62
31 // Chart background
63 // Combo box for selecting the chart's background
64 void MainWidget::initBackroundCombo(QGridLayout *grid)
65 {
32 QComboBox *backgroundCombo = new QComboBox(this);
66 QComboBox *backgroundCombo = new QComboBox(this);
33 backgroundCombo->addItem("Color");
67 backgroundCombo->addItem("Color");
34 backgroundCombo->addItem("Gradient");
68 backgroundCombo->addItem("Gradient");
@@ -36,8 +70,13 MainWidget::MainWidget(QWidget *parent) :
36 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
70 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
37 this, SLOT(backgroundChanged(int)));
71 this, SLOT(backgroundChanged(int)));
38
72
39 // Axis
73 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
40 // TODO: multiple axes?
74 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
75 }
76
77 // Scale related controls (auto-scale vs. manual min-max values)
78 void MainWidget::initScaleControls(QGridLayout *grid)
79 {
41 m_autoScaleCheck = new QCheckBox("Automatic scaling");
80 m_autoScaleCheck = new QCheckBox("Automatic scaling");
42 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
81 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
43 // Allow setting also non-sense values (like -2147483648 and 2147483647)
82 // Allow setting also non-sense values (like -2147483648 and 2147483647)
@@ -62,6 +101,22 MainWidget::MainWidget(QWidget *parent) :
62 m_yMaxSpin->setValue(10);
101 m_yMaxSpin->setValue(10);
63 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
102 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
64
103
104 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
105 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
106 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
107 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
108 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
109 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
110 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
111 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
112 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
113
114 m_autoScaleCheck->setChecked(true);
115 }
116
117 // Combo box for selecting theme
118 void MainWidget::initThemeCombo(QGridLayout *grid)
119 {
65 QComboBox *chartTheme = new QComboBox();
120 QComboBox *chartTheme = new QComboBox();
66 chartTheme->addItem("Default");
121 chartTheme->addItem("Default");
67 chartTheme->addItem("Vanilla");
122 chartTheme->addItem("Vanilla");
@@ -70,45 +125,13 MainWidget::MainWidget(QWidget *parent) :
70 chartTheme->addItem("Unnamed1");
125 chartTheme->addItem("Unnamed1");
71 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
126 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
72 this, SLOT(changeChartTheme(int)));
127 this, SLOT(changeChartTheme(int)));
73 // connect(chartTheme, SIGNAL(currentIndexChanged(int)),
74 // m_signalMapper, SLOT(map()));
75 // m_signalMapper->setMapping(chartTheme, (QChart::ChartThemeId)chartTheme->currentIndex());
76 // connect(m_signalMapper, SIGNAL(mapped(QChart::ChartThemeId)),
77 // m_chartWidget, SLOT(setTheme(QChart::ChartThemeId)));
78
79 QCheckBox *zoomCheckBox = new QCheckBox("Zoom enabled");
80 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
81 zoomCheckBox->setChecked(true);
82
83 QGridLayout *grid = new QGridLayout();
84 QGridLayout *mainLayout = new QGridLayout();
85 grid->addWidget(addSeriesButton, 0, 1);
86 grid->addWidget(new QLabel("Background:"), 2, 0);
87 grid->addWidget(backgroundCombo, 2, 1);
88 grid->addWidget(m_autoScaleCheck, 3, 0);
89 grid->addWidget(new QLabel("x min:"), 4, 0);
90 grid->addWidget(m_xMinSpin, 4, 1);
91 grid->addWidget(new QLabel("x max:"), 5, 0);
92 grid->addWidget(m_xMaxSpin, 5, 1);
93 grid->addWidget(new QLabel("y min:"), 6, 0);
94 grid->addWidget(m_yMinSpin, 6, 1);
95 grid->addWidget(new QLabel("y max:"), 7, 0);
96 grid->addWidget(m_yMaxSpin, 7, 1);
97 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
128 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
98 grid->addWidget(chartTheme, 8, 1);
129 grid->addWidget(chartTheme, 8, 1);
99 grid->addWidget(zoomCheckBox, 9, 0);
130 }
100 // add row with empty label to make all the other rows static
101 grid->addWidget(new QLabel(""), 10, 0);
102 grid->setRowStretch(10, 1);
103
104 mainLayout->addLayout(grid, 0, 0);
105
106 // Scatter specific settings
107 m_scatterLayout = new QGridLayout();
108 m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
109 m_scatterLayout->setEnabled(false);
110
131
111 // Pie specific settings
132 void MainWidget::initPieControls()
133 {
134 // Pie series specific settings
112 // Pie size factory
135 // Pie size factory
113 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
136 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
114 pieSizeSpin->setMinimum(LONG_MIN);
137 pieSizeSpin->setMinimum(LONG_MIN);
@@ -131,18 +154,6 MainWidget::MainWidget(QWidget *parent) :
131 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
154 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
132 m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
155 m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
133 m_pieLayout->addWidget(piePosCombo, 1, 1);
156 m_pieLayout->addWidget(piePosCombo, 1, 1);
134
135 mainLayout->addLayout(m_scatterLayout, 1, 0);
136 mainLayout->addLayout(m_pieLayout, 2, 0);
137
138 //m_chartWidget->setColor(Qt::red);
139 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
140 // hbox->setStretch(1, 1);
141
142 setLayout(mainLayout);
143
144 m_autoScaleCheck->setChecked(true);
145 testDataChanged(0);
146 }
157 }
147
158
148 void MainWidget::addSeries()
159 void MainWidget::addSeries()
@@ -19,6 +19,12 public:
19
19
20 signals:
20 signals:
21
21
22 private:
23 void initBackroundCombo(QGridLayout *grid);
24 void initScaleControls(QGridLayout *grid);
25 void initThemeCombo(QGridLayout *grid);
26 void initPieControls();
27
22 private slots:
28 private slots:
23 void addSeries();
29 void addSeries();
24 void addSeries(QString series, QString data);
30 void addSeries(QString series, QString data);
General Comments 0
You need to be logged in to leave comments. Login now