##// END OF EJS Templates
more error tolerant barseries set/remove barset functions
sauimone -
r1121:2f9ae4af73a8
parent child
Show More
@@ -106,54 +106,86 void QBarSeries::setCategories(QBarCategories categories)
106 /*!
106 /*!
107 Adds a set of bars to series. Takes ownership of \a set.
107 Adds a set of bars to series. Takes ownership of \a set.
108 */
108 */
109 void QBarSeries::appendBarSet(QBarSet *set)
109 bool QBarSeries::appendBarSet(QBarSet *set)
110 {
110 {
111 Q_D(QBarSeries);
111 Q_D(QBarSeries);
112 if ((d->m_barSets.contains(set)) || (set == 0)) {
113 // Fail if set is already in list or set is null.
114 return false;
115 }
112 d->m_barSets.append(set);
116 d->m_barSets.append(set);
113 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
117 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
114 emit d->restructuredBars();
118 emit d->restructuredBars();
119 return true;
115 }
120 }
116
121
117 /*!
122 /*!
118 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
123 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
119 */
124 */
120 void QBarSeries::removeBarSet(QBarSet *set)
125 bool QBarSeries::removeBarSet(QBarSet *set)
121 {
126 {
122 Q_D(QBarSeries);
127 Q_D(QBarSeries);
123 if (d->m_barSets.contains(set)) {
128 if (!d->m_barSets.contains(set)) {
124 d->m_barSets.removeOne(set);
129 // Fail if set is not in list
125 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
130 return false;
126 emit d->restructuredBars();
127 }
131 }
132 d->m_barSets.removeOne(set);
133 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
134 emit d->restructuredBars();
135 return true;
128 }
136 }
129
137
130 /*!
138 /*!
131 Adds a list of barsets to series. Takes ownership of \a sets.
139 Adds a list of barsets to series. Takes ownership of \a sets.
132 */
140 */
133 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
141 bool QBarSeries::appendBarSets(QList<QBarSet* > sets)
134 {
142 {
135 Q_D(QBarSeries);
143 Q_D(QBarSeries);
136 foreach (QBarSet* set, sets) {
144 foreach (QBarSet* set, sets) {
145 if ((set == 0) || (d->m_barSets.contains(set))) {
146 // Fail if any of the sets is null or is already appended.
147 return false;
148 }
149 if (sets.count(set) != 1) {
150 // Also fail if same set is more than once in given list.
151 return false;
152 }
153 }
154
155 foreach (QBarSet* set, sets) {
137 d->m_barSets.append(set);
156 d->m_barSets.append(set);
138 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
157 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
139 }
158 }
140 emit d->restructuredBars();
159 emit d->restructuredBars();
160 return true;
141 }
161 }
142
162
143 /*!
163 /*!
144 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
164 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
145 */
165 */
146 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
166 bool QBarSeries::removeBarSets(QList<QBarSet* > sets)
147 {
167 {
148 Q_D(QBarSeries);
168 Q_D(QBarSeries);
149
169
150 foreach (QBarSet* set, sets) {
170 foreach (QBarSet* set, sets) {
171 if ((set == 0) || (!d->m_barSets.contains(set))) {
172 // Fail if any of the sets is null or isn't in m_barSets
173 return false;
174 }
175 if (sets.count(set) != 1) {
176 // Also fail if same set is more than once in given list.
177 return false;
178 }
179 }
180
181 foreach (QBarSet* set, sets) {
151 if (d->m_barSets.contains(set)) {
182 if (d->m_barSets.contains(set)) {
152 d->m_barSets.removeOne(set);
183 d->m_barSets.removeOne(set);
153 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
184 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
154 }
185 }
155 }
186 }
156 emit d->restructuredBars();
187 emit d->restructuredBars();
188 return true;
157 }
189 }
158
190
159 /*!
191 /*!
@@ -45,10 +45,10 public:
45 QAbstractSeries::SeriesType type() const;
45 QAbstractSeries::SeriesType type() const;
46 void setCategories(QBarCategories categories);
46 void setCategories(QBarCategories categories);
47
47
48 void appendBarSet(QBarSet *set); // Takes ownership of set
48 bool appendBarSet(QBarSet *set); // Takes ownership of set
49 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
49 bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
50 void appendBarSets(QList<QBarSet* > sets);
50 bool appendBarSets(QList<QBarSet* > sets);
51 void removeBarSets(QList<QBarSet* > sets);
51 bool removeBarSets(QList<QBarSet* > sets);
52 int barsetCount() const;
52 int barsetCount() const;
53 int categoryCount() const;
53 int categoryCount() const;
54 QList<QBarSet*> barSets() const;
54 QList<QBarSet*> barSets() const;
General Comments 0
You need to be logged in to leave comments. Login now