Released version 6.1.3
This commit is contained in:
		
				commit
				
					
						a94503cb82
					
				
			
		
					 1885 changed files with 276310 additions and 0 deletions
				
			
		
							
								
								
									
										57
									
								
								examples/tvplot/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								examples/tvplot/main.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,57 @@
 | 
			
		|||
#include <qapplication.h>
 | 
			
		||||
#include <qmainwindow.h>
 | 
			
		||||
#include <qtoolbar.h>
 | 
			
		||||
#include <qtoolbutton.h>
 | 
			
		||||
#include <qcombobox.h>
 | 
			
		||||
#include "tvplot.h"
 | 
			
		||||
 | 
			
		||||
class MainWindow: public QMainWindow
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    MainWindow( QWidget * = NULL );
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    TVPlot *d_plot;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MainWindow::MainWindow( QWidget *parent ):
 | 
			
		||||
    QMainWindow( parent )
 | 
			
		||||
{
 | 
			
		||||
    d_plot = new TVPlot( this );
 | 
			
		||||
    setCentralWidget( d_plot );
 | 
			
		||||
 | 
			
		||||
    QToolBar *toolBar = new QToolBar( this );
 | 
			
		||||
 | 
			
		||||
    QComboBox *typeBox = new QComboBox( toolBar );
 | 
			
		||||
    typeBox->addItem( "Outline" );
 | 
			
		||||
    typeBox->addItem( "Columns" );
 | 
			
		||||
    typeBox->addItem( "Lines" );
 | 
			
		||||
    typeBox->addItem( "Column Symbol" );
 | 
			
		||||
    typeBox->setCurrentIndex( typeBox->count() - 1 );
 | 
			
		||||
    typeBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
 | 
			
		||||
 | 
			
		||||
    QToolButton *btnExport = new QToolButton( toolBar );
 | 
			
		||||
    btnExport->setText( "Export" );
 | 
			
		||||
    btnExport->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
 | 
			
		||||
    connect( btnExport, SIGNAL( clicked() ), d_plot, SLOT( exportPlot() ) );
 | 
			
		||||
 | 
			
		||||
    toolBar->addWidget( typeBox );
 | 
			
		||||
    toolBar->addWidget( btnExport );
 | 
			
		||||
    addToolBar( toolBar );
 | 
			
		||||
 | 
			
		||||
    d_plot->setMode( typeBox->currentIndex() );
 | 
			
		||||
    connect( typeBox, SIGNAL( currentIndexChanged( int ) ),
 | 
			
		||||
             d_plot, SLOT( setMode( int ) ) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main( int argc, char **argv )
 | 
			
		||||
{
 | 
			
		||||
    QApplication a( argc, argv );
 | 
			
		||||
 | 
			
		||||
    MainWindow mainWindow;
 | 
			
		||||
 | 
			
		||||
    mainWindow.resize( 600, 400 );
 | 
			
		||||
    mainWindow.show();
 | 
			
		||||
 | 
			
		||||
    return a.exec();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										169
									
								
								examples/tvplot/tvplot.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								examples/tvplot/tvplot.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,169 @@
 | 
			
		|||
#include "tvplot.h"
 | 
			
		||||
#include <qwt_plot_layout.h>
 | 
			
		||||
#include <qwt_plot_canvas.h>
 | 
			
		||||
#include <qwt_plot_renderer.h>
 | 
			
		||||
#include <qwt_legend.h>
 | 
			
		||||
#include <qwt_legend_label.h>
 | 
			
		||||
#include <qwt_plot_grid.h>
 | 
			
		||||
#include <qwt_plot_histogram.h>
 | 
			
		||||
#include <qwt_column_symbol.h>
 | 
			
		||||
#include <qwt_series_data.h>
 | 
			
		||||
#include <qpen.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
class Histogram: public QwtPlotHistogram
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    Histogram( const QString &, const QColor & );
 | 
			
		||||
 | 
			
		||||
    void setColor( const QColor & );
 | 
			
		||||
    void setValues( uint numValues, const double * );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Histogram::Histogram( const QString &title, const QColor &symbolColor ):
 | 
			
		||||
    QwtPlotHistogram( title )
 | 
			
		||||
{
 | 
			
		||||
    setStyle( QwtPlotHistogram::Columns );
 | 
			
		||||
 | 
			
		||||
    setColor( symbolColor );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Histogram::setColor( const QColor &color )
 | 
			
		||||
{
 | 
			
		||||
    QColor c = color;
 | 
			
		||||
    c.setAlpha( 180 );
 | 
			
		||||
    setBrush( QBrush( c ) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Histogram::setValues( uint numValues, const double *values )
 | 
			
		||||
{
 | 
			
		||||
    QVector<QwtIntervalSample> samples( numValues );
 | 
			
		||||
    for ( uint i = 0; i < numValues; i++ )
 | 
			
		||||
    {
 | 
			
		||||
        QwtInterval interval( double( i ), i + 1.0 );
 | 
			
		||||
        interval.setBorderFlags( QwtInterval::ExcludeMaximum );
 | 
			
		||||
 | 
			
		||||
        samples[i] = QwtIntervalSample( values[i], interval );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setData( new QwtIntervalSeriesData( samples ) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TVPlot::TVPlot( QWidget *parent ):
 | 
			
		||||
    QwtPlot( parent )
 | 
			
		||||
{
 | 
			
		||||
    setTitle( "Watching TV during a weekend" );
 | 
			
		||||
 | 
			
		||||
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
 | 
			
		||||
    canvas->setPalette( Qt::gray );
 | 
			
		||||
    canvas->setBorderRadius( 10 );
 | 
			
		||||
    setCanvas( canvas );
 | 
			
		||||
 | 
			
		||||
    plotLayout()->setAlignCanvasToScales( true );
 | 
			
		||||
 | 
			
		||||
    setAxisTitle( QwtPlot::yLeft, "Number of People" );
 | 
			
		||||
    setAxisTitle( QwtPlot::xBottom, "Number of Hours" );
 | 
			
		||||
 | 
			
		||||
    QwtLegend *legend = new QwtLegend;
 | 
			
		||||
    legend->setDefaultItemMode( QwtLegendData::Checkable );
 | 
			
		||||
    insertLegend( legend, QwtPlot::RightLegend );
 | 
			
		||||
 | 
			
		||||
    populate();
 | 
			
		||||
 | 
			
		||||
    connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
 | 
			
		||||
        SLOT( showItem( const QVariant &, bool ) ) );
 | 
			
		||||
 | 
			
		||||
    replot(); // creating the legend items
 | 
			
		||||
 | 
			
		||||
    QwtPlotItemList items = itemList( QwtPlotItem::Rtti_PlotHistogram );
 | 
			
		||||
    for ( int i = 0; i < items.size(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
        if ( i == 0 )
 | 
			
		||||
        {
 | 
			
		||||
            const QVariant itemInfo = itemToInfo( items[i] );
 | 
			
		||||
 | 
			
		||||
            QwtLegendLabel *legendLabel =
 | 
			
		||||
                qobject_cast<QwtLegendLabel *>( legend->legendWidget( itemInfo ) );
 | 
			
		||||
            if ( legendLabel )
 | 
			
		||||
                legendLabel->setChecked( true );
 | 
			
		||||
 | 
			
		||||
            items[i]->setVisible( true );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            items[i]->setVisible( false );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setAutoReplot( true );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVPlot::populate()
 | 
			
		||||
{
 | 
			
		||||
    QwtPlotGrid *grid = new QwtPlotGrid;
 | 
			
		||||
    grid->enableX( false );
 | 
			
		||||
    grid->enableY( true );
 | 
			
		||||
    grid->enableXMin( false );
 | 
			
		||||
    grid->enableYMin( false );
 | 
			
		||||
    grid->setMajorPen( Qt::black, 0, Qt::DotLine );
 | 
			
		||||
    grid->attach( this );
 | 
			
		||||
 | 
			
		||||
    const double juneValues[] = { 7, 19, 24, 32, 10, 5, 3 };
 | 
			
		||||
    const double novemberValues[] = { 4, 15, 22, 34, 13, 8, 4 };
 | 
			
		||||
 | 
			
		||||
    Histogram *histogramJune = new Histogram( "Summer", Qt::red );
 | 
			
		||||
    histogramJune->setValues(
 | 
			
		||||
        sizeof( juneValues ) / sizeof( double ), juneValues );
 | 
			
		||||
    histogramJune->attach( this );
 | 
			
		||||
 | 
			
		||||
    Histogram *histogramNovember = new Histogram( "Winter", Qt::blue );
 | 
			
		||||
    histogramNovember->setValues(
 | 
			
		||||
        sizeof( novemberValues ) / sizeof( double ), novemberValues );
 | 
			
		||||
    histogramNovember->attach( this );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVPlot::exportPlot()
 | 
			
		||||
{
 | 
			
		||||
    QwtPlotRenderer renderer;
 | 
			
		||||
    renderer.exportTo( this, "tvplot.pdf" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVPlot::setMode( int mode )
 | 
			
		||||
{
 | 
			
		||||
    QwtPlotItemList items = itemList( QwtPlotItem::Rtti_PlotHistogram );
 | 
			
		||||
 | 
			
		||||
    for ( int i = 0; i < items.size(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
        QwtPlotHistogram *histogram = static_cast<QwtPlotHistogram *>( items[i] );
 | 
			
		||||
        if ( mode < 3 )
 | 
			
		||||
        {
 | 
			
		||||
            histogram->setStyle( static_cast<QwtPlotHistogram::HistogramStyle>( mode ) );
 | 
			
		||||
            histogram->setSymbol( NULL );
 | 
			
		||||
 | 
			
		||||
            QPen pen( Qt::black, 0 );
 | 
			
		||||
            if ( mode == QwtPlotHistogram::Lines )
 | 
			
		||||
                pen.setBrush( histogram->brush() );
 | 
			
		||||
 | 
			
		||||
            histogram->setPen( pen );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            histogram->setStyle( QwtPlotHistogram::Columns );
 | 
			
		||||
 | 
			
		||||
            QwtColumnSymbol *symbol = new QwtColumnSymbol( QwtColumnSymbol::Box );
 | 
			
		||||
            symbol->setFrameStyle( QwtColumnSymbol::Raised );
 | 
			
		||||
            symbol->setLineWidth( 2 );
 | 
			
		||||
            symbol->setPalette( QPalette( histogram->brush().color() ) );
 | 
			
		||||
 | 
			
		||||
            histogram->setSymbol( symbol );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVPlot::showItem( const QVariant &itemInfo, bool on )
 | 
			
		||||
{
 | 
			
		||||
    QwtPlotItem *plotItem = infoToItem( itemInfo );
 | 
			
		||||
    if ( plotItem )
 | 
			
		||||
        plotItem->setVisible( on );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								examples/tvplot/tvplot.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								examples/tvplot/tvplot.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
#ifndef _TV_PLOT_H_
 | 
			
		||||
 | 
			
		||||
#include <qwt_plot.h>
 | 
			
		||||
 | 
			
		||||
class TVPlot: public QwtPlot
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    TVPlot( QWidget * = NULL );
 | 
			
		||||
 | 
			
		||||
public Q_SLOTS:
 | 
			
		||||
    void setMode( int );
 | 
			
		||||
    void exportPlot();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void populate();
 | 
			
		||||
 | 
			
		||||
private Q_SLOTS:
 | 
			
		||||
    void showItem( const QVariant &, bool on );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										19
									
								
								examples/tvplot/tvplot.pro
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								examples/tvplot/tvplot.pro
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
################################################################
 | 
			
		||||
# 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}/../examples.pri )
 | 
			
		||||
 | 
			
		||||
TARGET   = tvplot
 | 
			
		||||
 | 
			
		||||
SOURCES = \
 | 
			
		||||
    tvplot.cpp \
 | 
			
		||||
    main.cpp
 | 
			
		||||
 | 
			
		||||
HEADERS = \
 | 
			
		||||
    tvplot.h
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue