##// END OF EJS Templates
Adds area chart...
Adds area chart * adds area chart implementation * adds QAreaSeries * adds areachart example * adds documentation * updates "about" , "classes" and "example" documentation pages

File last commit:

r421:fe0a0dc06876
r421:fe0a0dc06876
Show More
charttheme.cpp
300 lines | 8.8 KiB | text/x-c | CppLexer
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 #include "charttheme_p.h"
#include "qchart.h"
Michal Klocek
Adds more axis handling...
r176 #include "qchartaxis.h"
Jani Honkonen
Fix color generation for pie
r324 #include <QTime>
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
Michal Klocek
Refactor themes...
r143 //series
sauimone
Added pen & brush to QBarSet
r214 #include "qbarset.h"
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 #include "qbarseries.h"
#include "qstackedbarseries.h"
#include "qpercentbarseries.h"
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 #include "qlineseries.h"
Michal Klocek
Adds area chart...
r421 #include "qareaseries.h"
Tero Ahola
Enabled theme colors in scatter again
r182 #include "qscatterseries.h"
Jani Honkonen
Make pie work better with chartwidgettest
r163 #include "qpieseries.h"
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 #include "qpieslice.h"
Jani Honkonen
Make pie work better with chartwidgettest
r163
Michal Klocek
Refactor themes...
r143 //items
#include "axisitem_p.h"
sauimone
added _p to private class headers
r381 #include "barpresenter_p.h"
#include "stackedbarpresenter_p.h"
#include "percentbarpresenter_p.h"
Michal Klocek
Fix previous broken commit
r145 #include "linechartitem_p.h"
Michal Klocek
Adds area chart...
r421 #include "areachartitem_p.h"
Tero Ahola
Moved scatter impl into a subfolder
r194 #include "scatterpresenter_p.h"
Jani Honkonen
Add _p to pie internal headers
r353 #include "piepresenter_p.h"
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
Michal Klocek
Refactor themes...
r143 //themes
#include "chartthemevanilla_p.h"
#include "chartthemeicy_p.h"
#include "chartthemegrayscale_p.h"
#include "chartthemescientific_p.h"
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
Tero Ahola
tuning theme colors
r125
Michal Klocek
Refactor themes...
r143 QTCOMMERCIALCHART_BEGIN_NAMESPACE
/* TODO
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 case QChart::ChartThemeUnnamed1:
Tero Ahola
One more alternative for changing themes
r108 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
m_gradientEndColor = QColor(QRgb(0xffafafaf));
Michal Klocek
Refactor themes...
r143 */
Michal Klocek
Adds missing ids to theme classes
r153 ChartTheme::ChartTheme(QChart::ChartTheme id)
Michal Klocek
Refactor themes...
r143 {
Michal Klocek
Adds missing ids to theme classes
r153 m_id = id;
Michal Klocek
Refactor themes...
r143 m_seriesColor.append(QRgb(0xff000000));
m_seriesColor.append(QRgb(0xff707070));
m_gradientStartColor = QColor(QRgb(0xffffffff));
m_gradientEndColor = QColor(QRgb(0xffafafaf));
Jani Honkonen
Fix color generation for pie
r324
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
Michal Klocek
Refactor themes...
r143 }
Michal Klocek
Adds missing ids to theme classes
r153 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
Michal Klocek
Refactor themes...
r143 {
switch(theme) {
case QChart::ChartThemeDefault:
Michal Klocek
Adds area chart...
r421 return new ChartTheme();
Michal Klocek
Refactor themes...
r143 case QChart::ChartThemeVanilla:
return new ChartThemeVanilla();
case QChart::ChartThemeIcy:
return new ChartThemeIcy();
case QChart::ChartThemeGrayscale:
return new ChartThemeGrayscale();
case QChart::ChartThemeScientific:
return new ChartThemeScientific();
}
}
void ChartTheme::decorate(QChart* chart)
{
QLinearGradient backgroundGradient;
backgroundGradient.setColorAt(0.0, m_gradientStartColor);
backgroundGradient.setColorAt(1.0, m_gradientEndColor);
backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
chart->setChartBackgroundBrush(backgroundGradient);
}
//TODO helper to by removed later
Michal Klocek
Rename QChartSeries to QSeries
r360 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
Michal Klocek
Refactor themes...
r143 {
switch(series->type())
{
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeLine: {
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 QLineSeries* s = static_cast<QLineSeries*>(series);
Michal Klocek
Fix previous broken commit
r145 LineChartItem* i = static_cast<LineChartItem*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,s,count);
break;
}
Michal Klocek
Adds area chart...
r421 case QSeries::SeriesTypeArea: {
QAreaSeries* s = static_cast<QAreaSeries*>(series);
AreaChartItem* i = static_cast<AreaChartItem*>(item);
decorate(i,s,count);
break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeBar: {
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QBarSeries* b = static_cast<QBarSeries*>(series);
sauimone
Common naming convention for barcharts
r216 BarPresenter* i = static_cast<BarPresenter*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,b,count);
break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeStackedBar: {
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
sauimone
Common naming convention for barcharts
r216 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,s,count);
break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypePercentBar: {
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
sauimone
Common naming convention for barcharts
r216 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,s,count);
break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeScatter: {
Tero Ahola
Scatter series marker visuals
r195 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
Q_ASSERT(s);
ScatterPresenter* i = static_cast<ScatterPresenter*>(item);
Q_ASSERT(i);
decorate(i, s, count);
break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypePie: {
Jani Honkonen
Make pie work better with chartwidgettest
r163 QPieSeries* s = static_cast<QPieSeries*>(series);
PiePresenter* i = static_cast<PiePresenter*>(item);
decorate(i,s,count);
break;
}
Michal Klocek
Refactor themes...
r143 default:
qDebug()<<"Wrong item to be decorated by theme";
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 break;
}
Michal Klocek
Refactor themes...
r143
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 }
Michal Klocek
Adds area chart...
r421 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
{
QPen pen;
QBrush brush;
if(pen != series->pen()){
item->setPen(series->pen());
}else{
pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
pen.setWidthF(2);
item->setPen(pen);
}
if(brush != series->brush()){
item->setBrush(series->brush());
}else{
QBrush brush(m_seriesColor.at(count%m_seriesColor.size()));
item->setBrush(brush);
}
}
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 {
Michal Klocek
Adds to themes support to lineseries
r152 QPen pen;
if(pen != series->pen()){
item->setPen(series->pen());
return;
}
pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
pen.setWidthF(2);
item->setPen(pen);
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 }
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
Tero Ahola
One more alternative for changing themes
r108 {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QList<QBarSet*> sets = series->barSets();
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 for (int i=0; i<series->barsetCount(); i++) {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
sauimone
integrating bar charts to test app.. crashes for now
r164 }
Tero Ahola
One more alternative for changing themes
r108 }
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QList<QBarSet*> sets = series->barSets();
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 for (int i=0; i<series->barsetCount(); i++) {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
sauimone
integrating bar charts to test app.. crashes for now
r164 }
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 }
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
Michal Klocek
Refactor themes...
r143 {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QList<QBarSet*> sets = series->barSets();
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 for (int i=0; i<series->barsetCount(); i++) {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
sauimone
integrating bar charts to test app.. crashes for now
r164 }
Michal Klocek
Refactor themes...
r143 }
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
Tero Ahola
Enabled theme colors in scatter again
r182 void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count)
{
Q_ASSERT(presenter);
Q_ASSERT(series);
Tero Ahola
Scatter series marker visuals
r195 QColor color = m_seriesColor.at(count % m_seriesColor.size());
// TODO: define alpha in the theme? or in the series?
Tero Ahola
Refactored chartwidgettest test data impl
r278 //color.setAlpha(120);
Tero Ahola
Scatter series marker visuals
r195
QBrush brush(color, Qt::SolidPattern);
presenter->m_markerBrush = brush;
Tero Ahola
Enabled theme colors in scatter again
r182
Tero Ahola
Refactored chartwidgettest test data impl
r278 QPen pen(brush, 3);
Tero Ahola
Scatter series marker visuals
r195 pen.setColor(color);
presenter->m_markerPen = pen;
Tero Ahola
Enabled theme colors in scatter again
r182 }
Jani Honkonen
Make pie work better with chartwidgettest
r163 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
{
Jani Honkonen
Drafting pie theme stuff
r166 // create a list of slice colors based on current theme
int i = 0;
QList<QColor> colors;
while (colors.count() < series->count()) {
// get base color
QColor c = m_seriesColor[i++];
i = i % m_seriesColor.count();
Jani Honkonen
Do not use black color from theme for pie. Looks bad.
r340 // dont use black colors... looks bad
if (c == Qt::black)
continue;
Jani Honkonen
Fix color generation for pie
r324 // by default use the "raw" theme color
if (!colors.contains(c)) {
colors << c;
continue;
}
// ...ok we need to generate something that looks like the same color
// but different lightness
int tryCount = 0;
while (tryCount++ < 100) {
Jani Honkonen
Drafting pie theme stuff
r166
Jani Honkonen
Fix color generation for pie
r324 // find maximum value we can raise the lightness
int lMax = 255;
if (lMax > 255 - c.red())
lMax = 255 - c.red();
if (lMax > 255 - c.green())
lMax = 255 - c.green();
if (lMax > 255 - c.blue())
lMax = 255 - c.blue();
Jani Honkonen
Drafting pie theme stuff
r166
Jani Honkonen
Fix color generation for pie
r324 // find maximum value we can make it darker
int dMax = 255;
if (dMax > c.red())
dMax = c.red();
if (dMax > c.green())
dMax = c.green();
if (dMax > c.blue())
dMax = c.blue();
int max = dMax + lMax;
if (max == 0) {
// no room to make color lighter or darker...
qDebug() << "cannot generate a color for pie!";
break;
}
// generate random color
int r = c.red() - dMax;
int g = c.green() - dMax;
int b = c.blue() - dMax;
int d = qrand() % max;
c.setRgb(r+d, g+d, b+d);
// found a unique color?
if (!colors.contains(c))
break;
Jani Honkonen
Drafting pie theme stuff
r166 }
Jani Honkonen
Fix color generation for pie
r324 qDebug() << "generated a color for pie" << c;
colors << c;
Jani Honkonen
Drafting pie theme stuff
r166 }
// finally update colors
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 foreach (QPieSlice* s, series->slices()) {
Jani Honkonen
Fix color generation for pie
r324 QColor c = colors.takeFirst();
s->setPen(c);
s->setBrush(c);
Jani Honkonen
Make pie work better with chartwidgettest
r163 }
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
Michal Klocek
Refactors axis handling...
r223 void ChartTheme::decorate(QChartAxis* axis,AxisItem* item)
Michal Klocek
Adds more axis handling...
r176 {
//TODO: dummy defults for now
Michal Klocek
Refactors axis handling...
r223 axis->setLabelsBrush(Qt::black);
axis->setLabelsPen(Qt::NoPen);
axis->setShadesPen(Qt::NoPen);
axis->setShadesOpacity(0.5);
Michal Klocek
Adds more axis handling...
r176 }
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 QTCOMMERCIALCHART_END_NAMESPACE