##// END OF EJS Templates
Add missing files from previous commit
Add missing files from previous commit

File last commit:

r679:2f2494d0880e
r680:86b5fb2a7994
Show More
barchartitem.cpp
266 lines | 7.3 KiB | text/x-c | CppLexer
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 #include "barchartitem_p.h"
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 #include "bar_p.h"
sauimone
Floating values to bar charts
r263 #include "barvalue_p.h"
sauimone
minor fix
r240 #include "qbarset.h"
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 #include "qbarseries.h"
sauimone
Labels for barchart to axis
r487 #include "qchart.h"
#include "qchartaxis.h"
#include "qchartaxiscategories.h"
sauimone
barhcart zvalue added
r594 #include "chartpresenter_p.h"
sauimone
Animation framework for barchart.
r671 #include "chartanimator_p.h"
Michal Klocek
Refactors barchart axis hadnling...
r679 #include "chartdataset_p.h"
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 #include <QDebug>
sauimone
moved tooltip to presenter
r288 #include <QToolTip>
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors chartitem...
r677 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
ChartItem(presenter),
Tero Ahola
Fixed initial bounding rect issue with bar series
r518 mLayoutSet(false),
Michal Klocek
Refactors chartitem...
r677 mSeries(series)
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 {
sauimone
moved tooltip to presenter
r288 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged()));
sauimone
Animation framework for barchart.
r671 //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged()));
connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int)));
sauimone
barhcart zvalue added
r594 setZValue(ChartPresenter::BarSeriesZValue);
sauimone
Labels for barchart to axis
r487 initAxisLabels();
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 dataChanged();
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 BarChartItem::~BarChartItem()
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 {
sauimone
moved tooltip to presenter
r288 disconnect(this,SLOT(showToolTip(QPoint,QString)));
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 {
if (!mLayoutSet) {
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 qDebug() << "BarChartItem::paint called without layout set. Aborting.";
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 return;
}
sauimone
Fixed layout for barcharts
r473 foreach(QGraphicsItem* i, childItems()) {
i->paint(painter,option,widget);
}
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 QRectF BarChartItem::boundingRect() const
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 {
Michal Klocek
Refactors barchart axis hadnling...
r679 return m_rect;
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::dataChanged()
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 {
sauimone
removed barchartseriesbase. functionality is now in model
r172 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 // Delete old bars
foreach (QGraphicsItem* item, childItems()) {
delete item;
}
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 mBars.clear();
sauimone
Floating values to bar charts
r263 mFloatingValues.clear();
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 // Create new graphic items for bars
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 for (int c=0; c<mSeries->categoryCount(); c++) {
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 QString category = mSeries->categoryName(c);
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 for (int s=0; s<mSeries->barsetCount(); s++) {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QBarSet *set = mSeries->barsetAt(s);
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 Bar *bar = new Bar(category,this);
sauimone
signals and slots for bars and sets
r239 childItems().append(bar);
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 mBars.append(bar);
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString)));
connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString)));
sauimone
right click feature for bar series. Enables drilldown
r412 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint)));
connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent()));
sauimone
signals and slots for bars and sets
r239 }
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
cleanup on barseries. removed old commented out separator code
r654
sauimone
Floating values to bar charts
r263 // Create floating values
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 for (int category=0; category<mSeries->categoryCount(); category++) {
for (int s=0; s<mSeries->barsetCount(); s++) {
sauimone
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
r357 QBarSet *set = mSeries->barsetAt(s);
sauimone
toggling of floating values. still bit buggy
r267 BarValue *value = new BarValue(*set, this);
sauimone
Floating values to bar charts
r263 childItems().append(value);
mFloatingValues.append(value);
sauimone
updated barchart examples. minor fixes
r276 connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible()));
sauimone
Floating values to bar charts
r263 }
}
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::layoutChanged()
{
// Scale bars to new layout
// Layout for bars:
if (mSeries->barsetCount() <= 0) {
qDebug() << "No sets in model!";
return;
}
if (childItems().count() == 0) {
qDebug() << "WARNING: BarChartitem::layoutChanged called before graphics items are created!";
return;
}
Michal Klocek
Refactors barchart axis hadnling...
r679 // Use temporary qreals for accurancy (we might get some compiler warnings... :)
qreal categoryCount = mSeries->categoryCount();
qreal setCount = mSeries->barsetCount();
qreal max = mSeries->max();
sauimone
barchart domain fix
r674
// Domain:
Michal Klocek
Refactors barchart axis hadnling...
r679 if (mDomainMaxY > max) {
max = mDomainMaxY;
}
sauimone
barchart domain fix
r674
Michal Klocek
Refactors barchart axis hadnling...
r679 qreal width = geometry().width();
qreal height = geometry().height();
qreal scale = (height/max);
qreal categoryWidth = width/categoryCount;
qreal barWidth = categoryWidth / (setCount+1);
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666
int itemIndex(0);
for (int category=0; category < categoryCount; category++) {
Michal Klocek
Refactors barchart axis hadnling...
r679 qreal xPos = categoryWidth * category + barWidth/2;
qreal yPos = height;
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 for (int set = 0; set < setCount; set++) {
qreal barHeight = mSeries->valueAt(set,category) * scale;
Bar* bar = mBars.at(itemIndex);
// TODO: width settable per bar?
Michal Klocek
Refactors barchart axis hadnling...
r679 bar->setRect(xPos, yPos-barHeight,barWidth, barHeight);
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 bar->setPen(mSeries->barsetAt(set)->pen());
bar->setBrush(mSeries->barsetAt(set)->brush());
Michal Klocek
Refactors barchart axis hadnling...
r679
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 itemIndex++;
Michal Klocek
Refactors barchart axis hadnling...
r679 xPos += barWidth;
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 }
}
// Position floating values
itemIndex = 0;
for (int category=0; category < mSeries->categoryCount(); category++) {
Michal Klocek
Refactors barchart axis hadnling...
r679 qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth;
qreal yPos = height;
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 for (int set=0; set < mSeries->barsetCount(); set++) {
qreal barHeight = mSeries->valueAt(set,category) * scale;
BarValue* value = mFloatingValues.at(itemIndex);
QBarSet* barSet = mSeries->barsetAt(set);
value->resize(100,50); // TODO: proper layout for this.
value->setPos(xPos, yPos-barHeight/2);
value->setPen(barSet->floatingValuePen());
if (mSeries->valueAt(set,category) != 0) {
value->setValueString(QString::number(mSeries->valueAt(set,category)));
} else {
value->setValueString(QString(""));
}
itemIndex++;
Michal Klocek
Refactors barchart axis hadnling...
r679 xPos += barWidth;
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 }
}
update();
}
sauimone
Animation framework for barchart.
r671 BarLayout BarChartItem::calculateLayout()
{
BarLayout layout;
foreach(Bar* bar, mBars) {
Michal Klocek
Refactors barchart axis hadnling...
r679 layout.insert(bar,bar->boundingRect());
sauimone
Animation framework for barchart.
r671 }
return layout;
}
void BarChartItem::applyLayout(const BarLayout &layout)
{
Michal Klocek
Refactors barchart axis hadnling...
r679 if (animator())
animator()->updateLayout(this, layout);
sauimone
Animation framework for barchart.
r671 else
setLayout(layout);
}
void BarChartItem::setLayout(const BarLayout &layout)
{
foreach (Bar *bar, layout.keys()) {
Michal Klocek
Refactors barchart axis hadnling...
r679 bar->setRect(layout.value(bar));
sauimone
Animation framework for barchart.
r671 }
update();
}
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666
void BarChartItem::initAxisLabels()
sauimone
Labels for barchart to axis
r487 {
int count = mSeries->categoryCount();
if (0 == count) {
return;
}
Michal Klocek
Refactors barchart axis hadnling...
r679 Domain* domain = presenter()->dataSet()->domain(mSeries);
sauimone
Labels for barchart to axis
r487
qreal min = 0;
Michal Klocek
Axis refactoring to support better barcharts
r502 qreal max = count+1;
sauimone
Labels for barchart to axis
r487
Michal Klocek
Refactors barchart axis hadnling...
r679 domain->setRangeX(min,max,count+1);
sauimone
Labels for barchart to axis
r487 }
Michal Klocek
Refactored for MVP...
r139 //handlers
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::handleModelChanged(int index)
Michal Klocek
Refactored for MVP...
r139 {
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(index)
sauimone
model delegate for bar series. updated examples
r161 dataChanged();
Michal Klocek
Refactored for MVP...
r139 }
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
Michal Klocek
Refactored for MVP...
r139 {
sauimone
barchart domain fix
r674 mDomainMinX = minX;
mDomainMaxX = maxX;
mDomainMinY = minY;
mDomainMaxY = maxY;
layoutChanged();
Tero Ahola
Squashed bunch of warnings
r611
sauimone
Labels for barchart to axis
r487 /*
int count = mSeries->categoryCount();
if (0 == count) {
return;
}
// Position labels to domain
qreal min = domain.minX();
qreal max = domain.maxX();
qreal step = (max-min)/count;
QChartAxisCategories& categories = mChart->axisX()->categories();
categories.clear();
for (int i=0; i<count; i++) {
categories.insert(min,mSeries->categoryName(i));
min += step;
}
*/
Michal Klocek
Refactored for MVP...
r139 }
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::handleGeometryChanged(const QRectF& rect)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactors barchart axis hadnling...
r679 m_rect=rect;
Michal Klocek
Refactored for MVP...
r139 layoutChanged();
mLayoutSet = true;
setPos(rect.topLeft());
}
sauimone
Animation framework for barchart.
r671 void BarChartItem::handleLayoutChanged()
{
BarLayout layout = calculateLayout();
applyLayout(layout);
update();
}
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 void BarChartItem::showToolTip(QPoint pos, QString tip)
sauimone
moved tooltip to presenter
r288 {
sauimone
enablers for tooltip and floating values, bug fixing, updated examples. tidying up the code
r296 // TODO: cool tooltip instead of default
QToolTip::showText(pos,tip);
sauimone
moved tooltip to presenter
r288 }
sauimone
barcharts: added legend to model. added signals for hover events (for tooltip). updated examples
r280
sauimone
combined barpresenterbase and barpresenter. renamed barchartpresenters to barchartitems
r666 #include "moc_barchartitem_p.cpp"
Michal Klocek
Refactored for MVP...
r139
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 QTCOMMERCIALCHART_END_NAMESPACE