@@ -93,7 +93,7 void BarChartItem::dataChanged() | |||
|
93 | 93 | } |
|
94 | 94 | } |
|
95 | 95 | |
|
96 |
// Create |
|
|
96 | // Create value items | |
|
97 | 97 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
98 | 98 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
99 | 99 | QBarSet *set = m_series->barsetAt(s); |
@@ -132,43 +132,32 QVector<QRectF> BarChartItem::calculateLayout() | |||
|
132 | 132 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
133 | 133 | qreal yPos = height; |
|
134 | 134 | for (int set = 0; set < setCount; set++) { |
|
135 |
|
|
|
135 | QBarSet* barSet = m_series->barsetAt(set); | |
|
136 | ||
|
137 | qreal barHeight = barSet->valueAt(category) * scale; | |
|
136 | 138 | Bar* bar = m_bars.at(itemIndex); |
|
137 | 139 | |
|
138 | 140 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
139 | 141 | layout.append(rect); |
|
140 |
bar->setPen( |
|
|
141 |
bar->setBrush( |
|
|
142 | itemIndex++; | |
|
143 | xPos += barWidth; | |
|
144 | } | |
|
145 | } | |
|
142 | bar->setPen(barSet->pen()); | |
|
143 | bar->setBrush(barSet->brush()); | |
|
146 | 144 | |
|
147 | // Position floating values | |
|
148 | itemIndex = 0; | |
|
149 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
|
150 | qreal xPos = categoryWidth * category + barWidth; | |
|
151 | qreal yPos = height; | |
|
152 | for (int set=0; set < m_series->barsetCount(); set++) { | |
|
153 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
|
154 | 145 | BarValue* value = m_values.at(itemIndex); |
|
155 | 146 | |
|
156 | QBarSet* barSet = m_series->barsetAt(set); | |
|
157 | ||
|
158 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
|
159 | value->setText(QString::number(m_series->valueAt(set, category))); | |
|
147 | if (!qFuzzyIsNull(barSet->valueAt(category))) { | |
|
148 | value->setText(QString::number(barSet->valueAt(category))); | |
|
160 | 149 | } else { |
|
161 | 150 | value->setText(QString("")); |
|
162 | 151 | } |
|
163 | 152 | |
|
164 | value->setPos(xPos, yPos-barHeight / 2); | |
|
165 | value->setPen(barSet->floatingValuePen()); | |
|
153 | value->setPos(xPos + (rect.width()/2 - value->boundingRect().width()/2) | |
|
154 | ,yPos - barHeight/2 - value->boundingRect().height()/2); | |
|
155 | value->setPen(barSet->valuePen()); | |
|
166 | 156 | |
|
167 | 157 | itemIndex++; |
|
168 | 158 | xPos += barWidth; |
|
169 | 159 | } |
|
170 | 160 | } |
|
171 | ||
|
172 | 161 | return layout; |
|
173 | 162 | } |
|
174 | 163 |
@@ -42,9 +42,6 public: | |||
|
42 | 42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
43 | 43 | virtual ~BarChartItem(); |
|
44 | 44 | |
|
45 | // Common implemantation of different presenters. Not to be instantiated. | |
|
46 | // TODO: combine this with BarPresenter and derive other presenters from it? | |
|
47 | ||
|
48 | 45 | public: |
|
49 | 46 | // From QGraphicsItem |
|
50 | 47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
@@ -82,6 +82,7 QRectF BarValue::boundingRect() const | |||
|
82 | 82 | |
|
83 | 83 | void BarValue::valuesVisibleChanged(bool visible) |
|
84 | 84 | { |
|
85 | qDebug() << "BarValue visiblle changed:" <<visible; | |
|
85 | 86 | setVisible(visible); |
|
86 | 87 | } |
|
87 | 88 |
@@ -30,7 +30,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
30 | 30 | |
|
31 | 31 | class QBarSet; |
|
32 | 32 | |
|
33 |
// Visual class for |
|
|
33 | // Visual class for bar values | |
|
34 | 34 | // By default these are not visible. |
|
35 | 35 | class BarValue : public QGraphicsObject |
|
36 | 36 | { |
@@ -50,31 +50,16 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
50 | 50 | qreal scale = (height / colSum); |
|
51 | 51 | qreal yPos = height; |
|
52 | 52 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
53 |
|
|
|
53 | QBarSet* barSet = m_series->barsetAt(set); | |
|
54 | qreal barHeight = barSet->valueAt(category) * scale; | |
|
54 | 55 | Bar* bar = m_bars.at(itemIndex); |
|
55 |
bar->setPen( |
|
|
56 |
bar->setBrush( |
|
|
56 | bar->setPen(barSet->pen()); | |
|
57 | bar->setBrush(barSet->brush()); | |
|
57 | 58 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
58 | 59 | layout.append(rect); |
|
59 | itemIndex++; | |
|
60 | yPos -= barHeight; | |
|
61 | } | |
|
62 | xPos += xStep; | |
|
63 | } | |
|
64 | 60 | |
|
65 | // Position floating values | |
|
66 | itemIndex = 0; | |
|
67 | xPos = (width/categoryCount); | |
|
68 | for (int category=0; category < m_series->categoryCount(); category++) { | |
|
69 | qreal yPos = height; | |
|
70 | qreal colSum = m_series->categorySum(category); | |
|
71 | qreal scale = (height / colSum); | |
|
72 | for (int set=0; set < m_series->barsetCount(); set++) { | |
|
73 | qreal barHeight = m_series->valueAt(set,category) * scale; | |
|
74 | 61 | BarValue* value = m_values.at(itemIndex); |
|
75 | 62 | |
|
76 | QBarSet* barSet = m_series->barsetAt(set); | |
|
77 | ||
|
78 | 63 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
79 | 64 | int p = m_series->percentageAt(set,category) * 100; |
|
80 | 65 | QString vString(QString::number(p)); |
@@ -85,9 +70,9 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
85 | 70 | value->setText(QString("")); |
|
86 | 71 | } |
|
87 | 72 | |
|
88 | value->setPos(xPos, yPos-barHeight / 2); | |
|
89 | value->setPen(barSet->floatingValuePen()); | |
|
90 | ||
|
73 | value->setPos(xPos + (rect.width()/2 - value->boundingRect().width()/2) | |
|
74 | ,yPos - barHeight/2 - value->boundingRect().height()/2); | |
|
75 | value->setPen(barSet->valuePen()); | |
|
91 | 76 | itemIndex++; |
|
92 | 77 | yPos -= barHeight; |
|
93 | 78 | } |
@@ -56,8 +56,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 |
\fn void QBarSet:: |
|
|
60 | \brief \internal | |
|
59 | \fn void QBarSet::setValuesVisible(bool visible = true) | |
|
60 | \brief Sets visibility of bar values. Values are visible, if parameter \a visible is true | |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
@@ -183,19 +183,19 QBrush QBarSet::brush() const | |||
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 |
Sets the pen for |
|
|
186 | Sets the pen for values that are drawn on top of this set | |
|
187 | 187 | */ |
|
188 |
void QBarSet::set |
|
|
188 | void QBarSet::setValuePen(const QPen &pen) | |
|
189 | 189 | { |
|
190 |
m_ |
|
|
190 | m_valuePen = pen; | |
|
191 | 191 | } |
|
192 | 192 | |
|
193 | 193 | /*! |
|
194 |
Returns the pen for |
|
|
194 | Returns the pen for values that are drawn on top of this set | |
|
195 | 195 | */ |
|
196 |
QPen QBarSet:: |
|
|
196 | QPen QBarSet::valuePen() const | |
|
197 | 197 | { |
|
198 |
return m_ |
|
|
198 | return m_valuePen; | |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | /*! |
@@ -55,8 +55,8 public: | |||
|
55 | 55 | void setBrush(const QBrush &brush); |
|
56 | 56 | QBrush brush() const; |
|
57 | 57 | |
|
58 |
void set |
|
|
59 |
QPen |
|
|
58 | void setValuePen(const QPen &pen); | |
|
59 | QPen valuePen() const; | |
|
60 | 60 | |
|
61 | 61 | void setValuesVisible(bool visible = true); |
|
62 | 62 | |
@@ -86,7 +86,7 private: | |||
|
86 | 86 | QMap<QString, qreal> m_mappedValues; |
|
87 | 87 | QPen m_pen; |
|
88 | 88 | QBrush m_brush; |
|
89 |
QPen m_ |
|
|
89 | QPen m_valuePen; | |
|
90 | 90 | }; |
|
91 | 91 | |
|
92 | 92 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -58,43 +58,33 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||
|
58 | 58 | for (int category = 0; category < categotyCount; category++) { |
|
59 | 59 | qreal yPos = height; |
|
60 | 60 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
61 |
|
|
|
61 | QBarSet* barSet = m_series->barsetAt(set); | |
|
62 | ||
|
63 | qreal barHeight = barSet->valueAt(category) * scale; //m_series->valueAt(set, category) * scale; | |
|
62 | 64 | Bar* bar = m_bars.at(itemIndex); |
|
63 |
bar->setPen( |
|
|
64 |
bar->setBrush( |
|
|
65 | bar->setPen(barSet->pen()); | |
|
66 | bar->setBrush(barSet->brush()); | |
|
65 | 67 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
66 | 68 | layout.append(rect); |
|
67 | itemIndex++; | |
|
68 | yPos -= barHeight; | |
|
69 | } | |
|
70 | xPos += xStep; | |
|
71 | } | |
|
72 | 69 | |
|
73 | // Position floating values | |
|
74 | itemIndex = 0; | |
|
75 | xPos = (width/categotyCount); | |
|
76 | for (int category=0; category < m_series->categoryCount(); category++) { | |
|
77 | qreal yPos = height; | |
|
78 | for (int set=0; set < m_series->barsetCount(); set++) { | |
|
79 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
|
80 | 70 | BarValue* value = m_values.at(itemIndex); |
|
81 | 71 | |
|
82 | QBarSet* barSet = m_series->barsetAt(set); | |
|
83 | ||
|
84 | if (!qFuzzyIsNull(m_series->valueAt(set, category))) { | |
|
85 | value->setText(QString::number(m_series->valueAt(set,category))); | |
|
72 | if (!qFuzzyIsNull(barSet->valueAt(category))) { | |
|
73 | value->setText(QString::number(barSet->valueAt(category))); | |
|
86 | 74 | } else { |
|
87 | 75 | value->setText(QString("")); |
|
88 | 76 | } |
|
89 | 77 | |
|
90 | value->setPos(xPos, yPos-barHeight / 2); | |
|
91 | value->setPen(barSet->floatingValuePen()); | |
|
78 | value->setPos(xPos + (rect.width()/2 - value->boundingRect().width()/2) | |
|
79 | ,yPos - barHeight/2 - value->boundingRect().height()/2); | |
|
80 | value->setPen(barSet->valuePen()); | |
|
92 | 81 | |
|
93 | 82 | itemIndex++; |
|
94 | 83 | yPos -= barHeight; |
|
95 | 84 | } |
|
96 | 85 | xPos += xStep; |
|
97 | 86 | } |
|
87 | ||
|
98 | 88 | return layout; |
|
99 | 89 | } |
|
100 | 90 |
@@ -183,9 +183,9 void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |||
|
183 | 183 | // Pick label color from the opposite end of the gradient. |
|
184 | 184 | // 0.3 as a boundary seems to work well. |
|
185 | 185 | if (takeAtPos < 0.3) |
|
186 |
sets.at(i)->set |
|
|
186 | sets.at(i)->setValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
|
187 | 187 | else |
|
188 |
sets.at(i)->set |
|
|
188 | sets.at(i)->setValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
|
189 | 189 | |
|
190 | 190 | if (pen == sets.at(i)->pen() || force) { |
|
191 | 191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
General Comments 0
You need to be logged in to leave comments.
Login now