Released version 6.1.3

This commit is contained in:
Wodann 2018-08-02 11:01:31 -04:00
commit a94503cb82
1885 changed files with 276310 additions and 0 deletions

View file

@ -0,0 +1,15 @@
#include <qapplication.h>
#include "mainwindow.h"
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MainWindow mainWindow;
mainWindow.resize( 800, 600 );
mainWindow.show();
return a.exec();
}

View file

@ -0,0 +1,146 @@
#include <cstdlib>
#include <qgroupbox.h>
#include <qcombobox.h>
#include <qlayout.h>
#include <qstatusbar.h>
#include <qlabel.h>
#include <qwt_plot.h>
#include <qwt_plot_rescaler.h>
#include <qwt_scale_div.h>
#include "plot.h"
#include "mainwindow.h"
MainWindow::MainWindow()
{
QFrame *w = new QFrame( this );
QWidget *panel = createPanel( w );
panel->setFixedWidth( 2 * panel->sizeHint().width() );
d_plot = createPlot( w );
QHBoxLayout *layout = new QHBoxLayout( w );
layout->setMargin( 0 );
layout->addWidget( panel, 0 );
layout->addWidget( d_plot, 10 );
setCentralWidget( w );
setRescaleMode( 0 );
( void )statusBar();
}
QWidget *MainWindow::createPanel( QWidget *parent )
{
QGroupBox *panel = new QGroupBox( "Navigation Panel", parent );
QComboBox *rescaleBox = new QComboBox( panel );
rescaleBox->setEditable( false );
rescaleBox->insertItem( KeepScales, "None" );
rescaleBox->insertItem( Fixed, "Fixed" );
rescaleBox->insertItem( Expanding, "Expanding" );
rescaleBox->insertItem( Fitting, "Fitting" );
connect( rescaleBox, SIGNAL( activated( int ) ), SLOT( setRescaleMode( int ) ) );
d_rescaleInfo = new QLabel( panel );
d_rescaleInfo->setSizePolicy(
QSizePolicy::Expanding, QSizePolicy::Expanding );
d_rescaleInfo->setWordWrap( true );
QVBoxLayout *layout = new QVBoxLayout( panel );
layout->addWidget( rescaleBox );
layout->addWidget( d_rescaleInfo );
layout->addStretch( 10 );
return panel;
}
Plot *MainWindow::createPlot( QWidget *parent )
{
Plot *plot = new Plot( parent, QwtInterval( 0.0, 1000.0 ) );
plot->replot();
d_rescaler = new QwtPlotRescaler( plot->canvas() );
d_rescaler->setReferenceAxis( QwtPlot::xBottom );
d_rescaler->setAspectRatio( QwtPlot::yLeft, 1.0 );
d_rescaler->setAspectRatio( QwtPlot::yRight, 0.0 );
d_rescaler->setAspectRatio( QwtPlot::xTop, 0.0 );
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
d_rescaler->setIntervalHint( axis, QwtInterval( 0.0, 1000.0 ) );
connect( plot, SIGNAL( resized( double, double ) ),
SLOT( showRatio( double, double ) ) );
return plot;
}
void MainWindow::setRescaleMode( int mode )
{
bool doEnable = true;
QString info;
QRectF rectOfInterest;
QwtPlotRescaler::ExpandingDirection direction = QwtPlotRescaler::ExpandUp;
switch( mode )
{
case KeepScales:
{
doEnable = false;
info = "All scales remain unchanged, when the plot is resized";
break;
}
case Fixed:
{
d_rescaler->setRescalePolicy( QwtPlotRescaler::Fixed );
info = "The scale of the bottom axis remains unchanged, "
"when the plot is resized. All other scales are changed, "
"so that a pixel on screen means the same distance for"
"all scales.";
break;
}
case Expanding:
{
d_rescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
info = "The scales of all axis are shrinked/expanded, when "
"resizing the plot, keeping the distance that is represented "
"by one pixel.";
d_rescaleInfo->setText( "Expanding" );
break;
}
case Fitting:
{
d_rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
const QwtInterval xIntv =
d_rescaler->intervalHint( QwtPlot::xBottom );
const QwtInterval yIntv =
d_rescaler->intervalHint( QwtPlot::yLeft );
rectOfInterest = QRectF( xIntv.minValue(), yIntv.minValue(),
xIntv.width(), yIntv.width() );
direction = QwtPlotRescaler::ExpandBoth;
info = "Fitting";
break;
}
}
d_plot->setRectOfInterest( rectOfInterest );
d_rescaleInfo->setText( info );
d_rescaler->setEnabled( doEnable );
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
d_rescaler->setExpandingDirection( direction );
if ( doEnable )
d_rescaler->rescale();
else
d_plot->replot();
}
void MainWindow::showRatio( double xRatio, double yRatio )
{
const QString msg = QString( "%1, %2" ).arg( xRatio ).arg( yRatio );
statusBar()->showMessage( msg );
}

View file

@ -0,0 +1,39 @@
#ifndef _MAINWINDOW_H_
#define _MAINWINDOW_H_ 1
#include <qmainwindow.h>
class QwtPlotRescaler;
class QLabel;
class Plot;
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
enum RescaleMode
{
KeepScales,
Fixed,
Expanding,
Fitting
};
MainWindow();
private Q_SLOTS:
void setRescaleMode( int );
void showRatio( double, double );
private:
QWidget *createPanel( QWidget * );
Plot *createPlot( QWidget * );
QwtPlotRescaler *d_rescaler;
QLabel *d_rescaleInfo;
Plot *d_plot;
};
#endif

