##// END OF EJS Templates
minor code review fixes, part n
sauimone -
r763:4467255a8e44
parent child
Show More
@@ -7,7 +7,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 Bar::Bar(QString category, QGraphicsItem *parent)
8 Bar::Bar(QString category, QGraphicsItem *parent)
9 : QGraphicsRectItem(parent),
9 : QGraphicsRectItem(parent),
10 m_Category(category)
10 m_category(category)
11 {
11 {
12 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
12 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
13 setAcceptHoverEvents(true);
13 setAcceptHoverEvents(true);
@@ -16,9 +16,9 Bar::Bar(QString category, QGraphicsItem *parent)
16 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
16 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
17 {
17 {
18 if (event->button() == Qt::LeftButton) {
18 if (event->button() == Qt::LeftButton) {
19 emit clicked(m_Category);
19 emit clicked(m_category);
20 } else if (event->button() == Qt::RightButton) {
20 } else if (event->button() == Qt::RightButton) {
21 emit rightClicked(m_Category);
21 emit rightClicked(m_category);
22 }
22 }
23 }
23 }
24
24
@@ -25,7 +25,7 Q_SIGNALS:
25 void hoverLeaved();
25 void hoverLeaved();
26
26
27 private:
27 private:
28 QString m_Category;
28 QString m_category;
29 };
29 };
30
30
31 QTCOMMERCIALCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
@@ -16,8 +16,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
16
16
17 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
17 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
18 ChartItem(presenter),
18 ChartItem(presenter),
19 m_LayoutSet(false),
19 m_layoutSet(false),
20 m_Series(series)
20 m_series(series)
21 {
21 {
22 connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString)));
22 connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString)));
23 connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
23 connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
@@ -34,7 +34,7 BarChartItem::~BarChartItem()
34
34
35 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
35 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
36 {
36 {
37 if (!m_LayoutSet) {
37 if (!m_layoutSet) {
38 qWarning() << "BarChartItem::paint called without layout set. Aborting.";
38 qWarning() << "BarChartItem::paint called without layout set. Aborting.";
39 return;
39 return;
40 }
40 }
@@ -55,33 +55,33 void BarChartItem::dataChanged()
55 foreach (QGraphicsItem *item, childItems())
55 foreach (QGraphicsItem *item, childItems())
56 delete item;
56 delete item;
57
57
58 m_Bars.clear();
58 m_bars.clear();
59 m_FloatingValues.clear();
59 m_floatingValues.clear();
60 m_Layout.clear();
60 m_layout.clear();
61
61
62 // Create new graphic items for bars
62 // Create new graphic items for bars
63 for (int c = 0; c < m_Series->categoryCount(); c++) {
63 for (int c = 0; c < m_series->categoryCount(); c++) {
64 QString category = m_Series->categoryName(c);
64 QString category = m_series->categoryName(c);
65 for (int s = 0; s < m_Series->barsetCount(); s++) {
65 for (int s = 0; s < m_series->barsetCount(); s++) {
66 QBarSet *set = m_Series->barsetAt(s);
66 QBarSet *set = m_series->barsetAt(s);
67 Bar *bar = new Bar(category,this);
67 Bar *bar = new Bar(category,this);
68 childItems().append(bar);
68 childItems().append(bar);
69 m_Bars.append(bar);
69 m_bars.append(bar);
70 connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString)));
70 connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString)));
71 connect(bar, SIGNAL(rightClicked(QString)), set, SIGNAL(rightClicked(QString)));
71 connect(bar, SIGNAL(rightClicked(QString)), set, SIGNAL(rightClicked(QString)));
72 connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint)));
72 connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint)));
73 connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent()));
73 connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent()));
74 m_Layout.append(QRectF(0, 0, 0, 0));
74 m_layout.append(QRectF(0, 0, 0, 0));
75 }
75 }
76 }
76 }
77
77
78 // Create floating values
78 // Create floating values
79 for (int category = 0; category < m_Series->categoryCount(); category++) {
79 for (int category = 0; category < m_series->categoryCount(); category++) {
80 for (int s = 0; s < m_Series->barsetCount(); s++) {
80 for (int s = 0; s < m_series->barsetCount(); s++) {
81 QBarSet *set = m_Series->barsetAt(s);
81 QBarSet *set = m_series->barsetAt(s);
82 BarValue *value = new BarValue(*set, this);
82 BarValue *value = new BarValue(*set, this);
83 childItems().append(value);
83 childItems().append(value);
84 m_FloatingValues.append(value);
84 m_floatingValues.append(value);
85 connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible()));
85 connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible()));
86 }
86 }
87 }
87 }
@@ -91,17 +91,17 QVector<QRectF> BarChartItem::calculateLayout()
91 QVector<QRectF> layout;
91 QVector<QRectF> layout;
92
92
93 // Use temporary qreals for accurancy (we might get some compiler warnings... :)
93 // Use temporary qreals for accurancy (we might get some compiler warnings... :)
94 qreal categoryCount = m_Series->categoryCount();
94 qreal categoryCount = m_series->categoryCount();
95 qreal setCount = m_Series->barsetCount();
95 qreal setCount = m_series->barsetCount();
96
96
97 qreal width = geometry().width();
97 qreal width = geometry().width();
98 qreal height = geometry().height();
98 qreal height = geometry().height();
99
99
100 qreal max = m_Series->max();
100 qreal max = m_series->max();
101
101
102 // Domain:
102 // Domain:
103 if (m_DomainMaxY > max) {
103 if (m_domainMaxY > max) {
104 max = m_DomainMaxY;
104 max = m_domainMaxY;
105 }
105 }
106
106
107 qreal scale = (height / max);
107 qreal scale = (height / max);
@@ -113,13 +113,13 QVector<QRectF> BarChartItem::calculateLayout()
113 qreal xPos = categoryWidth * category + barWidth / 2;
113 qreal xPos = categoryWidth * category + barWidth / 2;
114 qreal yPos = height;
114 qreal yPos = height;
115 for (int set = 0; set < setCount; set++) {
115 for (int set = 0; set < setCount; set++) {
116 qreal barHeight = m_Series->valueAt(set, category) * scale;
116 qreal barHeight = m_series->valueAt(set, category) * scale;
117 Bar* bar = m_Bars.at(itemIndex);
117 Bar* bar = m_bars.at(itemIndex);
118
118
119 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
119 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
120 layout.append(rect);
120 layout.append(rect);
121 bar->setPen(m_Series->barsetAt(set)->pen());
121 bar->setPen(m_series->barsetAt(set)->pen());
122 bar->setBrush(m_Series->barsetAt(set)->brush());
122 bar->setBrush(m_series->barsetAt(set)->brush());
123 itemIndex++;
123 itemIndex++;
124 xPos += barWidth;
124 xPos += barWidth;
125 }
125 }
@@ -127,20 +127,20 QVector<QRectF> BarChartItem::calculateLayout()
127
127
128 // Position floating values
128 // Position floating values
129 itemIndex = 0;
129 itemIndex = 0;
130 for (int category = 0; category < m_Series->categoryCount(); category++) {
130 for (int category = 0; category < m_series->categoryCount(); category++) {
131 qreal xPos = categoryWidth * category + barWidth;
131 qreal xPos = categoryWidth * category + barWidth;
132 qreal yPos = height;
132 qreal yPos = height;
133 for (int set=0; set < m_Series->barsetCount(); set++) {
133 for (int set=0; set < m_series->barsetCount(); set++) {
134 qreal barHeight = m_Series->valueAt(set, category) * scale;
134 qreal barHeight = m_series->valueAt(set, category) * scale;
135 BarValue* value = m_FloatingValues.at(itemIndex);
135 BarValue* value = m_floatingValues.at(itemIndex);
136
136
137 QBarSet* barSet = m_Series->barsetAt(set);
137 QBarSet* barSet = m_series->barsetAt(set);
138 value->resize(100, 50); // TODO: proper layout for this.
138 value->resize(100, 50); // TODO: proper layout for this.
139 value->setPos(xPos, yPos-barHeight / 2);
139 value->setPos(xPos, yPos-barHeight / 2);
140 value->setPen(barSet->floatingValuePen());
140 value->setPen(barSet->floatingValuePen());
141
141
142 if (m_Series->valueAt(set,category) != 0) {
142 if (m_series->valueAt(set,category) != 0) {
143 value->setValueString(QString::number(m_Series->valueAt(set, category)));
143 value->setValueString(QString::number(m_series->valueAt(set, category)));
144 } else {
144 } else {
145 value->setValueString(QString(""));
145 value->setValueString(QString(""));
146 }
146 }
@@ -156,17 +156,17 QVector<QRectF> BarChartItem::calculateLayout()
156 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
156 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
157 {
157 {
158 if (animator())
158 if (animator())
159 animator()->updateLayout(this, m_Layout, layout);
159 animator()->updateLayout(this, m_layout, layout);
160 else
160 else
161 setLayout(layout);
161 setLayout(layout);
162 }
162 }
163
163
164 void BarChartItem::setLayout(const QVector<QRectF> &layout)
164 void BarChartItem::setLayout(const QVector<QRectF> &layout)
165 {
165 {
166 m_Layout = layout;
166 m_layout = layout;
167
167
168 for (int i=0; i < m_Bars.count(); i++)
168 for (int i=0; i < m_bars.count(); i++)
169 m_Bars.at(i)->setRect(layout.at(i));
169 m_bars.at(i)->setRect(layout.at(i));
170
170
171 update();
171 update();
172 }
172 }
@@ -181,10 +181,10 void BarChartItem::handleModelChanged(int index)
181
181
182 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
182 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
183 {
183 {
184 m_DomainMinX = minX;
184 m_domainMinX = minX;
185 m_DomainMaxX = maxX;
185 m_domainMaxX = maxX;
186 m_DomainMinY = minY;
186 m_domainMinY = minY;
187 m_DomainMaxY = maxY;
187 m_domainMaxY = maxY;
188 handleLayoutChanged();
188 handleLayoutChanged();
189 }
189 }
190
190
@@ -192,7 +192,7 void BarChartItem::handleGeometryChanged(const QRectF &rect)
192 {
192 {
193 m_rect = rect;
193 m_rect = rect;
194 handleLayoutChanged();
194 handleLayoutChanged();
195 m_LayoutSet = true;
195 m_layoutSet = true;
196 setPos(rect.topLeft());
196 setPos(rect.topLeft());
197 }
197 }
198
198
@@ -55,19 +55,19 public slots:
55 protected:
55 protected:
56
56
57 // TODO: consider these.
57 // TODO: consider these.
58 qreal m_DomainMinX;
58 qreal m_domainMinX;
59 qreal m_DomainMaxX;
59 qreal m_domainMaxX;
60 qreal m_DomainMinY;
60 qreal m_domainMinY;
61 qreal m_DomainMaxY;
61 qreal m_domainMaxY;
62
62
63 QRectF m_rect;
63 QRectF m_rect;
64 bool m_LayoutSet; // True, if component has been laid out.
64 bool m_layoutSet; // True, if component has been laid out.
65 QVector<QRectF> m_Layout;
65 QVector<QRectF> m_layout;
66
66
67 // Not owned.
67 // Not owned.
68 QBarSeries *m_Series;
68 QBarSeries *m_series;
69 QList<Bar *> m_Bars;
69 QList<Bar *> m_bars;
70 QList<BarValue *> m_FloatingValues;
70 QList<BarValue *> m_floatingValues;
71 };
71 };
72
72
73 QTCOMMERCIALCHART_END_NAMESPACE
73 QTCOMMERCIALCHART_END_NAMESPACE
@@ -7,73 +7,73
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent),
9 BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent),
10 m_Category(categories)
10 m_category(categories)
11 {
11 {
12 }
12 }
13
13
14 QStringList BarChartModel::category()
14 QStringList BarChartModel::category()
15 {
15 {
16 return m_Category;
16 return m_category;
17 }
17 }
18
18
19 void BarChartModel::addBarSet(QBarSet *set)
19 void BarChartModel::addBarSet(QBarSet *set)
20 {
20 {
21 m_DataModel.append(set);
21 m_dataModel.append(set);
22 }
22 }
23
23
24 void BarChartModel::removeBarSet(QBarSet *set)
24 void BarChartModel::removeBarSet(QBarSet *set)
25 {
25 {
26 if (m_DataModel.contains(set)) {
26 if (m_dataModel.contains(set)) {
27 m_DataModel.removeOne(set);
27 m_dataModel.removeOne(set);
28 }
28 }
29 }
29 }
30
30
31 void BarChartModel::insertBarSet(int i, QBarSet *set)
31 void BarChartModel::insertBarSet(int i, QBarSet *set)
32 {
32 {
33 m_DataModel.insert(i, set);
33 m_dataModel.insert(i, set);
34 }
34 }
35
35
36 void BarChartModel::insertCategory(int i, QString category)
36 void BarChartModel::insertCategory(int i, QString category)
37 {
37 {
38 m_Category.insert(i, category);
38 m_category.insert(i, category);
39 }
39 }
40
40
41 void BarChartModel::removeCategory(int i)
41 void BarChartModel::removeCategory(int i)
42 {
42 {
43 m_Category.removeAt(i);
43 m_category.removeAt(i);
44 }
44 }
45
45
46 QBarSet* BarChartModel::setAt(int index)
46 QBarSet* BarChartModel::setAt(int index)
47 {
47 {
48 return m_DataModel.at(index);
48 return m_dataModel.at(index);
49 }
49 }
50
50
51 QList<QBarSet*> BarChartModel::barSets()
51 QList<QBarSet*> BarChartModel::barSets()
52 {
52 {
53 return m_DataModel;
53 return m_dataModel;
54 }
54 }
55
55
56 int BarChartModel::barsetCount()
56 int BarChartModel::barsetCount()
57 {
57 {
58 return m_DataModel.count();
58 return m_dataModel.count();
59 }
59 }
60
60
61 int BarChartModel::categoryCount()
61 int BarChartModel::categoryCount()
62 {
62 {
63 return m_Category.count();
63 return m_category.count();
64 }
64 }
65
65
66 qreal BarChartModel::min()
66 qreal BarChartModel::min()
67 {
67 {
68 Q_ASSERT(m_DataModel.count() > 0);
68 Q_ASSERT(m_dataModel.count() > 0);
69 // TODO: make min and max members and update them when data changes.
69 // TODO: make min and max members and update them when data changes.
70 // This is slower since they are checked every time, even if data is same since previous call.
70 // This is slower since they are checked every time, even if data is same since previous call.
71 qreal min = INT_MAX;
71 qreal min = INT_MAX;
72
72
73 for (int i = 0; i < m_DataModel.count(); i++) {
73 for (int i = 0; i < m_dataModel.count(); i++) {
74 int itemCount = m_DataModel.at(i)->count();
74 int itemCount = m_dataModel.at(i)->count();
75 for (int j = 0; j < itemCount; j++) {
75 for (int j = 0; j < itemCount; j++) {
76 qreal temp = m_DataModel.at(i)->valueAt(j);
76 qreal temp = m_dataModel.at(i)->valueAt(j);
77 if (temp < min)
77 if (temp < min)
78 min = temp;
78 min = temp;
79 }
79 }
@@ -83,16 +83,16 qreal BarChartModel::min()
83
83
84 qreal BarChartModel::max()
84 qreal BarChartModel::max()
85 {
85 {
86 Q_ASSERT(m_DataModel.count() > 0);
86 Q_ASSERT(m_dataModel.count() > 0);
87
87
88 // TODO: make min and max members and update them when data changes.
88 // TODO: make min and max members and update them when data changes.
89 // This is slower since they are checked every time, even if data is same since previous call.
89 // This is slower since they are checked every time, even if data is same since previous call.
90 qreal max = INT_MIN;
90 qreal max = INT_MIN;
91
91
92 for (int i = 0; i < m_DataModel.count(); i++) {
92 for (int i = 0; i < m_dataModel.count(); i++) {
93 int itemCount = m_DataModel.at(i)->count();
93 int itemCount = m_dataModel.at(i)->count();
94 for (int j = 0; j < itemCount; j++) {
94 for (int j = 0; j < itemCount; j++) {
95 qreal temp = m_DataModel.at(i)->valueAt(j);
95 qreal temp = m_dataModel.at(i)->valueAt(j);
96 if (temp > max)
96 if (temp > max)
97 max = temp;
97 max = temp;
98 }
98 }
@@ -103,28 +103,28 qreal BarChartModel::max()
103
103
104 qreal BarChartModel::valueAt(int set, int category)
104 qreal BarChartModel::valueAt(int set, int category)
105 {
105 {
106 if ((set < 0) || (set >= m_DataModel.count())) {
106 if ((set < 0) || (set >= m_dataModel.count())) {
107 // No set, no value.
107 // No set, no value.
108 return 0;
108 return 0;
109 } else if ((category < 0) || (category >= m_DataModel.at(set)->count())) {
109 } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) {
110 // No category, no value.
110 // No category, no value.
111 return 0;
111 return 0;
112 }
112 }
113
113
114 return m_DataModel.at(set)->valueAt(category);
114 return m_dataModel.at(set)->valueAt(category);
115 }
115 }
116
116
117 qreal BarChartModel::percentageAt(int set, int category)
117 qreal BarChartModel::percentageAt(int set, int category)
118 {
118 {
119 if ((set < 0) || (set >= m_DataModel.count())) {
119 if ((set < 0) || (set >= m_dataModel.count())) {
120 // No set, no value.
120 // No set, no value.
121 return 0;
121 return 0;
122 } else if ((category < 0) || (category >= m_DataModel.at(set)->count())) {
122 } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) {
123 // No category, no value.
123 // No category, no value.
124 return 0;
124 return 0;
125 }
125 }
126
126
127 qreal value = m_DataModel.at(set)->valueAt(category);
127 qreal value = m_dataModel.at(set)->valueAt(category);
128 qreal total = categorySum(category);
128 qreal total = categorySum(category);
129 if (0 == total)
129 if (0 == total)
130 return 100.0;
130 return 100.0;
@@ -136,11 +136,11 qreal BarChartModel::percentageAt(int set, int category)
136 qreal BarChartModel::categorySum(int category)
136 qreal BarChartModel::categorySum(int category)
137 {
137 {
138 qreal sum(0);
138 qreal sum(0);
139 int count = m_DataModel.count(); // Count sets
139 int count = m_dataModel.count(); // Count sets
140
140
141 for (int set = 0; set < count; set++) {
141 for (int set = 0; set < count; set++) {
142 if (category < m_DataModel.at(set)->count())
142 if (category < m_dataModel.at(set)->count())
143 sum += m_DataModel.at(set)->valueAt(category);
143 sum += m_dataModel.at(set)->valueAt(category);
144 }
144 }
145 return sum;
145 return sum;
146 }
146 }
@@ -160,7 +160,7 qreal BarChartModel::maxCategorySum()
160
160
161 QString BarChartModel::categoryName(int category)
161 QString BarChartModel::categoryName(int category)
162 {
162 {
163 return m_Category.at(category);
163 return m_category.at(category);
164 }
164 }
165
165
166 #include "moc_barchartmodel_p.cpp"
166 #include "moc_barchartmodel_p.cpp"
@@ -48,8 +48,8 public slots:
48
48
49 private:
49 private:
50
50
51 QList<QBarSet *> m_DataModel;
51 QList<QBarSet *> m_dataModel;
52 QStringList m_Category;
52 QStringList m_category;
53 };
53 };
54
54
55 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
@@ -6,45 +6,45 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
8 : QGraphicsObject(parent),
8 : QGraphicsObject(parent),
9 m_BarSet(set),
9 m_barSet(set),
10 m_Xpos(0),
10 m_xPos(0),
11 m_Ypos(0),
11 m_yPos(0),
12 m_Width(0),
12 m_width(0),
13 m_Height(0)
13 m_height(0)
14 {
14 {
15 setVisible(false);
15 setVisible(false);
16 }
16 }
17
17
18 void BarValue::setValueString(QString str)
18 void BarValue::setValueString(QString str)
19 {
19 {
20 m_ValueString = str;
20 m_valueString = str;
21 }
21 }
22
22
23 QString BarValue::valueString()
23 QString BarValue::valueString()
24 {
24 {
25 return m_ValueString;
25 return m_valueString;
26 }
26 }
27
27
28 void BarValue::setPen(const QPen pen)
28 void BarValue::setPen(const QPen pen)
29 {
29 {
30 m_Pen = pen;
30 m_pen = pen;
31 }
31 }
32
32
33 QPen BarValue::pen() const
33 QPen BarValue::pen() const
34 {
34 {
35 return m_Pen;
35 return m_pen;
36 }
36 }
37
37
38 void BarValue::resize(qreal w, qreal h)
38 void BarValue::resize(qreal w, qreal h)
39 {
39 {
40 m_Width = w;
40 m_width = w;
41 m_Height = h;
41 m_height = h;
42 }
42 }
43
43
44 void BarValue::setPos(qreal x, qreal y)
44 void BarValue::setPos(qreal x, qreal y)
45 {
45 {
46 m_Xpos = x;
46 m_xPos = x;
47 m_Ypos = y;
47 m_yPos = y;
48 }
48 }
49
49
50 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@@ -53,14 +53,14 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
53 Q_UNUSED(widget)
53 Q_UNUSED(widget)
54
54
55 if (isVisible()) {
55 if (isVisible()) {
56 painter->setPen(m_Pen);
56 painter->setPen(m_pen);
57 painter->drawText(boundingRect(), m_ValueString);
57 painter->drawText(boundingRect(), m_valueString);
58 }
58 }
59 }
59 }
60
60
61 QRectF BarValue::boundingRect() const
61 QRectF BarValue::boundingRect() const
62 {
62 {
63 QRectF r(m_Xpos, m_Ypos, m_Width, m_Height);
63 QRectF r(m_xPos, m_yPos, m_width, m_height);
64 return r;
64 return r;
65 }
65 }
66
66
@@ -35,14 +35,14 public Q_SLOTS:
35
35
36 private:
36 private:
37
37
38 QBarSet &m_BarSet;
38 QBarSet &m_barSet;
39 QPen m_Pen;
39 QPen m_pen;
40 QString m_ValueString;
40 QString m_valueString;
41
41
42 qreal m_Xpos;
42 qreal m_xPos;
43 qreal m_Ypos;
43 qreal m_yPos;
44 qreal m_Width;
44 qreal m_width;
45 qreal m_Height;
45 qreal m_height;
46 };
46 };
47
47
48 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
@@ -19,21 +19,21 QVector<QRectF> PercentBarChartItem::calculateLayout()
19 qreal width = geometry().width();
19 qreal width = geometry().width();
20 qreal height = geometry().height();
20 qreal height = geometry().height();
21
21
22 qreal categoryCount = m_Series->categoryCount();
22 qreal categoryCount = m_series->categoryCount();
23 qreal barWidth = width / (m_Series->categoryCount() * 2);
23 qreal barWidth = width / (m_series->categoryCount() * 2);
24 qreal xStep = width / categoryCount;
24 qreal xStep = width / categoryCount;
25 qreal xPos = xStep / 2 - barWidth / 2;
25 qreal xPos = xStep / 2 - barWidth / 2;
26
26
27 int itemIndex(0);
27 int itemIndex(0);
28 for (int category = 0; category < categoryCount; category++) {
28 for (int category = 0; category < categoryCount; category++) {
29 qreal colSum = m_Series->categorySum(category);
29 qreal colSum = m_series->categorySum(category);
30 qreal scale = (height / colSum);
30 qreal scale = (height / colSum);
31 qreal yPos = height;
31 qreal yPos = height;
32 for (int set=0; set < m_Series->barsetCount(); set++) {
32 for (int set=0; set < m_series->barsetCount(); set++) {
33 qreal barHeight = m_Series->valueAt(set, category) * scale;
33 qreal barHeight = m_series->valueAt(set, category) * scale;
34 Bar* bar = m_Bars.at(itemIndex);
34 Bar* bar = m_bars.at(itemIndex);
35 bar->setPen(m_Series->barsetAt(set)->pen());
35 bar->setPen(m_series->barsetAt(set)->pen());
36 bar->setBrush(m_Series->barsetAt(set)->brush());
36 bar->setBrush(m_series->barsetAt(set)->brush());
37 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
37 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
38 layout.append(rect);
38 layout.append(rect);
39 itemIndex++;
39 itemIndex++;
@@ -45,21 +45,21 QVector<QRectF> PercentBarChartItem::calculateLayout()
45 // Position floating values
45 // Position floating values
46 itemIndex = 0;
46 itemIndex = 0;
47 xPos = (width/categoryCount);
47 xPos = (width/categoryCount);
48 for (int category=0; category < m_Series->categoryCount(); category++) {
48 for (int category=0; category < m_series->categoryCount(); category++) {
49 qreal yPos = height;
49 qreal yPos = height;
50 qreal colSum = m_Series->categorySum(category);
50 qreal colSum = m_series->categorySum(category);
51 qreal scale = (height / colSum);
51 qreal scale = (height / colSum);
52 for (int set=0; set < m_Series->barsetCount(); set++) {
52 for (int set=0; set < m_series->barsetCount(); set++) {
53 qreal barHeight = m_Series->valueAt(set,category) * scale;
53 qreal barHeight = m_series->valueAt(set,category) * scale;
54 BarValue* value = m_FloatingValues.at(itemIndex);
54 BarValue* value = m_floatingValues.at(itemIndex);
55
55
56 QBarSet* barSet = m_Series->barsetAt(set);
56 QBarSet* barSet = m_series->barsetAt(set);
57 value->resize(100, 50); // TODO: proper layout for this.
57 value->resize(100, 50); // TODO: proper layout for this.
58 value->setPos(xPos, yPos-barHeight / 2);
58 value->setPos(xPos, yPos-barHeight / 2);
59 value->setPen(barSet->floatingValuePen());
59 value->setPen(barSet->floatingValuePen());
60
60
61 if (m_Series->valueAt(set,category) != 0) {
61 if (m_series->valueAt(set,category) != 0) {
62 int p = m_Series->percentageAt(set,category) * 100;
62 int p = m_series->percentageAt(set,category) * 100;
63 QString vString(QString::number(p));
63 QString vString(QString::number(p));
64 vString.truncate(3);
64 vString.truncate(3);
65 vString.append("%");
65 vString.append("%");
@@ -34,7 +34,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QBarSeries is QObject which is a child of a \a parent.
34 QBarSeries is QObject which is a child of a \a parent.
35 */
35 */
36 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent),
36 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent),
37 m_Model(new BarChartModel(categories, this))
37 m_internalModel(new BarChartModel(categories, this))
38 {
38 {
39 m_model = NULL;
39 m_model = NULL;
40 m_mapCategories = -1;
40 m_mapCategories = -1;
@@ -52,7 +52,7 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(par
52 */
52 */
53 void QBarSeries::addBarSet(QBarSet *set)
53 void QBarSeries::addBarSet(QBarSet *set)
54 {
54 {
55 m_Model->addBarSet(set);
55 m_internalModel->addBarSet(set);
56 connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString)));
56 connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString)));
57 connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString)));
57 connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString)));
58 connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
58 connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
@@ -68,24 +68,24 void QBarSeries::removeBarSet(QBarSet *set)
68 {
68 {
69 disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString)));
69 disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString)));
70 disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString)));
70 disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString)));
71 m_Model->removeBarSet(set);
71 m_internalModel->removeBarSet(set);
72 emit updatedBars();
72 emit updatedBars();
73 }
73 }
74
74
75 void QBarSeries::insertBarSet(int i, QBarSet *set)
75 void QBarSeries::insertBarSet(int i, QBarSet *set)
76 {
76 {
77 m_Model->insertBarSet(i, set);
77 m_internalModel->insertBarSet(i, set);
78 // emit barsetChanged();
78 // emit barsetChanged();
79 }
79 }
80
80
81 void QBarSeries::insertCategory(int i, QString category)
81 void QBarSeries::insertCategory(int i, QString category)
82 {
82 {
83 m_Model->insertCategory(i, category);
83 m_internalModel->insertCategory(i, category);
84 }
84 }
85
85
86 void QBarSeries::removeCategory(int i)
86 void QBarSeries::removeCategory(int i)
87 {
87 {
88 m_Model->removeCategory(i);
88 m_internalModel->removeCategory(i);
89 }
89 }
90
90
91 /*!
91 /*!
@@ -96,7 +96,7 int QBarSeries::barsetCount()
96 // if(m_model)
96 // if(m_model)
97 // return m_mapBarTop - m_mapBarBottom;
97 // return m_mapBarTop - m_mapBarBottom;
98 // else
98 // else
99 return m_Model->barsetCount();
99 return m_internalModel->barsetCount();
100 }
100 }
101
101
102 /*!
102 /*!
@@ -104,7 +104,7 int QBarSeries::barsetCount()
104 */
104 */
105 int QBarSeries::categoryCount()
105 int QBarSeries::categoryCount()
106 {
106 {
107 return m_Model->categoryCount();
107 return m_internalModel->categoryCount();
108 }
108 }
109
109
110 /*!
110 /*!
@@ -112,7 +112,7 int QBarSeries::categoryCount()
112 */
112 */
113 QList<QBarSet*> QBarSeries::barSets()
113 QList<QBarSet*> QBarSeries::barSets()
114 {
114 {
115 return m_Model->barSets();
115 return m_internalModel->barSets();
116 }
116 }
117
117
118 /*!
118 /*!
@@ -120,7 +120,7 QList<QBarSet*> QBarSeries::barSets()
120 */
120 */
121 QBarSet* QBarSeries::barsetAt(int index)
121 QBarSet* QBarSeries::barsetAt(int index)
122 {
122 {
123 return m_Model->setAt(index);
123 return m_internalModel->setAt(index);
124 }
124 }
125
125
126 /*!
126 /*!
@@ -128,7 +128,7 QBarSet* QBarSeries::barsetAt(int index)
128 */
128 */
129 QString QBarSeries::categoryName(int category)
129 QString QBarSeries::categoryName(int category)
130 {
130 {
131 return m_Model->categoryName(category);
131 return m_internalModel->categoryName(category);
132 }
132 }
133
133
134 /*!
134 /*!
@@ -140,13 +140,13 void QBarSeries::setToolTipEnabled(bool enabled)
140 {
140 {
141 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
141 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
142 if (enabled) {
142 if (enabled) {
143 for (int i=0; i<m_Model->barsetCount(); i++) {
143 for (int i=0; i<m_internalModel->barsetCount(); i++) {
144 QBarSet *set = m_Model->setAt(i);
144 QBarSet *set = m_internalModel->setAt(i);
145 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
145 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
146 }
146 }
147 } else {
147 } else {
148 for (int i=0; i<m_Model->barsetCount(); i++) {
148 for (int i=0; i<m_internalModel->barsetCount(); i++) {
149 QBarSet *set = m_Model->setAt(i);
149 QBarSet *set = m_internalModel->setAt(i);
150 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
150 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
151 }
151 }
152 }
152 }
@@ -175,7 +175,7 void QBarSeries::barsetRightClicked(QString category)
175 */
175 */
176 qreal QBarSeries::min()
176 qreal QBarSeries::min()
177 {
177 {
178 return m_Model->min();
178 return m_internalModel->min();
179 }
179 }
180
180
181 /*!
181 /*!
@@ -183,7 +183,7 qreal QBarSeries::min()
183 */
183 */
184 qreal QBarSeries::max()
184 qreal QBarSeries::max()
185 {
185 {
186 return m_Model->max();
186 return m_internalModel->max();
187 }
187 }
188
188
189 /*!
189 /*!
@@ -191,7 +191,7 qreal QBarSeries::max()
191 */
191 */
192 qreal QBarSeries::valueAt(int set, int category)
192 qreal QBarSeries::valueAt(int set, int category)
193 {
193 {
194 return m_Model->valueAt(set, category);
194 return m_internalModel->valueAt(set, category);
195 }
195 }
196
196
197 /*!
197 /*!
@@ -199,7 +199,7 qreal QBarSeries::valueAt(int set, int category)
199 */
199 */
200 qreal QBarSeries::percentageAt(int set, int category)
200 qreal QBarSeries::percentageAt(int set, int category)
201 {
201 {
202 return m_Model->percentageAt(set, category);
202 return m_internalModel->percentageAt(set, category);
203 }
203 }
204
204
205 /*!
205 /*!
@@ -207,7 +207,7 qreal QBarSeries::percentageAt(int set, int category)
207 */
207 */
208 qreal QBarSeries::categorySum(int category)
208 qreal QBarSeries::categorySum(int category)
209 {
209 {
210 return m_Model->categorySum(category);
210 return m_internalModel->categorySum(category);
211 }
211 }
212
212
213 /*!
213 /*!
@@ -215,7 +215,7 qreal QBarSeries::categorySum(int category)
215 */
215 */
216 qreal QBarSeries::maxCategorySum()
216 qreal QBarSeries::maxCategorySum()
217 {
217 {
218 return m_Model->maxCategorySum();
218 return m_internalModel->maxCategorySum();
219 }
219 }
220
220
221 /*!
221 /*!
@@ -223,7 +223,7 qreal QBarSeries::maxCategorySum()
223 */
223 */
224 BarChartModel& QBarSeries::model()
224 BarChartModel& QBarSeries::model()
225 {
225 {
226 return *m_Model;
226 return *m_internalModel;
227 }
227 }
228
228
229 bool QBarSeries::setModel(QAbstractItemModel *model)
229 bool QBarSeries::setModel(QAbstractItemModel *model)
@@ -286,12 +286,12 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound
286
286
287
287
288 // create the initial bars
288 // create the initial bars
289 delete m_Model;
289 delete m_internalModel;
290 if (m_mapOrientation == Qt::Vertical) {
290 if (m_mapOrientation == Qt::Vertical) {
291 QStringList categories;
291 QStringList categories;
292 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
292 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
293 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
293 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
294 m_Model = new BarChartModel(categories, this);
294 m_internalModel = new BarChartModel(categories, this);
295
295
296 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
296 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
297 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
297 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
@@ -303,7 +303,7 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound
303 QStringList categories;
303 QStringList categories;
304 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
304 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
305 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
305 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
306 m_Model = new BarChartModel(categories, this);
306 m_internalModel = new BarChartModel(categories, this);
307
307
308 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
308 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
309 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
309 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
@@ -375,9 +375,9 void QBarSeries::barsetChanged()
375 QBarCategories QBarSeries::categories() const
375 QBarCategories QBarSeries::categories() const
376 {
376 {
377 QBarCategories categories;
377 QBarCategories categories;
378 int count = m_Model->categoryCount();
378 int count = m_internalModel->categoryCount();
379 for (int i=1; i <= count; i++) {
379 for (int i=1; i <= count; i++) {
380 categories.insert(i, m_Model->categoryName(i - 1));
380 categories.insert(i, m_internalModel->categoryName(i - 1));
381 }
381 }
382 return categories;
382 return categories;
383 }
383 }
@@ -81,9 +81,9 private Q_SLOTS:
81 void barsetChanged();
81 void barsetChanged();
82
82
83 protected:
83 protected:
84 BarChartModel *m_Model;
84 BarChartModel *m_internalModel;
85
85
86 // QAbstractItemModel* m_model;
86 QAbstractItemModel* m_model;
87 int m_mapCategories;
87 int m_mapCategories;
88 int m_mapBarBottom;
88 int m_mapBarBottom;
89 int m_mapBarTop;
89 int m_mapBarTop;
@@ -56,7 +56,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
56 */
56 */
57 QBarSet::QBarSet(QString name, QObject *parent)
57 QBarSet::QBarSet(QString name, QObject *parent)
58 : QObject(parent)
58 : QObject(parent)
59 ,m_Name(name)
59 ,m_name(name)
60 {
60 {
61 }
61 }
62
62
@@ -65,7 +65,7 QBarSet::QBarSet(QString name, QObject *parent)
65 */
65 */
66 void QBarSet::setName(QString name)
66 void QBarSet::setName(QString name)
67 {
67 {
68 m_Name = name;
68 m_name = name;
69 }
69 }
70
70
71 /*!
71 /*!
@@ -73,7 +73,7 void QBarSet::setName(QString name)
73 */
73 */
74 QString QBarSet::name()
74 QString QBarSet::name()
75 {
75 {
76 return m_Name;
76 return m_name;
77 }
77 }
78
78
79 /*!
79 /*!
@@ -81,19 +81,19 QString QBarSet::name()
81 */
81 */
82 QBarSet& QBarSet::operator << (const qreal &value)
82 QBarSet& QBarSet::operator << (const qreal &value)
83 {
83 {
84 m_Values.append(value);
84 m_values.append(value);
85 emit structureChanged();
85 emit structureChanged();
86 return *this;
86 return *this;
87 }
87 }
88
88
89 void QBarSet::insertValue(int i, qreal value)
89 void QBarSet::insertValue(int i, qreal value)
90 {
90 {
91 m_Values.insert(i, value);
91 m_values.insert(i, value);
92 }
92 }
93
93
94 void QBarSet::removeValue(int i)
94 void QBarSet::removeValue(int i)
95 {
95 {
96 m_Values.removeAt(i);
96 m_values.removeAt(i);
97 }
97 }
98
98
99 /*!
99 /*!
@@ -101,7 +101,7 void QBarSet::removeValue(int i)
101 */
101 */
102 int QBarSet::count()
102 int QBarSet::count()
103 {
103 {
104 return m_Values.count();
104 return m_values.count();
105 }
105 }
106
106
107 /*!
107 /*!
@@ -109,7 +109,7 int QBarSet::count()
109 */
109 */
110 qreal QBarSet::valueAt(int index)
110 qreal QBarSet::valueAt(int index)
111 {
111 {
112 return m_Values.at(index);
112 return m_values.at(index);
113 }
113 }
114
114
115 /*!
115 /*!
@@ -117,7 +117,7 qreal QBarSet::valueAt(int index)
117 */
117 */
118 void QBarSet::setValue(int index, qreal value)
118 void QBarSet::setValue(int index, qreal value)
119 {
119 {
120 m_Values.replace(index,value);
120 m_values.replace(index,value);
121 emit valueChanged();
121 emit valueChanged();
122 }
122 }
123
123
@@ -127,8 +127,8 void QBarSet::setValue(int index, qreal value)
127 qreal QBarSet::total()
127 qreal QBarSet::total()
128 {
128 {
129 qreal total(0);
129 qreal total(0);
130 for (int i=0; i < m_Values.count(); i++) {
130 for (int i=0; i < m_values.count(); i++) {
131 total += m_Values.at(i);
131 total += m_values.at(i);
132 }
132 }
133 return total;
133 return total;
134 }
134 }
@@ -136,9 +136,9 qreal QBarSet::total()
136 /*!
136 /*!
137 Sets pen for set. Bars of this set are drawn using \a pen
137 Sets pen for set. Bars of this set are drawn using \a pen
138 */
138 */
139 void QBarSet::setPen(const QPen pen)
139 void QBarSet::setPen(const QPen &pen)
140 {
140 {
141 m_Pen = pen;
141 m_pen = pen;
142 emit valueChanged();
142 emit valueChanged();
143 }
143 }
144
144
@@ -147,15 +147,15 void QBarSet::setPen(const QPen pen)
147 */
147 */
148 QPen QBarSet::pen() const
148 QPen QBarSet::pen() const
149 {
149 {
150 return m_Pen;
150 return m_pen;
151 }
151 }
152
152
153 /*!
153 /*!
154 Sets brush for the set. Bars of this set are drawn using \a brush
154 Sets brush for the set. Bars of this set are drawn using \a brush
155 */
155 */
156 void QBarSet::setBrush(const QBrush brush)
156 void QBarSet::setBrush(const QBrush &brush)
157 {
157 {
158 m_Brush = brush;
158 m_brush = brush;
159 emit valueChanged();
159 emit valueChanged();
160 }
160 }
161
161
@@ -164,15 +164,15 void QBarSet::setBrush(const QBrush brush)
164 */
164 */
165 QBrush QBarSet::brush() const
165 QBrush QBarSet::brush() const
166 {
166 {
167 return m_Brush;
167 return m_brush;
168 }
168 }
169
169
170 /*!
170 /*!
171 Sets the pen for floating values that are drawn on top of this set
171 Sets the pen for floating values that are drawn on top of this set
172 */
172 */
173 void QBarSet::setFloatingValuePen(const QPen pen)
173 void QBarSet::setFloatingValuePen(const QPen &pen)
174 {
174 {
175 m_FloatingValuePen = pen;
175 m_floatingValuePen = pen;
176 }
176 }
177
177
178 /*!
178 /*!
@@ -180,7 +180,7 void QBarSet::setFloatingValuePen(const QPen pen)
180 */
180 */
181 QPen QBarSet::floatingValuePen() const
181 QPen QBarSet::floatingValuePen() const
182 {
182 {
183 return m_FloatingValuePen;
183 return m_floatingValuePen;
184 }
184 }
185
185
186 /*!
186 /*!
@@ -188,7 +188,7 QPen QBarSet::floatingValuePen() const
188 */
188 */
189 void QBarSet::barHoverEnterEvent(QPoint pos)
189 void QBarSet::barHoverEnterEvent(QPoint pos)
190 {
190 {
191 emit showToolTip(pos, m_Name);
191 emit showToolTip(pos, m_name);
192 emit hoverEnter(pos);
192 emit hoverEnter(pos);
193 }
193 }
194
194
@@ -29,13 +29,13 public:
29 //qreal value(QString category);
29 //qreal value(QString category);
30 //void setValue(QString category, qreal value);
30 //void setValue(QString category, qreal value);
31
31
32 void setPen(const QPen pen);
32 void setPen(const QPen &pen);
33 QPen pen() const;
33 QPen pen() const;
34
34
35 void setBrush(const QBrush brush);
35 void setBrush(const QBrush &brush);
36 QBrush brush() const;
36 QBrush brush() const;
37
37
38 void setFloatingValuePen(const QPen pen);
38 void setFloatingValuePen(const QPen &pen);
39 QPen floatingValuePen() const;
39 QPen floatingValuePen() const;
40
40
41 Q_SIGNALS:
41 Q_SIGNALS:
@@ -61,12 +61,12 public Q_SLOTS:
61
61
62 private:
62 private:
63
63
64 QString m_Name;
64 QString m_name;
65 QList<qreal> m_Values; // TODO: replace with map (category, value)
65 QList<qreal> m_values; // TODO: replace with map (category, value)
66 QMap<QString, qreal> m_MappedValues;
66 QMap<QString, qreal> m_mappedValues;
67 QPen m_Pen;
67 QPen m_pen;
68 QBrush m_Brush;
68 QBrush m_brush;
69 QPen m_FloatingValuePen;
69 QPen m_floatingValuePen;
70 };
70 };
71
71
72 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
@@ -20,16 +20,16 QVector<QRectF> StackedBarChartItem::calculateLayout()
20 QVector<QRectF> layout;
20 QVector<QRectF> layout;
21 // Use temporary qreals for accurancy (we might get some compiler warnings... :)
21 // Use temporary qreals for accurancy (we might get some compiler warnings... :)
22
22
23 qreal maxSum = m_Series->maxCategorySum();
23 qreal maxSum = m_series->maxCategorySum();
24 // Domain:
24 // Domain:
25 if (m_DomainMaxY > maxSum) {
25 if (m_domainMaxY > maxSum) {
26 maxSum = m_DomainMaxY;
26 maxSum = m_domainMaxY;
27 }
27 }
28
28
29 qreal height = geometry().height();
29 qreal height = geometry().height();
30 qreal width = geometry().width();
30 qreal width = geometry().width();
31 qreal scale = (height / m_Series->maxCategorySum());
31 qreal scale = (height / m_series->maxCategorySum());
32 qreal categotyCount = m_Series->categoryCount();
32 qreal categotyCount = m_series->categoryCount();
33 qreal barWidth = width / (categotyCount * 2);
33 qreal barWidth = width / (categotyCount * 2);
34 qreal xStep = width / categotyCount;
34 qreal xStep = width / categotyCount;
35 qreal xPos = xStep / 2 - barWidth / 2;
35 qreal xPos = xStep / 2 - barWidth / 2;
@@ -37,11 +37,11 QVector<QRectF> StackedBarChartItem::calculateLayout()
37 int itemIndex(0);
37 int itemIndex(0);
38 for (int category = 0; category < categotyCount; category++) {
38 for (int category = 0; category < categotyCount; category++) {
39 qreal yPos = height;
39 qreal yPos = height;
40 for (int set=0; set < m_Series->barsetCount(); set++) {
40 for (int set=0; set < m_series->barsetCount(); set++) {
41 qreal barHeight = m_Series->valueAt(set, category) * scale;
41 qreal barHeight = m_series->valueAt(set, category) * scale;
42 Bar* bar = m_Bars.at(itemIndex);
42 Bar* bar = m_bars.at(itemIndex);
43 bar->setPen(m_Series->barsetAt(set)->pen());
43 bar->setPen(m_series->barsetAt(set)->pen());
44 bar->setBrush(m_Series->barsetAt(set)->brush());
44 bar->setBrush(m_series->barsetAt(set)->brush());
45 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
45 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
46 layout.append(rect);
46 layout.append(rect);
47 itemIndex++;
47 itemIndex++;
@@ -53,19 +53,19 QVector<QRectF> StackedBarChartItem::calculateLayout()
53 // Position floating values
53 // Position floating values
54 itemIndex = 0;
54 itemIndex = 0;
55 xPos = (width/categotyCount);
55 xPos = (width/categotyCount);
56 for (int category=0; category < m_Series->categoryCount(); category++) {
56 for (int category=0; category < m_series->categoryCount(); category++) {
57 qreal yPos = height;
57 qreal yPos = height;
58 for (int set=0; set < m_Series->barsetCount(); set++) {
58 for (int set=0; set < m_series->barsetCount(); set++) {
59 qreal barHeight = m_Series->valueAt(set, category) * scale;
59 qreal barHeight = m_series->valueAt(set, category) * scale;
60 BarValue* value = m_FloatingValues.at(itemIndex);
60 BarValue* value = m_floatingValues.at(itemIndex);
61
61
62 QBarSet* barSet = m_Series->barsetAt(set);
62 QBarSet* barSet = m_series->barsetAt(set);
63 value->resize(100, 50); // TODO: proper layout for this.
63 value->resize(100, 50); // TODO: proper layout for this.
64 value->setPos(xPos, yPos-barHeight / 2);
64 value->setPos(xPos, yPos-barHeight / 2);
65 value->setPen(barSet->floatingValuePen());
65 value->setPen(barSet->floatingValuePen());
66
66
67 if (m_Series->valueAt(set, category) != 0) {
67 if (m_series->valueAt(set, category) != 0) {
68 value->setValueString(QString::number(m_Series->valueAt(set,category)));
68 value->setValueString(QString::number(m_series->valueAt(set,category)));
69 } else {
69 } else {
70 value->setValueString(QString(""));
70 value->setValueString(QString(""));
71 }
71 }
General Comments 0
You need to be logged in to leave comments. Login now