##// END OF EJS Templates
Restored bar series in chartwidgettest
Restored bar series in chartwidgettest

File last commit:

r276:d062a7f38647
r279:22961f3dbd96
Show More
percentbarpresenter.cpp
107 lines | 3.2 KiB | text/x-c | CppLexer
/ src / barchart / percentbarpresenter.cpp
sauimone
Common naming convention for barcharts
r216 #include "percentbarpresenter.h"
sauimone
renamed bar.h to bar_p.h
r118 #include "bar_p.h"
sauimone
added labels to barcharts
r114 #include "barlabel_p.h"
sauimone
Floating values to bar charts
r263 #include "barvalue_p.h"
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 #include "separator_p.h"
sauimone
Added pen & brush to QBarSet
r214 #include "qbarset.h"
sauimone
percent bar chart
r101 #include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
sauimone
Common naming convention for barcharts
r216 PercentBarPresenter::PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent) :
BarPresenterBase(model, parent)
sauimone
percent bar chart
r101 {
}
sauimone
Common naming convention for barcharts
r216 void PercentBarPresenter::layoutChanged()
sauimone
percent bar chart
r101 {
// Scale bars to new layout
// Layout for bars:
sauimone
Barset and barcategory implememtation. Updated test application
r171 if (mModel.countSets() <= 0) {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 qDebug() << "No sets in model!";
sauimone
percent bar chart
r101 // Nothing to do.
return;
}
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 if (childItems().count() == 0) {
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 qDebug() << "WARNING: PercentBarPresenter::layoutChanged called before graphics items are created!";
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 return;
}
sauimone
percent bar chart
r101 // TODO: better way to auto-layout
// Use reals for accurancy (we might get some compiler warnings... :)
sauimone
Barset and barcategory implememtation. Updated test application
r171 int count = mModel.countCategories();
sauimone
percent bar chart
r101 int itemIndex(0);
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 int labelIndex(0);
sauimone
percent bar chart
r101 qreal tW = mWidth;
qreal tC = count+1;
qreal xStep = (tW/tC);
sauimone
added labels to barcharts
r114 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
sauimone
Floating values to bar charts
r263 qreal h = mHeight;
sauimone
percent bar chart
r101
sauimone
brush support for bargroups
r183 for (int category = 0; category < mModel.countCategories(); category++) {
qreal colSum = mModel.categorySum(category);
sauimone
fixed naming mixup with percent and stacked groups
r105 qreal scale = (h / colSum);
sauimone
percent bar chart
r101 qreal yPos = h;
sauimone
brush support for bargroups
r183 for (int set=0; set < mModel.countSets(); set++) {
qreal barHeight = mModel.valueAt(set, category) * scale;
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 Bar* bar = mBars.at(itemIndex);
sauimone
percent bar chart
r101
// TODO: width settable per bar?
bar->resize(mBarDefaultWidth, barHeight);
sauimone
floating values working now. bounding rect bug fixed
r273 bar->setBrush(mModel.setAt(set)->brush());
sauimone
theme interface to barcharts. some minor fixes
r113 bar->setPos(xPos, yPos-barHeight);
sauimone
percent bar chart
r101 itemIndex++;
yPos -= barHeight;
}
sauimone
added labels to barcharts
r114
// TODO: Layout for labels, remove magic number
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 BarLabel* label = mLabels.at(labelIndex);
sauimone
added labels to barcharts
r114 label->setPos(xPos, mHeight + 20);
labelIndex++;
sauimone
percent bar chart
r101 xPos += xStep;
}
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126
// Position separators
sauimone
Bug fix for bar presenters. It appears that order of childItems may change. Relying on order caused crash
r256 xPos = xStep + xStep/2;
sauimone
Barset and barcategory implememtation. Updated test application
r171 for (int s=0; s < mModel.countCategories() - 1; s++) {
sauimone
Floating values to bar charts
r263 Separator* sep = mSeparators.at(s);
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 sep->setPos(xPos,0);
sep->setSize(QSizeF(1,mHeight));
xPos += xStep;
sauimone
Floating values to bar charts
r263 }
// Position floating values
itemIndex = 0;
xPos = ((tW/tC) - mBarDefaultWidth / 2);
for (int category=0; category < mModel.countCategories(); category++) {
qreal yPos = h;
qreal colSum = mModel.categorySum(category);
qreal scale = (h / colSum);
for (int set=0; set < mModel.countSets(); set++) {
qreal barHeight = mModel.valueAt(set,category) * scale;
BarValue* value = mFloatingValues.at(itemIndex);
// TODO: remove hard coding, apply layout
sauimone
updated barchart examples. minor fixes
r276 value->setPos(xPos, yPos-barHeight/2);
sauimone
Floating values to bar charts
r263 value->setPen(QPen(QColor(255,255,255,255)));
sauimone
updated barchart examples. minor fixes
r276 if (mModel.valueAt(set,category) != 0) {
QString vString(QString::number(mModel.percentageAt(set,category) * 100));
vString.append("%");
value->setValueString(vString);
} else {
value->setValueString(QString(""));
}
sauimone
Floating values to bar charts
r263
itemIndex++;
yPos -= barHeight;
}
xPos += xStep;
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
sauimone
model delegate for bar series. updated examples
r161
sauimone
percent bar chart
r101 mLayoutDirty = true;
}
QTCOMMERCIALCHART_END_NAMESPACE