##// END OF EJS Templates
Add ownerships takeover to chartaxis
Add ownerships takeover to chartaxis

File last commit:

r216:abacdc3682d1
r248:ded845353666
Show More
percentbarpresenter.cpp
80 lines | 2.6 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
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 {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 // qDebug() << "PercentBarGroup::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) {
qDebug() << "WARNING: PercentBarGroup::layoutChanged called before graphics items are created!";
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);
qreal tW = mWidth;
qreal tC = count+1;
qreal xStep = (tW/tC);
sauimone
added labels to barcharts
r114 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
sauimone
Barset and barcategory implememtation. Updated test application
r171 int labelIndex = mModel.countCategories() * mModel.countSets();
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 h = mHeight;
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
percent bar chart
r101 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
// TODO: width settable per bar?
bar->resize(mBarDefaultWidth, barHeight);
sauimone
Added pen & brush to QBarSet
r214 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
BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex));
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
int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these?
xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left.
sauimone
Barset and barcategory implememtation. Updated test application
r171 for (int s=0; s < mModel.countCategories() - 1; s++) {
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex));
sep->setPos(xPos,0);
sep->setSize(QSizeF(1,mHeight));
xPos += xStep;
separatorIndex++;
}
sauimone
model delegate for bar series. updated examples
r161
sauimone
percent bar chart
r101 mLayoutDirty = true;
}
QTCOMMERCIALCHART_END_NAMESPACE