##// END OF EJS Templates
Add fontsize 32 to chartviewer
Add fontsize 32 to chartviewer

File last commit:

r1594:7a5481b8168a
r1895:782345485068
Show More
mainwidget.cpp
262 lines | 8.0 KiB | text/x-c | CppLexer
Marek Rosa
License added to several files
r1365 /****************************************************************************
**
** Copyright (C) 2012 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$
**
****************************************************************************/
sauimone
legend detach example. Bug fixes to legend.
r1263 #include "mainwidget.h"
#include <QChart>
#include <QChartView>
#include <QPushButton>
#include <QLabel>
#include <QDebug>
#include <QBarSet>
sauimone
GroupedBarSeries to BarSeries
r1594 #include <QBarSeries>
sauimone
legend detach example. Bug fixes to legend.
r1263 #include <QLegend>
sauimone
better legend detach layout. updated legend example
r1444 #include <QFormLayout>
sauimone
legend detach example. Bug fixes to legend.
r1263
QTCOMMERCIALCHART_USE_NAMESPACE
MainWidget::MainWidget(QWidget *parent) :
QWidget(parent)
{
sauimone
legend example to documentation. minor legend fixes
r1300 // Create buttons for ui
sauimone
legend detach example. Bug fixes to legend.
r1263 m_buttonLayout = new QGridLayout();
QPushButton *detachLegendButton = new QPushButton("detach legend");
connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend()));
m_buttonLayout->addWidget(detachLegendButton, 0, 0);
QPushButton *attachLegendButton = new QPushButton("attach legend");
connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend()));
m_buttonLayout->addWidget(attachLegendButton, 1, 0);
QPushButton *addSetButton = new QPushButton("add barset");
connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset()));
m_buttonLayout->addWidget(addSetButton, 2, 0);
QPushButton *removeBarsetButton = new QPushButton("remove barset");
connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset()));
m_buttonLayout->addWidget(removeBarsetButton, 3, 0);
sauimone
better legend detach layout. updated legend example
r1444 QPushButton *leftButton = new QPushButton("Align legend left");
connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft()));
m_buttonLayout->addWidget(leftButton, 4, 0);
QPushButton *rightButton = new QPushButton("Align legend right");
connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight()));
m_buttonLayout->addWidget(rightButton, 5, 0);
QPushButton *topButton = new QPushButton("Align legend top");
connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop()));
m_buttonLayout->addWidget(topButton, 6, 0);
QPushButton *bottomButton = new QPushButton("Align legend bottom");
connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom()));
m_buttonLayout->addWidget(bottomButton, 7, 0);
sauimone
legend font fix
r1522 QPushButton *boldButton = new QPushButton("Toggle bold");
connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold()));
m_buttonLayout->addWidget(boldButton, 8, 0);
QPushButton *italicButton = new QPushButton("Toggle italic");
connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic()));
m_buttonLayout->addWidget(italicButton, 9, 0);
sauimone
better legend detach layout. updated legend example
r1444 m_legendPosX = new QDoubleSpinBox();
m_legendPosY = new QDoubleSpinBox();
m_legendWidth = new QDoubleSpinBox();
m_legendHeight = new QDoubleSpinBox();
connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
QFormLayout* legendLayout = new QFormLayout();
legendLayout->addRow("Horizontal position", m_legendPosX);
legendLayout->addRow("Vertical position", m_legendPosY);
legendLayout->addRow("Width", m_legendWidth);
legendLayout->addRow("Height", m_legendHeight);
m_legendSettings = new QGroupBox("Detached legend");
m_legendSettings->setLayout(legendLayout);
m_buttonLayout->addWidget(m_legendSettings);
m_legendSettings->setVisible(false);
sauimone
legend detach example. Bug fixes to legend.
r1263 // Create chart view with the chart
sauimone
legend example to documentation. minor legend fixes
r1300 m_chart = new QChart();
sauimone
legend detach example. Bug fixes to legend.
r1263 m_chartView = new QChartView(m_chart, this);
sauimone
legend font fix
r1522 // Create spinbox to modify font size
m_fontSize = new QDoubleSpinBox();
m_fontSize->setValue(m_chart->legend()->font().pointSizeF());
connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged()));
QFormLayout* fontLayout = new QFormLayout();
fontLayout->addRow("Legend font size", m_fontSize);
sauimone
legend detach example. Bug fixes to legend.
r1263 // Create layout for grid and detached legend
m_mainLayout = new QGridLayout();
m_mainLayout->addLayout(m_buttonLayout, 0, 0);
sauimone
legend font fix
r1522 m_mainLayout->addLayout(fontLayout,1,0);
sauimone
legend detach example. Bug fixes to legend.
r1263 m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
setLayout(m_mainLayout);
createSeries();
}
void MainWidget::createSeries()
{
sauimone
GroupedBarSeries to BarSeries
r1594 m_series = new QBarSeries();
sauimone
legend detach example. Bug fixes to legend.
r1263 addBarset();
addBarset();
addBarset();
addBarset();
m_chart->addSeries(m_series);
m_chart->setTitle("Legend detach example");
Marek Rosa
Updated spline nad legend example
r1585 m_chart->createDefaultAxes();
sauimone
updated legend documentation
r1447 //![1]
sauimone
legend detach example. Bug fixes to legend.
r1263 m_chart->legend()->setVisible(true);
Tero Ahola
Qml ChartView properties; legend to use Qt alignments
r1357 m_chart->legend()->setAlignment(Qt::AlignBottom);
sauimone
updated legend documentation
r1447 //![1]
sauimone
legend detach example. Bug fixes to legend.
r1263
Michal Klocek
Refactors QAxis to QAbstractAxis...
r1541 //TODO:m_chart->axisY()->setNiceNumbersEnabled(true);
sauimone
legend detach example. Bug fixes to legend.
r1263 m_chartView->setRenderHint(QPainter::Antialiasing);
}
sauimone
better legend detach layout. updated legend example
r1444 void MainWidget::showLegendSpinbox()
{
m_legendSettings->setVisible(true);
QRectF chartViewRect = m_chartView->rect();
m_legendPosX->setMinimum(0);
m_legendPosX->setMaximum(chartViewRect.width());
m_legendPosX->setValue(150);
m_legendPosY->setMinimum(0);
m_legendPosY->setMaximum(chartViewRect.height());
m_legendPosY->setValue(150);
m_legendWidth->setMinimum(0);
m_legendWidth->setMaximum(chartViewRect.width());
m_legendWidth->setValue(150);
m_legendHeight->setMinimum(0);
m_legendHeight->setMaximum(chartViewRect.height());
sauimone
fixed legend scrolling in detached mode. updated example
r1446 m_legendHeight->setValue(75);
sauimone
better legend detach layout. updated legend example
r1444 }
void MainWidget::hideLegendSpinbox()
{
m_legendSettings->setVisible(false);
}
sauimone
legend example update
r1273 void MainWidget::detachLegend()
sauimone
legend detach example. Bug fixes to legend.
r1263 {
sauimone
updated legend documentation
r1447 //![2]
sauimone
legend detach example. Bug fixes to legend.
r1263 QLegend *legend = m_chart->legend();
sauimone
legend example update
r1273 legend->detachFromChart();
sauimone
better legend detach layout. updated legend example
r1444
m_chart->legend()->setBackgroundVisible(true);
m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128)));
sauimone
added roundness to legend background
r1453 m_chart->legend()->setPen(QPen(QColor(192,192,192,192)));
sauimone
updated legend documentation
r1447 //![2]
sauimone
legend detach example. Bug fixes to legend.
r1263
sauimone
better legend detach layout. updated legend example
r1444 showLegendSpinbox();
updateLegendLayout();
update();
sauimone
legend detach example. Bug fixes to legend.
r1263 }
sauimone
legend example update
r1273
void MainWidget::attachLegend()
sauimone
legend detach example. Bug fixes to legend.
r1263 {
sauimone
updated legend documentation
r1447 //![3]
sauimone
legend detach example. Bug fixes to legend.
r1263 QLegend *legend = m_chart->legend();
sauimone
better legend detach layout. updated legend example
r1444 legend->attachToChart();
m_chart->legend()->setBackgroundVisible(false);
sauimone
updated legend documentation
r1447 //![3]
sauimone
legend detach example. Bug fixes to legend.
r1263
sauimone
better legend detach layout. updated legend example
r1444 hideLegendSpinbox();
update();
sauimone
legend detach example. Bug fixes to legend.
r1263 }
void MainWidget::addBarset()
{
sauimone
barsetCount -> count in tests and examples too
r1463 QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count()));
qreal delta = m_series->count() * 0.1;
sauimone
Removed QPointF from QBarSet
r1580 *barSet << 1 + delta << 2 + delta << 3 + delta << 4 + delta;
sauimone
legend detach example. Bug fixes to legend.
r1263 m_series->append(barSet);
}
void MainWidget::removeBarset()
{
sauimone
fixed crash in legend example
r1396 QList<QBarSet*> sets = m_series->barSets();
if (sets.count() > 0) {
m_series->remove(sets.at(sets.count()-1));
}
sauimone
legend detach example. Bug fixes to legend.
r1263 }
sauimone
better legend detach layout. updated legend example
r1444
void MainWidget::setLegendLeft()
{
m_chart->legend()->setAlignment(Qt::AlignLeft);
}
void MainWidget::setLegendRight()
{
m_chart->legend()->setAlignment(Qt::AlignRight);
}
void MainWidget::setLegendTop()
{
m_chart->legend()->setAlignment(Qt::AlignTop);
}
void MainWidget::setLegendBottom()
{
m_chart->legend()->setAlignment(Qt::AlignBottom);
}
sauimone
legend font fix
r1522 void MainWidget::toggleBold()
{
QFont font = m_chart->legend()->font();
font.setBold(!font.bold());
m_chart->legend()->setFont(font);
}
void MainWidget::toggleItalic()
{
QFont font = m_chart->legend()->font();
font.setItalic(!font.italic());
m_chart->legend()->setFont(font);
}
void MainWidget::fontSizeChanged()
{
QFont font = m_chart->legend()->font();
font.setPointSizeF(m_fontSize->value());
m_chart->legend()->setFont(font);
}
sauimone
better legend detach layout. updated legend example
r1444 void MainWidget::updateLegendLayout()
{
sauimone
updated legend documentation
r1447 //![4]
Michal Klocek
Refactors layout managment...
r1534 m_chart->legend()->setGeometry(QRectF(m_legendPosX->value()
sauimone
better legend detach layout. updated legend example
r1444 ,m_legendPosY->value()
,m_legendWidth->value()
Michal Klocek
Refactors layout managment...
r1534 ,m_legendHeight->value()));
sauimone
better legend detach layout. updated legend example
r1444 m_chart->legend()->update();
sauimone
updated legend documentation
r1447 //![4]
sauimone
better legend detach layout. updated legend example
r1444 }