Add files from zip
This commit is contained in:
67
playground/timescale/MainWindow.cpp
Normal file
67
playground/timescale/MainWindow.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "Plot.h"
|
||||
#include "Panel.h"
|
||||
|
||||
#include <QwtDate>
|
||||
#include <QwtScaleWidget>
|
||||
|
||||
#include <QLayout>
|
||||
|
||||
MainWindow::MainWindow( QWidget* parent )
|
||||
: QMainWindow( parent )
|
||||
{
|
||||
Settings settings;
|
||||
#if 1
|
||||
settings.startDateTime = QDateTime( QDate( 2012, 10, 27 ), QTime( 18, 5, 0, 0 ) );
|
||||
settings.endDateTime = QDateTime( QDate( 2012, 10, 28 ), QTime( 12, 12, 0, 0 ) );
|
||||
#else
|
||||
settings.startDateTime = QDateTime( QDate( 2011, 5, 3 ), QTime( 0, 6, 0, 0 ) );
|
||||
settings.endDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 5, 0, 0 ) );
|
||||
#endif
|
||||
settings.maxMajorSteps = 10;
|
||||
settings.maxMinorSteps = 8;
|
||||
settings.maxWeeks = -1;
|
||||
|
||||
m_plot = new Plot();
|
||||
m_panel = new Panel();
|
||||
m_panel->setSettings( settings );
|
||||
|
||||
QWidget* box = new QWidget( this );
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout( box );
|
||||
layout->addWidget( m_plot, 10 );
|
||||
layout->addWidget( m_panel );
|
||||
|
||||
setCentralWidget( box );
|
||||
|
||||
updatePlot();
|
||||
|
||||
connect( m_panel, SIGNAL(edited()), SLOT(updatePlot()) );
|
||||
connect( m_plot->axisWidget( QwtAxis::YLeft ),
|
||||
SIGNAL(scaleDivChanged()), SLOT(updatePanel()) );
|
||||
}
|
||||
|
||||
void MainWindow::updatePlot()
|
||||
{
|
||||
m_plot->blockSignals( true );
|
||||
m_plot->applySettings( m_panel->settings() );
|
||||
m_plot->blockSignals( false );
|
||||
}
|
||||
|
||||
void MainWindow::updatePanel()
|
||||
{
|
||||
const QwtScaleDiv scaleDiv = m_plot->axisScaleDiv( QwtAxis::YLeft );
|
||||
|
||||
Settings settings = m_panel->settings();
|
||||
settings.startDateTime = QwtDate::toDateTime( scaleDiv.lowerBound(), Qt::LocalTime );
|
||||
settings.endDateTime = QwtDate::toDateTime( scaleDiv.upperBound(), Qt::LocalTime );
|
||||
|
||||
m_panel->setSettings( settings );
|
||||
}
|
||||
|
||||
#include "moc_MainWindow.cpp"
|
||||
27
playground/timescale/MainWindow.h
Normal file
27
playground/timescale/MainWindow.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class Plot;
|
||||
class Panel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow( QWidget* parent = 0 );
|
||||
|
||||
private Q_SLOTS:
|
||||
void updatePlot();
|
||||
void updatePanel();
|
||||
|
||||
private:
|
||||
Plot* m_plot;
|
||||
Panel* m_panel;
|
||||
};
|
||||
102
playground/timescale/Panel.cpp
Normal file
102
playground/timescale/Panel.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <QDateTimeEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
|
||||
Panel::Panel( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
// create widgets
|
||||
|
||||
m_startDateTime = new QDateTimeEdit();
|
||||
m_startDateTime->setDisplayFormat( "M/d/yyyy h:mm AP :zzz" );
|
||||
m_startDateTime->setCalendarPopup( true );
|
||||
|
||||
m_endDateTime = new QDateTimeEdit();
|
||||
m_endDateTime->setDisplayFormat( "M/d/yyyy h:mm AP :zzz" );
|
||||
m_endDateTime->setCalendarPopup( true );
|
||||
|
||||
m_maxMajorSteps = new QSpinBox();
|
||||
m_maxMajorSteps->setRange( 0, 50 );
|
||||
|
||||
m_maxMinorSteps = new QSpinBox();
|
||||
m_maxMinorSteps->setRange( 0, 50 );
|
||||
|
||||
m_maxWeeks = new QSpinBox();
|
||||
m_maxWeeks->setRange( -1, 100 );
|
||||
m_maxWeeks->setSpecialValueText( "Disabled" );
|
||||
|
||||
// layout
|
||||
|
||||
QGridLayout* layout = new QGridLayout( this );
|
||||
layout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
|
||||
|
||||
int row = 0;
|
||||
layout->addWidget( new QLabel( "From" ), row, 0 );
|
||||
layout->addWidget( m_startDateTime, row, 1 );
|
||||
|
||||
row++;
|
||||
layout->addWidget( new QLabel( "To" ), row, 0 );
|
||||
layout->addWidget( m_endDateTime, row, 1 );
|
||||
|
||||
row++;
|
||||
layout->addWidget( new QLabel( "Max. Major Steps" ), row, 0 );
|
||||
layout->addWidget( m_maxMajorSteps, row, 1 );
|
||||
|
||||
row++;
|
||||
layout->addWidget( new QLabel( "Max. Minor Steps" ), row, 0 );
|
||||
layout->addWidget( m_maxMinorSteps, row, 1 );
|
||||
|
||||
row++;
|
||||
layout->addWidget( new QLabel( "Max Weeks" ), row, 0 );
|
||||
layout->addWidget( m_maxWeeks, row, 1 );
|
||||
|
||||
connect( m_startDateTime,
|
||||
SIGNAL(dateTimeChanged(const QDateTime&)), SIGNAL(edited()) );
|
||||
connect( m_endDateTime,
|
||||
SIGNAL(dateTimeChanged(const QDateTime&)), SIGNAL(edited()) );
|
||||
connect( m_maxMajorSteps,
|
||||
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_maxMinorSteps,
|
||||
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_maxWeeks,
|
||||
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
|
||||
}
|
||||
|
||||
void Panel::setSettings( const Settings& settings )
|
||||
{
|
||||
blockSignals( true );
|
||||
|
||||
m_startDateTime->setDateTime( settings.startDateTime );
|
||||
m_endDateTime->setDateTime( settings.endDateTime );
|
||||
|
||||
m_maxMajorSteps->setValue( settings.maxMajorSteps );
|
||||
m_maxMinorSteps->setValue( settings.maxMinorSteps );
|
||||
m_maxWeeks->setValue( settings.maxWeeks );
|
||||
|
||||
blockSignals( false );
|
||||
}
|
||||
|
||||
Settings Panel::settings() const
|
||||
{
|
||||
Settings settings;
|
||||
|
||||
settings.startDateTime = m_startDateTime->dateTime();
|
||||
settings.endDateTime = m_endDateTime->dateTime();
|
||||
|
||||
settings.maxMajorSteps = m_maxMajorSteps->value();
|
||||
settings.maxMinorSteps = m_maxMinorSteps->value();
|
||||
settings.maxWeeks = m_maxWeeks->value();
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
#include "moc_Panel.cpp"
|
||||
34
playground/timescale/Panel.h
Normal file
34
playground/timescale/Panel.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.h"
|
||||
#include <QWidget>
|
||||
|
||||
class QDateTimeEdit;
|
||||
class QSpinBox;
|
||||
|
||||
class Panel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Panel( QWidget* parent = NULL );
|
||||
|
||||
void setSettings( const Settings&);
|
||||
Settings settings() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void edited();
|
||||
|
||||
private:
|
||||
QDateTimeEdit* m_startDateTime;
|
||||
QDateTimeEdit* m_endDateTime;
|
||||
|
||||
QSpinBox* m_maxMajorSteps;
|
||||
QSpinBox* m_maxMinorSteps;
|
||||
QSpinBox* m_maxWeeks;
|
||||
};
|
||||
97
playground/timescale/Plot.cpp
Normal file
97
playground/timescale/Plot.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plot.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <QwtDate>
|
||||
#include <QwtDateScaleDraw>
|
||||
#include <QwtDateScaleEngine>
|
||||
#include <QwtPlotPanner>
|
||||
#include <QwtPlotMagnifier>
|
||||
#include <QwtPlotGrid>
|
||||
#include <QwtPlotLayout>
|
||||
|
||||
Plot::Plot( QWidget* parent )
|
||||
: QwtPlot( parent )
|
||||
{
|
||||
setAutoFillBackground( true );
|
||||
setPalette( Qt::darkGray );
|
||||
setCanvasBackground( Qt::white );
|
||||
|
||||
plotLayout()->setAlignCanvasToScales( true );
|
||||
|
||||
initAxis( QwtAxis::YLeft, "Local Time", Qt::LocalTime );
|
||||
initAxis( QwtAxis::YRight,
|
||||
"Coordinated Universal Time ( UTC )", Qt::UTC );
|
||||
|
||||
QwtPlotPanner* panner = new QwtPlotPanner( canvas() );
|
||||
QwtPlotMagnifier* magnifier = new QwtPlotMagnifier( canvas() );
|
||||
|
||||
for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
|
||||
{
|
||||
const bool on = QwtAxis::isYAxis( axis );
|
||||
|
||||
setAxisVisible( axis, on );
|
||||
panner->setAxisEnabled( axis, on );
|
||||
magnifier->setAxisEnabled( axis, on );
|
||||
}
|
||||
|
||||
QwtPlotGrid* grid = new QwtPlotGrid();
|
||||
grid->setMajorPen( Qt::black, 0, Qt::SolidLine );
|
||||
grid->setMinorPen( Qt::gray, 0, Qt::SolidLine );
|
||||
grid->enableX( false );
|
||||
grid->enableXMin( false );
|
||||
grid->enableY( true );
|
||||
grid->enableYMin( true );
|
||||
|
||||
grid->attach( this );
|
||||
}
|
||||
|
||||
void Plot::initAxis( int axis,
|
||||
const QString& title, Qt::TimeSpec timeSpec )
|
||||
{
|
||||
setAxisTitle( axis, title );
|
||||
|
||||
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( timeSpec );
|
||||
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine( timeSpec );
|
||||
|
||||
#if 0
|
||||
if ( timeSpec == Qt::LocalTime )
|
||||
{
|
||||
scaleDraw->setTimeSpec( Qt::OffsetFromUTC );
|
||||
scaleDraw->setUtcOffset( 10 );
|
||||
|
||||
scaleEngine->setTimeSpec( Qt::OffsetFromUTC );
|
||||
scaleEngine->setUtcOffset( 10 );
|
||||
}
|
||||
#endif
|
||||
setAxisScaleDraw( axis, scaleDraw );
|
||||
setAxisScaleEngine( axis, scaleEngine );
|
||||
}
|
||||
|
||||
void Plot::applySettings( const Settings& settings )
|
||||
{
|
||||
applyAxisSettings( QwtAxis::YLeft, settings );
|
||||
applyAxisSettings( QwtAxis::YRight, settings );
|
||||
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::applyAxisSettings( int axis, const Settings& settings )
|
||||
{
|
||||
QwtDateScaleEngine* scaleEngine =
|
||||
static_cast< QwtDateScaleEngine* >( axisScaleEngine( axis ) );
|
||||
|
||||
scaleEngine->setMaxWeeks( settings.maxWeeks );
|
||||
setAxisMaxMinor( axis, settings.maxMinorSteps );
|
||||
setAxisMaxMajor( axis, settings.maxMajorSteps );
|
||||
|
||||
|
||||
setAxisScale( axis, QwtDate::toDouble( settings.startDateTime ),
|
||||
QwtDate::toDouble( settings.endDateTime ) );
|
||||
}
|
||||
|
||||
#include "moc_Plot.cpp"
|
||||
25
playground/timescale/Plot.h
Normal file
25
playground/timescale/Plot.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QwtPlot>
|
||||
|
||||
class Settings;
|
||||
|
||||
class Plot : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* parent = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
void applySettings( const Settings& );
|
||||
|
||||
private:
|
||||
void initAxis( int axis, const QString& title, Qt::TimeSpec );
|
||||
void applyAxisSettings( int axis, const Settings& );
|
||||
};
|
||||
27
playground/timescale/Settings.h
Normal file
27
playground/timescale/Settings.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
Settings()
|
||||
: maxMajorSteps( 10 )
|
||||
, maxMinorSteps( 5 )
|
||||
, maxWeeks( -1 )
|
||||
{
|
||||
};
|
||||
|
||||
QDateTime startDateTime;
|
||||
QDateTime endDateTime;
|
||||
|
||||
int maxMajorSteps;
|
||||
int maxMinorSteps;
|
||||
|
||||
int maxWeeks;
|
||||
};
|
||||
18
playground/timescale/main.cpp
Normal file
18
playground/timescale/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
MainWindow window;
|
||||
window.resize( 800, 600 );
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
20
playground/timescale/timescale.pro
Normal file
20
playground/timescale/timescale.pro
Normal file
@@ -0,0 +1,20 @@
|
||||
######################################################################
|
||||
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
# This file may be used under the terms of the 3-clause BSD License
|
||||
######################################################################
|
||||
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
TARGET = timescale
|
||||
|
||||
HEADERS = \
|
||||
Panel.h \
|
||||
Plot.h \
|
||||
MainWindow.h
|
||||
|
||||
SOURCES = \
|
||||
Panel.cpp \
|
||||
Plot.cpp \
|
||||
MainWindow.cpp \
|
||||
main.cpp
|
||||
|
||||
Reference in New Issue
Block a user