Changeset View
Changeset View
Standalone View
Standalone View
src/KChart/KChartChart.cpp
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Line(s) | 153 | public: | |||
---|---|---|---|---|---|
159 | 159 | | |||
160 | // All of the methods are reimplemented from QWidgetItem, and work around some oddity in QLayout and / or | 160 | // All of the methods are reimplemented from QWidgetItem, and work around some oddity in QLayout and / or | ||
161 | // KD Chart - I forgot the details between writing this code as an experiment and committing it, very | 161 | // KD Chart - I forgot the details between writing this code as an experiment and committing it, very | ||
162 | // sorry about that! | 162 | // sorry about that! | ||
163 | // Feel free to comment out any of them and then try the line-breaking feature in horizontal legends in | 163 | // Feel free to comment out any of them and then try the line-breaking feature in horizontal legends in | ||
164 | // the Legends/Advanced example. It will not work well in various ways - won't get enough space and look | 164 | // the Legends/Advanced example. It will not work well in various ways - won't get enough space and look | ||
165 | // very broken, will inhibit resizing the window etc. | 165 | // very broken, will inhibit resizing the window etc. | ||
166 | 166 | | |||
167 | QSize sizeHint() const Q_DECL_OVERRIDE | 167 | QSize sizeHint() const override | ||
168 | { | 168 | { | ||
169 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 169 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
170 | return w->sizeHint(); | 170 | return w->sizeHint(); | ||
171 | } | 171 | } | ||
172 | 172 | | |||
173 | QSize minimumSize() const Q_DECL_OVERRIDE | 173 | QSize minimumSize() const override | ||
174 | { | 174 | { | ||
175 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 175 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
176 | return w->minimumSize(); | 176 | return w->minimumSize(); | ||
177 | } | 177 | } | ||
178 | 178 | | |||
179 | QSize maximumSize() const Q_DECL_OVERRIDE | 179 | QSize maximumSize() const override | ||
180 | { | 180 | { | ||
181 | // Not just passing on w->maximumSize() fixes that the size policy of Legend is disregarded, making | 181 | // Not just passing on w->maximumSize() fixes that the size policy of Legend is disregarded, making | ||
182 | // Legend take all available space, which makes both the Legend internal layout and the overall | 182 | // Legend take all available space, which makes both the Legend internal layout and the overall | ||
183 | // layout of chart + legend look bad. QWidget::maximumSize() is not a virtual method, it's a | 183 | // layout of chart + legend look bad. QWidget::maximumSize() is not a virtual method, it's a | ||
184 | // property, so "overriding" that one would be even uglier, and prevent user-set property | 184 | // property, so "overriding" that one would be even uglier, and prevent user-set property | ||
185 | // values from doing anything. | 185 | // values from doing anything. | ||
186 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 186 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
187 | QSize ret = w->maximumSize(); | 187 | QSize ret = w->maximumSize(); | ||
188 | const QSize hint = w->sizeHint(); | 188 | const QSize hint = w->sizeHint(); | ||
189 | const QSizePolicy::Policy hPolicy = w->sizePolicy().horizontalPolicy(); | 189 | const QSizePolicy::Policy hPolicy = w->sizePolicy().horizontalPolicy(); | ||
190 | if (hPolicy == QSizePolicy::Fixed || hPolicy == QSizePolicy::Maximum) { | 190 | if (hPolicy == QSizePolicy::Fixed || hPolicy == QSizePolicy::Maximum) { | ||
191 | ret.rwidth() = hint.width(); | 191 | ret.rwidth() = hint.width(); | ||
192 | } | 192 | } | ||
193 | const QSizePolicy::Policy vPolicy = w->sizePolicy().verticalPolicy(); | 193 | const QSizePolicy::Policy vPolicy = w->sizePolicy().verticalPolicy(); | ||
194 | if (vPolicy == QSizePolicy::Fixed || vPolicy == QSizePolicy::Maximum) { | 194 | if (vPolicy == QSizePolicy::Fixed || vPolicy == QSizePolicy::Maximum) { | ||
195 | ret.rheight() = hint.height(); | 195 | ret.rheight() = hint.height(); | ||
196 | } | 196 | } | ||
197 | return ret; | 197 | return ret; | ||
198 | } | 198 | } | ||
199 | 199 | | |||
200 | Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE | 200 | Qt::Orientations expandingDirections() const override | ||
201 | { | 201 | { | ||
202 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 202 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
203 | if ( isEmpty() ) { | 203 | if ( isEmpty() ) { | ||
204 | return Qt::Orientations(); | 204 | return Qt::Orientations(); | ||
205 | } | 205 | } | ||
206 | Qt::Orientations e = w->sizePolicy().expandingDirections(); | 206 | Qt::Orientations e = w->sizePolicy().expandingDirections(); | ||
207 | return e; | 207 | return e; | ||
208 | } | 208 | } | ||
209 | 209 | | |||
210 | void setGeometry(const QRect &g) Q_DECL_OVERRIDE | 210 | void setGeometry(const QRect &g) override | ||
211 | { | 211 | { | ||
212 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 212 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
213 | w->setGeometry(g); | 213 | w->setGeometry(g); | ||
214 | } | 214 | } | ||
215 | 215 | | |||
216 | QRect geometry() const Q_DECL_OVERRIDE | 216 | QRect geometry() const override | ||
217 | { | 217 | { | ||
218 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 218 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
219 | return w->geometry(); | 219 | return w->geometry(); | ||
220 | } | 220 | } | ||
221 | 221 | | |||
222 | bool hasHeightForWidth() const Q_DECL_OVERRIDE | 222 | bool hasHeightForWidth() const override | ||
223 | { | 223 | { | ||
224 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 224 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
225 | bool ret = !isEmpty() && | 225 | bool ret = !isEmpty() && | ||
226 | qobject_cast< Legend* >( w )->hasHeightForWidth(); | 226 | qobject_cast< Legend* >( w )->hasHeightForWidth(); | ||
227 | return ret; | 227 | return ret; | ||
228 | } | 228 | } | ||
229 | 229 | | |||
230 | int heightForWidth( int width ) const Q_DECL_OVERRIDE | 230 | int heightForWidth( int width ) const override | ||
231 | { | 231 | { | ||
232 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 232 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
233 | int ret = w->heightForWidth( width ); | 233 | int ret = w->heightForWidth( width ); | ||
234 | return ret; | 234 | return ret; | ||
235 | } | 235 | } | ||
236 | 236 | | |||
237 | bool isEmpty() const Q_DECL_OVERRIDE { | 237 | bool isEmpty() const override { | ||
238 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | 238 | QWidget* w = const_cast< MyWidgetItem * >( this )->widget(); | ||
239 | // legend->hide() should indeed hide the legend, | 239 | // legend->hide() should indeed hide the legend, | ||
240 | // but a legend in a chart that hasn't been shown yet isn't hidden | 240 | // but a legend in a chart that hasn't been shown yet isn't hidden | ||
241 | // (as can happen when using Chart::paint() without showing the chart) | 241 | // (as can happen when using Chart::paint() without showing the chart) | ||
242 | return w->isHidden() && w->testAttribute( Qt::WA_WState_ExplicitShowHide ); | 242 | return w->isHidden() && w->testAttribute( Qt::WA_WState_ExplicitShowHide ); | ||
243 | } | 243 | } | ||
244 | }; | 244 | }; | ||
245 | 245 | | |||
▲ Show 20 Lines • Show All 1528 Lines • Show Last 20 Lines |