diff --git a/tests/boxplottester/boxplottester.pro b/tests/boxplottester/boxplottester.pro index 57436c0..f77ef1b 100644 --- a/tests/boxplottester/boxplottester.pro +++ b/tests/boxplottester/boxplottester.pro @@ -11,8 +11,10 @@ contains(QT_MAJOR_VERSION, 5) { SOURCES += main.cpp \ mainwidget.cpp \ - customtablemodel.cpp + customtablemodel.cpp \ + pentool.cpp HEADERS += \ mainwidget.h \ - customtablemodel.h + customtablemodel.h \ + pentool.h diff --git a/tests/boxplottester/mainwidget.cpp b/tests/boxplottester/mainwidget.cpp index 27efa4b..f2f3650 100644 --- a/tests/boxplottester/mainwidget.cpp +++ b/tests/boxplottester/mainwidget.cpp @@ -20,6 +20,7 @@ #include "mainwidget.h" #include "customtablemodel.h" +#include "pentool.h" #include #include #include @@ -59,6 +60,8 @@ MainWidget::MainWidget(QWidget *parent) : { m_chart = new QChart(); + m_penTool = new PenTool("Whiskers pen", this); + // Grid layout for the controls for configuring the chart widget QGridLayout *grid = new QGridLayout(); @@ -97,12 +100,17 @@ MainWidget::MainWidget(QWidget *parent) : connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); grid->addWidget(clearBoxButton, m_rowPos++, 1); - // Create set brush button QPushButton *setBrushButton = new QPushButton("Set brush"); connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); grid->addWidget(setBrushButton, m_rowPos++, 1); + // Create set whiskers pen button + QPushButton *setWhiskersButton = new QPushButton("Whiskers pen"); + connect(setWhiskersButton, SIGNAL(clicked()), m_penTool, SLOT(show())); + connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); + grid->addWidget(setWhiskersButton, m_rowPos++, 1); + initThemeCombo(grid); initCheckboxes(grid); @@ -126,6 +134,9 @@ MainWidget::MainWidget(QWidget *parent) : // Create chart view with the chart m_chartView = new QChartView(m_chart, this); + // As a default antialiasing is off + m_chartView->setRenderHint(QPainter::Antialiasing, false); + // Another grid layout as a main layout QGridLayout *mainLayout = new QGridLayout(); mainLayout->addLayout(grid, 0, 0); @@ -172,6 +183,12 @@ void MainWidget::initCheckboxes(QGridLayout *grid) titleCheckBox->setChecked(false); grid->addWidget(titleCheckBox, m_rowPos++, 0); + QCheckBox *renderCheckBox = new QCheckBox("Render Hint"); + connect(renderCheckBox, SIGNAL(toggled(bool)), this, SLOT(renderToggled(bool))); + renderCheckBox->setChecked(false); + grid->addWidget(renderCheckBox, m_rowPos++, 0); + + QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); modelMapperCheckBox->setChecked(false); @@ -361,6 +378,13 @@ void MainWidget::titleToggled(bool enabled) m_chart->setTitle(""); } +void MainWidget::renderToggled(bool enabled) +{ + qDebug() << "BoxPlotTester::renderToggled toggled to " << enabled; + m_chartView->setRenderHint(QPainter::Antialiasing, enabled); +} + + void MainWidget::modelMapperToggled(bool enabled) { if (enabled) { @@ -417,3 +441,11 @@ void MainWidget::singleBoxHovered(bool state) else qDebug() << "single box hover ended"; } + +void MainWidget::changePen() +{ + qDebug() << "changePen() = " << m_penTool->pen(); + for (int i = 0; i < m_seriesCount; i++) + m_series[i]->setPen(m_penTool->pen()); + +} diff --git a/tests/boxplottester/pentool.cpp b/tests/boxplottester/pentool.cpp new file mode 100644 index 0000000..0c1b30b --- /dev/null +++ b/tests/boxplottester/pentool.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "pentool.h" +#include +#include +#include +#include +#include + +PenTool::PenTool(QString title, QWidget *parent) + : QWidget(parent) +{ + setWindowTitle(title); + setWindowFlags(Qt::Tool); + + m_colorButton = new QPushButton(); + + m_widthSpinBox = new QDoubleSpinBox(); + + m_styleCombo = new QComboBox(); + m_styleCombo->addItem("NoPen"); + m_styleCombo->addItem("SolidLine"); + m_styleCombo->addItem("DashLine"); + m_styleCombo->addItem("DotLine"); + m_styleCombo->addItem("DashDotLine"); + m_styleCombo->addItem("DashDotDotLine"); + + m_capStyleCombo = new QComboBox(); + m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); + m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); + m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); + + m_joinStyleCombo = new QComboBox(); + m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); + m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); + m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); + m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); + + QFormLayout *layout = new QFormLayout(); + layout->addRow("Color", m_colorButton); + layout->addRow("Width", m_widthSpinBox); + layout->addRow("Style", m_styleCombo); + layout->addRow("Cap style", m_capStyleCombo); + layout->addRow("Join style", m_joinStyleCombo); + setLayout(layout); + + connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); + connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); + connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); + connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); + connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); +} + +void PenTool::setPen(const QPen &pen) +{ + m_pen = pen; + m_colorButton->setText(m_pen.color().name()); + m_widthSpinBox->setValue(m_pen.widthF()); + m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum + m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); + m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); +} + +QPen PenTool::pen() const +{ + return m_pen; +} + +QString PenTool::name() +{ + return name(m_pen); +} + +QString PenTool::name(const QPen &pen) +{ + return pen.color().name() + ":" + QString::number(pen.widthF()); +} + +void PenTool::showColorDialog() +{ + QColorDialog dialog(m_pen.color()); + dialog.show(); + dialog.exec(); + m_pen.setColor(dialog.selectedColor()); + m_colorButton->setText(m_pen.color().name()); + emit changed(); +} + +void PenTool::updateWidth(double width) +{ + if (!qFuzzyCompare((qreal) width, m_pen.widthF())) { + m_pen.setWidthF(width); + emit changed(); + } +} + +void PenTool::updateStyle(int style) +{ + if (m_pen.style() != style) { + m_pen.setStyle((Qt::PenStyle) style); + emit changed(); + } +} + +void PenTool::updateCapStyle(int index) +{ + Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); + if (m_pen.capStyle() != capStyle) { + m_pen.setCapStyle(capStyle); + emit changed(); + } +} + +void PenTool::updateJoinStyle(int index) +{ + Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); + if (m_pen.joinStyle() != joinStyle) { + m_pen.setJoinStyle(joinStyle); + emit changed(); + } +} + +#include "moc_pentool.cpp" diff --git a/tests/boxplottester/pentool.h b/tests/boxplottester/pentool.h new file mode 100644 index 0000000..2a26c53 --- /dev/null +++ b/tests/boxplottester/pentool.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PENTOOL_H +#define PENTOOL_H + +#include +#include + +class QPushButton; +class QDoubleSpinBox; +class QComboBox; + +class PenTool : public QWidget +{ + Q_OBJECT + +public: + explicit PenTool(QString title, QWidget *parent = 0); + void setPen(const QPen &pen); + QPen pen() const; + QString name(); + static QString name(const QPen &pen); + +Q_SIGNALS: + void changed(); + +public Q_SLOTS: + void showColorDialog(); + void updateWidth(double width); + void updateStyle(int style); + void updateCapStyle(int index); + void updateJoinStyle(int index); + +private: + QPen m_pen; + QPushButton *m_colorButton; + QDoubleSpinBox *m_widthSpinBox; + QComboBox *m_styleCombo; + QComboBox *m_capStyleCombo; + QComboBox *m_joinStyleCombo; +}; + +#endif // PENTOOL_H