@@ -122,7 +122,7 QVector<QRectF> BarChartItem::calculateLayout() | |||||
122 | for (int set = 0; set < setCount; set++) { |
|
122 | for (int set = 0; set < setCount; set++) { | |
123 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
123 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
124 |
|
124 | |||
125 |
qreal barHeight = barSet-> |
|
125 | qreal barHeight = barSet->at(category) * scale; | |
126 | Bar* bar = m_bars.at(itemIndex); |
|
126 | Bar* bar = m_bars.at(itemIndex); | |
127 |
|
127 | |||
128 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
128 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
@@ -132,8 +132,8 QVector<QRectF> BarChartItem::calculateLayout() | |||||
132 |
|
132 | |||
133 | BarLabel* label = m_labels.at(itemIndex); |
|
133 | BarLabel* label = m_labels.at(itemIndex); | |
134 |
|
134 | |||
135 |
if (!qFuzzyIsNull(barSet-> |
|
135 | if (!qFuzzyIsNull(barSet->at(category))) { | |
136 |
label->setText(QString::number(barSet-> |
|
136 | label->setText(QString::number(barSet->at(category))); | |
137 | } else { |
|
137 | } else { | |
138 | label->setText(QString("")); |
|
138 | label->setText(QString("")); | |
139 | } |
|
139 | } |
@@ -93,7 +93,7 qreal BarChartModel::min() const | |||||
93 | for (int i = 0; i < m_dataModel.count(); i++) { |
|
93 | for (int i = 0; i < m_dataModel.count(); i++) { | |
94 | int itemCount = m_dataModel.at(i)->count(); |
|
94 | int itemCount = m_dataModel.at(i)->count(); | |
95 | for (int j = 0; j < itemCount; j++) { |
|
95 | for (int j = 0; j < itemCount; j++) { | |
96 |
qreal temp = m_dataModel.at(i)-> |
|
96 | qreal temp = m_dataModel.at(i)->at(j); | |
97 | if (temp < min) |
|
97 | if (temp < min) | |
98 | min = temp; |
|
98 | min = temp; | |
99 | } |
|
99 | } | |
@@ -111,7 +111,7 qreal BarChartModel::max() const | |||||
111 | for (int i = 0; i < m_dataModel.count(); i++) { |
|
111 | for (int i = 0; i < m_dataModel.count(); i++) { | |
112 | int itemCount = m_dataModel.at(i)->count(); |
|
112 | int itemCount = m_dataModel.at(i)->count(); | |
113 | for (int j = 0; j < itemCount; j++) { |
|
113 | for (int j = 0; j < itemCount; j++) { | |
114 |
qreal temp = m_dataModel.at(i)-> |
|
114 | qreal temp = m_dataModel.at(i)->at(j); | |
115 | if (temp > max) |
|
115 | if (temp > max) | |
116 | max = temp; |
|
116 | max = temp; | |
117 | } |
|
117 | } | |
@@ -130,7 +130,7 qreal BarChartModel::valueAt(int set, int category) const | |||||
130 | return 0; |
|
130 | return 0; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 |
return m_dataModel.at(set)-> |
|
133 | return m_dataModel.at(set)->at(category); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | qreal BarChartModel::percentageAt(int set, int category) const |
|
136 | qreal BarChartModel::percentageAt(int set, int category) const | |
@@ -143,7 +143,7 qreal BarChartModel::percentageAt(int set, int category) const | |||||
143 | return 0; |
|
143 | return 0; | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 |
qreal value = m_dataModel.at(set)-> |
|
146 | qreal value = m_dataModel.at(set)->at(category); | |
147 | qreal total = categorySum(category); |
|
147 | qreal total = categorySum(category); | |
148 | if ( qFuzzyCompare(total, 0) ) |
|
148 | if ( qFuzzyCompare(total, 0) ) | |
149 | return 0; |
|
149 | return 0; | |
@@ -158,7 +158,7 qreal BarChartModel::categorySum(int category) const | |||||
158 |
|
158 | |||
159 | for (int set = 0; set < count; set++) { |
|
159 | for (int set = 0; set < count; set++) { | |
160 | if (category < m_dataModel.at(set)->count()) |
|
160 | if (category < m_dataModel.at(set)->count()) | |
161 |
sum += m_dataModel.at(set)-> |
|
161 | sum += m_dataModel.at(set)->at(category); | |
162 | } |
|
162 | } | |
163 | return sum; |
|
163 | return sum; | |
164 | } |
|
164 | } | |
@@ -170,7 +170,7 qreal BarChartModel::absoluteCategorySum(int category) const | |||||
170 |
|
170 | |||
171 | for (int set = 0; set < count; set++) { |
|
171 | for (int set = 0; set < count; set++) { | |
172 | if (category < m_dataModel.at(set)->count()) |
|
172 | if (category < m_dataModel.at(set)->count()) | |
173 |
sum += qAbs(m_dataModel.at(set)-> |
|
173 | sum += qAbs(m_dataModel.at(set)->at(category)); | |
174 | } |
|
174 | } | |
175 | return sum; |
|
175 | return sum; | |
176 | } |
|
176 | } |
@@ -55,7 +55,7 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||||
55 | qreal yPos = height + domainScale * m_domainMinY + geometry().topLeft().y(); |
|
55 | qreal yPos = height + domainScale * m_domainMinY + geometry().topLeft().y(); | |
56 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
56 | for (int set=0; set < m_series->barsetCount(); set++) { | |
57 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
57 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
58 |
qreal barHeight = barSet-> |
|
58 | qreal barHeight = barSet->at(category) * percentage * domainScale; | |
59 | Bar* bar = m_bars.at(itemIndex); |
|
59 | Bar* bar = m_bars.at(itemIndex); | |
60 | bar->setPen(barSet->pen()); |
|
60 | bar->setPen(barSet->pen()); | |
61 | bar->setBrush(barSet->brush()); |
|
61 | bar->setBrush(barSet->brush()); |
@@ -387,13 +387,13 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRigh | |||||
387 | { |
|
387 | { | |
388 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
388 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
389 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
389 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
390 |
barsetAt(topLeft.column() - m_mapBarBottom)-> |
|
390 | barsetAt(topLeft.column() - m_mapBarBottom)->replace(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
391 | } |
|
391 | } | |
392 | else |
|
392 | else | |
393 | { |
|
393 | { | |
394 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
394 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
395 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
395 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
396 |
barsetAt(topLeft.row() - m_mapBarBottom)-> |
|
396 | barsetAt(topLeft.row() - m_mapBarBottom)->replace(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
397 | } |
|
397 | } | |
398 | } |
|
398 | } | |
399 |
|
399 |
@@ -60,7 +60,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
60 | /*! |
|
60 | /*! | |
61 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
61 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
62 | */ |
|
62 | */ | |
63 | QBarSet::QBarSet(QString name, QObject *parent) |
|
63 | QBarSet::QBarSet(const QString name, QObject *parent) | |
64 | : QObject(parent) |
|
64 | : QObject(parent) | |
65 | ,d_ptr(new QBarSetPrivate(name,this)) |
|
65 | ,d_ptr(new QBarSetPrivate(name,this)) | |
66 | { |
|
66 | { | |
@@ -77,7 +77,7 QBarSet::~QBarSet() | |||||
77 | /*! |
|
77 | /*! | |
78 | Sets new \a name for set. |
|
78 | Sets new \a name for set. | |
79 | */ |
|
79 | */ | |
80 | void QBarSet::setName(QString name) |
|
80 | void QBarSet::setName(const QString name) | |
81 | { |
|
81 | { | |
82 | d_ptr->m_name = name; |
|
82 | d_ptr->m_name = name; | |
83 | } |
|
83 | } | |
@@ -93,55 +93,71 QString QBarSet::name() const | |||||
93 | /*! |
|
93 | /*! | |
94 | Appends new value \a value to the end of set. |
|
94 | Appends new value \a value to the end of set. | |
95 | */ |
|
95 | */ | |
96 |
|
|
96 | void QBarSet::append(const qreal value) | |
97 | { |
|
97 | { | |
98 | d_ptr->m_values.append(value); |
|
98 | d_ptr->m_values.append(value); | |
99 | emit d_ptr->structureChanged(); |
|
99 | emit d_ptr->structureChanged(); | |
|
100 | } | |||
|
101 | ||||
|
102 | /*! | |||
|
103 | Appends new value \a value to the end of set. | |||
|
104 | */ | |||
|
105 | QBarSet& QBarSet::operator << (const qreal &value) | |||
|
106 | { | |||
|
107 | append(value); | |||
100 | return *this; |
|
108 | return *this; | |
101 | } |
|
109 | } | |
102 |
|
110 | |||
103 | /*! |
|
111 | /*! | |
104 | Inserts new \a value on the \a i position. |
|
112 | Inserts new \a value on the \a index position. | |
105 | The value that is currently at this postion is moved to postion i + 1 |
|
113 | The value that is currently at this postion is moved to postion index + 1 | |
106 |
\sa remove |
|
114 | \sa remove() | |
107 | */ |
|
115 | */ | |
108 |
void QBarSet::insert |
|
116 | void QBarSet::insert(const int index, const qreal value) | |
109 | { |
|
117 | { | |
110 | d_ptr->m_values.insert(i, value); |
|
118 | d_ptr->m_values.insert(index, value); | |
111 | } |
|
119 | } | |
112 |
|
120 | |||
113 | /*! |
|
121 | /*! | |
114 | Removes the value specified by \a i |
|
122 | Removes the value specified by \a index | |
115 |
\sa insert |
|
123 | \sa insert() | |
116 | */ |
|
124 | */ | |
117 |
void QBarSet::remove |
|
125 | void QBarSet::remove(const int index) | |
118 | { |
|
126 | { | |
119 | d_ptr->m_values.removeAt(i); |
|
127 | d_ptr->m_values.removeAt(index); | |
120 | } |
|
128 | } | |
121 |
|
129 | |||
122 | /*! |
|
130 | /*! | |
123 | Returns count of values in set. |
|
131 | Sets a new value \a value to set, indexed by \a index | |
124 | */ |
|
132 | */ | |
125 | int QBarSet::count() const |
|
133 | void QBarSet::replace(const int index, const qreal value) | |
126 | { |
|
134 | { | |
127 |
|
|
135 | d_ptr->m_values.replace(index,value); | |
|
136 | emit d_ptr->valueChanged(); | |||
128 | } |
|
137 | } | |
129 |
|
138 | |||
130 | /*! |
|
139 | /*! | |
131 | Returns value of set indexed by \a index |
|
140 | Returns value of set indexed by \a index | |
132 | */ |
|
141 | */ | |
133 |
qreal QBarSet:: |
|
142 | qreal QBarSet::at(const int index) const | |
134 | { |
|
143 | { | |
135 | return d_ptr->m_values.at(index); |
|
144 | return d_ptr->m_values.at(index); | |
136 | } |
|
145 | } | |
137 |
|
146 | |||
138 | /*! |
|
147 | /*! | |
139 |
|
|
148 | Returns value of set indexed by \a index | |
140 | */ |
|
149 | */ | |
141 | void QBarSet::setValue(int index, qreal value) |
|
150 | qreal QBarSet::operator [] (int index) const | |
142 | { |
|
151 | { | |
143 |
d_ptr->m_values. |
|
152 | return d_ptr->m_values.at(index); | |
144 | emit d_ptr->valueChanged(); |
|
153 | } | |
|
154 | ||||
|
155 | /*! | |||
|
156 | Returns count of values in set. | |||
|
157 | */ | |||
|
158 | int QBarSet::count() const | |||
|
159 | { | |||
|
160 | return d_ptr->m_values.count(); | |||
145 | } |
|
161 | } | |
146 |
|
162 | |||
147 | /*! |
|
163 | /*! | |
@@ -274,7 +290,7 bool QBarSet::labelsVisible() const | |||||
274 |
|
290 | |||
275 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
291 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
276 |
|
292 | |||
277 | QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent), |
|
293 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), | |
278 | q_ptr(parent), |
|
294 | q_ptr(parent), | |
279 | m_name(name), |
|
295 | m_name(name), | |
280 | m_labelsVisible(false) |
|
296 | m_labelsVisible(false) |
@@ -34,18 +34,20 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |||||
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit QBarSet(QString name, QObject *parent = 0); |
|
37 | explicit QBarSet(const QString name, QObject *parent = 0); | |
38 | virtual ~QBarSet(); |
|
38 | virtual ~QBarSet(); | |
39 |
|
39 | |||
40 | void setName(QString name); |
|
40 | void setName(const QString name); | |
41 | QString name() const; |
|
41 | QString name() const; | |
42 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
42 | void append(const qreal value); | |
43 | void insertValue(int i, qreal value); |
|
43 | QBarSet& operator << (const qreal &value); | |
44 | void removeValue(int i); |
|
44 | void insert(const int index, const qreal value); | |
45 | int count() const; // count of values in set |
|
45 | void remove(const int index); | |
46 | qreal valueAt(int index) const; // for modifying individual values |
|
46 | void replace(const int index, const qreal value); | |
47 | void setValue(int index, qreal value); // setter for individual value |
|
47 | qreal at(const int index) const; | |
48 | qreal sum() const; // sum of all values in the set |
|
48 | qreal operator [] (int index) const; | |
|
49 | int count() const; | |||
|
50 | qreal sum() const; | |||
49 |
|
51 | |||
50 | void setPen(const QPen &pen); |
|
52 | void setPen(const QPen &pen); | |
51 | QPen pen() const; |
|
53 | QPen pen() const; |
@@ -10,7 +10,7 class QBarSetPrivate : public QObject | |||||
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 |
|
11 | |||
12 | public: |
|
12 | public: | |
13 | QBarSetPrivate(QString name, QBarSet *parent); |
|
13 | QBarSetPrivate(const QString name, QBarSet *parent); | |
14 | ~QBarSetPrivate(); |
|
14 | ~QBarSetPrivate(); | |
15 |
|
15 | |||
16 | Q_SIGNALS: |
|
16 | Q_SIGNALS: |
@@ -53,7 +53,7 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
53 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
53 | for (int set=0; set < m_series->barsetCount(); set++) { | |
54 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
54 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
55 |
|
55 | |||
56 |
qreal barHeight = barSet-> |
|
56 | qreal barHeight = barSet->at(category) * scale; | |
57 | Bar* bar = m_bars.at(itemIndex); |
|
57 | Bar* bar = m_bars.at(itemIndex); | |
58 | bar->setPen(barSet->pen()); |
|
58 | bar->setPen(barSet->pen()); | |
59 | bar->setBrush(barSet->brush()); |
|
59 | bar->setBrush(barSet->brush()); | |
@@ -62,8 +62,8 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||||
62 |
|
62 | |||
63 | BarLabel* label = m_labels.at(itemIndex); |
|
63 | BarLabel* label = m_labels.at(itemIndex); | |
64 |
|
64 | |||
65 |
if (!qFuzzyIsNull(barSet-> |
|
65 | if (!qFuzzyIsNull(barSet->at(category))) { | |
66 |
label->setText(QString::number(barSet-> |
|
66 | label->setText(QString::number(barSet->at(category))); | |
67 | } else { |
|
67 | } else { | |
68 | label->setText(QString("")); |
|
68 | label->setText(QString("")); | |
69 | } |
|
69 | } |
General Comments 0
You need to be logged in to leave comments.
Login now