@@ -0,0 +1,141 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "pentool.h" | |||
|
22 | #include <QPushButton> | |||
|
23 | #include <QDoubleSpinBox> | |||
|
24 | #include <QComboBox> | |||
|
25 | #include <QFormLayout> | |||
|
26 | #include <QColorDialog> | |||
|
27 | ||||
|
28 | PenTool::PenTool(QString title, QWidget *parent) | |||
|
29 | : QWidget(parent) | |||
|
30 | { | |||
|
31 | setWindowTitle(title); | |||
|
32 | setWindowFlags(Qt::Tool); | |||
|
33 | ||||
|
34 | m_colorButton = new QPushButton(); | |||
|
35 | ||||
|
36 | m_widthSpinBox = new QDoubleSpinBox(); | |||
|
37 | ||||
|
38 | m_styleCombo = new QComboBox(); | |||
|
39 | m_styleCombo->addItem("NoPen"); | |||
|
40 | m_styleCombo->addItem("SolidLine"); | |||
|
41 | m_styleCombo->addItem("DashLine"); | |||
|
42 | m_styleCombo->addItem("DotLine"); | |||
|
43 | m_styleCombo->addItem("DashDotLine"); | |||
|
44 | m_styleCombo->addItem("DashDotDotLine"); | |||
|
45 | ||||
|
46 | m_capStyleCombo = new QComboBox(); | |||
|
47 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); | |||
|
48 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); | |||
|
49 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); | |||
|
50 | ||||
|
51 | m_joinStyleCombo = new QComboBox(); | |||
|
52 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); | |||
|
53 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); | |||
|
54 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); | |||
|
55 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); | |||
|
56 | ||||
|
57 | QFormLayout *layout = new QFormLayout(); | |||
|
58 | layout->addRow("Color", m_colorButton); | |||
|
59 | layout->addRow("Width", m_widthSpinBox); | |||
|
60 | layout->addRow("Style", m_styleCombo); | |||
|
61 | layout->addRow("Cap style", m_capStyleCombo); | |||
|
62 | layout->addRow("Join style", m_joinStyleCombo); | |||
|
63 | setLayout(layout); | |||
|
64 | ||||
|
65 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | |||
|
66 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); | |||
|
67 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); | |||
|
68 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); | |||
|
69 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); | |||
|
70 | } | |||
|
71 | ||||
|
72 | void PenTool::setPen(const QPen &pen) | |||
|
73 | { | |||
|
74 | m_pen = pen; | |||
|
75 | m_colorButton->setText(m_pen.color().name()); | |||
|
76 | m_widthSpinBox->setValue(m_pen.widthF()); | |||
|
77 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum | |||
|
78 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); | |||
|
79 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); | |||
|
80 | } | |||
|
81 | ||||
|
82 | QPen PenTool::pen() const | |||
|
83 | { | |||
|
84 | return m_pen; | |||
|
85 | } | |||
|
86 | ||||
|
87 | QString PenTool::name() | |||
|
88 | { | |||
|
89 | return name(m_pen); | |||
|
90 | } | |||
|
91 | ||||
|
92 | QString PenTool::name(const QPen &pen) | |||
|
93 | { | |||
|
94 | return pen.color().name() + ":" + QString::number(pen.widthF()); | |||
|
95 | } | |||
|
96 | ||||
|
97 | void PenTool::showColorDialog() | |||
|
98 | { | |||
|
99 | QColorDialog dialog(m_pen.color()); | |||
|
100 | dialog.show(); | |||
|
101 | dialog.exec(); | |||
|
102 | m_pen.setColor(dialog.selectedColor()); | |||
|
103 | m_colorButton->setText(m_pen.color().name()); | |||
|
104 | emit changed(); | |||
|
105 | } | |||
|
106 | ||||
|
107 | void PenTool::updateWidth(double width) | |||
|
108 | { | |||
|
109 | if (!qFuzzyCompare((qreal) width, m_pen.widthF())) { | |||
|
110 | m_pen.setWidthF(width); | |||
|
111 | emit changed(); | |||
|
112 | } | |||
|
113 | } | |||
|
114 | ||||
|
115 | void PenTool::updateStyle(int style) | |||
|
116 | { | |||
|
117 | if (m_pen.style() != style) { | |||
|
118 | m_pen.setStyle((Qt::PenStyle) style); | |||
|
119 | emit changed(); | |||
|
120 | } | |||
|
121 | } | |||
|
122 | ||||
|
123 | void PenTool::updateCapStyle(int index) | |||
|
124 | { | |||
|
125 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); | |||
|
126 | if (m_pen.capStyle() != capStyle) { | |||
|
127 | m_pen.setCapStyle(capStyle); | |||
|
128 | emit changed(); | |||
|
129 | } | |||
|
130 | } | |||
|
131 | ||||
|
132 | void PenTool::updateJoinStyle(int index) | |||
|
133 | { | |||
|
134 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); | |||
|
135 | if (m_pen.joinStyle() != joinStyle) { | |||
|
136 | m_pen.setJoinStyle(joinStyle); | |||
|
137 | emit changed(); | |||
|
138 | } | |||
|
139 | } | |||
|
140 | ||||
|
141 | #include "moc_pentool.cpp" |
@@ -0,0 +1,60 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | #ifndef PENTOOL_H | |||
|
21 | #define PENTOOL_H | |||
|
22 | ||||
|
23 | #include <QWidget> | |||
|
24 | #include <QPen> | |||
|
25 | ||||
|
26 | class QPushButton; | |||
|
27 | class QDoubleSpinBox; | |||
|
28 | class QComboBox; | |||
|
29 | ||||
|
30 | class PenTool : public QWidget | |||
|
31 | { | |||
|
32 | Q_OBJECT | |||
|
33 | ||||
|
34 | public: | |||
|
35 | explicit PenTool(QString title, QWidget *parent = 0); | |||
|
36 | void setPen(const QPen &pen); | |||
|
37 | QPen pen() const; | |||
|
38 | QString name(); | |||
|
39 | static QString name(const QPen &pen); | |||
|
40 | ||||
|
41 | Q_SIGNALS: | |||
|
42 | void changed(); | |||
|
43 | ||||
|
44 | public Q_SLOTS: | |||
|
45 | void showColorDialog(); | |||
|
46 | void updateWidth(double width); | |||
|
47 | void updateStyle(int style); | |||
|
48 | void updateCapStyle(int index); | |||
|
49 | void updateJoinStyle(int index); | |||
|
50 | ||||
|
51 | private: | |||
|
52 | QPen m_pen; | |||
|
53 | QPushButton *m_colorButton; | |||
|
54 | QDoubleSpinBox *m_widthSpinBox; | |||
|
55 | QComboBox *m_styleCombo; | |||
|
56 | QComboBox *m_capStyleCombo; | |||
|
57 | QComboBox *m_joinStyleCombo; | |||
|
58 | }; | |||
|
59 | ||||
|
60 | #endif // PENTOOL_H |
@@ -11,8 +11,10 contains(QT_MAJOR_VERSION, 5) { | |||||
11 |
|
11 | |||
12 | SOURCES += main.cpp \ |
|
12 | SOURCES += main.cpp \ | |
13 | mainwidget.cpp \ |
|
13 | mainwidget.cpp \ | |
14 | customtablemodel.cpp |
|
14 | customtablemodel.cpp \ | |
|
15 | pentool.cpp | |||
15 |
|
16 | |||
16 | HEADERS += \ |
|
17 | HEADERS += \ | |
17 | mainwidget.h \ |
|
18 | mainwidget.h \ | |
18 | customtablemodel.h |
|
19 | customtablemodel.h \ | |
|
20 | pentool.h |
@@ -20,6 +20,7 | |||||
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
|
23 | #include "pentool.h" | |||
23 | #include <QVBoxPlotModelMapper> |
|
24 | #include <QVBoxPlotModelMapper> | |
24 | #include <QTableView> |
|
25 | #include <QTableView> | |
25 | #include <QHeaderView> |
|
26 | #include <QHeaderView> | |
@@ -59,6 +60,8 MainWidget::MainWidget(QWidget *parent) : | |||||
59 | { |
|
60 | { | |
60 | m_chart = new QChart(); |
|
61 | m_chart = new QChart(); | |
61 |
|
62 | |||
|
63 | m_penTool = new PenTool("Whiskers pen", this); | |||
|
64 | ||||
62 | // Grid layout for the controls for configuring the chart widget |
|
65 | // Grid layout for the controls for configuring the chart widget | |
63 | QGridLayout *grid = new QGridLayout(); |
|
66 | QGridLayout *grid = new QGridLayout(); | |
64 |
|
67 | |||
@@ -97,12 +100,17 MainWidget::MainWidget(QWidget *parent) : | |||||
97 | connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); |
|
100 | connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); | |
98 | grid->addWidget(clearBoxButton, m_rowPos++, 1); |
|
101 | grid->addWidget(clearBoxButton, m_rowPos++, 1); | |
99 |
|
102 | |||
100 |
|
||||
101 | // Create set brush button |
|
103 | // Create set brush button | |
102 | QPushButton *setBrushButton = new QPushButton("Set brush"); |
|
104 | QPushButton *setBrushButton = new QPushButton("Set brush"); | |
103 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); |
|
105 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); | |
104 | grid->addWidget(setBrushButton, m_rowPos++, 1); |
|
106 | grid->addWidget(setBrushButton, m_rowPos++, 1); | |
105 |
|
107 | |||
|
108 | // Create set whiskers pen button | |||
|
109 | QPushButton *setWhiskersButton = new QPushButton("Whiskers pen"); | |||
|
110 | connect(setWhiskersButton, SIGNAL(clicked()), m_penTool, SLOT(show())); | |||
|
111 | connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); | |||
|
112 | grid->addWidget(setWhiskersButton, m_rowPos++, 1); | |||
|
113 | ||||
106 | initThemeCombo(grid); |
|
114 | initThemeCombo(grid); | |
107 | initCheckboxes(grid); |
|
115 | initCheckboxes(grid); | |
108 |
|
116 | |||
@@ -126,6 +134,9 MainWidget::MainWidget(QWidget *parent) : | |||||
126 | // Create chart view with the chart |
|
134 | // Create chart view with the chart | |
127 | m_chartView = new QChartView(m_chart, this); |
|
135 | m_chartView = new QChartView(m_chart, this); | |
128 |
|
136 | |||
|
137 | // As a default antialiasing is off | |||
|
138 | m_chartView->setRenderHint(QPainter::Antialiasing, false); | |||
|
139 | ||||
129 | // Another grid layout as a main layout |
|
140 | // Another grid layout as a main layout | |
130 | QGridLayout *mainLayout = new QGridLayout(); |
|
141 | QGridLayout *mainLayout = new QGridLayout(); | |
131 | mainLayout->addLayout(grid, 0, 0); |
|
142 | mainLayout->addLayout(grid, 0, 0); | |
@@ -172,6 +183,12 void MainWidget::initCheckboxes(QGridLayout *grid) | |||||
172 | titleCheckBox->setChecked(false); |
|
183 | titleCheckBox->setChecked(false); | |
173 | grid->addWidget(titleCheckBox, m_rowPos++, 0); |
|
184 | grid->addWidget(titleCheckBox, m_rowPos++, 0); | |
174 |
|
185 | |||
|
186 | QCheckBox *renderCheckBox = new QCheckBox("Render Hint"); | |||
|
187 | connect(renderCheckBox, SIGNAL(toggled(bool)), this, SLOT(renderToggled(bool))); | |||
|
188 | renderCheckBox->setChecked(false); | |||
|
189 | grid->addWidget(renderCheckBox, m_rowPos++, 0); | |||
|
190 | ||||
|
191 | ||||
175 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); |
|
192 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); | |
176 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); |
|
193 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); | |
177 | modelMapperCheckBox->setChecked(false); |
|
194 | modelMapperCheckBox->setChecked(false); | |
@@ -361,6 +378,13 void MainWidget::titleToggled(bool enabled) | |||||
361 | m_chart->setTitle(""); |
|
378 | m_chart->setTitle(""); | |
362 | } |
|
379 | } | |
363 |
|
380 | |||
|
381 | void MainWidget::renderToggled(bool enabled) | |||
|
382 | { | |||
|
383 | qDebug() << "BoxPlotTester::renderToggled toggled to " << enabled; | |||
|
384 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |||
|
385 | } | |||
|
386 | ||||
|
387 | ||||
364 | void MainWidget::modelMapperToggled(bool enabled) |
|
388 | void MainWidget::modelMapperToggled(bool enabled) | |
365 | { |
|
389 | { | |
366 | if (enabled) { |
|
390 | if (enabled) { | |
@@ -417,3 +441,11 void MainWidget::singleBoxHovered(bool state) | |||||
417 | else |
|
441 | else | |
418 | qDebug() << "single box hover ended"; |
|
442 | qDebug() << "single box hover ended"; | |
419 | } |
|
443 | } | |
|
444 | ||||
|
445 | void MainWidget::changePen() | |||
|
446 | { | |||
|
447 | qDebug() << "changePen() = " << m_penTool->pen(); | |||
|
448 | for (int i = 0; i < m_seriesCount; i++) | |||
|
449 | m_series[i]->setPen(m_penTool->pen()); | |||
|
450 | ||||
|
451 | } |
General Comments 0
You need to be logged in to leave comments.
Login now