@@ -27,6 +27,7 void Bar::setColor( QColor col ) | |||
|
27 | 27 | { |
|
28 | 28 | mColor = col; |
|
29 | 29 | } |
|
30 | ||
|
30 | 31 | void Bar::setPos(qreal x, qreal y) |
|
31 | 32 | { |
|
32 | 33 | // qDebug() << "Bar::setpos" << x << y; |
@@ -34,14 +35,25 void Bar::setPos(qreal x, qreal y) | |||
|
34 | 35 | mYpos = y; |
|
35 | 36 | } |
|
36 | 37 | |
|
38 | void Bar::setPen(QPen pen) | |
|
39 | { | |
|
40 | mPen = pen; | |
|
41 | } | |
|
42 | ||
|
43 | void Bar::setBrush(QBrush brush) | |
|
44 | { | |
|
45 | mBrush = brush; | |
|
46 | } | |
|
47 | ||
|
37 | 48 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
38 | 49 | { |
|
39 | 50 | if (0 == mHeight) { |
|
40 | 51 | return; |
|
41 | 52 | } |
|
42 | 53 | // TODO: accept brush instead of color |
|
43 | QBrush brush(mColor); | |
|
44 | painter->setBrush(brush); | |
|
54 | painter->setBrush(mBrush); | |
|
55 | // QBrush brush(mColor); | |
|
56 | // painter->setBrush(brush); | |
|
45 | 57 | |
|
46 | 58 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. |
|
47 | 59 | int x0 = mXpos; |
@@ -4,6 +4,8 | |||
|
4 | 4 | #include "chartitem_p.h" |
|
5 | 5 | #include "qchartglobal.h" |
|
6 | 6 | #include <QGraphicsItem> |
|
7 | #include <QPen> | |
|
8 | #include <QBrush> | |
|
7 | 9 | |
|
8 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 11 | |
@@ -17,9 +19,11 public: // from ChartItem | |||
|
17 | 19 | void setSize(const QSizeF &size); |
|
18 | 20 | |
|
19 | 21 | // Layout Stuff |
|
20 |
void resize( |
|
|
21 | void setColor( QColor col ); // Color of bar | |
|
22 | void resize(qreal w, qreal h); // Size of bar. | |
|
22 | 23 | void setPos(qreal x, qreal y); |
|
24 | void setPen(QPen pen); | |
|
25 | void setBrush(QBrush brush); | |
|
26 | void setColor( QColor col); // deprecated | |
|
23 | 27 | |
|
24 | 28 | public: |
|
25 | 29 | // From QGraphicsItem |
@@ -35,6 +39,9 private: | |||
|
35 | 39 | qreal mYpos; |
|
36 | 40 | QColor mColor; |
|
37 | 41 | |
|
42 | QBrush mBrush; | |
|
43 | QPen mPen; | |
|
44 | ||
|
38 | 45 | }; |
|
39 | 46 | |
|
40 | 47 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -29,36 +29,39 void BarGroup::layoutChanged() | |||
|
29 | 29 | // TODO: better way to auto-layout? |
|
30 | 30 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
31 | 31 | int itemCount = mModel.countCategories(); |
|
32 |
int se |
|
|
32 | int setCount = mModel.countSets(); | |
|
33 | 33 | |
|
34 | 34 | qreal tW = mWidth; |
|
35 | 35 | qreal tH = mHeight; |
|
36 | 36 | qreal tM = mModel.max(); |
|
37 | 37 | qreal scale = (tH/tM); |
|
38 | 38 | qreal tC = itemCount+1; |
|
39 |
qreal xStepPerSe |
|
|
39 | qreal xStepPerSet = (tW/tC); | |
|
40 | 40 | |
|
41 | 41 | // Scaling. |
|
42 | 42 | int itemIndex(0); |
|
43 |
int labelIndex = itemCount * se |
|
|
43 | int labelIndex = itemCount * setCount; | |
|
44 | 44 | |
|
45 | 45 | for (int item=0; item < itemCount; item++) { |
|
46 |
qreal xPos = xStepPerSe |
|
|
46 | qreal xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2)); | |
|
47 | 47 | qreal yPos = mHeight; |
|
48 |
for (int se |
|
|
49 |
qreal barHeight = mModel.valueAt(se |
|
|
48 | for (int set = 0; set < setCount; set++) { | |
|
49 | qreal barHeight = mModel.valueAt(set, item) * scale; | |
|
50 | 50 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
51 | 51 | |
|
52 | 52 | // TODO: width settable per bar? |
|
53 | 53 | bar->resize(mBarDefaultWidth, barHeight); |
|
54 |
bar->set |
|
|
55 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
|
54 | bar->setBrush(mBrushes.at(set)); | |
|
55 | // bar->setPen(mModel.barSet(set).pen()); | |
|
56 | // bar->setColor(mColors.at(set)); | |
|
57 | // bar->setPen(); | |
|
58 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight); | |
|
56 | 59 | itemIndex++; |
|
57 | 60 | xPos += mBarDefaultWidth; |
|
58 | 61 | } |
|
59 | 62 | |
|
60 | 63 | // TODO: Layout for labels, remove magic number |
|
61 |
xPos = xStepPerSe |
|
|
64 | xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2)); | |
|
62 | 65 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
63 | 66 | label->setPos(xPos, mHeight + 20); |
|
64 | 67 | labelIndex++; |
@@ -46,7 +46,7 void BarGroupBase::setBarWidth( int w ) | |||
|
46 | 46 | { |
|
47 | 47 | mBarDefaultWidth = w; |
|
48 | 48 | } |
|
49 | ||
|
49 | /* | |
|
50 | 50 | int BarGroupBase::addColor( QColor color ) |
|
51 | 51 |
|
|
52 | 52 |
|
@@ -54,12 +54,24 int BarGroupBase::addColor( QColor color ) | |||
|
54 | 54 | mColors.append(color); |
|
55 | 55 | return colorIndex; |
|
56 | 56 |
|
|
57 | ||
|
57 | */ | |
|
58 | /* | |
|
58 | 59 | void BarGroupBase::resetColors() |
|
59 | 60 |
|
|
60 | 61 |
|
|
61 | 62 | mColors.clear(); |
|
62 | 63 |
|
|
64 | */ | |
|
65 | void BarGroupBase::resetBrushes() | |
|
66 | { | |
|
67 | mBrushes.clear(); | |
|
68 | } | |
|
69 | ||
|
70 | void BarGroupBase::addBrush(QBrush brush) | |
|
71 | { | |
|
72 | mBrushes.append(brush); | |
|
73 | } | |
|
74 | ||
|
63 | 75 | |
|
64 | 76 | void BarGroupBase::dataChanged() |
|
65 | 77 | { |
@@ -3,6 +3,8 | |||
|
3 | 3 | |
|
4 | 4 | #include "chartitem_p.h" |
|
5 | 5 | #include "barchartmodel_p.h" |
|
6 | #include <QPen> | |
|
7 | #include <QBrush> | |
|
6 | 8 | #include <QGraphicsItem> |
|
7 | 9 | |
|
8 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -23,8 +25,18 public: | |||
|
23 | 25 | |
|
24 | 26 | // TODO: these may change with layout awarness. |
|
25 | 27 | void setBarWidth( int w ); |
|
26 | int addColor( QColor color ); | |
|
27 | void resetColors(); | |
|
28 | // int addColor( QColor color ); | |
|
29 | // void resetColors(); | |
|
30 | ||
|
31 | void resetBrushes(); | |
|
32 | void addBrush(QBrush brush); | |
|
33 | ||
|
34 | void setPen(QPen pen); | |
|
35 | QPen pen(); | |
|
36 | ||
|
37 | void setBrush(QBrush brush); | |
|
38 | QBrush brush(); | |
|
39 | ||
|
28 | 40 | |
|
29 | 41 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
30 | 42 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
@@ -49,6 +61,8 protected: | |||
|
49 | 61 | bool mSeparatorsVisible; |
|
50 | 62 | BarChartModel& mModel; |
|
51 | 63 | |
|
64 | QPen mPen; | |
|
65 | QList<QBrush> mBrushes; | |
|
52 | 66 | }; |
|
53 | 67 | |
|
54 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -38,18 +38,20 void PercentBarGroup::layoutChanged() | |||
|
38 | 38 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
39 | 39 | int labelIndex = mModel.countCategories() * mModel.countSets(); |
|
40 | 40 | |
|
41 |
for (int c |
|
|
42 |
qreal colSum = mModel.categorySum(c |
|
|
41 | for (int category = 0; category < mModel.countCategories(); category++) { | |
|
42 | qreal colSum = mModel.categorySum(category); | |
|
43 | 43 | qreal h = mHeight; |
|
44 | 44 | qreal scale = (h / colSum); |
|
45 | 45 | qreal yPos = h; |
|
46 |
for (int |
|
|
47 |
qreal barHeight = mModel.valueAt( |
|
|
46 | for (int set=0; set < mModel.countSets(); set++) { | |
|
47 | qreal barHeight = mModel.valueAt(set, category) * scale; | |
|
48 | 48 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
49 | 49 | |
|
50 | 50 | // TODO: width settable per bar? |
|
51 | 51 | bar->resize(mBarDefaultWidth, barHeight); |
|
52 |
bar->set |
|
|
52 | bar->setBrush(mBrushes.at(set)); | |
|
53 | // bar->setBrush(mBrush); | |
|
54 | // bar->setColor(mColors.at(set)); | |
|
53 | 55 | bar->setPos(xPos, yPos-barHeight); |
|
54 | 56 | itemIndex++; |
|
55 | 57 | yPos -= barHeight; |
@@ -31,6 +31,11 qreal QBarSet::valueAt(int index) | |||
|
31 | 31 | return mValues.at(index); |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | void QBarSet::setValue(int index, qreal value) | |
|
35 | { | |
|
36 | mValues.replace(index,value); | |
|
37 | } | |
|
38 | ||
|
34 | 39 | //TODO?: |
|
35 | 40 | //#include "moc_qbarset.cpp" |
|
36 | 41 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -2,6 +2,8 | |||
|
2 | 2 | #define QBARSET_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | #include <QPen> | |
|
6 | #include <QBrush> | |
|
5 | 7 | |
|
6 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 9 | |
@@ -13,18 +15,16 public: | |||
|
13 | 15 | |
|
14 | 16 | void setName(QString name); |
|
15 | 17 | QString name(); |
|
16 | QBarSet& operator << (const qreal &value); | |
|
18 | QBarSet& operator << (const qreal &value); // appends new value to set | |
|
17 | 19 | |
|
18 | //TODO: What is the way to set a single value to n:th item? Is there need for such functionality? | |
|
19 | ||
|
20 | int count(); | |
|
21 | qreal valueAt(int index); | |
|
20 | int count(); // count of values in set | |
|
21 | qreal valueAt(int index); // for modifying individual values | |
|
22 | void setValue(int index, qreal value); // | |
|
22 | 23 | |
|
23 | 24 | private: |
|
24 | 25 | |
|
25 | 26 | QString mName; |
|
26 | 27 | QList<qreal> mValues; |
|
27 | ||
|
28 | 28 | }; |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -35,7 +35,7 void StackedBarGroup::layoutChanged() | |||
|
35 | 35 | |
|
36 | 36 | // TODO: better way to auto-layout |
|
37 | 37 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
38 |
// TODO: use temp variable for c |
|
|
38 | // TODO: use temp variable for category count... | |
|
39 | 39 | qreal maxSum = mModel.maxCategorySum(); |
|
40 | 40 | qreal h = mHeight; |
|
41 | 41 | qreal scale = (h / maxSum); |
@@ -47,14 +47,16 void StackedBarGroup::layoutChanged() | |||
|
47 | 47 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
48 | 48 | int labelIndex = mModel.countSets() * mModel.countCategories(); |
|
49 | 49 | |
|
50 |
for (int c |
|
|
50 | for (int category = 0; category < mModel.countCategories(); category++) { | |
|
51 | 51 | qreal yPos = h; |
|
52 |
for (int |
|
|
53 |
qreal barHeight = mModel.valueAt( |
|
|
52 | for (int set=0; set < mModel.countSets(); set++) { | |
|
53 | qreal barHeight = mModel.valueAt(set, category) * scale; | |
|
54 | 54 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
55 | 55 | |
|
56 | 56 | bar->resize(mBarDefaultWidth, barHeight); |
|
57 |
bar->set |
|
|
57 | bar->setBrush(mBrushes.at(set)); | |
|
58 | // bar->setBrush(mBrush); | |
|
59 | // bar->setColor(mColors.at(set)); | |
|
58 | 60 | bar->setPos(xPos, yPos-barHeight); |
|
59 | 61 | itemIndex++; |
|
60 | 62 | yPos -= barHeight; |
@@ -131,41 +131,47 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int coun | |||
|
131 | 131 | |
|
132 | 132 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) |
|
133 | 133 | { |
|
134 | item->resetColors(); | |
|
134 | // TODO: better way to descide series color and remove hard coded colors. | |
|
135 | item->resetBrushes(); | |
|
135 | 136 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
136 |
|
|
|
137 | QBrush brush(m_seriesColor.at(i)); | |
|
138 | item->addBrush(brush); | |
|
137 | 139 | } |
|
138 |
item->add |
|
|
139 |
item->add |
|
|
140 |
item->add |
|
|
141 |
item->add |
|
|
142 |
item->add |
|
|
140 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
|
141 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
|
142 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
|
143 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
|
144 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
|
143 | 145 | } |
|
144 | 146 | |
|
145 | 147 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) |
|
146 | 148 | { |
|
147 | item->resetColors(); | |
|
148 | for (int i=0; i< m_seriesColor.count(); i++) { | |
|
149 | item->addColor(m_seriesColor.at(i)); | |
|
149 | // TODO: better way to descide series color and remove hard coded colors. | |
|
150 | item->resetBrushes(); | |
|
151 | for (int i=0; i<m_seriesColor.count(); i++) { | |
|
152 | QBrush brush(m_seriesColor.at(i)); | |
|
153 | item->addBrush(brush); | |
|
150 | 154 | } |
|
151 |
item->add |
|
|
152 |
item->add |
|
|
153 |
item->add |
|
|
154 |
item->add |
|
|
155 |
item->add |
|
|
155 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
|
156 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
|
157 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
|
158 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
|
159 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
|
156 | 160 | } |
|
157 | 161 | |
|
158 | 162 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) |
|
159 | 163 | { |
|
160 | item->resetColors(); | |
|
161 | for (int i=0; i< m_seriesColor.count(); i++) { | |
|
162 | item->addColor(m_seriesColor.at(i)); | |
|
164 | // TODO: better way to descide series color and remove hard coded colors. | |
|
165 | item->resetBrushes(); | |
|
166 | for (int i=0; i<m_seriesColor.count(); i++) { | |
|
167 | QBrush brush(m_seriesColor.at(i)); | |
|
168 | item->addBrush(brush); | |
|
163 | 169 | } |
|
164 |
item->add |
|
|
165 |
item->add |
|
|
166 |
item->add |
|
|
167 |
item->add |
|
|
168 |
item->add |
|
|
170 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
|
171 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
|
172 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
|
173 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
|
174 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
|
169 | 175 | } |
|
170 | 176 | |
|
171 | 177 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
General Comments 0
You need to be logged in to leave comments.
Login now