@@ -46,6 +46,11 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbs | |||||
46 | void QCategoriesAxis::append(const QStringList &categories) |
|
46 | void QCategoriesAxis::append(const QStringList &categories) | |
47 | { |
|
47 | { | |
48 | Q_D(QCategoriesAxis); |
|
48 | Q_D(QCategoriesAxis); | |
|
49 | if (d->m_categories.isEmpty()) { | |||
|
50 | d->m_minCategory = categories.first(); | |||
|
51 | d->m_maxCategory = categories.last(); | |||
|
52 | } | |||
|
53 | ||||
49 | d->m_categories.append(categories); |
|
54 | d->m_categories.append(categories); | |
50 | emit categoriesChanged(); |
|
55 | emit categoriesChanged(); | |
51 | } |
|
56 | } | |
@@ -56,6 +61,11 void QCategoriesAxis::append(const QStringList &categories) | |||||
56 | void QCategoriesAxis::append(const QString &category) |
|
61 | void QCategoriesAxis::append(const QString &category) | |
57 | { |
|
62 | { | |
58 | Q_D(QCategoriesAxis); |
|
63 | Q_D(QCategoriesAxis); | |
|
64 | if (d->m_categories.isEmpty()) { | |||
|
65 | d->m_minCategory = category; | |||
|
66 | d->m_maxCategory = category; | |||
|
67 | } | |||
|
68 | ||||
59 | d->m_categories.append(category); |
|
69 | d->m_categories.append(category); | |
60 | emit categoriesChanged(); |
|
70 | emit categoriesChanged(); | |
61 | } |
|
71 | } | |
@@ -68,6 +78,8 void QCategoriesAxis::remove(const QString &category) | |||||
68 | Q_D(QCategoriesAxis); |
|
78 | Q_D(QCategoriesAxis); | |
69 | if (d->m_categories.contains(category)) { |
|
79 | if (d->m_categories.contains(category)) { | |
70 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
80 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
|
81 | d->m_minCategory = d->m_categories.first(); | |||
|
82 | d->m_maxCategory = d->m_categories.last(); | |||
71 | emit categoriesChanged(); |
|
83 | emit categoriesChanged(); | |
72 | } |
|
84 | } | |
73 | } |
|
85 | } | |
@@ -78,6 +90,10 void QCategoriesAxis::remove(const QString &category) | |||||
78 | void QCategoriesAxis::insert(int index, const QString &category) |
|
90 | void QCategoriesAxis::insert(int index, const QString &category) | |
79 | { |
|
91 | { | |
80 | Q_D(QCategoriesAxis); |
|
92 | Q_D(QCategoriesAxis); | |
|
93 | if (d->m_categories.isEmpty()) { | |||
|
94 | d->m_minCategory = category; | |||
|
95 | d->m_maxCategory = category; | |||
|
96 | } | |||
81 | d->m_categories.insert(index,category); |
|
97 | d->m_categories.insert(index,category); | |
82 | emit categoriesChanged(); |
|
98 | emit categoriesChanged(); | |
83 | } |
|
99 | } | |
@@ -89,6 +105,8 void QCategoriesAxis::clear() | |||||
89 | { |
|
105 | { | |
90 | Q_D(QCategoriesAxis); |
|
106 | Q_D(QCategoriesAxis); | |
91 | d->m_categories.clear(); |
|
107 | d->m_categories.clear(); | |
|
108 | d->m_minCategory.clear(); | |||
|
109 | d->m_maxCategory.clear(); | |||
92 | emit categoriesChanged(); |
|
110 | emit categoriesChanged(); | |
93 | } |
|
111 | } | |
94 |
|
112 | |||
@@ -96,6 +114,8 void QCategoriesAxis::setCategories(const QStringList &categories) | |||||
96 | { |
|
114 | { | |
97 | Q_D(QCategoriesAxis); |
|
115 | Q_D(QCategoriesAxis); | |
98 | d->m_categories = categories; |
|
116 | d->m_categories = categories; | |
|
117 | d->m_minCategory = categories.first(); | |||
|
118 | d->m_maxCategory = categories.last(); | |||
99 | emit categoriesChanged(); |
|
119 | emit categoriesChanged(); | |
100 | } |
|
120 | } | |
101 |
|
121 | |||
@@ -124,36 +144,36 QString QCategoriesAxis::at(int index) const | |||||
124 | } |
|
144 | } | |
125 |
|
145 | |||
126 | /*! |
|
146 | /*! | |
127 |
Sets minimum category to \a min |
|
147 | Sets minimum category to \a min. | |
128 | */ |
|
148 | */ | |
129 |
void QCategoriesAxis::setMin |
|
149 | void QCategoriesAxis::setMin(const QString& min) | |
130 | { |
|
150 | { | |
131 | Q_D(QCategoriesAxis); |
|
151 | Q_D(QCategoriesAxis); | |
132 |
d-> |
|
152 | setRange(min,d->m_maxCategory); | |
133 | } |
|
153 | } | |
134 |
|
154 | |||
135 | /*! |
|
155 | /*! | |
136 | Returns minimum category. |
|
156 | Returns minimum category. | |
137 | */ |
|
157 | */ | |
138 |
QString QCategoriesAxis::min |
|
158 | QString QCategoriesAxis::min() const | |
139 | { |
|
159 | { | |
140 | Q_D(const QCategoriesAxis); |
|
160 | Q_D(const QCategoriesAxis); | |
141 | return d->m_minCategory; |
|
161 | return d->m_minCategory; | |
142 | } |
|
162 | } | |
143 |
|
163 | |||
144 | /*! |
|
164 | /*! | |
145 |
Sets maximum category to \a max |
|
165 | Sets maximum category to \a max. | |
146 | */ |
|
166 | */ | |
147 |
void QCategoriesAxis::setMax |
|
167 | void QCategoriesAxis::setMax(const QString& max) | |
148 | { |
|
168 | { | |
149 | Q_D(QCategoriesAxis); |
|
169 | Q_D(QCategoriesAxis); | |
150 | d->setMaxCategory(maxCategory); |
|
170 | setRange(d->m_minCategory,max); | |
151 | } |
|
171 | } | |
152 |
|
172 | |||
153 | /*! |
|
173 | /*! | |
154 | Returns maximum category |
|
174 | Returns maximum category | |
155 | */ |
|
175 | */ | |
156 |
QString QCategoriesAxis::max |
|
176 | QString QCategoriesAxis::max() const | |
157 | { |
|
177 | { | |
158 | Q_D(const QCategoriesAxis); |
|
178 | Q_D(const QCategoriesAxis); | |
159 | return d->m_maxCategory; |
|
179 | return d->m_maxCategory; | |
@@ -162,10 +182,44 QString QCategoriesAxis::maxCategory() const | |||||
162 | /*! |
|
182 | /*! | |
163 | Sets range from \a minCategory to \a maxCategory |
|
183 | Sets range from \a minCategory to \a maxCategory | |
164 | */ |
|
184 | */ | |
165 |
void QCategoriesAxis::set |
|
185 | void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
166 | { |
|
186 | { | |
167 | Q_D(QCategoriesAxis); |
|
187 | Q_D(QCategoriesAxis); | |
168 | d->setRangeCategory(minCategory,maxCategory); |
|
188 | ||
|
189 | int minIndex = d->m_categories.indexOf(minCategory); | |||
|
190 | if (minIndex == -1) { | |||
|
191 | return; | |||
|
192 | } | |||
|
193 | int maxIndex = d->m_categories.indexOf(maxCategory); | |||
|
194 | if (maxIndex == -1) { | |||
|
195 | return; | |||
|
196 | } | |||
|
197 | ||||
|
198 | if (maxIndex <= minIndex) { | |||
|
199 | // max must be greater than min | |||
|
200 | return; | |||
|
201 | } | |||
|
202 | ||||
|
203 | d->m_minCategory = minCategory; | |||
|
204 | d->m_maxCategory = maxCategory; | |||
|
205 | ||||
|
206 | bool changed = false; | |||
|
207 | if (!qFuzzyIsNull(d->m_min - (minIndex))) { | |||
|
208 | d->m_min = minIndex; | |||
|
209 | changed = true; | |||
|
210 | } | |||
|
211 | ||||
|
212 | if (!qFuzzyIsNull(d->m_max - (maxIndex))) { | |||
|
213 | d->m_max = maxIndex; | |||
|
214 | changed = true; | |||
|
215 | } | |||
|
216 | ||||
|
217 | if ((changed)) { | |||
|
218 | if(!signalsBlocked()){ | |||
|
219 | emit d->changed(d->m_min -0.5, d->m_max +0.5, qCeil(d->m_max + 0.5) -qCeil(d->m_min - 0.5) +1, false); | |||
|
220 | } | |||
|
221 | emit categoriesChanged(); | |||
|
222 | } | |||
169 | } |
|
223 | } | |
170 |
|
224 | |||
171 | /*! |
|
225 | /*! | |
@@ -189,88 +243,23 QCategoriesAxisPrivate::~QCategoriesAxisPrivate() | |||||
189 |
|
243 | |||
190 | } |
|
244 | } | |
191 |
|
245 | |||
192 | void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory) |
|
|||
193 | { |
|
|||
194 | // Convert the category to value |
|
|||
195 | int minIndex = m_categories.indexOf(minCategory); |
|
|||
196 | if (minIndex == -1) { |
|
|||
197 | return; |
|
|||
198 | } |
|
|||
199 |
|
||||
200 | int maxIndex = qFloor(m_max); |
|
|||
201 | if (minIndex > maxIndex) { |
|
|||
202 | maxIndex = m_categories.count()-1; |
|
|||
203 | } |
|
|||
204 | setRange(minIndex - 0.5, maxIndex + 0.5); |
|
|||
205 | } |
|
|||
206 |
|
||||
207 | void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory) |
|
|||
208 | { |
|
|||
209 | // Convert the category to value |
|
|||
210 | int maxIndex = m_categories.indexOf(maxCategory); |
|
|||
211 | if (maxIndex == -1) { |
|
|||
212 | return; |
|
|||
213 | } |
|
|||
214 |
|
||||
215 | int minIndex = qCeil(m_min); |
|
|||
216 | if (maxIndex < minIndex) { |
|
|||
217 | minIndex = 0; |
|
|||
218 | } |
|
|||
219 | setRange(minIndex - 0.5, maxIndex + 0.5); |
|
|||
220 | } |
|
|||
221 |
|
||||
222 | void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory) |
|
|||
223 | { |
|
|||
224 | // TODO: |
|
|||
225 | int minIndex = m_categories.indexOf(minCategory); |
|
|||
226 | if (minIndex == -1) { |
|
|||
227 | return; |
|
|||
228 | } |
|
|||
229 | int maxIndex = m_categories.indexOf(maxCategory); |
|
|||
230 | if (maxIndex == -1) { |
|
|||
231 | return; |
|
|||
232 | } |
|
|||
233 | setRange(minIndex -0.5, maxIndex + 0.5); |
|
|||
234 | } |
|
|||
235 |
|
||||
236 | void QCategoriesAxisPrivate::setMin(const QVariant &min) |
|
246 | void QCategoriesAxisPrivate::setMin(const QVariant &min) | |
237 | { |
|
247 | { | |
238 | setRange(min,m_max); |
|
248 | setRange(min,m_maxCategory); | |
239 | } |
|
249 | } | |
240 |
|
250 | |||
241 | void QCategoriesAxisPrivate::setMax(const QVariant &max) |
|
251 | void QCategoriesAxisPrivate::setMax(const QVariant &max) | |
242 | { |
|
252 | { | |
243 | setRange(m_min,max); |
|
253 | setRange(m_minCategory,max); | |
244 | } |
|
254 | } | |
245 |
|
255 | |||
246 | void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force) |
|
256 | void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force) | |
247 | { |
|
257 | { | |
248 | Q_UNUSED(min); |
|
258 | Q_UNUSED(force); // TODO: use this? | |
249 | Q_UNUSED(max); |
|
|||
250 | Q_UNUSED(force); |
|
|||
251 | // TODO: refactor |
|
|||
252 | /* |
|
|||
253 | if (max <= min) { |
|
|||
254 | // max must be greater than min |
|
|||
255 | return; |
|
|||
256 | } |
|
|||
257 | Q_Q(QCategoriesAxis); |
|
259 | Q_Q(QCategoriesAxis); | |
258 | bool changed = false; |
|
260 | QString value1 = min.toString(); | |
259 | if (!qFuzzyIsNull(m_min - min)) { |
|
261 | QString value2 = max.toString(); | |
260 | m_min = min; |
|
262 | q->setRange(value1,value2); | |
261 | changed = true; |
|
|||
262 | } |
|
|||
263 |
|
||||
264 | if (!qFuzzyIsNull(m_max - max)) { |
|
|||
265 | m_max = max; |
|
|||
266 | changed = true; |
|
|||
267 | } |
|
|||
268 |
|
||||
269 | if ((changed) ||(force)) { |
|
|||
270 | emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false); |
|
|||
271 | emit q->categoriesChanged(); |
|
|||
272 | } |
|
|||
273 | */ |
|
|||
274 | } |
|
263 | } | |
275 |
|
264 | |||
276 | int QCategoriesAxisPrivate::ticksCount() const |
|
265 | int QCategoriesAxisPrivate::ticksCount() const |
@@ -49,19 +49,14 public: | |||||
49 | void setCategories(const QStringList &categories); |
|
49 | void setCategories(const QStringList &categories); | |
50 | QStringList categories(); |
|
50 | QStringList categories(); | |
51 | int count() const; |
|
51 | int count() const; | |
52 |
|
||||
53 | QString at(int index) const; |
|
52 | QString at(int index) const; | |
54 |
|
53 | |||
55 |
//range handling |
|
54 | //range handling | |
56 |
void setMin |
|
55 | void setMin(const QString& minCategory); | |
57 |
QString min |
|
56 | QString min() const; | |
58 |
void setMax |
|
57 | void setMax(const QString& maxCategory); | |
59 |
QString max |
|
58 | QString max() const; | |
60 |
void set |
|
59 | void setRange(const QString& minCategory, const QString& maxCategory); | |
61 |
|
||||
62 | void setMin(const QVariant &min); |
|
|||
63 | void setMax(const QVariant &max); |
|
|||
64 | void setRange(const QVariant &min, const QVariant &max); |
|
|||
65 |
|
60 | |||
66 | Q_SIGNALS: |
|
61 | Q_SIGNALS: | |
67 | void categoriesChanged(); |
|
62 | void categoriesChanged(); |
@@ -48,10 +48,6 public: | |||||
48 | void updateRange(); |
|
48 | void updateRange(); | |
49 |
|
49 | |||
50 | private: |
|
50 | private: | |
51 | void setMinCategory(const QString& minCategory); |
|
|||
52 | void setMaxCategory(const QString& maxCategory); |
|
|||
53 | void setRangeCategory(const QString& minCategory, const QString& maxCategory); |
|
|||
54 |
|
||||
55 | //range handling |
|
51 | //range handling | |
56 | void setMin(const QVariant &min); |
|
52 | void setMin(const QVariant &min); | |
57 | void setMax(const QVariant &max); |
|
53 | void setMax(const QVariant &max); |
General Comments 0
You need to be logged in to leave comments.
Login now