Debian Codegraph @

qwt/playground/timescale/MainWindow.cpp

raw
1 /*****************************************************************************
2 * Qwt Examples - Copyright (C) 2002 Uwe Rathmann
3 * This file may be used under the terms of the 3-clause BSD License
4 *****************************************************************************/
5
6 #include "MainWindow.h"
7 #include "Plot.h"
8 #include "Panel.h"
9
10 #include <QwtDate>
11 #include <QwtScaleWidget>
12
13 #include <QLayout>
14
15 MainWindow::MainWindow( QWidget* parent )
16 : QMainWindow( parent )
17 {
18 Settings settings;
19 #if 1
20 settings.startDateTime = QDateTime( QDate( 2012, 10, 27 ), QTime( 18, 5, 0, 0 ) );
21 settings.endDateTime = QDateTime( QDate( 2012, 10, 28 ), QTime( 12, 12, 0, 0 ) );
22 #else
23 settings.startDateTime = QDateTime( QDate( 2011, 5, 3 ), QTime( 0, 6, 0, 0 ) );
24 settings.endDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 5, 0, 0 ) );
25 #endif
26 settings.maxMajorSteps = 10;
27 settings.maxMinorSteps = 8;
28 settings.maxWeeks = -1;
29
30 m_plot = new Plot();
31 m_panel = new Panel();
32 m_panel->setSettings( settings );
33
34 QWidget* box = new QWidget( this );
35
36 QHBoxLayout* layout = new QHBoxLayout( box );
37 layout->addWidget( m_plot, 10 );
38 layout->addWidget( m_panel );
39
40 setCentralWidget( box );
41
42 updatePlot();
43
44 connect( m_panel, SIGNAL(edited()), SLOT(updatePlot()) );
45 connect( m_plot->axisWidget( QwtAxis::YLeft ),
46 SIGNAL(scaleDivChanged()), SLOT(updatePanel()) );
47 }
48
49 void MainWindow::updatePlot()
50 {
51 m_plot->blockSignals( true );
52 m_plot->applySettings( m_panel->settings() );
53 m_plot->blockSignals( false );
54 }
55
56 void MainWindow::updatePanel()
57 {
58 const QwtScaleDiv scaleDiv = m_plot->axisScaleDiv( QwtAxis::YLeft );
59
60 Settings settings = m_panel->settings();
61 settings.startDateTime = QwtDate::toDateTime( scaleDiv.lowerBound(), Qt::LocalTime );
62 settings.endDateTime = QwtDate::toDateTime( scaleDiv.upperBound(), Qt::LocalTime );
63
64 m_panel->setSettings( settings );
65 }
66
67 #include "moc_MainWindow.cpp"