View file

@ -0,0 +1,181 @@
#include "plot.h"
#include <qglobal.h>
#include <qpainter.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_layout.h>
#include <qwt_interval.h>
#include <qwt_painter.h>
#include <qwt_plot_item.h>
class TextItem: public QwtPlotItem
{
public:
void setText( const QString &text )
{
m_text = text;
}
virtual void draw( QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &,
const QRectF &canvasRect ) const
{
const int margin = 5;
const QRectF textRect =
canvasRect.adjusted( margin, margin, -margin, -margin );
painter->setPen( Qt::white );
painter->drawText( textRect,
Qt::AlignBottom | Qt::AlignRight, m_text );
}
private:
QString m_text;
};
// RectItem shows how to implement a simple plot item,
// what wouldn't be necessary as QwtPlotShapeItem
// would do the same
class RectItem: public QwtPlotItem
{
public:
enum Type
{
Rect,
Ellipse
};
RectItem( Type type ):
d_type( type )
{
}
void setPen( const QPen &pen )
{
if ( pen != d_pen )
{
d_pen = pen;
itemChanged();
}
}
void setBrush( const QBrush &brush )
{
if ( brush != d_brush )
{
d_brush = brush;
itemChanged();
}
}
void setRect( const QRectF &rect )
{
if ( d_rect != rect )
{
d_rect = rect;
itemChanged();
}
}
virtual QRectF boundingRect() const
{
return d_rect;
}
virtual void draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF & ) const
{
if ( d_rect.isValid() )
{
const QRectF rect = QwtScaleMap::transform(
xMap, yMap, d_rect );
painter->setPen( d_pen );
painter->setBrush( d_brush );
if ( d_type == Ellipse )
QwtPainter::drawEllipse( painter, rect );
else
QwtPainter::drawRect( painter, rect );
}
}
private:
QPen d_pen;
QBrush d_brush;
QRectF d_rect;
Type d_type;
};
Plot::Plot( QWidget *parent, const QwtInterval &interval ):
QwtPlot( parent )
{
for ( int axis = 0; axis < QwtPlot::axisCnt; axis ++ )
setAxisScale( axis, interval.minValue(), interval.maxValue() );
setCanvasBackground( QColor( Qt::darkBlue ) );
plotLayout()->setAlignCanvasToScales( true );
// grid
QwtPlotGrid *grid = new QwtPlotGrid;
//grid->enableXMin(true);
grid->setMajorPen( Qt::white, 0, Qt::DotLine );
grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
grid->attach( this );
const int numEllipses = 10;
for ( int i = 0; i < numEllipses; i++ )
{
const double x = interval.minValue() +
qrand() % qRound( interval.width() );
const double y = interval.minValue() +
qrand() % qRound( interval.width() );
const double r = interval.minValue() +
qrand() % qRound( interval.width() / 6 );
const QRectF area( x - r, y - r , 2 * r, 2 * r );
RectItem *item = new RectItem( RectItem::Ellipse );
item->setRenderHint( QwtPlotItem::RenderAntialiased, true );
item->setRect( area );
item->setPen( QPen( Qt::yellow ) );
item->attach( this );
}
TextItem *textItem = new TextItem();
textItem->setText( "Navigation Example" );
textItem->attach( this );
d_rectOfInterest = new RectItem( RectItem::Rect );
d_rectOfInterest->setPen( Qt::NoPen );
QColor c = Qt::gray;
c.setAlpha( 100 );
d_rectOfInterest->setBrush( QBrush( c ) );
d_rectOfInterest->attach( this );
}
void Plot::updateLayout()
{
QwtPlot::updateLayout();
const QwtScaleMap xMap = canvasMap( QwtPlot::xBottom );
const QwtScaleMap yMap = canvasMap( QwtPlot::yLeft );
const QRect cr = canvas()->contentsRect();
const double x1 = xMap.invTransform( cr.left() );
const double x2 = xMap.invTransform( cr.right() );
const double y1 = yMap.invTransform( cr.bottom() );
const double y2 = yMap.invTransform( cr.top() );
const double xRatio = ( x2 - x1 ) / cr.width();
const double yRatio = ( y2 - y1 ) / cr.height();
Q_EMIT resized( xRatio, yRatio );
}
void Plot::setRectOfInterest( const QRectF &rect )
{
d_rectOfInterest->setRect( rect );
}

View file

@ -0,0 +1,28 @@
#ifndef _PLOT_H_
#define _PLOT_H_ 1
#include <qwt_plot.h>
class RectItem;
class QwtInterval;
class Plot: public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget *parent, const QwtInterval & );
virtual void updateLayout();
void setRectOfInterest( const QRectF & );
Q_SIGNALS:
void resized( double xRatio, double yRatio );
private:
RectItem *d_rectOfInterest;
};
#endif

View file

@ -0,0 +1,22 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = rescaler
HEADERS = \
mainwindow.h \
plot.h
SOURCES = \
mainwindow.cpp \
plot.cpp \
main.cpp