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