@@ -9,11 +9,11 Bar::Bar(QString category, QGraphicsItem *parent) | |||||
9 | : QGraphicsRectItem(parent), |
|
9 | : QGraphicsRectItem(parent), | |
10 | mCategory(category) |
|
10 | mCategory(category) | |
11 | { |
|
11 | { | |
12 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
12 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | |
13 | setAcceptHoverEvents(true); |
|
13 | setAcceptHoverEvents(true); | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 |
void Bar::mousePressEvent(QGraphicsSceneMouseEvent* |
|
16 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
17 | { |
|
17 | { | |
18 | if (event->button() == Qt::LeftButton) { |
|
18 | if (event->button() == Qt::LeftButton) { | |
19 | emit clicked(mCategory); |
|
19 | emit clicked(mCategory); | |
@@ -22,13 +22,14 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event) | |||||
22 | } |
|
22 | } | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 |
void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* |
|
25 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
26 | { |
|
26 | { | |
27 | emit hoverEntered(event->lastScreenPos()); |
|
27 | emit hoverEntered(event->lastScreenPos()); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 |
void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* |
|
30 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
31 | { |
|
31 | { | |
|
32 | Q_UNUSED(event) | |||
32 | emit hoverLeaved(); |
|
33 | emit hoverLeaved(); | |
33 | } |
|
34 | } | |
34 |
|
35 |
@@ -11,7 +11,7 class Bar : public QObject, public QGraphicsRectItem | |||||
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | Bar(QString category, QGraphicsItem *parent=0); |
|
14 | Bar(QString category, QGraphicsItem *parent = 0); | |
15 |
|
15 | |||
16 | public: |
|
16 | public: | |
17 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
17 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
@@ -19,7 +19,7 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |||||
19 | mLayoutSet(false), |
|
19 | mLayoutSet(false), | |
20 | mSeries(series) |
|
20 | mSeries(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())); | |
24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); | |
25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
@@ -38,9 +38,9 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti | |||||
38 | qDebug() << "BarChartItem::paint called without layout set. Aborting."; |
|
38 | qDebug() << "BarChartItem::paint called without layout set. Aborting."; | |
39 | return; |
|
39 | return; | |
40 | } |
|
40 | } | |
41 | foreach(QGraphicsItem* i, childItems()) { |
|
41 | ||
|
42 | foreach(QGraphicsItem* i, childItems()) | |||
42 | i->paint(painter,option,widget); |
|
43 | i->paint(painter,option,widget); | |
43 | } |
|
|||
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QRectF BarChartItem::boundingRect() const |
|
46 | QRectF BarChartItem::boundingRect() const | |
@@ -52,38 +52,37 void BarChartItem::dataChanged() | |||||
52 | { |
|
52 | { | |
53 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
53 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
54 | // Delete old bars |
|
54 | // Delete old bars | |
55 |
foreach (QGraphicsItem* |
|
55 | foreach (QGraphicsItem *item, childItems()) | |
56 | delete item; |
|
56 | delete item; | |
57 | } |
|
|||
58 |
|
57 | |||
59 | mBars.clear(); |
|
58 | mBars.clear(); | |
60 | mFloatingValues.clear(); |
|
59 | mFloatingValues.clear(); | |
61 | mLayout.clear(); |
|
60 | mLayout.clear(); | |
62 |
|
61 | |||
63 | // Create new graphic items for bars |
|
62 | // Create new graphic items for bars | |
64 | for (int c=0; c<mSeries->categoryCount(); c++) { |
|
63 | for (int c = 0; c < mSeries->categoryCount(); c++) { | |
65 | QString category = mSeries->categoryName(c); |
|
64 | QString category = mSeries->categoryName(c); | |
66 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
65 | for (int s = 0; s < mSeries->barsetCount(); s++) { | |
67 | QBarSet *set = mSeries->barsetAt(s); |
|
66 | QBarSet *set = mSeries->barsetAt(s); | |
68 | Bar *bar = new Bar(category,this); |
|
67 | Bar *bar = new Bar(category,this); | |
69 | childItems().append(bar); |
|
68 | childItems().append(bar); | |
70 | mBars.append(bar); |
|
69 | mBars.append(bar); | |
71 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); |
|
70 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); | |
72 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); |
|
71 | connect(bar, SIGNAL(rightClicked(QString)), set, SIGNAL(rightClicked(QString))); | |
73 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); |
|
72 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
74 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); |
|
73 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
75 | mLayout.append(QRectF(0,0,0,0)); |
|
74 | mLayout.append(QRectF(0, 0, 0, 0)); | |
76 | } |
|
75 | } | |
77 | } |
|
76 | } | |
78 |
|
77 | |||
79 | // Create floating values |
|
78 | // Create floating values | |
80 | for (int category=0; category<mSeries->categoryCount(); category++) { |
|
79 | for (int category = 0; category < mSeries->categoryCount(); category++) { | |
81 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
80 | for (int s = 0; s < mSeries->barsetCount(); s++) { | |
82 | QBarSet *set = mSeries->barsetAt(s); |
|
81 | QBarSet *set = mSeries->barsetAt(s); | |
83 | BarValue *value = new BarValue(*set, this); |
|
82 | BarValue *value = new BarValue(*set, this); | |
84 | childItems().append(value); |
|
83 | childItems().append(value); | |
85 | mFloatingValues.append(value); |
|
84 | mFloatingValues.append(value); | |
86 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); |
|
85 | connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible())); | |
87 | } |
|
86 | } | |
88 | } |
|
87 | } | |
89 | } |
|
88 | } | |
@@ -105,19 +104,19 QVector<QRectF> BarChartItem::calculateLayout() | |||||
105 | max = mDomainMaxY; |
|
104 | max = mDomainMaxY; | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | qreal scale = (height/max); |
|
107 | qreal scale = (height / max); | |
109 | qreal categoryWidth = width/categoryCount; |
|
108 | qreal categoryWidth = width / categoryCount; | |
110 | qreal barWidth = categoryWidth / (setCount+1); |
|
109 | qreal barWidth = categoryWidth / (setCount+1); | |
111 |
|
110 | |||
112 | int itemIndex(0); |
|
111 | int itemIndex(0); | |
113 | for (int category=0; category < categoryCount; category++) { |
|
112 | for (int category = 0; category < categoryCount; category++) { | |
114 | qreal xPos = categoryWidth * category + barWidth/2; |
|
113 | qreal xPos = categoryWidth * category + barWidth / 2; | |
115 | qreal yPos = height; |
|
114 | qreal yPos = height; | |
116 | for (int set = 0; set < setCount; set++) { |
|
115 | for (int set = 0; set < setCount; set++) { | |
117 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
116 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
118 | Bar* bar = mBars.at(itemIndex); |
|
117 | Bar* bar = mBars.at(itemIndex); | |
119 |
|
118 | |||
120 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); |
|
119 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
121 | layout.append(rect); |
|
120 | layout.append(rect); | |
122 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
121 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
123 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
122 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
@@ -128,20 +127,20 QVector<QRectF> BarChartItem::calculateLayout() | |||||
128 |
|
127 | |||
129 | // Position floating values |
|
128 | // Position floating values | |
130 | itemIndex = 0; |
|
129 | itemIndex = 0; | |
131 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
130 | for (int category = 0; category < mSeries->categoryCount(); category++) { | |
132 | qreal xPos = categoryWidth * category + barWidth; |
|
131 | qreal xPos = categoryWidth * category + barWidth; | |
133 | qreal yPos = height; |
|
132 | qreal yPos = height; | |
134 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
133 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
135 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
134 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
136 | BarValue* value = mFloatingValues.at(itemIndex); |
|
135 | BarValue* value = mFloatingValues.at(itemIndex); | |
137 |
|
136 | |||
138 | QBarSet* barSet = mSeries->barsetAt(set); |
|
137 | QBarSet* barSet = mSeries->barsetAt(set); | |
139 | value->resize(100,50); // TODO: proper layout for this. |
|
138 | value->resize(100, 50); // TODO: proper layout for this. | |
140 | value->setPos(xPos, yPos-barHeight/2); |
|
139 | value->setPos(xPos, yPos-barHeight / 2); | |
141 | value->setPen(barSet->floatingValuePen()); |
|
140 | value->setPen(barSet->floatingValuePen()); | |
142 |
|
141 | |||
143 | if (mSeries->valueAt(set,category) != 0) { |
|
142 | if (mSeries->valueAt(set,category) != 0) { | |
144 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
143 | value->setValueString(QString::number(mSeries->valueAt(set, category))); | |
145 | } else { |
|
144 | } else { | |
146 | value->setValueString(QString("")); |
|
145 | value->setValueString(QString("")); | |
147 | } |
|
146 | } | |
@@ -166,9 +165,8 void BarChartItem::setLayout(const QVector<QRectF> &layout) | |||||
166 | { |
|
165 | { | |
167 | mLayout = layout; |
|
166 | mLayout = layout; | |
168 |
|
167 | |||
169 |
for (int i=0; i<mBars.count(); i++) |
|
168 | for (int i=0; i < mBars.count(); i++) | |
170 | mBars.at(i)->setRect(layout.at(i)); |
|
169 | mBars.at(i)->setRect(layout.at(i)); | |
171 | } |
|
|||
172 |
|
170 | |||
173 | update(); |
|
171 | update(); | |
174 | } |
|
172 | } | |
@@ -190,9 +188,9 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal | |||||
190 | handleLayoutChanged(); |
|
188 | handleLayoutChanged(); | |
191 | } |
|
189 | } | |
192 |
|
190 | |||
193 |
void BarChartItem::handleGeometryChanged(const QRectF& |
|
191 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
194 | { |
|
192 | { | |
195 | m_rect=rect; |
|
193 | m_rect = rect; | |
196 | handleLayoutChanged(); |
|
194 | handleLayoutChanged(); | |
197 | mLayoutSet = true; |
|
195 | mLayoutSet = true; | |
198 | setPos(rect.topLeft()); |
|
196 | setPos(rect.topLeft()); | |
@@ -209,7 +207,7 void BarChartItem::handleLayoutChanged() | |||||
209 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
207 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
210 | { |
|
208 | { | |
211 | // TODO: cool tooltip instead of default |
|
209 | // TODO: cool tooltip instead of default | |
212 | QToolTip::showText(pos,tip); |
|
210 | QToolTip::showText(pos, tip); | |
213 | } |
|
211 | } | |
214 |
|
212 | |||
215 | #include "moc_barchartitem_p.cpp" |
|
213 | #include "moc_barchartitem_p.cpp" |
@@ -46,7 +46,7 public: | |||||
46 | public slots: |
|
46 | public slots: | |
47 | void handleModelChanged(int index); |
|
47 | void handleModelChanged(int index); | |
48 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
48 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
49 |
void handleGeometryChanged(const QRectF& |
|
49 | void handleGeometryChanged(const QRectF &size); | |
50 | void handleLayoutChanged(); |
|
50 | void handleLayoutChanged(); | |
51 |
|
51 | |||
52 | // Internal slots |
|
52 | // Internal slots | |
@@ -65,9 +65,9 protected: | |||||
65 | QVector<QRectF> mLayout; |
|
65 | QVector<QRectF> mLayout; | |
66 |
|
66 | |||
67 | // Not owned. |
|
67 | // Not owned. | |
68 |
QBarSeries* |
|
68 | QBarSeries *mSeries; | |
69 | QList<Bar*> mBars; |
|
69 | QList<Bar *> mBars; | |
70 | QList<BarValue*> mFloatingValues; |
|
70 | QList<BarValue *> mFloatingValues; | |
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -71,13 +71,12 qreal BarChartModel::min() | |||||
71 | // This is slower since they are checked every time, even if data is same since previous call. |
|
71 | // This is slower since they are checked every time, even if data is same since previous call. | |
72 | qreal min = INT_MAX; |
|
72 | qreal min = INT_MAX; | |
73 |
|
73 | |||
74 | for (int i=0; i <mDataModel.count(); i++) { |
|
74 | for (int i = 0; i < mDataModel.count(); i++) { | |
75 | int itemCount = mDataModel.at(i)->count(); |
|
75 | int itemCount = mDataModel.at(i)->count(); | |
76 | for (int j=0; j<itemCount; j++) { |
|
76 | for (int j = 0; j < itemCount; j++) { | |
77 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
77 | qreal temp = mDataModel.at(i)->valueAt(j); | |
78 |
if (temp < min) |
|
78 | if (temp < min) | |
79 | min = temp; |
|
79 | min = temp; | |
80 | } |
|
|||
81 | } |
|
80 | } | |
82 | } |
|
81 | } | |
83 | return min; |
|
82 | return min; | |
@@ -91,13 +90,12 qreal BarChartModel::max() | |||||
91 | // This is slower since they are checked every time, even if data is same since previous call. |
|
90 | // This is slower since they are checked every time, even if data is same since previous call. | |
92 | qreal max = INT_MIN; |
|
91 | qreal max = INT_MIN; | |
93 |
|
92 | |||
94 | for (int i=0; i <mDataModel.count(); i++) { |
|
93 | for (int i = 0; i < mDataModel.count(); i++) { | |
95 | int itemCount = mDataModel.at(i)->count(); |
|
94 | int itemCount = mDataModel.at(i)->count(); | |
96 | for (int j=0; j<itemCount; j++) { |
|
95 | for (int j = 0; j < itemCount; j++) { | |
97 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
96 | qreal temp = mDataModel.at(i)->valueAt(j); | |
98 |
if (temp > max) |
|
97 | if (temp > max) | |
99 | max = temp; |
|
98 | max = temp; | |
100 | } |
|
|||
101 | } |
|
99 | } | |
102 | } |
|
100 | } | |
103 |
|
101 | |||
@@ -129,9 +127,8 qreal BarChartModel::percentageAt(int set, int category) | |||||
129 |
|
127 | |||
130 | qreal value = mDataModel.at(set)->valueAt(category); |
|
128 | qreal value = mDataModel.at(set)->valueAt(category); | |
131 | qreal total = categorySum(category); |
|
129 | qreal total = categorySum(category); | |
132 |
if (0 == total) |
|
130 | if (0 == total) | |
133 | return 100.0; |
|
131 | return 100.0; | |
134 | } |
|
|||
135 |
|
132 | |||
136 | return value / total; |
|
133 | return value / total; | |
137 | } |
|
134 | } | |
@@ -143,9 +140,8 qreal BarChartModel::categorySum(int category) | |||||
143 | int count = mDataModel.count(); // Count sets |
|
140 | int count = mDataModel.count(); // Count sets | |
144 |
|
141 | |||
145 | for (int set = 0; set < count; set++) { |
|
142 | for (int set = 0; set < count; set++) { | |
146 |
if (category < mDataModel.at(set)->count()) |
|
143 | if (category < mDataModel.at(set)->count()) | |
147 | sum += mDataModel.at(set)->valueAt(category); |
|
144 | sum += mDataModel.at(set)->valueAt(category); | |
148 | } |
|
|||
149 | } |
|
145 | } | |
150 | return sum; |
|
146 | return sum; | |
151 | } |
|
147 | } | |
@@ -155,11 +151,10 qreal BarChartModel::maxCategorySum() | |||||
155 | qreal max = INT_MIN; |
|
151 | qreal max = INT_MIN; | |
156 | int count = categoryCount(); |
|
152 | int count = categoryCount(); | |
157 |
|
153 | |||
158 | for (int col=0; col<count; col++) { |
|
154 | for (int col = 0; col < count; col++) { | |
159 | qreal sum = categorySum(col); |
|
155 | qreal sum = categorySum(col); | |
160 |
if (sum > max) |
|
156 | if (sum > max) | |
161 | max = sum; |
|
157 | max = sum; | |
162 | } |
|
|||
163 | } |
|
158 | } | |
164 | return max; |
|
159 | return max; | |
165 | } |
|
160 | } |
@@ -26,7 +26,7 public: | |||||
26 | void insertCategory(int i, QString category); |
|
26 | void insertCategory(int i, QString category); | |
27 | void removeCategory(int i); |
|
27 | void removeCategory(int i); | |
28 | QBarSet *setAt(int index); |
|
28 | QBarSet *setAt(int index); | |
29 | QList<QBarSet*> barSets(); |
|
29 | QList<QBarSet *> barSets(); | |
30 |
|
30 | |||
31 | int barsetCount(); // Number of sets in model |
|
31 | int barsetCount(); // Number of sets in model | |
32 | int categoryCount(); // Number of categories |
|
32 | int categoryCount(); // Number of categories | |
@@ -48,11 +48,9 public slots: | |||||
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 |
|
50 | |||
51 | QList<QBarSet*> mDataModel; |
|
51 | QList<QBarSet *> mDataModel; | |
52 | QStringList mCategory; |
|
52 | QStringList mCategory; | |
53 |
|
||||
54 | int mCurrentSet; |
|
53 | int mCurrentSet; | |
55 |
|
||||
56 | }; |
|
54 | }; | |
57 |
|
55 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -54,7 +54,7 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | |||||
54 |
|
54 | |||
55 | if (isVisible()) { |
|
55 | if (isVisible()) { | |
56 | painter->setPen(mPen); |
|
56 | painter->setPen(mPen); | |
57 | painter->drawText(boundingRect(),mValueString); |
|
57 | painter->drawText(boundingRect(), mValueString); | |
58 | } |
|
58 | } | |
59 | } |
|
59 | } | |
60 |
|
60 |
@@ -35,7 +35,7 public Q_SLOTS: | |||||
35 |
|
35 | |||
36 | private: |
|
36 | private: | |
37 |
|
37 | |||
38 |
QBarSet& |
|
38 | QBarSet &mBarSet; | |
39 | QPen mPen; |
|
39 | QPen mPen; | |
40 | QString mValueString; |
|
40 | QString mValueString; | |
41 |
|
41 |
@@ -6,7 +6,7 | |||||
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 |
PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter* |
|
9 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
10 | BarChartItem(series, presenter) |
|
10 | BarChartItem(series, presenter) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
@@ -21,11 +21,11 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||||
21 |
|
21 | |||
22 | qreal categoryCount = mSeries->categoryCount(); |
|
22 | qreal categoryCount = mSeries->categoryCount(); | |
23 | qreal barWidth = width / (mSeries->categoryCount() * 2); |
|
23 | qreal barWidth = width / (mSeries->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 |
|
28 | for (int category = 0; category < categoryCount; category++) { | |
29 | qreal colSum = mSeries->categorySum(category); |
|
29 | qreal colSum = mSeries->categorySum(category); | |
30 | qreal scale = (height / colSum); |
|
30 | qreal scale = (height / colSum); | |
31 | qreal yPos = height; |
|
31 | qreal yPos = height; | |
@@ -34,7 +34,7 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||||
34 | Bar* bar = mBars.at(itemIndex); |
|
34 | Bar* bar = mBars.at(itemIndex); | |
35 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
35 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
36 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
36 | bar->setBrush(mSeries->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++; | |
40 | yPos -= barHeight; |
|
40 | yPos -= barHeight; | |
@@ -54,8 +54,8 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||||
54 | BarValue* value = mFloatingValues.at(itemIndex); |
|
54 | BarValue* value = mFloatingValues.at(itemIndex); | |
55 |
|
55 | |||
56 | QBarSet* barSet = mSeries->barsetAt(set); |
|
56 | QBarSet* barSet = mSeries->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 (mSeries->valueAt(set,category) != 0) { |
|
61 | if (mSeries->valueAt(set,category) != 0) { |
@@ -54,8 +54,8 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) | |||||
54 | void QBarSeries::addBarSet(QBarSet *set) |
|
54 | void QBarSeries::addBarSet(QBarSet *set) | |
55 | { |
|
55 | { | |
56 | mModel->addBarSet(set); |
|
56 | mModel->addBarSet(set); | |
57 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
57 | connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); | |
58 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
58 | connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); | |
59 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
59 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
60 | emit updatedBars(); |
|
60 | emit updatedBars(); | |
61 | } |
|
61 | } | |
@@ -67,8 +67,8 void QBarSeries::addBarSet(QBarSet *set) | |||||
67 | */ |
|
67 | */ | |
68 | void QBarSeries::removeBarSet(QBarSet *set) |
|
68 | void QBarSeries::removeBarSet(QBarSet *set) | |
69 | { |
|
69 | { | |
70 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
70 | disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); | |
71 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
71 | disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); | |
72 | mModel->removeBarSet(set); |
|
72 | mModel->removeBarSet(set); | |
73 | emit updatedBars(); |
|
73 | emit updatedBars(); | |
74 | } |
|
74 | } | |
@@ -143,12 +143,12 void QBarSeries::setToolTipEnabled(bool enabled) | |||||
143 | if (enabled) { |
|
143 | if (enabled) { | |
144 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
144 | for (int i=0; i<mModel->barsetCount(); i++) { | |
145 | QBarSet *set = mModel->setAt(i); |
|
145 | QBarSet *set = mModel->setAt(i); | |
146 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
146 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
147 | } |
|
147 | } | |
148 | } else { |
|
148 | } else { | |
149 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
149 | for (int i=0; i<mModel->barsetCount(); i++) { | |
150 | QBarSet *set = mModel->setAt(i); |
|
150 | QBarSet *set = mModel->setAt(i); | |
151 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
151 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
152 | } |
|
152 | } | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
@@ -192,7 +192,7 qreal QBarSeries::max() | |||||
192 | */ |
|
192 | */ | |
193 | qreal QBarSeries::valueAt(int set, int category) |
|
193 | qreal QBarSeries::valueAt(int set, int category) | |
194 | { |
|
194 | { | |
195 | return mModel->valueAt(set,category); |
|
195 | return mModel->valueAt(set, category); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
@@ -200,7 +200,7 qreal QBarSeries::valueAt(int set, int category) | |||||
200 | */ |
|
200 | */ | |
201 | qreal QBarSeries::percentageAt(int set, int category) |
|
201 | qreal QBarSeries::percentageAt(int set, int category) | |
202 | { |
|
202 | { | |
203 | return mModel->percentageAt(set,category); |
|
203 | return mModel->percentageAt(set, category); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
@@ -227,7 +227,7 BarChartModel& QBarSeries::model() | |||||
227 | return *mModel; |
|
227 | return *mModel; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 |
bool QBarSeries::setModel(QAbstractItemModel* |
|
230 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
231 | { |
|
231 | { | |
232 | // disconnect signals from old model |
|
232 | // disconnect signals from old model | |
233 | if(m_model) |
|
233 | if(m_model) | |
@@ -259,6 +259,7 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
259 | { |
|
259 | { | |
260 | if (m_model == NULL) |
|
260 | if (m_model == NULL) | |
261 | return; |
|
261 | return; | |
|
262 | ||||
262 | m_mapCategories = categories; |
|
263 | m_mapCategories = categories; | |
263 | m_mapBarBottom = bottomBoundry; |
|
264 | m_mapBarBottom = bottomBoundry; | |
264 | m_mapBarTop = topBoundry; |
|
265 | m_mapBarTop = topBoundry; | |
@@ -266,48 +267,46 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
266 | m_mapOrientation = orientation; |
|
267 | m_mapOrientation = orientation; | |
267 |
|
268 | |||
268 | // connect the signals |
|
269 | // connect the signals | |
269 | if (m_mapOrientation == Qt::Vertical) |
|
270 | if (m_mapOrientation == Qt::Vertical) { | |
270 | { |
|
|||
271 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
271 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
272 |
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
272 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
273 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
273 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
274 |
connect(m_model, |
|
274 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
275 | } |
|
275 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
276 | else |
|
276 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
277 | { |
|
277 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
278 | } else { | |||
278 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
279 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
279 |
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
280 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
280 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
281 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
281 |
connect(m_model, |
|
282 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
|
283 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |||
|
284 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |||
|
285 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |||
282 | } |
|
286 | } | |
283 |
|
287 | |||
284 |
|
288 | |||
285 | // create the initial bars |
|
289 | // create the initial bars | |
286 | delete mModel; |
|
290 | delete mModel; | |
287 | if (m_mapOrientation == Qt::Vertical) |
|
291 | if (m_mapOrientation == Qt::Vertical) { | |
288 | { |
|
|||
289 | QStringList categories; |
|
292 | QStringList categories; | |
290 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
293 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
291 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
294 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
292 | mModel = new BarChartModel(categories, this); |
|
295 | mModel = new BarChartModel(categories, this); | |
293 |
|
296 | |||
294 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
297 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
295 | { |
|
|||
296 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
298 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
297 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
299 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
298 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
300 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
299 | addBarSet(barSet); |
|
301 | addBarSet(barSet); | |
300 | } |
|
302 | } | |
301 | } |
|
303 | } else { | |
302 | else |
|
|||
303 | { |
|
|||
304 | QStringList categories; |
|
304 | QStringList categories; | |
305 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
305 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
306 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
306 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
307 | mModel = new BarChartModel(categories, this); |
|
307 | mModel = new BarChartModel(categories, this); | |
308 |
|
308 | |||
309 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
309 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
310 | { |
|
|||
311 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
310 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
312 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
311 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
313 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
312 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
@@ -342,27 +341,25 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||||
342 |
|
341 | |||
343 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
342 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
344 | { |
|
343 | { | |
345 | if (m_mapOrientation == Qt::Vertical) |
|
344 | if (m_mapOrientation == Qt::Vertical) { | |
346 | { |
|
|||
347 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
345 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
348 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
346 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
349 | { |
|
|||
350 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
347 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
351 | } |
|
348 | } | |
352 | } |
|
349 | } else { | |
353 | else |
|
|||
354 | { |
|
|||
355 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
350 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
356 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
351 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
357 | { |
|
|||
358 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
352 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
359 | } |
|
353 | } | |
360 | } |
|
354 | } | |
361 | emit restructuredBar(1); |
|
355 | emit restructuredBar(1); | |
362 | } |
|
356 | } | |
363 |
|
357 | |||
364 |
void QBarSeries::modelDataRemoved(QModelIndex |
|
358 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
365 | { |
|
359 | { | |
|
360 | Q_UNUSED(parent) | |||
|
361 | Q_UNUSED(end) | |||
|
362 | ||||
366 | removeCategory(start - m_mapFirst); |
|
363 | removeCategory(start - m_mapFirst); | |
367 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
364 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
368 | { |
|
365 | { | |
@@ -380,8 +377,8 QBarCategories QBarSeries::categories() const | |||||
380 | { |
|
377 | { | |
381 | QBarCategories categories; |
|
378 | QBarCategories categories; | |
382 | int count = mModel->categoryCount(); |
|
379 | int count = mModel->categoryCount(); | |
383 | for (int i=1; i<=count; i++) { |
|
380 | for (int i=1; i <= count; i++) { | |
384 | categories.insert(i, mModel->categoryName(i-1)); |
|
381 | categories.insert(i, mModel->categoryName(i - 1)); | |
385 | } |
|
382 | } | |
386 | return categories; |
|
383 | return categories; | |
387 | } |
|
384 | } |
@@ -17,7 +17,7 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |||||
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 |
QBarSeries(QStringList categories, QObject* |
|
20 | QBarSeries(QStringList categories, QObject *parent = 0); | |
21 |
|
21 | |||
22 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
22 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
23 |
|
23 | |||
@@ -31,9 +31,8 public: | |||||
31 | QList<QBarSet*> barSets(); |
|
31 | QList<QBarSet*> barSets(); | |
32 | QBarCategories categories() const; |
|
32 | QBarCategories categories() const; | |
33 |
|
33 | |||
34 |
|
34 | bool setModel(QAbstractItemModel *model); | ||
35 |
|
|
35 | QAbstractItemModel *modelExt() { return m_model; } | |
36 | QAbstractItemModel* modelExt() {return m_model;} |
|
|||
37 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
36 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
38 | void setModelMappingShift(int first, int count); |
|
37 | void setModelMappingShift(int first, int count); | |
39 |
|
38 | |||
@@ -54,8 +53,8 public: | |||||
54 |
|
53 | |||
55 | signals: |
|
54 | signals: | |
56 | //void changed(int index); |
|
55 | //void changed(int index); | |
57 |
void clicked(QBarSet* |
|
56 | void clicked(QBarSet *barset, QString category); // Up to user of api, what to do with these signals | |
58 |
void rightClicked(QBarSet* |
|
57 | void rightClicked(QBarSet *barset, QString category); | |
59 |
|
58 | |||
60 | // |
|
59 | // | |
61 | void updatedBars(); |
|
60 | void updatedBars(); | |
@@ -67,7 +66,7 signals: | |||||
67 | // <--- TO PIMPL |
|
66 | // <--- TO PIMPL | |
68 |
|
67 | |||
69 | public Q_SLOTS: |
|
68 | public Q_SLOTS: | |
70 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
69 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
71 |
|
70 | |||
72 | // TODO: TO PIMPL ---> |
|
71 | // TODO: TO PIMPL ---> | |
73 | void barsetClicked(QString category); |
|
72 | void barsetClicked(QString category); | |
@@ -82,7 +81,7 private Q_SLOTS: | |||||
82 | void barsetChanged(); |
|
81 | void barsetChanged(); | |
83 |
|
82 | |||
84 | protected: |
|
83 | protected: | |
85 |
BarChartModel* |
|
84 | BarChartModel *mModel; | |
86 |
|
85 | |||
87 | // QAbstractItemModel* m_model; |
|
86 | // QAbstractItemModel* m_model; | |
88 | int m_mapCategories; |
|
87 | int m_mapCategories; |
@@ -127,7 +127,7 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<mValues.count(); i++) { |
|
130 | for (int i=0; i < mValues.count(); i++) { | |
131 | total += mValues.at(i); |
|
131 | total += mValues.at(i); | |
132 | } |
|
132 | } | |
133 | return total; |
|
133 | return total; | |
@@ -202,4 +202,5 void QBarSet::barHoverLeaveEvent() | |||||
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | #include "moc_qbarset.cpp" |
|
204 | #include "moc_qbarset.cpp" | |
|
205 | ||||
205 | QTCOMMERCIALCHART_END_NAMESPACE |
|
206 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -63,7 +63,7 private: | |||||
63 |
|
63 | |||
64 | QString mName; |
|
64 | QString mName; | |
65 | QList<qreal> mValues; // TODO: replace with map (category, value) |
|
65 | QList<qreal> mValues; // TODO: replace with map (category, value) | |
66 | QMap<QString,qreal> mMappedValues; |
|
66 | QMap<QString, qreal> mMappedValues; | |
67 | QPen mPen; |
|
67 | QPen mPen; | |
68 | QBrush mBrush; |
|
68 | QBrush mBrush; | |
69 | QPen mFloatingValuePen; |
|
69 | QPen mFloatingValuePen; |
@@ -10,12 +10,10 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries | |||||
10 | { |
|
10 | { | |
11 | Q_OBJECT |
|
11 | Q_OBJECT | |
12 | public: |
|
12 | public: | |
13 |
QPercentBarSeries(QStringList categories, QObject* |
|
13 | QPercentBarSeries(QStringList categories, QObject *parent = 0); | |
14 |
|
||||
15 | virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; } |
|
14 | virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; } | |
16 | }; |
|
15 | }; | |
17 |
|
16 | |||
18 | QTCOMMERCIALCHART_END_NAMESPACE |
|
17 | QTCOMMERCIALCHART_END_NAMESPACE | |
19 |
|
18 | |||
20 |
|
||||
21 | #endif // PERCENTBARSERIES_H |
|
19 | #endif // PERCENTBARSERIES_H |
@@ -10,8 +10,7 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries | |||||
10 | { |
|
10 | { | |
11 | Q_OBJECT |
|
11 | Q_OBJECT | |
12 | public: |
|
12 | public: | |
13 |
QStackedBarSeries(QStringList categories, QObject* |
|
13 | QStackedBarSeries(QStringList categories, QObject *parent = 0); | |
14 |
|
||||
15 | virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; } |
|
14 | virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; } | |
16 | }; |
|
15 | }; | |
17 |
|
16 |
@@ -7,7 +7,7 | |||||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
9 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
10 | BarChartItem(series,presenter) |
|
10 | BarChartItem(series, presenter) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
@@ -15,7 +15,6 StackedBarChartItem::~StackedBarChartItem() | |||||
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
|
||||
19 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
18 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
20 | { |
|
19 | { | |
21 | QVector<QRectF> layout; |
|
20 | QVector<QRectF> layout; | |
@@ -31,9 +30,9 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
31 | qreal width = geometry().width(); |
|
30 | qreal width = geometry().width(); | |
32 | qreal scale = (height / mSeries->maxCategorySum()); |
|
31 | qreal scale = (height / mSeries->maxCategorySum()); | |
33 | qreal categotyCount = mSeries->categoryCount(); |
|
32 | qreal categotyCount = mSeries->categoryCount(); | |
34 | qreal barWidth = width / (categotyCount *2); |
|
33 | qreal barWidth = width / (categotyCount * 2); | |
35 | qreal xStep = width/categotyCount; |
|
34 | qreal xStep = width / categotyCount; | |
36 | qreal xPos = xStep/2 - barWidth/2; |
|
35 | qreal xPos = xStep / 2 - barWidth / 2; | |
37 |
|
36 | |||
38 | int itemIndex(0); |
|
37 | int itemIndex(0); | |
39 | for (int category = 0; category < categotyCount; category++) { |
|
38 | for (int category = 0; category < categotyCount; category++) { | |
@@ -43,7 +42,7 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
43 | Bar* bar = mBars.at(itemIndex); |
|
42 | Bar* bar = mBars.at(itemIndex); | |
44 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
43 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
45 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
44 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
46 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); |
|
45 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
47 | layout.append(rect); |
|
46 | layout.append(rect); | |
48 | itemIndex++; |
|
47 | itemIndex++; | |
49 | yPos -= barHeight; |
|
48 | yPos -= barHeight; | |
@@ -57,15 +56,15 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
57 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
56 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
58 | qreal yPos = height; |
|
57 | qreal yPos = height; | |
59 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
58 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
60 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
59 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
61 | BarValue* value = mFloatingValues.at(itemIndex); |
|
60 | BarValue* value = mFloatingValues.at(itemIndex); | |
62 |
|
61 | |||
63 | QBarSet* barSet = mSeries->barsetAt(set); |
|
62 | QBarSet* barSet = mSeries->barsetAt(set); | |
64 | value->resize(100,50); // TODO: proper layout for this. |
|
63 | value->resize(100, 50); // TODO: proper layout for this. | |
65 | value->setPos(xPos, yPos-barHeight/2); |
|
64 | value->setPos(xPos, yPos-barHeight / 2); | |
66 | value->setPen(barSet->floatingValuePen()); |
|
65 | value->setPen(barSet->floatingValuePen()); | |
67 |
|
66 | |||
68 | if (mSeries->valueAt(set,category) != 0) { |
|
67 | if (mSeries->valueAt(set, category) != 0) { | |
69 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
68 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
70 | } else { |
|
69 | } else { | |
71 | value->setValueString(QString("")); |
|
70 | value->setValueString(QString("")); |
@@ -84,10 +84,14 QLegend::QLegend(QGraphicsItem *parent) | |||||
84 | mScrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); |
|
84 | mScrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); | |
85 | mScrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); |
|
85 | mScrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); | |
86 |
|
86 | |||
87 |
connect(mScrollButtonLeft,SIGNAL(clicked(QGraphicsSceneMouseEvent*)), |
|
87 | connect(mScrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
88 |
|
|
88 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
89 |
connect(mScrollButton |
|
89 | connect(mScrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
90 |
|
|
90 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
|
91 | connect(mScrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |||
|
92 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |||
|
93 | connect(mScrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |||
|
94 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |||
91 |
|
95 | |||
92 | setZValue(ChartPresenter::LegendZValue); |
|
96 | setZValue(ChartPresenter::LegendZValue); | |
93 | } |
|
97 | } | |
@@ -117,9 +121,9 QRectF QLegend::boundingRect() const | |||||
117 | /*! |
|
121 | /*! | |
118 | Sets the \a brush of legend. Brush affects the background of legend. |
|
122 | Sets the \a brush of legend. Brush affects the background of legend. | |
119 | */ |
|
123 | */ | |
120 |
void QLegend::setBrush(const QBrush& |
|
124 | void QLegend::setBrush(const QBrush &brush) | |
121 | { |
|
125 | { | |
122 | if(m_brush!=brush){ |
|
126 | if (m_brush != brush) { | |
123 | m_brush = brush; |
|
127 | m_brush = brush; | |
124 | update(); |
|
128 | update(); | |
125 | } |
|
129 | } | |
@@ -136,9 +140,9 QBrush QLegend::brush() const | |||||
136 | /*! |
|
140 | /*! | |
137 | Sets the \a pen of legend. Pen affects the legend borders. |
|
141 | Sets the \a pen of legend. Pen affects the legend borders. | |
138 | */ |
|
142 | */ | |
139 |
void QLegend::setPen(const QPen& |
|
143 | void QLegend::setPen(const QPen &pen) | |
140 | { |
|
144 | { | |
141 | if(m_pen!=pen){ |
|
145 | if (m_pen != pen) { | |
142 | m_pen = pen; |
|
146 | m_pen = pen; | |
143 | update(); |
|
147 | update(); | |
144 | } |
|
148 | } | |
@@ -224,7 +228,7 void QLegend::setPos(const QPointF &pos) | |||||
224 | /*! |
|
228 | /*! | |
225 | \internal \a series \a domain Should be called when series is added to chart. |
|
229 | \internal \a series \a domain Should be called when series is added to chart. | |
226 | */ |
|
230 | */ | |
227 |
void QLegend::handleSeriesAdded(QSeries* |
|
231 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) | |
228 | { |
|
232 | { | |
229 | Q_UNUSED(domain) |
|
233 | Q_UNUSED(domain) | |
230 |
|
234 | |||
@@ -236,14 +240,14 void QLegend::handleSeriesAdded(QSeries* series, Domain* domain) | |||||
236 | /*! |
|
240 | /*! | |
237 | \internal \a series Should be called when series is removed from chart. |
|
241 | \internal \a series Should be called when series is removed from chart. | |
238 | */ |
|
242 | */ | |
239 |
void QLegend::handleSeriesRemoved(QSeries* |
|
243 | void QLegend::handleSeriesRemoved(QSeries *series) | |
240 | { |
|
244 | { | |
241 | disconnectSeries(series); |
|
245 | disconnectSeries(series); | |
242 |
|
246 | |||
243 | if (series->type() == QSeries::SeriesTypeArea) |
|
247 | if (series->type() == QSeries::SeriesTypeArea) | |
244 | { |
|
248 | { | |
245 | // This is special case. Area series has upper and lower series, which each have markers |
|
249 | // This is special case. Area series has upper and lower series, which each have markers | |
246 | QAreaSeries* s = static_cast<QAreaSeries*> (series); |
|
250 | QAreaSeries* s = static_cast<QAreaSeries *> (series); | |
247 | deleteMarkers(s->upperSeries()); |
|
251 | deleteMarkers(s->upperSeries()); | |
248 | deleteMarkers(s->lowerSeries()); |
|
252 | deleteMarkers(s->lowerSeries()); | |
249 | } else { |
|
253 | } else { | |
@@ -256,17 +260,18 void QLegend::handleSeriesRemoved(QSeries* series) | |||||
256 | /*! |
|
260 | /*! | |
257 | \internal \a slices Should be called when slices are added to pie chart. |
|
261 | \internal \a slices Should be called when slices are added to pie chart. | |
258 | */ |
|
262 | */ | |
259 | void QLegend::handleAdded(QList<QPieSlice*> slices) |
|
263 | void QLegend::handleAdded(QList<QPieSlice *> slices) | |
260 | { |
|
264 | { | |
261 | QPieSeries* series = static_cast<QPieSeries*> (sender()); |
|
265 | QPieSeries* series = static_cast<QPieSeries *> (sender()); | |
262 | foreach(QPieSlice* s, slices) { |
|
266 | foreach(QPieSlice* s, slices) { | |
263 | LegendMarker* marker = new LegendMarker(series,s,this); |
|
267 | LegendMarker* marker = new LegendMarker(series, s, this); | |
264 | marker->setName(s->label()); |
|
268 | marker->setName(s->label()); | |
265 | marker->setBrush(s->sliceBrush()); |
|
269 | marker->setBrush(s->sliceBrush()); | |
266 |
connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)), |
|
270 | connect(marker, SIGNAL(clicked(QPieSlice*,Qt::MouseButton)), | |
267 | connect(s,SIGNAL(changed()),marker,SLOT(changed())); |
|
271 | this, SIGNAL(clicked(QPieSlice*,Qt::MouseButton))); | |
268 |
connect(s,SIGNAL( |
|
272 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); | |
269 |
connect( |
|
273 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); | |
|
274 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |||
270 | mMarkers.append(marker); |
|
275 | mMarkers.append(marker); | |
271 | childItems().append(marker); |
|
276 | childItems().append(marker); | |
272 | } |
|
277 | } | |
@@ -291,7 +296,7 void QLegend::handleRemoved(QList<QPieSlice *> slices) | |||||
291 | void QLegend::handleMarkerDestroyed() |
|
296 | void QLegend::handleMarkerDestroyed() | |
292 | { |
|
297 | { | |
293 | // TODO: what if more than one markers are destroyed and we update layout after first one? |
|
298 | // TODO: what if more than one markers are destroyed and we update layout after first one? | |
294 | LegendMarker* m = static_cast<LegendMarker*> (sender()); |
|
299 | LegendMarker* m = static_cast<LegendMarker *> (sender()); | |
295 | mMarkers.removeOne(m); |
|
300 | mMarkers.removeOne(m); | |
296 | updateLayout(); |
|
301 | updateLayout(); | |
297 | } |
|
302 | } | |
@@ -303,7 +308,7 void QLegend::handleScrollButtonClicked(QGraphicsSceneMouseEvent *event) | |||||
303 | { |
|
308 | { | |
304 | Q_UNUSED(event); // Maybe later something happens with right click... |
|
309 | Q_UNUSED(event); // Maybe later something happens with right click... | |
305 |
|
310 | |||
306 | LegendScrollButton* scrollButton = static_cast<LegendScrollButton*> (sender()); |
|
311 | LegendScrollButton* scrollButton = static_cast<LegendScrollButton *> (sender()); | |
307 | Q_ASSERT(scrollButton); |
|
312 | Q_ASSERT(scrollButton); | |
308 |
|
313 | |||
309 | switch (scrollButton->id()) { |
|
314 | switch (scrollButton->id()) { | |
@@ -411,7 +416,7 void QLegend::disconnectSeries(QSeries *series) | |||||
411 | } |
|
416 | } | |
412 | case QSeries::SeriesTypePie: { |
|
417 | case QSeries::SeriesTypePie: { | |
413 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
418 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
414 | disconnect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); |
|
419 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); | |
415 | // disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>))); |
|
420 | // disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>))); | |
416 | break; |
|
421 | break; | |
417 | } |
|
422 | } | |
@@ -436,32 +441,32 void QLegend::createMarkers(QSeries *series) | |||||
436 | switch (series->type()) |
|
441 | switch (series->type()) | |
437 | { |
|
442 | { | |
438 | case QSeries::SeriesTypeLine: { |
|
443 | case QSeries::SeriesTypeLine: { | |
439 |
QLineSeries* |
|
444 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); | |
440 | appendMarkers(lineSeries); |
|
445 | appendMarkers(lineSeries); | |
441 | break; |
|
446 | break; | |
442 | } |
|
447 | } | |
443 | case QSeries::SeriesTypeArea: { |
|
448 | case QSeries::SeriesTypeArea: { | |
444 |
QAreaSeries* |
|
449 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
445 | appendMarkers(areaSeries->upperSeries()); |
|
450 | appendMarkers(areaSeries->upperSeries()); | |
446 | if(areaSeries->lowerSeries()) |
|
451 | if(areaSeries->lowerSeries()) | |
447 | appendMarkers(areaSeries->lowerSeries()); |
|
452 | appendMarkers(areaSeries->lowerSeries()); | |
448 | break; |
|
453 | break; | |
449 | } |
|
454 | } | |
450 |
|
455 | |||
451 | case QSeries::SeriesTypeBar: { |
|
456 | case QSeries::SeriesTypeBar: { | |
452 |
QBarSeries* |
|
457 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); | |
453 | appendMarkers(barSeries); |
|
458 | appendMarkers(barSeries); | |
454 | break; |
|
459 | break; | |
455 | } |
|
460 | } | |
456 |
|
461 | |||
457 | case QSeries::SeriesTypeStackedBar: { |
|
462 | case QSeries::SeriesTypeStackedBar: { | |
458 |
QStackedBarSeries* |
|
463 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); | |
459 | appendMarkers(stackedBarSeries); |
|
464 | appendMarkers(stackedBarSeries); | |
460 | break; |
|
465 | break; | |
461 | } |
|
466 | } | |
462 |
|
467 | |||
463 | case QSeries::SeriesTypePercentBar: { |
|
468 | case QSeries::SeriesTypePercentBar: { | |
464 |
QPercentBarSeries* |
|
469 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); | |
465 | appendMarkers(percentBarSeries); |
|
470 | appendMarkers(percentBarSeries); | |
466 | break; |
|
471 | break; | |
467 | } |
|
472 | } | |
@@ -479,7 +484,7 void QLegend::createMarkers(QSeries *series) | |||||
479 | } |
|
484 | } | |
480 |
|
485 | |||
481 | case QSeries::SeriesTypeSpline: { |
|
486 | case QSeries::SeriesTypeSpline: { | |
482 |
QSplineSeries* |
|
487 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); | |
483 | appendMarkers(splineSeries); |
|
488 | appendMarkers(splineSeries); | |
484 | break; |
|
489 | break; | |
485 | } |
|
490 | } | |
@@ -499,8 +504,8 void QLegend::appendMarkers(QXYSeries* series) | |||||
499 | marker->setName(series->name()); |
|
504 | marker->setName(series->name()); | |
500 | marker->setPen(series->pen()); |
|
505 | marker->setPen(series->pen()); | |
501 | marker->setBrush(series->brush()); |
|
506 | marker->setBrush(series->brush()); | |
502 | connect(marker,SIGNAL(clicked(QSeries*,Qt::MouseButton)),this,SIGNAL(clicked(QSeries*,Qt::MouseButton))); |
|
507 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); | |
503 | connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed())); |
|
508 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
504 | mMarkers.append(marker); |
|
509 | mMarkers.append(marker); | |
505 | childItems().append(marker); |
|
510 | childItems().append(marker); | |
506 | } |
|
511 | } | |
@@ -511,13 +516,14 void QLegend::appendMarkers(QXYSeries* series) | |||||
511 | void QLegend::appendMarkers(QBarSeries *series) |
|
516 | void QLegend::appendMarkers(QBarSeries *series) | |
512 | { |
|
517 | { | |
513 | foreach(QBarSet* s, series->barSets()) { |
|
518 | foreach(QBarSet* s, series->barSets()) { | |
514 | LegendMarker* marker = new LegendMarker(series,s,this); |
|
519 | LegendMarker* marker = new LegendMarker(series, s, this); | |
515 | marker->setName(s->name()); |
|
520 | marker->setName(s->name()); | |
516 | marker->setPen(s->pen()); |
|
521 | marker->setPen(s->pen()); | |
517 | marker->setBrush(s->brush()); |
|
522 | marker->setBrush(s->brush()); | |
518 |
connect(marker,SIGNAL(clicked(QBarSet*,Qt::MouseButton)), |
|
523 | connect(marker, SIGNAL(clicked(QBarSet *, Qt::MouseButton)), | |
519 | connect(s,SIGNAL(valueChanged()),marker,SLOT(changed())); |
|
524 | this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); | |
520 | connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed())); |
|
525 | connect(s, SIGNAL(valueChanged()), marker, SLOT(changed())); | |
|
526 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |||
521 | mMarkers.append(marker); |
|
527 | mMarkers.append(marker); | |
522 | childItems().append(marker); |
|
528 | childItems().append(marker); | |
523 | } |
|
529 | } | |
@@ -529,14 +535,15 void QLegend::appendMarkers(QBarSeries *series) | |||||
529 | void QLegend::appendMarkers(QPieSeries *series) |
|
535 | void QLegend::appendMarkers(QPieSeries *series) | |
530 | { |
|
536 | { | |
531 | foreach(QPieSlice* s, series->slices()) { |
|
537 | foreach(QPieSlice* s, series->slices()) { | |
532 | LegendMarker* marker = new LegendMarker(series,s,this); |
|
538 | LegendMarker* marker = new LegendMarker(series, s, this); | |
533 | marker->setName(s->label()); |
|
539 | marker->setName(s->label()); | |
534 | marker->setPen(s->slicePen()); |
|
540 | marker->setPen(s->slicePen()); | |
535 | marker->setBrush(s->sliceBrush()); |
|
541 | marker->setBrush(s->sliceBrush()); | |
536 |
connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)), |
|
542 | connect(marker, SIGNAL(clicked(QPieSlice *, Qt::MouseButton)), | |
537 | connect(s,SIGNAL(changed()),marker,SLOT(changed())); |
|
543 | this, SIGNAL(clicked(QPieSlice *, Qt::MouseButton))); | |
538 |
connect(s,SIGNAL( |
|
544 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); | |
539 |
connect( |
|
545 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); | |
|
546 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |||
540 | mMarkers.append(marker); |
|
547 | mMarkers.append(marker); | |
541 | childItems().append(marker); |
|
548 | childItems().append(marker); | |
542 | } |
|
549 | } | |
@@ -576,7 +583,6 void QLegend::updateLayout() | |||||
576 | // Use max height as scroll button size |
|
583 | // Use max height as scroll button size | |
577 | rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height())); |
|
584 | rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height())); | |
578 |
|
585 | |||
579 |
|
||||
580 | qreal totalWidth = 0; |
|
586 | qreal totalWidth = 0; | |
581 | qreal totalHeight = 0; |
|
587 | qreal totalHeight = 0; | |
582 | switch (mPreferredLayout) |
|
588 | switch (mPreferredLayout) | |
@@ -596,9 +602,11 void QLegend::updateLayout() | |||||
596 | if (scrollButtonsVisible()) { |
|
602 | if (scrollButtonsVisible()) { | |
597 | mScrollButtonLeft->setVisible(true); |
|
603 | mScrollButtonLeft->setVisible(true); | |
598 | mScrollButtonRight->setVisible(true); |
|
604 | mScrollButtonRight->setVisible(true); | |
599 |
|
|
605 | // scrollbuttons visible, so add their width to total width | |
|
606 | totalWidth += (mScrollButtonLeft->boundingRect().width() + mMargin) * 2; | |||
600 | scrollButtonWidth = mScrollButtonLeft->boundingRect().width() + mMargin; |
|
607 | scrollButtonWidth = mScrollButtonLeft->boundingRect().width() + mMargin; | |
601 |
|
|
608 | // start position changes by scrollbutton width | |
|
609 | x += scrollButtonWidth; | |||
602 | } else { |
|
610 | } else { | |
603 | mScrollButtonLeft->setVisible(false); |
|
611 | mScrollButtonLeft->setVisible(false); | |
604 | mScrollButtonRight->setVisible(false); |
|
612 | mScrollButtonRight->setVisible(false); | |
@@ -606,9 +614,9 void QLegend::updateLayout() | |||||
606 | mScrollButtonUp->setVisible(false); |
|
614 | mScrollButtonUp->setVisible(false); | |
607 | mScrollButtonDown->setVisible(false); |
|
615 | mScrollButtonDown->setVisible(false); | |
608 |
|
616 | |||
609 | for (int i=0; i<mMarkers.count(); i++) { |
|
617 | for (int i=0; i < mMarkers.count(); i++) { | |
610 |
LegendMarker* |
|
618 | LegendMarker *m = mMarkers.at(i); | |
611 | if (i<mFirstMarker) { |
|
619 | if (i < mFirstMarker) { | |
612 | // Markers before first are not visible. |
|
620 | // Markers before first are not visible. | |
613 | m->setVisible(false); |
|
621 | m->setVisible(false); | |
614 | } else { |
|
622 | } else { | |
@@ -618,7 +626,7 void QLegend::updateLayout() | |||||
618 | } else { |
|
626 | } else { | |
619 | // This marker is ok |
|
627 | // This marker is ok | |
620 | m->setVisible(true); |
|
628 | m->setVisible(true); | |
621 | m->setPos(x,y); |
|
629 | m->setPos(x, y); | |
622 | x += xStep; |
|
630 | x += xStep; | |
623 | column++; |
|
631 | column++; | |
624 | } |
|
632 | } | |
@@ -627,7 +635,7 void QLegend::updateLayout() | |||||
627 | } |
|
635 | } | |
628 |
|
636 | |||
629 | mScrollButtonLeft->setPos(mPos.x() + mMargin, y); |
|
637 | mScrollButtonLeft->setPos(mPos.x() + mMargin, y); | |
630 | mScrollButtonRight->setPos(x+mMargin,y); |
|
638 | mScrollButtonRight->setPos(x + mMargin, y); | |
631 |
|
639 | |||
632 | totalWidth += maxColumns * markerMaxSize.width() + mMargin * 2; |
|
640 | totalWidth += maxColumns * markerMaxSize.width() + mMargin * 2; | |
633 | totalHeight = markerMaxSize.height() + mMargin * 2; |
|
641 | totalHeight = markerMaxSize.height() + mMargin * 2; | |
@@ -658,9 +666,9 void QLegend::updateLayout() | |||||
658 | mScrollButtonLeft->setVisible(false); |
|
666 | mScrollButtonLeft->setVisible(false); | |
659 | mScrollButtonRight->setVisible(false); |
|
667 | mScrollButtonRight->setVisible(false); | |
660 |
|
668 | |||
661 | for (int i=0; i<mMarkers.count(); i++) { |
|
669 | for (int i=0; i < mMarkers.count(); i++) { | |
662 | LegendMarker* m = mMarkers.at(i); |
|
670 | LegendMarker* m = mMarkers.at(i); | |
663 | if (i<mFirstMarker) { |
|
671 | if (i < mFirstMarker) { | |
664 | // Markers before first are not visible. |
|
672 | // Markers before first are not visible. | |
665 | m->setVisible(false); |
|
673 | m->setVisible(false); | |
666 | } else { |
|
674 | } else { | |
@@ -670,7 +678,7 void QLegend::updateLayout() | |||||
670 | } else { |
|
678 | } else { | |
671 | // This marker is ok |
|
679 | // This marker is ok | |
672 | m->setVisible(true); |
|
680 | m->setVisible(true); | |
673 | m->setPos(x,y); |
|
681 | m->setPos(x, y); | |
674 | y += yStep; |
|
682 | y += yStep; | |
675 | row++; |
|
683 | row++; | |
676 | } |
|
684 | } | |
@@ -702,13 +710,13 void QLegend::updateLayout() | |||||
702 | void QLegend::rescaleScrollButtons(const QSize &size) |
|
710 | void QLegend::rescaleScrollButtons(const QSize &size) | |
703 | { |
|
711 | { | |
704 | QPolygonF left; |
|
712 | QPolygonF left; | |
705 | left << QPointF(size.width(),0) << QPointF(0,size.height()/2) << QPointF(size.width(),size.height()); |
|
713 | left << QPointF(size.width(), 0) << QPointF(0, size.height() / 2) << QPointF(size.width(), size.height()); | |
706 | QPolygonF right; |
|
714 | QPolygonF right; | |
707 | right << QPointF(0,0) << QPointF(size.width(),size.height()/2) << QPointF(0,size.height()); |
|
715 | right << QPointF(0, 0) << QPointF(size.width(), size.height() / 2) << QPointF(0, size.height()); | |
708 | QPolygonF up; |
|
716 | QPolygonF up; | |
709 | up << QPointF(0,size.height()) << QPointF(size.width()/2,0) << QPointF(size.width(),size.height()); |
|
717 | up << QPointF(0, size.height()) << QPointF(size.width() / 2,0) << QPointF(size.width(), size.height()); | |
710 | QPolygonF down; |
|
718 | QPolygonF down; | |
711 | down << QPointF(0,0) << QPointF(size.width()/2,size.height()) << QPointF(size.width(),0); |
|
719 | down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0); | |
712 |
|
720 | |||
713 | mScrollButtonLeft->setPolygon(left); |
|
721 | mScrollButtonLeft->setPolygon(left); | |
714 | mScrollButtonRight->setPolygon(right); |
|
722 | mScrollButtonRight->setPolygon(right); | |
@@ -723,12 +731,10 QSizeF QLegend::maximumMarkerSize() | |||||
723 | { |
|
731 | { | |
724 | QSizeF max(0,0); |
|
732 | QSizeF max(0,0); | |
725 | foreach (LegendMarker* m, mMarkers) { |
|
733 | foreach (LegendMarker* m, mMarkers) { | |
726 |
if (m->boundingRect().width() > max.width()) |
|
734 | if (m->boundingRect().width() > max.width()) | |
727 | max.setWidth(m->boundingRect().width()); |
|
735 | max.setWidth(m->boundingRect().width()); | |
728 | } |
|
736 | if (m->boundingRect().height() > max.height()) | |
729 | if (m->boundingRect().height() > max.height()) { |
|
|||
730 | max.setHeight(m->boundingRect().height()); |
|
737 | max.setHeight(m->boundingRect().height()); | |
731 | } |
|
|||
732 | } |
|
738 | } | |
733 | return max; |
|
739 | return max; | |
734 | } |
|
740 | } | |
@@ -743,14 +749,13 void QLegend::checkFirstMarkerBounds() | |||||
743 | // Bounds limited by height. |
|
749 | // Bounds limited by height. | |
744 | int max; |
|
750 | int max; | |
745 | if (scrollButtonsVisible()) { |
|
751 | if (scrollButtonsVisible()) { | |
746 | max = (mMaximumSize.height() - mScrollButtonLeft->boundingRect().height() * 2 - mMargin*4) / maximumMarkerSize().height(); |
|
752 | max = (mMaximumSize.height() - mScrollButtonLeft->boundingRect().height() * 2 - mMargin * 4) / maximumMarkerSize().height(); | |
747 | } else { |
|
753 | } else { | |
748 | max = mMaximumSize.height() / maximumMarkerSize().height(); |
|
754 | max = mMaximumSize.height() / maximumMarkerSize().height(); | |
749 | } |
|
755 | } | |
750 |
|
756 | |||
751 |
if (mFirstMarker > mMarkers.count() - max) |
|
757 | if (mFirstMarker > mMarkers.count() - max) | |
752 | mFirstMarker = mMarkers.count() - max; |
|
758 | mFirstMarker = mMarkers.count() - max; | |
753 | } |
|
|||
754 | } else { |
|
759 | } else { | |
755 | // Bounds limited by width |
|
760 | // Bounds limited by width | |
756 | int max; |
|
761 | int max; | |
@@ -760,14 +765,12 void QLegend::checkFirstMarkerBounds() | |||||
760 | max = mMaximumSize.width() / maximumMarkerSize().width(); |
|
765 | max = mMaximumSize.width() / maximumMarkerSize().width(); | |
761 | } |
|
766 | } | |
762 |
|
767 | |||
763 |
if (mFirstMarker > mMarkers.count() - max) |
|
768 | if (mFirstMarker > mMarkers.count() - max) | |
764 | mFirstMarker = mMarkers.count() - max; |
|
769 | mFirstMarker = mMarkers.count() - max; | |
765 | } |
|
|||
766 | } |
|
770 | } | |
767 |
|
771 | |||
768 |
if (mFirstMarker < 0) |
|
772 | if (mFirstMarker < 0) | |
769 | mFirstMarker = 0; |
|
773 | mFirstMarker = 0; | |
770 | } |
|
|||
771 | } |
|
774 | } | |
772 |
|
775 | |||
773 | /*! |
|
776 | /*! | |
@@ -786,4 +789,5 bool QLegend::scrollButtonsVisible() | |||||
786 | } |
|
789 | } | |
787 |
|
790 | |||
788 | #include "moc_qlegend.cpp" |
|
791 | #include "moc_qlegend.cpp" | |
|
792 | ||||
789 | QTCOMMERCIALCHART_END_NAMESPACE |
|
793 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -25,7 +25,7 public: | |||||
25 | PreferredLayoutTop, |
|
25 | PreferredLayoutTop, | |
26 | PreferredLayoutBottom, |
|
26 | PreferredLayoutBottom, | |
27 | PreferredLayoutLeft, |
|
27 | PreferredLayoutLeft, | |
28 |
PreferredLayoutRight |
|
28 | PreferredLayoutRight | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | explicit QLegend(QGraphicsItem *parent = 0); |
|
31 | explicit QLegend(QGraphicsItem *parent = 0); | |
@@ -33,10 +33,10 public: | |||||
33 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
33 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
34 | QRectF boundingRect() const; |
|
34 | QRectF boundingRect() const; | |
35 |
|
35 | |||
36 |
void setBrush(const QBrush& |
|
36 | void setBrush(const QBrush &brush); | |
37 | QBrush brush() const; |
|
37 | QBrush brush() const; | |
38 |
|
38 | |||
39 |
void setPen(const QPen& |
|
39 | void setPen(const QPen &pen); | |
40 | QPen pen() const; |
|
40 | QPen pen() const; | |
41 |
|
41 | |||
42 | void setPreferredLayout(QLegend::PreferredLayout preferred); |
|
42 | void setPreferredLayout(QLegend::PreferredLayout preferred); | |
@@ -51,31 +51,31 public: | |||||
51 |
|
51 | |||
52 | signals: |
|
52 | signals: | |
53 | // for interactions. |
|
53 | // for interactions. | |
54 |
void clicked(QSeries* |
|
54 | void clicked(QSeries *series, Qt::MouseButton button); | |
55 |
void clicked(QBarSet* |
|
55 | void clicked(QBarSet *barset, Qt::MouseButton button); | |
56 |
void clicked(QPieSlice* |
|
56 | void clicked(QPieSlice *slice, Qt::MouseButton button); | |
57 |
|
57 | |||
58 | public slots: |
|
58 | public slots: | |
59 | // PIMPL ---> |
|
59 | // PIMPL ---> | |
60 |
void handleSeriesAdded(QSeries* |
|
60 | void handleSeriesAdded(QSeries *series, Domain *domain); | |
61 |
void handleSeriesRemoved(QSeries* |
|
61 | void handleSeriesRemoved(QSeries *series); | |
62 | void handleAdded(QList<QPieSlice*> slices); |
|
62 | void handleAdded(QList<QPieSlice *> slices); | |
63 | void handleRemoved(QList<QPieSlice*> slices); |
|
63 | void handleRemoved(QList<QPieSlice *> slices); | |
64 | void handleMarkerDestroyed(); |
|
64 | void handleMarkerDestroyed(); | |
65 |
void handleScrollButtonClicked(QGraphicsSceneMouseEvent* |
|
65 | void handleScrollButtonClicked(QGraphicsSceneMouseEvent *event); | |
66 | // PIMPL <--- |
|
66 | // PIMPL <--- | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
69 | // PIMPL ---> |
|
69 | // PIMPL ---> | |
70 |
void connectSeries(QSeries* |
|
70 | void connectSeries(QSeries *series); | |
71 |
void disconnectSeries(QSeries* |
|
71 | void disconnectSeries(QSeries *series); | |
72 |
void createMarkers(QSeries* |
|
72 | void createMarkers(QSeries *series); | |
73 |
void appendMarkers(QXYSeries* |
|
73 | void appendMarkers(QXYSeries *series); // All line series are derived from QXYSeries, so this works for now | |
74 |
void appendMarkers(QBarSeries* |
|
74 | void appendMarkers(QBarSeries *series); | |
75 |
void appendMarkers(QPieSeries* |
|
75 | void appendMarkers(QPieSeries *series); | |
76 |
void deleteMarkers(QSeries* |
|
76 | void deleteMarkers(QSeries *series); | |
77 | void updateLayout(); |
|
77 | void updateLayout(); | |
78 |
void rescaleScrollButtons(const QSize& |
|
78 | void rescaleScrollButtons(const QSize &size); | |
79 | QSizeF maximumMarkerSize(); |
|
79 | QSizeF maximumMarkerSize(); | |
80 | void checkFirstMarkerBounds(); |
|
80 | void checkFirstMarkerBounds(); | |
81 | bool scrollButtonsVisible(); |
|
81 | bool scrollButtonsVisible(); | |
@@ -85,7 +85,7 private: | |||||
85 | QSizeF mMinimumSize; |
|
85 | QSizeF mMinimumSize; | |
86 | QSizeF mMaximumSize; |
|
86 | QSizeF mMaximumSize; | |
87 |
|
87 | |||
88 | QList<LegendMarker*> mMarkers; |
|
88 | QList<LegendMarker *> mMarkers; | |
89 |
|
89 | |||
90 | QBrush m_brush; |
|
90 | QBrush m_brush; | |
91 | QPen m_pen; |
|
91 | QPen m_pen; | |
@@ -93,10 +93,10 private: | |||||
93 |
|
93 | |||
94 | int mFirstMarker; |
|
94 | int mFirstMarker; | |
95 |
|
95 | |||
96 |
LegendScrollButton* |
|
96 | LegendScrollButton *mScrollButtonLeft; | |
97 |
LegendScrollButton* |
|
97 | LegendScrollButton *mScrollButtonRight; | |
98 |
LegendScrollButton* |
|
98 | LegendScrollButton *mScrollButtonUp; | |
99 |
LegendScrollButton* |
|
99 | LegendScrollButton *mScrollButtonDown; | |
100 |
|
100 | |||
101 | qreal mMargin; |
|
101 | qreal mMargin; | |
102 | // <--- PIMPL |
|
102 | // <--- PIMPL |
General Comments 0
You need to be logged in to leave comments.
Login now