@@ -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 | mCategory(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(mCategory); |
|
19 | emit clicked(m_Category); | |
20 | } else if (event->button() == Qt::RightButton) { |
|
20 | } else if (event->button() == Qt::RightButton) { | |
21 | emit rightClicked(mCategory); |
|
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 mCategory; |
|
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 | mLayoutSet(false), |
|
19 | m_LayoutSet(false), | |
20 | mSeries(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,8 +34,8 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 (!mLayoutSet) { |
|
37 | if (!m_LayoutSet) { | |
38 |
q |
|
38 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; | |
39 | return; |
|
39 | return; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
@@ -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 | mBars.clear(); |
|
58 | m_Bars.clear(); | |
59 | mFloatingValues.clear(); |
|
59 | m_FloatingValues.clear(); | |
60 | mLayout.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 < mSeries->categoryCount(); c++) { |
|
63 | for (int c = 0; c < m_Series->categoryCount(); c++) { | |
64 | QString category = mSeries->categoryName(c); |
|
64 | QString category = m_Series->categoryName(c); | |
65 | for (int s = 0; s < mSeries->barsetCount(); s++) { |
|
65 | for (int s = 0; s < m_Series->barsetCount(); s++) { | |
66 | QBarSet *set = mSeries->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 | mBars.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 | mLayout.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 < mSeries->categoryCount(); category++) { |
|
79 | for (int category = 0; category < m_Series->categoryCount(); category++) { | |
80 | for (int s = 0; s < mSeries->barsetCount(); s++) { |
|
80 | for (int s = 0; s < m_Series->barsetCount(); s++) { | |
81 | QBarSet *set = mSeries->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 | mFloatingValues.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 = mSeries->categoryCount(); |
|
94 | qreal categoryCount = m_Series->categoryCount(); | |
95 | qreal setCount = mSeries->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 = mSeries->max(); |
|
100 | qreal max = m_Series->max(); | |
101 |
|
101 | |||
102 | // Domain: |
|
102 | // Domain: | |
103 | if (mDomainMaxY > max) { |
|
103 | if (m_DomainMaxY > max) { | |
104 | max = mDomainMaxY; |
|
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 = mSeries->valueAt(set, category) * scale; |
|
116 | qreal barHeight = m_Series->valueAt(set, category) * scale; | |
117 | Bar* bar = mBars.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(mSeries->barsetAt(set)->pen()); |
|
121 | bar->setPen(m_Series->barsetAt(set)->pen()); | |
122 | bar->setBrush(mSeries->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 < mSeries->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 < mSeries->barsetCount(); set++) { |
|
133 | for (int set=0; set < m_Series->barsetCount(); set++) { | |
134 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
134 | qreal barHeight = m_Series->valueAt(set, category) * scale; | |
135 | BarValue* value = mFloatingValues.at(itemIndex); |
|
135 | BarValue* value = m_FloatingValues.at(itemIndex); | |
136 |
|
136 | |||
137 | QBarSet* barSet = mSeries->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 (mSeries->valueAt(set,category) != 0) { |
|
142 | if (m_Series->valueAt(set,category) != 0) { | |
143 | value->setValueString(QString::number(mSeries->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, mLayout, 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 | mLayout = layout; |
|
166 | m_Layout = layout; | |
167 |
|
167 | |||
168 | for (int i=0; i < mBars.count(); i++) |
|
168 | for (int i=0; i < m_Bars.count(); i++) | |
169 | mBars.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 | mDomainMinX = minX; |
|
184 | m_DomainMinX = minX; | |
185 | mDomainMaxX = maxX; |
|
185 | m_DomainMaxX = maxX; | |
186 | mDomainMinY = minY; |
|
186 | m_DomainMinY = minY; | |
187 | mDomainMaxY = 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 | mLayoutSet = 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 mDomainMinX; |
|
58 | qreal m_DomainMinX; | |
59 | qreal mDomainMaxX; |
|
59 | qreal m_DomainMaxX; | |
60 | qreal mDomainMinY; |
|
60 | qreal m_DomainMinY; | |
61 | qreal mDomainMaxY; |
|
61 | qreal m_DomainMaxY; | |
62 |
|
62 | |||
63 | QRectF m_rect; |
|
63 | QRectF m_rect; | |
64 | bool mLayoutSet; // True, if component has been laid out. |
|
64 | bool m_LayoutSet; // True, if component has been laid out. | |
65 | QVector<QRectF> mLayout; |
|
65 | QVector<QRectF> m_Layout; | |
66 |
|
66 | |||
67 | // Not owned. |
|
67 | // Not owned. | |
68 | QBarSeries *mSeries; |
|
68 | QBarSeries *m_Series; | |
69 | QList<Bar *> mBars; |
|
69 | QList<Bar *> m_Bars; | |
70 | QList<BarValue *> mFloatingValues; |
|
70 | QList<BarValue *> m_FloatingValues; | |
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -6,75 +6,74 | |||||
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : |
|
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent), | |
10 | QObject(parent) |
|
10 | m_Category(categories) | |
11 | ,mCategory(categories) |
|
|||
12 | { |
|
11 | { | |
13 | } |
|
12 | } | |
14 |
|
13 | |||
15 | QStringList BarChartModel::category() |
|
14 | QStringList BarChartModel::category() | |
16 | { |
|
15 | { | |
17 | return mCategory; |
|
16 | return m_Category; | |
18 | } |
|
17 | } | |
19 |
|
18 | |||
20 | void BarChartModel::addBarSet(QBarSet *set) |
|
19 | void BarChartModel::addBarSet(QBarSet *set) | |
21 | { |
|
20 | { | |
22 | mDataModel.append(set); |
|
21 | m_DataModel.append(set); | |
23 | } |
|
22 | } | |
24 |
|
23 | |||
25 | void BarChartModel::removeBarSet(QBarSet *set) |
|
24 | void BarChartModel::removeBarSet(QBarSet *set) | |
26 | { |
|
25 | { | |
27 | if (mDataModel.contains(set)) { |
|
26 | if (m_DataModel.contains(set)) { | |
28 | mDataModel.removeOne(set); |
|
27 | m_DataModel.removeOne(set); | |
29 | } |
|
28 | } | |
30 | } |
|
29 | } | |
31 |
|
30 | |||
32 | void BarChartModel::insertBarSet(int i, QBarSet *set) |
|
31 | void BarChartModel::insertBarSet(int i, QBarSet *set) | |
33 | { |
|
32 | { | |
34 | mDataModel.insert(i, set); |
|
33 | m_DataModel.insert(i, set); | |
35 | } |
|
34 | } | |
36 |
|
35 | |||
37 | void BarChartModel::insertCategory(int i, QString category) |
|
36 | void BarChartModel::insertCategory(int i, QString category) | |
38 | { |
|
37 | { | |
39 | mCategory.insert(i, category); |
|
38 | m_Category.insert(i, category); | |
40 | } |
|
39 | } | |
41 |
|
40 | |||
42 | void BarChartModel::removeCategory(int i) |
|
41 | void BarChartModel::removeCategory(int i) | |
43 | { |
|
42 | { | |
44 | mCategory.removeAt(i); |
|
43 | m_Category.removeAt(i); | |
45 | } |
|
44 | } | |
46 |
|
45 | |||
47 | QBarSet* BarChartModel::setAt(int index) |
|
46 | QBarSet* BarChartModel::setAt(int index) | |
48 | { |
|
47 | { | |
49 | return mDataModel.at(index); |
|
48 | return m_DataModel.at(index); | |
50 | } |
|
49 | } | |
51 |
|
50 | |||
52 | QList<QBarSet*> BarChartModel::barSets() |
|
51 | QList<QBarSet*> BarChartModel::barSets() | |
53 | { |
|
52 | { | |
54 | return mDataModel; |
|
53 | return m_DataModel; | |
55 | } |
|
54 | } | |
56 |
|
55 | |||
57 | int BarChartModel::barsetCount() |
|
56 | int BarChartModel::barsetCount() | |
58 | { |
|
57 | { | |
59 | return mDataModel.count(); |
|
58 | return m_DataModel.count(); | |
60 | } |
|
59 | } | |
61 |
|
60 | |||
62 | int BarChartModel::categoryCount() |
|
61 | int BarChartModel::categoryCount() | |
63 | { |
|
62 | { | |
64 | return mCategory.count(); |
|
63 | return m_Category.count(); | |
65 | } |
|
64 | } | |
66 |
|
65 | |||
67 | qreal BarChartModel::min() |
|
66 | qreal BarChartModel::min() | |
68 | { |
|
67 | { | |
69 | Q_ASSERT(mDataModel.count() > 0); |
|
68 | Q_ASSERT(m_DataModel.count() > 0); | |
70 | // 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. | |
71 | // 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. | |
72 | qreal min = INT_MAX; |
|
71 | qreal min = INT_MAX; | |
73 |
|
72 | |||
74 | for (int i = 0; i < mDataModel.count(); i++) { |
|
73 | for (int i = 0; i < m_DataModel.count(); i++) { | |
75 | int itemCount = mDataModel.at(i)->count(); |
|
74 | int itemCount = m_DataModel.at(i)->count(); | |
76 | for (int j = 0; j < itemCount; j++) { |
|
75 | for (int j = 0; j < itemCount; j++) { | |
77 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
76 | qreal temp = m_DataModel.at(i)->valueAt(j); | |
78 | if (temp < min) |
|
77 | if (temp < min) | |
79 | min = temp; |
|
78 | min = temp; | |
80 | } |
|
79 | } | |
@@ -84,16 +83,16 qreal BarChartModel::min() | |||||
84 |
|
83 | |||
85 | qreal BarChartModel::max() |
|
84 | qreal BarChartModel::max() | |
86 | { |
|
85 | { | |
87 | Q_ASSERT(mDataModel.count() > 0); |
|
86 | Q_ASSERT(m_DataModel.count() > 0); | |
88 |
|
87 | |||
89 | // 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. | |
90 | // 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. | |
91 | qreal max = INT_MIN; |
|
90 | qreal max = INT_MIN; | |
92 |
|
91 | |||
93 | for (int i = 0; i < mDataModel.count(); i++) { |
|
92 | for (int i = 0; i < m_DataModel.count(); i++) { | |
94 | int itemCount = mDataModel.at(i)->count(); |
|
93 | int itemCount = m_DataModel.at(i)->count(); | |
95 | for (int j = 0; j < itemCount; j++) { |
|
94 | for (int j = 0; j < itemCount; j++) { | |
96 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
95 | qreal temp = m_DataModel.at(i)->valueAt(j); | |
97 | if (temp > max) |
|
96 | if (temp > max) | |
98 | max = temp; |
|
97 | max = temp; | |
99 | } |
|
98 | } | |
@@ -104,28 +103,28 qreal BarChartModel::max() | |||||
104 |
|
103 | |||
105 | qreal BarChartModel::valueAt(int set, int category) |
|
104 | qreal BarChartModel::valueAt(int set, int category) | |
106 | { |
|
105 | { | |
107 | if ((set < 0) || (set >= mDataModel.count())) { |
|
106 | if ((set < 0) || (set >= m_DataModel.count())) { | |
108 | // No set, no value. |
|
107 | // No set, no value. | |
109 | return 0; |
|
108 | return 0; | |
110 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
109 | } else if ((category < 0) || (category >= m_DataModel.at(set)->count())) { | |
111 | // No category, no value. |
|
110 | // No category, no value. | |
112 | return 0; |
|
111 | return 0; | |
113 | } |
|
112 | } | |
114 |
|
113 | |||
115 | return mDataModel.at(set)->valueAt(category); |
|
114 | return m_DataModel.at(set)->valueAt(category); | |
116 | } |
|
115 | } | |
117 |
|
116 | |||
118 | qreal BarChartModel::percentageAt(int set, int category) |
|
117 | qreal BarChartModel::percentageAt(int set, int category) | |
119 | { |
|
118 | { | |
120 | if ((set < 0) || (set >= mDataModel.count())) { |
|
119 | if ((set < 0) || (set >= m_DataModel.count())) { | |
121 | // No set, no value. |
|
120 | // No set, no value. | |
122 | return 0; |
|
121 | return 0; | |
123 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
122 | } else if ((category < 0) || (category >= m_DataModel.at(set)->count())) { | |
124 | // No category, no value. |
|
123 | // No category, no value. | |
125 | return 0; |
|
124 | return 0; | |
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 | qreal value = mDataModel.at(set)->valueAt(category); |
|
127 | qreal value = m_DataModel.at(set)->valueAt(category); | |
129 | qreal total = categorySum(category); |
|
128 | qreal total = categorySum(category); | |
130 | if (0 == total) |
|
129 | if (0 == total) | |
131 | return 100.0; |
|
130 | return 100.0; | |
@@ -137,11 +136,11 qreal BarChartModel::percentageAt(int set, int category) | |||||
137 | qreal BarChartModel::categorySum(int category) |
|
136 | qreal BarChartModel::categorySum(int category) | |
138 | { |
|
137 | { | |
139 | qreal sum(0); |
|
138 | qreal sum(0); | |
140 | int count = mDataModel.count(); // Count sets |
|
139 | int count = m_DataModel.count(); // Count sets | |
141 |
|
140 | |||
142 | for (int set = 0; set < count; set++) { |
|
141 | for (int set = 0; set < count; set++) { | |
143 | if (category < mDataModel.at(set)->count()) |
|
142 | if (category < m_DataModel.at(set)->count()) | |
144 | sum += mDataModel.at(set)->valueAt(category); |
|
143 | sum += m_DataModel.at(set)->valueAt(category); | |
145 | } |
|
144 | } | |
146 | return sum; |
|
145 | return sum; | |
147 | } |
|
146 | } | |
@@ -161,7 +160,7 qreal BarChartModel::maxCategorySum() | |||||
161 |
|
160 | |||
162 | QString BarChartModel::categoryName(int category) |
|
161 | QString BarChartModel::categoryName(int category) | |
163 | { |
|
162 | { | |
164 | return mCategory.at(category); |
|
163 | return m_Category.at(category); | |
165 | } |
|
164 | } | |
166 |
|
165 | |||
167 | #include "moc_barchartmodel_p.cpp" |
|
166 | #include "moc_barchartmodel_p.cpp" |
@@ -48,9 +48,8 public slots: | |||||
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 |
|
50 | |||
51 | QList<QBarSet *> mDataModel; |
|
51 | QList<QBarSet *> m_DataModel; | |
52 | QStringList mCategory; |
|
52 | QStringList m_Category; | |
53 | int mCurrentSet; |
|
|||
54 | }; |
|
53 | }; | |
55 |
|
54 | |||
56 | 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 | mBarSet(set), |
|
9 | m_BarSet(set), | |
10 | mXpos(0), |
|
10 | m_Xpos(0), | |
11 | mYpos(0), |
|
11 | m_Ypos(0), | |
12 | mWidth(0), |
|
12 | m_Width(0), | |
13 | mHeight(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 | mValueString = str; |
|
20 | m_ValueString = str; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | QString BarValue::valueString() |
|
23 | QString BarValue::valueString() | |
24 | { |
|
24 | { | |
25 | return mValueString; |
|
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 | mPen = pen; |
|
30 | m_Pen = pen; | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QPen BarValue::pen() const |
|
33 | QPen BarValue::pen() const | |
34 | { |
|
34 | { | |
35 | return mPen; |
|
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 | mWidth = w; |
|
40 | m_Width = w; | |
41 | mHeight = 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 | mXpos = x; |
|
46 | m_Xpos = x; | |
47 | mYpos = 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(mPen); |
|
56 | painter->setPen(m_Pen); | |
57 | painter->drawText(boundingRect(), mValueString); |
|
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(mXpos, mYpos, mWidth, mHeight); |
|
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 &mBarSet; |
|
38 | QBarSet &m_BarSet; | |
39 | QPen mPen; |
|
39 | QPen m_Pen; | |
40 | QString mValueString; |
|
40 | QString m_ValueString; | |
41 |
|
41 | |||
42 | qreal mXpos; |
|
42 | qreal m_Xpos; | |
43 | qreal mYpos; |
|
43 | qreal m_Ypos; | |
44 | qreal mWidth; |
|
44 | qreal m_Width; | |
45 | qreal mHeight; |
|
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 = mSeries->categoryCount(); |
|
22 | qreal categoryCount = m_Series->categoryCount(); | |
23 | qreal barWidth = width / (mSeries->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 = mSeries->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 < mSeries->barsetCount(); set++) { |
|
32 | for (int set=0; set < m_Series->barsetCount(); set++) { | |
33 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
33 | qreal barHeight = m_Series->valueAt(set, category) * scale; | |
34 | Bar* bar = mBars.at(itemIndex); |
|
34 | Bar* bar = m_Bars.at(itemIndex); | |
35 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
35 | bar->setPen(m_Series->barsetAt(set)->pen()); | |
36 | bar->setBrush(mSeries->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 < mSeries->categoryCount(); category++) { |
|
48 | for (int category=0; category < m_Series->categoryCount(); category++) { | |
49 | qreal yPos = height; |
|
49 | qreal yPos = height; | |
50 | qreal colSum = mSeries->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 < mSeries->barsetCount(); set++) { |
|
52 | for (int set=0; set < m_Series->barsetCount(); set++) { | |
53 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
53 | qreal barHeight = m_Series->valueAt(set,category) * scale; | |
54 | BarValue* value = mFloatingValues.at(itemIndex); |
|
54 | BarValue* value = m_FloatingValues.at(itemIndex); | |
55 |
|
55 | |||
56 | QBarSet* barSet = mSeries->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 (mSeries->valueAt(set,category) != 0) { |
|
61 | if (m_Series->valueAt(set,category) != 0) { | |
62 | int p = mSeries->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("%"); |
@@ -33,9 +33,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
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) |
|
36 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
37 | : QSeries(parent) |
|
37 | m_Model(new BarChartModel(categories, this)) | |
38 | ,mModel(new BarChartModel(categories, this)) |
|
|||
39 | { |
|
38 | { | |
40 | m_model = NULL; |
|
39 | m_model = NULL; | |
41 | m_mapCategories = -1; |
|
40 | m_mapCategories = -1; | |
@@ -53,7 +52,7 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) | |||||
53 | */ |
|
52 | */ | |
54 | void QBarSeries::addBarSet(QBarSet *set) |
|
53 | void QBarSeries::addBarSet(QBarSet *set) | |
55 | { |
|
54 | { | |
56 | mModel->addBarSet(set); |
|
55 | m_Model->addBarSet(set); | |
57 | connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); |
|
56 | connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); | |
58 | connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); |
|
57 | connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); | |
59 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
58 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
@@ -69,24 +68,24 void QBarSeries::removeBarSet(QBarSet *set) | |||||
69 | { |
|
68 | { | |
70 | disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); |
|
69 | disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); | |
71 | disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); |
|
70 | disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); | |
72 | mModel->removeBarSet(set); |
|
71 | m_Model->removeBarSet(set); | |
73 | emit updatedBars(); |
|
72 | emit updatedBars(); | |
74 | } |
|
73 | } | |
75 |
|
74 | |||
76 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
75 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
77 | { |
|
76 | { | |
78 | mModel->insertBarSet(i, set); |
|
77 | m_Model->insertBarSet(i, set); | |
79 | // emit barsetChanged(); |
|
78 | // emit barsetChanged(); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 | void QBarSeries::insertCategory(int i, QString category) |
|
81 | void QBarSeries::insertCategory(int i, QString category) | |
83 | { |
|
82 | { | |
84 | mModel->insertCategory(i, category); |
|
83 | m_Model->insertCategory(i, category); | |
85 | } |
|
84 | } | |
86 |
|
85 | |||
87 | void QBarSeries::removeCategory(int i) |
|
86 | void QBarSeries::removeCategory(int i) | |
88 | { |
|
87 | { | |
89 | mModel->removeCategory(i); |
|
88 | m_Model->removeCategory(i); | |
90 | } |
|
89 | } | |
91 |
|
90 | |||
92 | /*! |
|
91 | /*! | |
@@ -97,7 +96,7 int QBarSeries::barsetCount() | |||||
97 | // if(m_model) |
|
96 | // if(m_model) | |
98 | // return m_mapBarTop - m_mapBarBottom; |
|
97 | // return m_mapBarTop - m_mapBarBottom; | |
99 | // else |
|
98 | // else | |
100 | return mModel->barsetCount(); |
|
99 | return m_Model->barsetCount(); | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | /*! |
|
102 | /*! | |
@@ -105,7 +104,7 int QBarSeries::barsetCount() | |||||
105 | */ |
|
104 | */ | |
106 | int QBarSeries::categoryCount() |
|
105 | int QBarSeries::categoryCount() | |
107 | { |
|
106 | { | |
108 | return mModel->categoryCount(); |
|
107 | return m_Model->categoryCount(); | |
109 | } |
|
108 | } | |
110 |
|
109 | |||
111 | /*! |
|
110 | /*! | |
@@ -113,7 +112,7 int QBarSeries::categoryCount() | |||||
113 | */ |
|
112 | */ | |
114 | QList<QBarSet*> QBarSeries::barSets() |
|
113 | QList<QBarSet*> QBarSeries::barSets() | |
115 | { |
|
114 | { | |
116 | return mModel->barSets(); |
|
115 | return m_Model->barSets(); | |
117 | } |
|
116 | } | |
118 |
|
117 | |||
119 | /*! |
|
118 | /*! | |
@@ -121,7 +120,7 QList<QBarSet*> QBarSeries::barSets() | |||||
121 | */ |
|
120 | */ | |
122 | QBarSet* QBarSeries::barsetAt(int index) |
|
121 | QBarSet* QBarSeries::barsetAt(int index) | |
123 | { |
|
122 | { | |
124 | return mModel->setAt(index); |
|
123 | return m_Model->setAt(index); | |
125 | } |
|
124 | } | |
126 |
|
125 | |||
127 | /*! |
|
126 | /*! | |
@@ -129,7 +128,7 QBarSet* QBarSeries::barsetAt(int index) | |||||
129 | */ |
|
128 | */ | |
130 | QString QBarSeries::categoryName(int category) |
|
129 | QString QBarSeries::categoryName(int category) | |
131 | { |
|
130 | { | |
132 | return mModel->categoryName(category); |
|
131 | return m_Model->categoryName(category); | |
133 | } |
|
132 | } | |
134 |
|
133 | |||
135 | /*! |
|
134 | /*! | |
@@ -141,13 +140,13 void QBarSeries::setToolTipEnabled(bool enabled) | |||||
141 | { |
|
140 | { | |
142 | // 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. | |
143 | if (enabled) { |
|
142 | if (enabled) { | |
144 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
143 | for (int i=0; i<m_Model->barsetCount(); i++) { | |
145 | QBarSet *set = mModel->setAt(i); |
|
144 | QBarSet *set = m_Model->setAt(i); | |
146 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
145 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
147 | } |
|
146 | } | |
148 | } else { |
|
147 | } else { | |
149 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
148 | for (int i=0; i<m_Model->barsetCount(); i++) { | |
150 | QBarSet *set = mModel->setAt(i); |
|
149 | QBarSet *set = m_Model->setAt(i); | |
151 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
150 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
152 | } |
|
151 | } | |
153 | } |
|
152 | } | |
@@ -176,7 +175,7 void QBarSeries::barsetRightClicked(QString category) | |||||
176 | */ |
|
175 | */ | |
177 | qreal QBarSeries::min() |
|
176 | qreal QBarSeries::min() | |
178 | { |
|
177 | { | |
179 | return mModel->min(); |
|
178 | return m_Model->min(); | |
180 | } |
|
179 | } | |
181 |
|
180 | |||
182 | /*! |
|
181 | /*! | |
@@ -184,7 +183,7 qreal QBarSeries::min() | |||||
184 | */ |
|
183 | */ | |
185 | qreal QBarSeries::max() |
|
184 | qreal QBarSeries::max() | |
186 | { |
|
185 | { | |
187 | return mModel->max(); |
|
186 | return m_Model->max(); | |
188 | } |
|
187 | } | |
189 |
|
188 | |||
190 | /*! |
|
189 | /*! | |
@@ -192,7 +191,7 qreal QBarSeries::max() | |||||
192 | */ |
|
191 | */ | |
193 | qreal QBarSeries::valueAt(int set, int category) |
|
192 | qreal QBarSeries::valueAt(int set, int category) | |
194 | { |
|
193 | { | |
195 | return mModel->valueAt(set, category); |
|
194 | return m_Model->valueAt(set, category); | |
196 | } |
|
195 | } | |
197 |
|
196 | |||
198 | /*! |
|
197 | /*! | |
@@ -200,7 +199,7 qreal QBarSeries::valueAt(int set, int category) | |||||
200 | */ |
|
199 | */ | |
201 | qreal QBarSeries::percentageAt(int set, int category) |
|
200 | qreal QBarSeries::percentageAt(int set, int category) | |
202 | { |
|
201 | { | |
203 | return mModel->percentageAt(set, category); |
|
202 | return m_Model->percentageAt(set, category); | |
204 | } |
|
203 | } | |
205 |
|
204 | |||
206 | /*! |
|
205 | /*! | |
@@ -208,7 +207,7 qreal QBarSeries::percentageAt(int set, int category) | |||||
208 | */ |
|
207 | */ | |
209 | qreal QBarSeries::categorySum(int category) |
|
208 | qreal QBarSeries::categorySum(int category) | |
210 | { |
|
209 | { | |
211 | return mModel->categorySum(category); |
|
210 | return m_Model->categorySum(category); | |
212 | } |
|
211 | } | |
213 |
|
212 | |||
214 | /*! |
|
213 | /*! | |
@@ -216,7 +215,7 qreal QBarSeries::categorySum(int category) | |||||
216 | */ |
|
215 | */ | |
217 | qreal QBarSeries::maxCategorySum() |
|
216 | qreal QBarSeries::maxCategorySum() | |
218 | { |
|
217 | { | |
219 | return mModel->maxCategorySum(); |
|
218 | return m_Model->maxCategorySum(); | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 | /*! |
|
221 | /*! | |
@@ -224,7 +223,7 qreal QBarSeries::maxCategorySum() | |||||
224 | */ |
|
223 | */ | |
225 | BarChartModel& QBarSeries::model() |
|
224 | BarChartModel& QBarSeries::model() | |
226 | { |
|
225 | { | |
227 | return *mModel; |
|
226 | return *m_Model; | |
228 | } |
|
227 | } | |
229 |
|
228 | |||
230 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
229 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
@@ -287,12 +286,12 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
287 |
|
286 | |||
288 |
|
287 | |||
289 | // create the initial bars |
|
288 | // create the initial bars | |
290 | delete mModel; |
|
289 | delete m_Model; | |
291 | if (m_mapOrientation == Qt::Vertical) { |
|
290 | if (m_mapOrientation == Qt::Vertical) { | |
292 | QStringList categories; |
|
291 | QStringList categories; | |
293 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
292 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
294 | 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(); | |
295 | mModel = new BarChartModel(categories, this); |
|
294 | m_Model = new BarChartModel(categories, this); | |
296 |
|
295 | |||
297 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
296 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
298 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
297 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
@@ -304,7 +303,7 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
304 | QStringList categories; |
|
303 | QStringList categories; | |
305 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
304 | 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(); |
|
305 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
307 | mModel = new BarChartModel(categories, this); |
|
306 | m_Model = new BarChartModel(categories, this); | |
308 |
|
307 | |||
309 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
308 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
310 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
309 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
@@ -376,9 +375,9 void QBarSeries::barsetChanged() | |||||
376 | QBarCategories QBarSeries::categories() const |
|
375 | QBarCategories QBarSeries::categories() const | |
377 | { |
|
376 | { | |
378 | QBarCategories categories; |
|
377 | QBarCategories categories; | |
379 | int count = mModel->categoryCount(); |
|
378 | int count = m_Model->categoryCount(); | |
380 | for (int i=1; i <= count; i++) { |
|
379 | for (int i=1; i <= count; i++) { | |
381 | categories.insert(i, mModel->categoryName(i - 1)); |
|
380 | categories.insert(i, m_Model->categoryName(i - 1)); | |
382 | } |
|
381 | } | |
383 | return categories; |
|
382 | return categories; | |
384 | } |
|
383 | } |
@@ -81,7 +81,7 private Q_SLOTS: | |||||
81 | void barsetChanged(); |
|
81 | void barsetChanged(); | |
82 |
|
82 | |||
83 | protected: |
|
83 | protected: | |
84 | BarChartModel *mModel; |
|
84 | BarChartModel *m_Model; | |
85 |
|
85 | |||
86 | // QAbstractItemModel* m_model; |
|
86 | // QAbstractItemModel* m_model; | |
87 | int m_mapCategories; |
|
87 | int m_mapCategories; |
@@ -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 | ,mName(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 | mName = 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 mName; |
|
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 | mValues.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 | mValues.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 | mValues.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 mValues.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 mValues.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 | mValues.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 < mValues.count(); i++) { |
|
130 | for (int i=0; i < m_Values.count(); i++) { | |
131 | total += mValues.at(i); |
|
131 | total += m_Values.at(i); | |
132 | } |
|
132 | } | |
133 | return total; |
|
133 | return total; | |
134 | } |
|
134 | } | |
@@ -138,7 +138,7 qreal QBarSet::total() | |||||
138 | */ |
|
138 | */ | |
139 | void QBarSet::setPen(const QPen pen) |
|
139 | void QBarSet::setPen(const QPen pen) | |
140 | { |
|
140 | { | |
141 | mPen = pen; |
|
141 | m_Pen = pen; | |
142 | emit valueChanged(); |
|
142 | emit valueChanged(); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
@@ -147,7 +147,7 void QBarSet::setPen(const QPen pen) | |||||
147 | */ |
|
147 | */ | |
148 | QPen QBarSet::pen() const |
|
148 | QPen QBarSet::pen() const | |
149 | { |
|
149 | { | |
150 | return mPen; |
|
150 | return m_Pen; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
@@ -155,7 +155,7 QPen QBarSet::pen() const | |||||
155 | */ |
|
155 | */ | |
156 | void QBarSet::setBrush(const QBrush brush) |
|
156 | void QBarSet::setBrush(const QBrush brush) | |
157 | { |
|
157 | { | |
158 | mBrush = brush; |
|
158 | m_Brush = brush; | |
159 | emit valueChanged(); |
|
159 | emit valueChanged(); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
@@ -164,7 +164,7 void QBarSet::setBrush(const QBrush brush) | |||||
164 | */ |
|
164 | */ | |
165 | QBrush QBarSet::brush() const |
|
165 | QBrush QBarSet::brush() const | |
166 | { |
|
166 | { | |
167 | return mBrush; |
|
167 | return m_Brush; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
@@ -172,7 +172,7 QBrush QBarSet::brush() const | |||||
172 | */ |
|
172 | */ | |
173 | void QBarSet::setFloatingValuePen(const QPen pen) |
|
173 | void QBarSet::setFloatingValuePen(const QPen pen) | |
174 | { |
|
174 | { | |
175 | mFloatingValuePen = 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 mFloatingValuePen; |
|
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, mName); |
|
191 | emit showToolTip(pos, m_Name); | |
192 | emit hoverEnter(pos); |
|
192 | emit hoverEnter(pos); | |
193 | } |
|
193 | } | |
194 |
|
194 |
@@ -61,12 +61,12 public Q_SLOTS: | |||||
61 |
|
61 | |||
62 | private: |
|
62 | private: | |
63 |
|
63 | |||
64 | QString mName; |
|
64 | QString m_Name; | |
65 | QList<qreal> mValues; // TODO: replace with map (category, value) |
|
65 | QList<qreal> m_Values; // TODO: replace with map (category, value) | |
66 | QMap<QString, qreal> mMappedValues; |
|
66 | QMap<QString, qreal> m_MappedValues; | |
67 | QPen mPen; |
|
67 | QPen m_Pen; | |
68 | QBrush mBrush; |
|
68 | QBrush m_Brush; | |
69 | QPen mFloatingValuePen; |
|
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 = mSeries->maxCategorySum(); |
|
23 | qreal maxSum = m_Series->maxCategorySum(); | |
24 | // Domain: |
|
24 | // Domain: | |
25 | if (mDomainMaxY > maxSum) { |
|
25 | if (m_DomainMaxY > maxSum) { | |
26 | maxSum = mDomainMaxY; |
|
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 / mSeries->maxCategorySum()); |
|
31 | qreal scale = (height / m_Series->maxCategorySum()); | |
32 | qreal categotyCount = mSeries->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 < mSeries->barsetCount(); set++) { |
|
40 | for (int set=0; set < m_Series->barsetCount(); set++) { | |
41 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
41 | qreal barHeight = m_Series->valueAt(set, category) * scale; | |
42 | Bar* bar = mBars.at(itemIndex); |
|
42 | Bar* bar = m_Bars.at(itemIndex); | |
43 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
43 | bar->setPen(m_Series->barsetAt(set)->pen()); | |
44 | bar->setBrush(mSeries->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 < mSeries->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 < mSeries->barsetCount(); set++) { |
|
58 | for (int set=0; set < m_Series->barsetCount(); set++) { | |
59 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
59 | qreal barHeight = m_Series->valueAt(set, category) * scale; | |
60 | BarValue* value = mFloatingValues.at(itemIndex); |
|
60 | BarValue* value = m_FloatingValues.at(itemIndex); | |
61 |
|
61 | |||
62 | QBarSet* barSet = mSeries->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 (mSeries->valueAt(set, category) != 0) { |
|
67 | if (m_Series->valueAt(set, category) != 0) { | |
68 | value->setValueString(QString::number(mSeries->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 | } |
@@ -66,31 +66,28 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
66 | /*! |
|
66 | /*! | |
67 | Constructs the legend object and sets the parent to \a parent |
|
67 | Constructs the legend object and sets the parent to \a parent | |
68 | */ |
|
68 | */ | |
69 | QLegend::QLegend(QGraphicsItem *parent) |
|
69 | QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent), | |
70 | : QGraphicsObject(parent) |
|
70 | m_Pos(0,0), | |
71 |
|
|
71 | m_Size(0,0), | |
72 | ,mSize(0,0) |
|
72 | m_MinimumSize(50,20), // TODO: magic numbers | |
73 | ,mMinimumSize(50,20) // TODO: magic numbers |
|
73 | m_MaximumSize(150,100), | |
74 | ,mMaximumSize(150,100) |
|
74 | m_brush(Qt::darkGray), // TODO: from theme? | |
75 | ,m_brush(Qt::darkGray) // TODO: from theme? |
|
75 | m_PreferredLayout(QLegend::PreferredLayoutTop), | |
76 | ,mPreferredLayout(QLegend::PreferredLayoutTop) |
|
76 | mFirstMarker(0), | |
77 | ,mFirstMarker(0) |
|
77 | m_Margin(5) | |
78 | ,mMargin(5) |
|
78 | { | |
79 | { |
|
79 | m_ScrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this); | |
80 | // setVisible(false); |
|
80 | m_ScrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); | |
81 |
|
81 | m_ScrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); | ||
82 |
mScrollButton |
|
82 | m_ScrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); | |
83 | mScrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); |
|
83 | ||
84 | mScrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); |
|
84 | connect(m_ScrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
85 | mScrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); |
|
|||
86 |
|
||||
87 | connect(mScrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), |
|
|||
88 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
85 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
89 | connect(mScrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), |
|
86 | connect(m_ScrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
90 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
87 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
91 | connect(mScrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), |
|
88 | connect(m_ScrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
92 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
89 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
93 | connect(mScrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), |
|
90 | connect(m_ScrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
94 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
91 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
95 |
|
92 | |||
96 | setZValue(ChartPresenter::LegendZValue); |
|
93 | setZValue(ChartPresenter::LegendZValue); | |
@@ -115,7 +112,7 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q | |||||
115 | */ |
|
112 | */ | |
116 | QRectF QLegend::boundingRect() const |
|
113 | QRectF QLegend::boundingRect() const | |
117 | { |
|
114 | { | |
118 | return QRectF(mPos,mSize); |
|
115 | return QRectF(m_Pos,m_Size); | |
119 | } |
|
116 | } | |
120 |
|
117 | |||
121 | /*! |
|
118 | /*! | |
@@ -163,7 +160,7 QPen QLegend::pen() const | |||||
163 | */ |
|
160 | */ | |
164 | void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred) |
|
161 | void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred) | |
165 | { |
|
162 | { | |
166 | mPreferredLayout = preferred; |
|
163 | m_PreferredLayout = preferred; | |
167 | updateLayout(); |
|
164 | updateLayout(); | |
168 | } |
|
165 | } | |
169 |
|
166 | |||
@@ -172,7 +169,7 void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred) | |||||
172 | */ |
|
169 | */ | |
173 | QLegend::PreferredLayout QLegend::preferredLayout() const |
|
170 | QLegend::PreferredLayout QLegend::preferredLayout() const | |
174 | { |
|
171 | { | |
175 | return mPreferredLayout; |
|
172 | return m_PreferredLayout; | |
176 | } |
|
173 | } | |
177 |
|
174 | |||
178 | /*! |
|
175 | /*! | |
@@ -180,7 +177,7 QLegend::PreferredLayout QLegend::preferredLayout() const | |||||
180 | */ |
|
177 | */ | |
181 | QSizeF QLegend::maximumSize() const |
|
178 | QSizeF QLegend::maximumSize() const | |
182 | { |
|
179 | { | |
183 | return mMaximumSize; |
|
180 | return m_MaximumSize; | |
184 | } |
|
181 | } | |
185 |
|
182 | |||
186 | /*! |
|
183 | /*! | |
@@ -189,7 +186,7 QSizeF QLegend::maximumSize() const | |||||
189 | */ |
|
186 | */ | |
190 | void QLegend::setMaximumSize(const QSizeF size) |
|
187 | void QLegend::setMaximumSize(const QSizeF size) | |
191 | { |
|
188 | { | |
192 | mMaximumSize = size; |
|
189 | m_MaximumSize = size; | |
193 | updateLayout(); |
|
190 | updateLayout(); | |
194 | } |
|
191 | } | |
195 |
|
192 | |||
@@ -198,7 +195,7 void QLegend::setMaximumSize(const QSizeF size) | |||||
198 | */ |
|
195 | */ | |
199 | QSizeF QLegend::size() const |
|
196 | QSizeF QLegend::size() const | |
200 | { |
|
197 | { | |
201 | return mSize; |
|
198 | return m_Size; | |
202 | } |
|
199 | } | |
203 |
|
200 | |||
204 | /*! |
|
201 | /*! | |
@@ -207,12 +204,12 QSizeF QLegend::size() const | |||||
207 | */ |
|
204 | */ | |
208 | void QLegend::setSize(const QSizeF size) |
|
205 | void QLegend::setSize(const QSizeF size) | |
209 | { |
|
206 | { | |
210 | mSize = size; |
|
207 | m_Size = size; | |
211 | if (mSize.width() > mMaximumSize.width()) { |
|
208 | if (m_Size.width() > m_MaximumSize.width()) { | |
212 | mSize.setWidth(mMaximumSize.width()); |
|
209 | m_Size.setWidth(m_MaximumSize.width()); | |
213 | } |
|
210 | } | |
214 | if (mSize.height() > mMaximumSize.height()) { |
|
211 | if (m_Size.height() > m_MaximumSize.height()) { | |
215 | mSize.setHeight(mMaximumSize.height()); |
|
212 | m_Size.setHeight(m_MaximumSize.height()); | |
216 | } |
|
213 | } | |
217 | } |
|
214 | } | |
218 |
|
215 | |||
@@ -221,7 +218,7 void QLegend::setSize(const QSizeF size) | |||||
221 | */ |
|
218 | */ | |
222 | void QLegend::setPos(const QPointF &pos) |
|
219 | void QLegend::setPos(const QPointF &pos) | |
223 | { |
|
220 | { | |
224 | mPos = pos; |
|
221 | m_Pos = pos; | |
225 | updateLayout(); |
|
222 | updateLayout(); | |
226 | } |
|
223 | } | |
227 |
|
224 | |||
@@ -272,7 +269,7 void QLegend::handleAdded(QList<QPieSlice *> slices) | |||||
272 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); |
|
269 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); | |
273 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); |
|
270 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); | |
274 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
271 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
275 | mMarkers.append(marker); |
|
272 | m_Markers.append(marker); | |
276 | childItems().append(marker); |
|
273 | childItems().append(marker); | |
277 | } |
|
274 | } | |
278 | updateLayout(); |
|
275 | updateLayout(); | |
@@ -285,8 +282,6 void QLegend::handleAdded(QList<QPieSlice *> slices) | |||||
285 | void QLegend::handleRemoved(QList<QPieSlice *> slices) |
|
282 | void QLegend::handleRemoved(QList<QPieSlice *> slices) | |
286 | { |
|
283 | { | |
287 | Q_UNUSED(slices) |
|
284 | Q_UNUSED(slices) | |
288 | // Propably no need to listen for this, since removed slices are deleted and we listen destroyed signal |
|
|||
289 | // qDebug() << "QLegend::handleRemoved(QList<QPieSlice*> slices) count:" << slices.count(); |
|
|||
290 | } |
|
285 | } | |
291 |
|
286 | |||
292 |
|
287 | |||
@@ -297,7 +292,7 void QLegend::handleMarkerDestroyed() | |||||
297 | { |
|
292 | { | |
298 | // TODO: what if more than one markers are destroyed and we update layout after first one? |
|
293 | // TODO: what if more than one markers are destroyed and we update layout after first one? | |
299 | LegendMarker* m = static_cast<LegendMarker *> (sender()); |
|
294 | LegendMarker* m = static_cast<LegendMarker *> (sender()); | |
300 | mMarkers.removeOne(m); |
|
295 | m_Markers.removeOne(m); | |
301 | updateLayout(); |
|
296 | updateLayout(); | |
302 | } |
|
297 | } | |
303 |
|
298 | |||
@@ -376,7 +371,7 void QLegend::connectSeries(QSeries *series) | |||||
376 | break; |
|
371 | break; | |
377 | } |
|
372 | } | |
378 | default: { |
|
373 | default: { | |
379 |
q |
|
374 | qWarning() << "QLegend::connectSeries" << series->type() << "not implemented."; | |
380 | break; |
|
375 | break; | |
381 | } |
|
376 | } | |
382 | } |
|
377 | } | |
@@ -425,7 +420,7 void QLegend::disconnectSeries(QSeries *series) | |||||
425 | break; |
|
420 | break; | |
426 | } |
|
421 | } | |
427 | default: { |
|
422 | default: { | |
428 |
q |
|
423 | qWarning()<< "QLegend::disconnectSeries" << series->type() << "not implemented."; | |
429 | break; |
|
424 | break; | |
430 | } |
|
425 | } | |
431 | } |
|
426 | } | |
@@ -489,7 +484,7 void QLegend::createMarkers(QSeries *series) | |||||
489 | break; |
|
484 | break; | |
490 | } |
|
485 | } | |
491 | default: { |
|
486 | default: { | |
492 |
q |
|
487 | qWarning()<< "QLegend::createMarkers" << series->type() << "not implemented."; | |
493 | break; |
|
488 | break; | |
494 | } |
|
489 | } | |
495 | } |
|
490 | } | |
@@ -506,7 +501,7 void QLegend::appendMarkers(QXYSeries* series) | |||||
506 | marker->setBrush(series->brush()); |
|
501 | marker->setBrush(series->brush()); | |
507 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); |
|
502 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); | |
508 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
503 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
509 | mMarkers.append(marker); |
|
504 | m_Markers.append(marker); | |
510 | childItems().append(marker); |
|
505 | childItems().append(marker); | |
511 | } |
|
506 | } | |
512 |
|
507 | |||
@@ -524,7 +519,7 void QLegend::appendMarkers(QBarSeries *series) | |||||
524 | this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); |
|
519 | this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); | |
525 | connect(s, SIGNAL(valueChanged()), marker, SLOT(changed())); |
|
520 | connect(s, SIGNAL(valueChanged()), marker, SLOT(changed())); | |
526 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
521 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
527 | mMarkers.append(marker); |
|
522 | m_Markers.append(marker); | |
528 | childItems().append(marker); |
|
523 | childItems().append(marker); | |
529 | } |
|
524 | } | |
530 | } |
|
525 | } | |
@@ -544,7 +539,7 void QLegend::appendMarkers(QPieSeries *series) | |||||
544 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); |
|
539 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); | |
545 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); |
|
540 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); | |
546 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
541 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
547 | mMarkers.append(marker); |
|
542 | m_Markers.append(marker); | |
548 | childItems().append(marker); |
|
543 | childItems().append(marker); | |
549 | } |
|
544 | } | |
550 | } |
|
545 | } | |
@@ -555,9 +550,9 void QLegend::appendMarkers(QPieSeries *series) | |||||
555 | void QLegend::deleteMarkers(QSeries *series) |
|
550 | void QLegend::deleteMarkers(QSeries *series) | |
556 | { |
|
551 | { | |
557 | // Search all markers that belong to given series and delete them. |
|
552 | // Search all markers that belong to given series and delete them. | |
558 | foreach (LegendMarker *m, mMarkers) { |
|
553 | foreach (LegendMarker *m, m_Markers) { | |
559 | if (m->series() == series) { |
|
554 | if (m->series() == series) { | |
560 | mMarkers.removeOne(m); |
|
555 | m_Markers.removeOne(m); | |
561 | delete m; |
|
556 | delete m; | |
562 | } |
|
557 | } | |
563 | } |
|
558 | } | |
@@ -571,7 +566,7 void QLegend::deleteMarkers(QSeries *series) | |||||
571 | void QLegend::updateLayout() |
|
566 | void QLegend::updateLayout() | |
572 | { |
|
567 | { | |
573 | // Calculate layout for markers and text |
|
568 | // Calculate layout for markers and text | |
574 | if (mMarkers.count() <= 0) { |
|
569 | if (m_Markers.count() <= 0) { | |
575 | // Nothing to do |
|
570 | // Nothing to do | |
576 | return; |
|
571 | return; | |
577 | } |
|
572 | } | |
@@ -585,42 +580,42 void QLegend::updateLayout() | |||||
585 |
|
580 | |||
586 | qreal totalWidth = 0; |
|
581 | qreal totalWidth = 0; | |
587 | qreal totalHeight = 0; |
|
582 | qreal totalHeight = 0; | |
588 | switch (mPreferredLayout) |
|
583 | switch (m_PreferredLayout) | |
589 | { |
|
584 | { | |
590 | // Both cases organise items horizontally |
|
585 | // Both cases organise items horizontally | |
591 | case QLegend::PreferredLayoutBottom: |
|
586 | case QLegend::PreferredLayoutBottom: | |
592 | case QLegend::PreferredLayoutTop: { |
|
587 | case QLegend::PreferredLayoutTop: { | |
593 |
|
588 | |||
594 | qreal xStep = markerMaxSize.width(); |
|
589 | qreal xStep = markerMaxSize.width(); | |
595 | qreal x = mPos.x() + mMargin; |
|
590 | qreal x = m_Pos.x() + m_Margin; | |
596 | qreal y = mPos.y() + mMargin; |
|
591 | qreal y = m_Pos.y() + m_Margin; | |
597 | int column = 0; |
|
592 | int column = 0; | |
598 | int maxColumns = 1; |
|
593 | int maxColumns = 1; | |
599 | qreal scrollButtonWidth = 0; |
|
594 | qreal scrollButtonWidth = 0; | |
600 |
|
595 | |||
601 | // Set correct visibility for scroll scrollbuttons |
|
596 | // Set correct visibility for scroll scrollbuttons | |
602 | if (scrollButtonsVisible()) { |
|
597 | if (scrollButtonsVisible()) { | |
603 | mScrollButtonLeft->setVisible(true); |
|
598 | m_ScrollButtonLeft->setVisible(true); | |
604 | mScrollButtonRight->setVisible(true); |
|
599 | m_ScrollButtonRight->setVisible(true); | |
605 | // scrollbuttons visible, so add their width to total width |
|
600 | // scrollbuttons visible, so add their width to total width | |
606 | totalWidth += (mScrollButtonLeft->boundingRect().width() + mMargin) * 2; |
|
601 | totalWidth += (m_ScrollButtonLeft->boundingRect().width() + m_Margin) * 2; | |
607 | scrollButtonWidth = mScrollButtonLeft->boundingRect().width() + mMargin; |
|
602 | scrollButtonWidth = m_ScrollButtonLeft->boundingRect().width() + m_Margin; | |
608 | // start position changes by scrollbutton width |
|
603 | // start position changes by scrollbutton width | |
609 | x += scrollButtonWidth; |
|
604 | x += scrollButtonWidth; | |
610 | } else { |
|
605 | } else { | |
611 | mScrollButtonLeft->setVisible(false); |
|
606 | m_ScrollButtonLeft->setVisible(false); | |
612 | mScrollButtonRight->setVisible(false); |
|
607 | m_ScrollButtonRight->setVisible(false); | |
613 | } |
|
608 | } | |
614 | mScrollButtonUp->setVisible(false); |
|
609 | m_ScrollButtonUp->setVisible(false); | |
615 | mScrollButtonDown->setVisible(false); |
|
610 | m_ScrollButtonDown->setVisible(false); | |
616 |
|
611 | |||
617 | for (int i=0; i < mMarkers.count(); i++) { |
|
612 | for (int i=0; i < m_Markers.count(); i++) { | |
618 | LegendMarker *m = mMarkers.at(i); |
|
613 | LegendMarker *m = m_Markers.at(i); | |
619 | if (i < mFirstMarker) { |
|
614 | if (i < mFirstMarker) { | |
620 | // Markers before first are not visible. |
|
615 | // Markers before first are not visible. | |
621 | m->setVisible(false); |
|
616 | m->setVisible(false); | |
622 | } else { |
|
617 | } else { | |
623 | if ((x + xStep + scrollButtonWidth + mMargin) > (mPos.x() + mMaximumSize.width())) { |
|
618 | if ((x + xStep + scrollButtonWidth + m_Margin) > (m_Pos.x() + m_MaximumSize.width())) { | |
624 | // This marker would go outside legend rect. |
|
619 | // This marker would go outside legend rect. | |
625 | m->setVisible(false); |
|
620 | m->setVisible(false); | |
626 | } else { |
|
621 | } else { | |
@@ -634,11 +629,11 void QLegend::updateLayout() | |||||
634 | maxColumns = column; |
|
629 | maxColumns = column; | |
635 | } |
|
630 | } | |
636 |
|
631 | |||
637 | mScrollButtonLeft->setPos(mPos.x() + mMargin, y); |
|
632 | m_ScrollButtonLeft->setPos(m_Pos.x() + m_Margin, y); | |
638 | mScrollButtonRight->setPos(x + mMargin, y); |
|
633 | m_ScrollButtonRight->setPos(x + m_Margin, y); | |
639 |
|
634 | |||
640 | totalWidth += maxColumns * markerMaxSize.width() + mMargin * 2; |
|
635 | totalWidth += maxColumns * markerMaxSize.width() + m_Margin * 2; | |
641 | totalHeight = markerMaxSize.height() + mMargin * 2; |
|
636 | totalHeight = markerMaxSize.height() + m_Margin * 2; | |
642 |
|
637 | |||
643 | break; |
|
638 | break; | |
644 | } |
|
639 | } | |
@@ -646,33 +641,33 void QLegend::updateLayout() | |||||
646 | case QLegend::PreferredLayoutLeft: |
|
641 | case QLegend::PreferredLayoutLeft: | |
647 | case QLegend::PreferredLayoutRight: { |
|
642 | case QLegend::PreferredLayoutRight: { | |
648 | qreal yStep = markerMaxSize.height(); |
|
643 | qreal yStep = markerMaxSize.height(); | |
649 | qreal x = mPos.x() + mMargin; |
|
644 | qreal x = m_Pos.x() + m_Margin; | |
650 | qreal y = mPos.y() + mMargin; |
|
645 | qreal y = m_Pos.y() + m_Margin; | |
651 | int row = 1; |
|
646 | int row = 1; | |
652 | int maxRows = 1; |
|
647 | int maxRows = 1; | |
653 | qreal scrollButtonHeight = 0; |
|
648 | qreal scrollButtonHeight = 0; | |
654 |
|
649 | |||
655 | // Set correct visibility for scroll scrollbuttons |
|
650 | // Set correct visibility for scroll scrollbuttons | |
656 | if (scrollButtonsVisible()) { |
|
651 | if (scrollButtonsVisible()) { | |
657 | mScrollButtonUp->setVisible(true); |
|
652 | m_ScrollButtonUp->setVisible(true); | |
658 | mScrollButtonDown->setVisible(true); |
|
653 | m_ScrollButtonDown->setVisible(true); | |
659 | totalHeight += (mScrollButtonUp->boundingRect().height() + mMargin) * 2; // scrollbuttons visible, so add their height to total height |
|
654 | totalHeight += (m_ScrollButtonUp->boundingRect().height() + m_Margin) * 2; // scrollbuttons visible, so add their height to total height | |
660 | scrollButtonHeight = mScrollButtonUp->boundingRect().height(); |
|
655 | scrollButtonHeight = m_ScrollButtonUp->boundingRect().height(); | |
661 | y += scrollButtonHeight + mMargin; // start position changes by scrollbutton height |
|
656 | y += scrollButtonHeight + m_Margin; // start position changes by scrollbutton height | |
662 | } else { |
|
657 | } else { | |
663 | mScrollButtonUp->setVisible(false); |
|
658 | m_ScrollButtonUp->setVisible(false); | |
664 | mScrollButtonDown->setVisible(false); |
|
659 | m_ScrollButtonDown->setVisible(false); | |
665 | } |
|
660 | } | |
666 | mScrollButtonLeft->setVisible(false); |
|
661 | m_ScrollButtonLeft->setVisible(false); | |
667 | mScrollButtonRight->setVisible(false); |
|
662 | m_ScrollButtonRight->setVisible(false); | |
668 |
|
663 | |||
669 | for (int i=0; i < mMarkers.count(); i++) { |
|
664 | for (int i=0; i < m_Markers.count(); i++) { | |
670 | LegendMarker* m = mMarkers.at(i); |
|
665 | LegendMarker* m = m_Markers.at(i); | |
671 | if (i < mFirstMarker) { |
|
666 | if (i < mFirstMarker) { | |
672 | // Markers before first are not visible. |
|
667 | // Markers before first are not visible. | |
673 | m->setVisible(false); |
|
668 | m->setVisible(false); | |
674 | } else { |
|
669 | } else { | |
675 | if ((y + yStep + scrollButtonHeight) > (mPos.y() + mMaximumSize.height())) { |
|
670 | if ((y + yStep + scrollButtonHeight) > (m_Pos.y() + m_MaximumSize.height())) { | |
676 | // This marker would go outside legend rect. |
|
671 | // This marker would go outside legend rect. | |
677 | m->setVisible(false); |
|
672 | m->setVisible(false); | |
678 | } else { |
|
673 | } else { | |
@@ -686,11 +681,11 void QLegend::updateLayout() | |||||
686 | maxRows = row; |
|
681 | maxRows = row; | |
687 | } |
|
682 | } | |
688 |
|
683 | |||
689 | mScrollButtonUp->setPos(mPos.x() + mMargin, mPos.y() + mMargin); |
|
684 | m_ScrollButtonUp->setPos(m_Pos.x() + m_Margin, m_Pos.y() + m_Margin); | |
690 | mScrollButtonDown->setPos(mPos.x() + mMargin, y + mMargin); |
|
685 | m_ScrollButtonDown->setPos(m_Pos.x() + m_Margin, y + m_Margin); | |
691 |
|
686 | |||
692 | totalWidth += markerMaxSize.width() + mMargin * 2; |
|
687 | totalWidth += markerMaxSize.width() + m_Margin * 2; | |
693 | totalHeight = maxRows * markerMaxSize.height() + mMargin * 4 + scrollButtonHeight; // TODO: check this |
|
688 | totalHeight = maxRows * markerMaxSize.height() + m_Margin * 4 + scrollButtonHeight; // TODO: check this | |
694 | break; |
|
689 | break; | |
695 | } |
|
690 | } | |
696 | default: { |
|
691 | default: { | |
@@ -698,8 +693,8 void QLegend::updateLayout() | |||||
698 | } |
|
693 | } | |
699 | } |
|
694 | } | |
700 |
|
695 | |||
701 | mSize.setWidth(totalWidth); |
|
696 | m_Size.setWidth(totalWidth); | |
702 | mSize.setHeight(totalHeight); |
|
697 | m_Size.setHeight(totalHeight); | |
703 |
|
698 | |||
704 | update(); |
|
699 | update(); | |
705 | } |
|
700 | } | |
@@ -718,10 +713,10 void QLegend::rescaleScrollButtons(const QSize &size) | |||||
718 | QPolygonF down; |
|
713 | QPolygonF down; | |
719 | down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0); |
|
714 | down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0); | |
720 |
|
715 | |||
721 | mScrollButtonLeft->setPolygon(left); |
|
716 | m_ScrollButtonLeft->setPolygon(left); | |
722 | mScrollButtonRight->setPolygon(right); |
|
717 | m_ScrollButtonRight->setPolygon(right); | |
723 | mScrollButtonUp->setPolygon(up); |
|
718 | m_ScrollButtonUp->setPolygon(up); | |
724 | mScrollButtonDown->setPolygon(down); |
|
719 | m_ScrollButtonDown->setPolygon(down); | |
725 | } |
|
720 | } | |
726 |
|
721 | |||
727 | /*! |
|
722 | /*! | |
@@ -730,7 +725,7 void QLegend::rescaleScrollButtons(const QSize &size) | |||||
730 | QSizeF QLegend::maximumMarkerSize() |
|
725 | QSizeF QLegend::maximumMarkerSize() | |
731 | { |
|
726 | { | |
732 | QSizeF max(0,0); |
|
727 | QSizeF max(0,0); | |
733 | foreach (LegendMarker* m, mMarkers) { |
|
728 | foreach (LegendMarker* m, m_Markers) { | |
734 | if (m->boundingRect().width() > max.width()) |
|
729 | if (m->boundingRect().width() > max.width()) | |
735 | max.setWidth(m->boundingRect().width()); |
|
730 | max.setWidth(m->boundingRect().width()); | |
736 | if (m->boundingRect().height() > max.height()) |
|
731 | if (m->boundingRect().height() > max.height()) | |
@@ -745,28 +740,28 QSizeF QLegend::maximumMarkerSize() | |||||
745 | */ |
|
740 | */ | |
746 | void QLegend::checkFirstMarkerBounds() |
|
741 | void QLegend::checkFirstMarkerBounds() | |
747 | { |
|
742 | { | |
748 | if ((mPreferredLayout == QLegend::PreferredLayoutLeft) || (mPreferredLayout == QLegend::PreferredLayoutRight)) { |
|
743 | if ((m_PreferredLayout == QLegend::PreferredLayoutLeft) || (m_PreferredLayout == QLegend::PreferredLayoutRight)) { | |
749 | // Bounds limited by height. |
|
744 | // Bounds limited by height. | |
750 | int max; |
|
745 | int max; | |
751 | if (scrollButtonsVisible()) { |
|
746 | if (scrollButtonsVisible()) { | |
752 | max = (mMaximumSize.height() - mScrollButtonLeft->boundingRect().height() * 2 - mMargin * 4) / maximumMarkerSize().height(); |
|
747 | max = (m_MaximumSize.height() - m_ScrollButtonLeft->boundingRect().height() * 2 - m_Margin * 4) / maximumMarkerSize().height(); | |
753 | } else { |
|
748 | } else { | |
754 | max = mMaximumSize.height() / maximumMarkerSize().height(); |
|
749 | max = m_MaximumSize.height() / maximumMarkerSize().height(); | |
755 | } |
|
750 | } | |
756 |
|
751 | |||
757 | if (mFirstMarker > mMarkers.count() - max) |
|
752 | if (mFirstMarker > m_Markers.count() - max) | |
758 | mFirstMarker = mMarkers.count() - max; |
|
753 | mFirstMarker = m_Markers.count() - max; | |
759 | } else { |
|
754 | } else { | |
760 | // Bounds limited by width |
|
755 | // Bounds limited by width | |
761 | int max; |
|
756 | int max; | |
762 | if (scrollButtonsVisible()) { |
|
757 | if (scrollButtonsVisible()) { | |
763 | max = (mMaximumSize.width() - mScrollButtonLeft->boundingRect().width() * 2 - mMargin*4) / maximumMarkerSize().width(); |
|
758 | max = (m_MaximumSize.width() - m_ScrollButtonLeft->boundingRect().width() * 2 - m_Margin*4) / maximumMarkerSize().width(); | |
764 | } else { |
|
759 | } else { | |
765 | max = mMaximumSize.width() / maximumMarkerSize().width(); |
|
760 | max = m_MaximumSize.width() / maximumMarkerSize().width(); | |
766 | } |
|
761 | } | |
767 |
|
762 | |||
768 | if (mFirstMarker > mMarkers.count() - max) |
|
763 | if (mFirstMarker > m_Markers.count() - max) | |
769 | mFirstMarker = mMarkers.count() - max; |
|
764 | mFirstMarker = m_Markers.count() - max; | |
770 | } |
|
765 | } | |
771 |
|
766 | |||
772 | if (mFirstMarker < 0) |
|
767 | if (mFirstMarker < 0) | |
@@ -779,13 +774,13 void QLegend::checkFirstMarkerBounds() | |||||
779 | bool QLegend::scrollButtonsVisible() |
|
774 | bool QLegend::scrollButtonsVisible() | |
780 | { |
|
775 | { | |
781 | // Just a helper to clarify, what the magic below means :) |
|
776 | // Just a helper to clarify, what the magic below means :) | |
782 | if ((mPreferredLayout == QLegend::PreferredLayoutTop) || (mPreferredLayout == QLegend::PreferredLayoutBottom)) { |
|
777 | if ((m_PreferredLayout == QLegend::PreferredLayoutTop) || (m_PreferredLayout == QLegend::PreferredLayoutBottom)) { | |
783 | return (maximumMarkerSize().width() * mMarkers.count() + mMargin * 2 > mMaximumSize.width()); |
|
778 | return (maximumMarkerSize().width() * m_Markers.count() + m_Margin * 2 > m_MaximumSize.width()); | |
784 | } else if ((mPreferredLayout == QLegend::PreferredLayoutLeft) || (mPreferredLayout == QLegend::PreferredLayoutRight)) { |
|
779 | } else if ((m_PreferredLayout == QLegend::PreferredLayoutLeft) || (m_PreferredLayout == QLegend::PreferredLayoutRight)) { | |
785 | return (maximumMarkerSize().height() * mMarkers.count() + mMargin * 2 > mMaximumSize.height()); |
|
780 | return (maximumMarkerSize().height() * m_Markers.count() + m_Margin * 2 > m_MaximumSize.height()); | |
786 | } |
|
781 | } | |
787 |
|
782 | |||
788 | return (maximumMarkerSize().height() * mMarkers.count() + mMargin * 2 > mMaximumSize.height()); |
|
783 | return (maximumMarkerSize().height() * m_Markers.count() + m_Margin * 2 > m_MaximumSize.height()); | |
789 | } |
|
784 | } | |
790 |
|
785 | |||
791 | #include "moc_qlegend.cpp" |
|
786 | #include "moc_qlegend.cpp" |
@@ -2,8 +2,9 | |||||
2 | #define QLEGEND_H |
|
2 | #define QLEGEND_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qseries.h> |
|
|||
6 | #include <QGraphicsObject> |
|
5 | #include <QGraphicsObject> | |
|
6 | #include <QPen> | |||
|
7 | #include <QBrush> | |||
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
@@ -15,6 +16,7 class QBarSet; | |||||
15 | class QBarSeries; |
|
16 | class QBarSeries; | |
16 | class QPieSeries; |
|
17 | class QPieSeries; | |
17 | class LegendScrollButton; |
|
18 | class LegendScrollButton; | |
|
19 | class QSeries; | |||
18 |
|
20 | |||
19 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject |
|
21 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject | |
20 | { |
|
22 | { | |
@@ -80,25 +82,25 private: | |||||
80 | void checkFirstMarkerBounds(); |
|
82 | void checkFirstMarkerBounds(); | |
81 | bool scrollButtonsVisible(); |
|
83 | bool scrollButtonsVisible(); | |
82 |
|
84 | |||
83 | QPointF mPos; |
|
85 | QPointF m_Pos; | |
84 | QSizeF mSize; |
|
86 | QSizeF m_Size; | |
85 | QSizeF mMinimumSize; |
|
87 | QSizeF m_MinimumSize; | |
86 | QSizeF mMaximumSize; |
|
88 | QSizeF m_MaximumSize; | |
87 |
|
89 | |||
88 | QList<LegendMarker *> mMarkers; |
|
90 | QList<LegendMarker *> m_Markers; | |
89 |
|
91 | |||
90 | QBrush m_brush; |
|
92 | QBrush m_brush; | |
91 | QPen m_pen; |
|
93 | QPen m_pen; | |
92 | QLegend::PreferredLayout mPreferredLayout; |
|
94 | QLegend::PreferredLayout m_PreferredLayout; | |
93 |
|
95 | |||
94 | int mFirstMarker; |
|
96 | int mFirstMarker; | |
95 |
|
97 | |||
96 | LegendScrollButton *mScrollButtonLeft; |
|
98 | LegendScrollButton *m_ScrollButtonLeft; | |
97 | LegendScrollButton *mScrollButtonRight; |
|
99 | LegendScrollButton *m_ScrollButtonRight; | |
98 | LegendScrollButton *mScrollButtonUp; |
|
100 | LegendScrollButton *m_ScrollButtonUp; | |
99 | LegendScrollButton *mScrollButtonDown; |
|
101 | LegendScrollButton *m_ScrollButtonDown; | |
100 |
|
102 | |||
101 | qreal mMargin; |
|
103 | qreal m_Margin; | |
102 | // <--- PIMPL |
|
104 | // <--- PIMPL | |
103 | }; |
|
105 | }; | |
104 |
|
106 |
General Comments 0
You need to be logged in to leave comments.
Login now