Changeset View
Changeset View
Standalone View
Standalone View
qtests/DrawIntoPainter/mainwindow.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
53 | 53 | | |||
54 | 54 | | |||
55 | MainWindow::MainWindow( QWidget* parent ) : | 55 | MainWindow::MainWindow( QWidget* parent ) : | ||
56 | QWidget( parent ) | 56 | QWidget( parent ) | ||
57 | { | 57 | { | ||
58 | 58 | | |||
59 | setupUi( this ); | 59 | setupUi( this ); | ||
60 | 60 | | |||
61 | connect( lineTypeCB, SIGNAL(currentIndexChanged(QString)), this, SLOT(setLineType(QString)) ); | ||||
tbaumgart: Why don't you use the new functor based connections as in
```
connect( lineTypeCB, &QComboBox… | |||||
The corresponding overload of QComboBox::currentIndexChanged must be selected, and QOverload is the best way to do it: But QOverload was added in Qt 5.7 and KDiagram still requires only Qt 5.6. volkov: The corresponding overload of QComboBox::currentIndexChanged must be selected, and QOverload is… | |||||
tbaumgart: Makes sense. Thanks for clarifying. | |||||
62 | connect( paintLegendCB, SIGNAL(toggled(bool)), this, SLOT(setLegendVisible(bool)) ); | ||||
63 | connect( paintValuesCB, SIGNAL(toggled(bool)), this, SLOT(setValuesVisible(bool)) ); | ||||
64 | connect( paintMarkersCB, SIGNAL(toggled(bool)), this, SLOT(setMarkersVisible(bool)) ); | ||||
65 | connect( markersStyleCB, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMarkers()) ); | ||||
66 | connect( markersWidthSB, SIGNAL(valueChanged(int)), this, SLOT(updateMarkersHeight()) ); | ||||
67 | connect( markersHeightSB, SIGNAL(valueChanged(int)), this, SLOT(updateMarkersWidth()) ); | ||||
68 | connect( displayAreasCB, SIGNAL(toggled(bool)), this, SLOT(updateAreas(bool)) ); | ||||
69 | connect( transparencySB, SIGNAL(valueChanged(int)), this, SLOT(updateAreasTransparency()) ); | ||||
70 | connect( zoomFactorSB, SIGNAL(valueChanged(double)), this, SLOT(setZoomFactor(qreal)) ); | ||||
71 | connect( hSBar, SIGNAL(valueChanged(int)), this, SLOT(setHPos(int)) ); | ||||
72 | connect( vSBar, SIGNAL(valueChanged(int)), this, SLOT(setVPos(int)) ); | ||||
73 | connect( savePB, SIGNAL(clicked()), this, SLOT(saveChart()) ); | ||||
74 | | ||||
61 | QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame ); | 75 | QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame ); | ||
62 | #ifdef USE_FRAME_WIDGET | 76 | #ifdef USE_FRAME_WIDGET | ||
63 | FrameWidget* chartFrameWidget = new FrameWidget(); | 77 | FrameWidget* chartFrameWidget = new FrameWidget(); | ||
64 | chartLayout->addWidget( chartFrameWidget ); | 78 | chartLayout->addWidget( chartFrameWidget ); | ||
65 | #endif | 79 | #endif | ||
66 | hSBar->setVisible( false ); | 80 | hSBar->setVisible( false ); | ||
67 | vSBar->setVisible( false ); | 81 | vSBar->setVisible( false ); | ||
68 | 82 | | |||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 114 | #endif | |||
165 | 179 | | |||
166 | faChart.setPen( QPen(QColor(0xb0,0xb0,0xff), 8) ); | 180 | faChart.setPen( QPen(QColor(0xb0,0xb0,0xff), 8) ); | ||
167 | m_chart->setFrameAttributes( faChart ); | 181 | m_chart->setFrameAttributes( faChart ); | ||
168 | 182 | | |||
169 | // initialize attributes; this is necessary because we need to enable data value attributes before | 183 | // initialize attributes; this is necessary because we need to enable data value attributes before | ||
170 | // any of them (e.g. only markers) can be displayed. but if we enable data value attributs, a default | 184 | // any of them (e.g. only markers) can be displayed. but if we enable data value attributs, a default | ||
171 | // data value text is included, even if we only wanted to set markers. so we enable DVA and then | 185 | // data value text is included, even if we only wanted to set markers. so we enable DVA and then | ||
172 | // individually disable the parts we don't want. | 186 | // individually disable the parts we don't want. | ||
173 | on_paintValuesCB_toggled( false ); | 187 | setValuesVisible( false ); | ||
174 | on_paintMarkersCB_toggled( false ); | 188 | setMarkersVisible( false ); | ||
175 | } | 189 | } | ||
176 | 190 | | |||
177 | void MainWindow::updateData(QString data) | 191 | void MainWindow::updateData(QString data) | ||
178 | { | 192 | { | ||
179 | QTime t; | 193 | QTime t; | ||
180 | t.start(); | 194 | t.start(); | ||
181 | 195 | | |||
182 | m_model.loadFromCSV( data ); | 196 | m_model.loadFromCSV( data ); | ||
Show All 20 Lines | |||||
203 | m_smallChart1->show(); | 217 | m_smallChart1->show(); | ||
204 | m_smallChart2->show(); | 218 | m_smallChart2->show(); | ||
205 | 219 | | |||
206 | qDebug("Time for setting pixmap %s: %d ms", data.toLatin1().constData(), t.elapsed()); | 220 | qDebug("Time for setting pixmap %s: %d ms", data.toLatin1().constData(), t.elapsed()); | ||
207 | t.restart(); | 221 | t.restart(); | ||
208 | 222 | | |||
209 | } | 223 | } | ||
210 | 224 | | |||
211 | void MainWindow::on_lineTypeCB_currentIndexChanged( const QString & text ) | 225 | void MainWindow::setLineType( const QString & text ) | ||
212 | { | 226 | { | ||
213 | if ( text == "Normal" ) | 227 | if ( text == "Normal" ) | ||
214 | m_lines->setType( LineDiagram::Normal ); | 228 | m_lines->setType( LineDiagram::Normal ); | ||
215 | else if ( text == "Stacked" ) | 229 | else if ( text == "Stacked" ) | ||
216 | m_lines->setType( LineDiagram::Stacked ); | 230 | m_lines->setType( LineDiagram::Stacked ); | ||
217 | else if ( text == "Percent" ) | 231 | else if ( text == "Percent" ) | ||
218 | m_lines->setType( LineDiagram::Percent ); | 232 | m_lines->setType( LineDiagram::Percent ); | ||
219 | else | 233 | else | ||
220 | qWarning (" Does not match any type"); | 234 | qWarning (" Does not match any type"); | ||
221 | } | 235 | } | ||
222 | 236 | | |||
223 | void MainWindow::on_paintLegendCB_toggled( bool checked ) | 237 | void MainWindow::setLegendVisible(bool visible ) | ||
224 | { | 238 | { | ||
225 | KChart::Legend* legend = m_chart->legend(); | 239 | KChart::Legend* legend = m_chart->legend(); | ||
226 | if ( checked != ( legend != nullptr ) ) { | 240 | if ( visible != ( legend != nullptr ) ) { | ||
227 | if ( checked ) | 241 | if ( visible ) | ||
228 | m_chart->addLegend( m_legend ); | 242 | m_chart->addLegend( m_legend ); | ||
229 | else | 243 | else | ||
230 | m_chart->takeLegend( legend ); | 244 | m_chart->takeLegend( legend ); | ||
231 | } | 245 | } | ||
232 | } | 246 | } | ||
233 | 247 | | |||
234 | void MainWindow::on_paintValuesCB_toggled( bool checked ) | 248 | void MainWindow::setValuesVisible(bool visible ) | ||
235 | { | 249 | { | ||
236 | const int colCount = m_lines->model()->columnCount(); | 250 | const int colCount = m_lines->model()->columnCount(); | ||
237 | for ( int iColumn = 0; iColumn<colCount; ++iColumn ) { | 251 | for ( int iColumn = 0; iColumn<colCount; ++iColumn ) { | ||
238 | DataValueAttributes a = m_lines->dataValueAttributes( iColumn ); | 252 | DataValueAttributes a = m_lines->dataValueAttributes( iColumn ); | ||
239 | a.setVisible( true ); | 253 | a.setVisible( true ); | ||
240 | 254 | | |||
241 | TextAttributes ta = a.textAttributes(); | 255 | TextAttributes ta = a.textAttributes(); | ||
242 | ta.setRotation( 0 ); | 256 | ta.setRotation( 0 ); | ||
243 | ta.setFont( QFont( "Comic", 10 ) ); | 257 | ta.setFont( QFont( "Comic", 10 ) ); | ||
244 | ta.setPen( m_lines->brush( iColumn ).color() ); | 258 | ta.setPen( m_lines->brush( iColumn ).color() ); | ||
245 | ta.setVisible( checked ); | 259 | ta.setVisible( visible ); | ||
246 | 260 | | |||
247 | a.setTextAttributes( ta ); | 261 | a.setTextAttributes( ta ); | ||
248 | m_lines->setDataValueAttributes( iColumn, a); | 262 | m_lines->setDataValueAttributes( iColumn, a); | ||
249 | } | 263 | } | ||
250 | } | 264 | } | ||
251 | 265 | | |||
252 | 266 | | |||
253 | void MainWindow::on_paintMarkersCB_toggled( bool checked ) | 267 | void MainWindow::setMarkersVisible( bool visible ) | ||
254 | { | 268 | { | ||
255 | paintMarkers( checked, QSize() ); | 269 | paintMarkers( visible, QSize() ); | ||
256 | } | 270 | } | ||
257 | 271 | | |||
258 | void MainWindow::on_markersStyleCB_currentIndexChanged( const QString & text ) | 272 | void MainWindow::updateMarkers() | ||
259 | { | 273 | { | ||
260 | Q_UNUSED( text ); | 274 | setMarkersVisible( paintMarkersCB->isChecked() ); | ||
261 | on_paintMarkersCB_toggled( paintMarkersCB->isChecked() ); | | |||
262 | } | 275 | } | ||
263 | 276 | | |||
264 | 277 | void MainWindow::updateMarkersHeight() | |||
265 | void MainWindow::on_markersWidthSB_valueChanged( int i ) | | |||
266 | { | 278 | { | ||
267 | Q_UNUSED( i ); | | |||
268 | markersHeightSB->setValue( markersWidthSB->value() ); | 279 | markersHeightSB->setValue( markersWidthSB->value() ); | ||
269 | on_paintMarkersCB_toggled( paintMarkersCB->isChecked() ); | 280 | updateMarkers(); | ||
270 | } | 281 | } | ||
271 | 282 | | |||
272 | void MainWindow::on_markersHeightSB_valueChanged( int i ) | 283 | void MainWindow::updateMarkersWidth() | ||
273 | { | 284 | { | ||
274 | Q_UNUSED( i ); | | |||
275 | markersWidthSB->setValue( markersHeightSB->value() ); | 285 | markersWidthSB->setValue( markersHeightSB->value() ); | ||
276 | on_paintMarkersCB_toggled( paintMarkersCB->isChecked() ); | 286 | updateMarkers(); | ||
277 | } | 287 | } | ||
278 | 288 | | |||
279 | 289 | void MainWindow::updateAreas( bool visible ) | |||
280 | void MainWindow::on_displayAreasCB_toggled( bool checked ) | | |||
281 | { | 290 | { | ||
282 | const int colCount = m_lines->model()->columnCount(); | 291 | const int colCount = m_lines->model()->columnCount(); | ||
283 | for ( int iColumn = 0; iColumn<colCount; ++iColumn ) { | 292 | for ( int iColumn = 0; iColumn<colCount; ++iColumn ) { | ||
284 | LineAttributes la( m_lines->lineAttributes( iColumn ) ); | 293 | LineAttributes la( m_lines->lineAttributes( iColumn ) ); | ||
285 | la.setDisplayArea( checked ); | 294 | la.setDisplayArea( visible ); | ||
286 | if ( checked ) | 295 | if ( visible ) | ||
287 | la.setTransparency( transparencySB->value() ); | 296 | la.setTransparency( transparencySB->value() ); | ||
288 | m_lines->setLineAttributes( iColumn, la ); | 297 | m_lines->setLineAttributes( iColumn, la ); | ||
289 | } | 298 | } | ||
290 | } | 299 | } | ||
291 | 300 | | |||
292 | void MainWindow::on_transparencySB_valueChanged( int alpha ) | 301 | void MainWindow::updateAreasTransparency() | ||
293 | { | 302 | { | ||
294 | Q_UNUSED( alpha ); | | |||
295 | if ( !displayAreasCB->isChecked() ) | 303 | if ( !displayAreasCB->isChecked() ) | ||
296 | displayAreasCB->setChecked( true ); | 304 | displayAreasCB->setChecked( true ); | ||
297 | else | 305 | else | ||
298 | on_displayAreasCB_toggled( true ); | 306 | updateAreas( true ); | ||
299 | } | 307 | } | ||
300 | 308 | | |||
301 | void MainWindow::on_zoomFactorSB_valueChanged( qreal factor ) | 309 | void MainWindow::setZoomFactor( qreal factor ) | ||
302 | { | 310 | { | ||
303 | const bool isZoomedIn = factor > 1.0f; | 311 | const bool isZoomedIn = factor > 1.0f; | ||
304 | hSBar->setVisible( isZoomedIn ); | 312 | hSBar->setVisible( isZoomedIn ); | ||
305 | vSBar->setVisible( isZoomedIn ); | 313 | vSBar->setVisible( isZoomedIn ); | ||
306 | if ( !isZoomedIn ) { | 314 | if ( !isZoomedIn ) { | ||
307 | hSBar->setValue( 500 ); | 315 | hSBar->setValue( 500 ); | ||
308 | vSBar->setValue( 500 ); | 316 | vSBar->setValue( 500 ); | ||
309 | } | 317 | } | ||
310 | m_chart->coordinatePlane()->setZoomFactorX( factor ); | 318 | m_chart->coordinatePlane()->setZoomFactorX( factor ); | ||
311 | m_chart->coordinatePlane()->setZoomFactorY( factor ); | 319 | m_chart->coordinatePlane()->setZoomFactorY( factor ); | ||
312 | } | 320 | } | ||
313 | 321 | | |||
314 | void MainWindow::on_hSBar_valueChanged( int hPos ) | 322 | void MainWindow::setHPos( int hPos ) | ||
315 | { | 323 | { | ||
316 | m_chart->coordinatePlane()->setZoomCenter( QPointF(hPos/1000.0, vSBar->value()/1000.0) ); | 324 | m_chart->coordinatePlane()->setZoomCenter( QPointF(hPos/1000.0, vSBar->value()/1000.0) ); | ||
317 | m_chart->update(); | 325 | m_chart->update(); | ||
318 | } | 326 | } | ||
319 | 327 | | |||
320 | void MainWindow::on_vSBar_valueChanged( int vPos ) | 328 | void MainWindow::setVPos( int vPos ) | ||
321 | { | 329 | { | ||
322 | m_chart->coordinatePlane()->setZoomCenter( QPointF( hSBar->value()/1000.0, vPos/1000.0) ); | 330 | m_chart->coordinatePlane()->setZoomCenter( QPointF( hSBar->value()/1000.0, vPos/1000.0) ); | ||
323 | } | 331 | } | ||
324 | 332 | | |||
325 | // since DataValue markers have no relative sizing mode we need to scale them for printing | 333 | // since DataValue markers have no relative sizing mode we need to scale them for printing | ||
326 | void MainWindow::paintMarkers( bool checked, const QSize& printSize ) | 334 | void MainWindow::paintMarkers( bool checked, const QSize& printSize ) | ||
327 | { | 335 | { | ||
328 | MarkerAttributes::MarkerStylesMap map; | 336 | MarkerAttributes::MarkerStylesMap map; | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 398 | for ( int j=0; j< rowCount; ++j ) { | |||
394 | /* Set a specific color - marker for a specific value */ | 402 | /* Set a specific color - marker for a specific value */ | ||
395 | if ( value == 13 ) { | 403 | if ( value == 13 ) { | ||
396 | m_lines->setDataValueAttributes( index, yellowAttributes ); | 404 | m_lines->setDataValueAttributes( index, yellowAttributes ); | ||
397 | } | 405 | } | ||
398 | } | 406 | } | ||
399 | } | 407 | } | ||
400 | } | 408 | } | ||
401 | 409 | | |||
402 | void MainWindow::on_savePB_clicked() | 410 | void MainWindow::saveChart() | ||
403 | { | 411 | { | ||
404 | qDebug() << "Painting into PNG"; | 412 | qDebug() << "Painting into PNG"; | ||
405 | QPixmap qpix(600,600); | 413 | QPixmap qpix(600,600); | ||
406 | QPainter painter(&qpix); | 414 | QPainter painter(&qpix); | ||
407 | painter.setBrush(Qt::white); | 415 | painter.setBrush(Qt::white); | ||
408 | painter.fillRect( 0, 0, 600, 600, Qt::white); | 416 | painter.fillRect( 0, 0, 600, 600, Qt::white); | ||
409 | m_chart->paint( &painter, | 417 | m_chart->paint( &painter, | ||
410 | QRect(100, 100, 400, 400) ); | 418 | QRect(100, 100, 400, 400) ); | ||
Show All 14 Lines |
Why don't you use the new functor based connections as in