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