##// END OF EJS Templates
enablers for tooltip and floating values, bug fixing, updated examples. tidying up the code
enablers for tooltip and floating values, bug fixing, updated examples. tidying up the code

File last commit:

r278:1d8f8b316dca
r296:8254aab7233d
Show More
charttheme.cpp
229 lines | 6.9 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"
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
Common naming convention for barcharts
r216 #include "qbarchartseries.h"
#include "qstackedbarchartseries.h"
#include "qpercentbarchartseries.h"
Michal Klocek
Fix previous broken commit
r145 #include "qlinechartseries.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
Common naming convention for barcharts
r216 #include "barpresenter.h"
#include "stackedbarpresenter.h"
Michal Klocek
Fix previous broken commit
r145 #include "linechartitem_p.h"
sauimone
Common naming convention for barcharts
r216 #include "percentbarpresenter.h"
Tero Ahola
Moved scatter impl into a subfolder
r194 #include "scatterpresenter_p.h"
Jani Honkonen
Make pie work better with chartwidgettest
r163 #include "piepresenter.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));
}
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:
return new ChartTheme();
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
void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
{
switch(series->type())
{
case QChartSeries::SeriesTypeLine: {
Michal Klocek
Fix previous broken commit
r145 QLineChartSeries* s = static_cast<QLineChartSeries*>(series);
LineChartItem* i = static_cast<LineChartItem*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,s,count);
break;
}
case QChartSeries::SeriesTypeBar: {
sauimone
Common naming convention for barcharts
r216 QBarChartSeries* b = static_cast<QBarChartSeries*>(series);
BarPresenter* i = static_cast<BarPresenter*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,b,count);
break;
}
case QChartSeries::SeriesTypeStackedBar: {
sauimone
Common naming convention for barcharts
r216 QStackedBarChartSeries* s = static_cast<QStackedBarChartSeries*>(series);
StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,s,count);
break;
}
case QChartSeries::SeriesTypePercentBar: {
sauimone
Common naming convention for barcharts
r216 QPercentBarChartSeries* s = static_cast<QPercentBarChartSeries*>(series);
PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
Michal Klocek
Refactor themes...
r143 decorate(i,s,count);
break;
}
Tero Ahola
Scatter series marker visuals
r195 case QChartSeries::SeriesTypeScatter: {
QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
Q_ASSERT(s);
ScatterPresenter* i = static_cast<ScatterPresenter*>(item);
Q_ASSERT(i);
decorate(i, s, count);
break;
}
Jani Honkonen
Make pie work better with chartwidgettest
r163 case QChartSeries::SeriesTypePie: {
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
Fix previous broken commit
r145 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* 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
Common naming convention for barcharts
r216 void ChartTheme::decorate(BarPresenter* item, QBarChartSeries* series,int count)
Tero Ahola
One more alternative for changing themes
r108 {
sauimone
Added pen & brush to QBarSet
r214 for (int i=0; i<series->countSets(); i++) {
series->nextSet(0==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
Common naming convention for barcharts
r216 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarChartSeries* series,int count)
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 {
sauimone
Added pen & brush to QBarSet
r214 for (int i=0; i<series->countSets(); i++) {
series->nextSet(0==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
Common naming convention for barcharts
r216 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count)
Michal Klocek
Refactor themes...
r143 {
sauimone
Added pen & brush to QBarSet
r214 for (int i=0; i<series->countSets(); i++) {
series->nextSet(0==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();
// -1 means achromatic color -> cannot manipulate lightness
// TODO: find a better way to randomize lightness
if (c.toHsv().hue() == -1)
qWarning() << "ChartTheme::decorate() warning: achromatic theme color";
// randomize lightness
qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter
c = c.lighter(f);
// find duplicates
bool isUnique = true;
foreach (QColor color, colors) {
if (c == color)
isUnique = false;
}
// add to array if unique
//if (isUnique)
colors << c;
}
// 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()) {
s->setPen(QPen(Qt::black)); // TODO: get from theme
s->setBrush(colors.takeFirst());
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