-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "Plot2d_Curve.h"
#include "Plot2d_PlotItems.h"
#include "Plot2d_FitDataDlg.h"
+#ifndef NO_SUIT
#include "Plot2d_ViewWindow.h"
+#endif
#include "Plot2d_SetupViewDlg.h"
+#ifndef NO_ANALYTICAL_CURVES
#include "Plot2d_AnalyticalCurveDlg.h"
#include "Plot2d_AnalyticalCurve.h"
+#endif
#include "Plot2d_ToolTip.h"
+#ifndef NO_SUIT
#include "SUIT_Tools.h"
#include "SUIT_Session.h"
#include "SUIT_MessageBox.h"
#include "SUIT_ResourceMgr.h"
#include "SUIT_Application.h"
+#else
+#include <QMessageBox>
+#endif
#include <QApplication>
#include <QToolBar>
#include <qwt_scale_engine.h>
#include <qwt_plot_zoomer.h>
#include <qwt_curve_fitter.h>
+#include <qwt_plot_renderer.h>
+#include <qwt_legend.h>
+#include <qwt_scale_widget.h>
#include <stdlib.h>
#include <limits>
-#include <qprinter.h>
-
-#include <qwt_legend.h>
-#include <qwt_scale_widget.h>
#define DEFAULT_LINE_WIDTH 0 // (default) line width
#define DEFAULT_MARKER_SIZE 9 // default marker size
#define FITALL_EVENT ( QEvent::User + 9999 )
-const char* imageZoomCursor[] = {
+const char* imageZoomCursor[] = {
"32 32 3 1",
". c None",
"a c #000000",
"................................",
"................................"};
-const char* imageCrossCursor[] = {
+const char* imageCrossCursor[] = {
"32 32 3 1",
". c None",
"a c #000000",
#undef min
#endif
#endif
-
+
/*!
Constructor
*/
Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
: QWidget (parent, 0),
- myOperation( NoOpId ),
- myCurveType( 1 ),
- myShowLegend( true ), myLegendPos( 1 ), myLegendFont("Helvetic",12),
- myLegendColor(Qt::black),
+ myOperation( NoOpId ),
+ myCurveType( 1 ),
+ myShowLegend( true ), myLegendPos( 1 ), myLegendSymbolType( 0 ), myLegendFont("Helvetic",12),
+ myLegendColor(Qt::black), mySelectedLegendFontColor( Qt::darkBlue ),
myMarkerSize( DEFAULT_MARKER_SIZE ),
myBackground( Qt::white ),
+ mySelectionColor( Qt::gray ),
myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
myTitleEnabled( true ), myXTitleEnabled( true ),
myYTitleEnabled( true ), myY2TitleEnabled (true),
- myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
+ myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
myRNormAlgo = new Plot2d_NormalizeAlgorithm(this);
myLNormAlgo = new Plot2d_NormalizeAlgorithm(this);
/* Plot 2d View */
- QVBoxLayout* aLayout = new QVBoxLayout( this );
+ QVBoxLayout* aLayout = new QVBoxLayout( this );
aLayout->setMargin(0);
myPlot = new Plot2d_Plot2d( this );
new Plot2d_ToolTip( this );
aLayout->addWidget( myPlot );
- // createActions();
- connect( myPlot, SIGNAL( legendClicked( QwtPlotItem* ) ),
- this, SIGNAL( legendClicked( QwtPlotItem* ) ) );
-
- // IPAL 21465
- /* connect( myPlot->axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ),
- myPlot, SLOT( onScaleDivChanged() ) );
- connect( myPlot->axisWidget( QwtPlot::yLeft ), SIGNAL( scaleDivChanged() ),
- myPlot, SLOT( onScaleDivChanged() ) );
- if (mySecondY)
- connect( myPlot->axisWidget( QwtPlot::yRight ), SIGNAL( scaleDivChanged() ),
- myPlot, SLOT( onScaleDivChanged() ) );*/
-
+#ifndef NO_SUIT
+ Init();
+#endif
+}
+/*!
+ Destructor
+*/
+Plot2d_ViewFrame::~Plot2d_ViewFrame()
+{
+}
+/*!
+ Performs the initial setup.
+*/
+void Plot2d_ViewFrame::Init()
+{
/* Initial Setup - get from the preferences */
readPreferences();
- myPlot->setMargin( 5 );
setCurveType( myCurveType, false );
setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
setHorScaleMode( myXMode, false );
setVerScaleMode( myYMode, false );
setBackgroundColor( myBackground );
+ setSelectionColor( mySelectionColor );
setLegendPos( myLegendPos );
+ setLegendSymbolType( myLegendSymbolType );
setLegendFont( myLegendFont );
setLegendFontColor( myLegendColor );
+ setSelectedLegendFontColor( mySelectedLegendFontColor );
showLegend( myShowLegend, false );
myPlot->replot();
- if ( parent ) {
- resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) );
+ QWidget* aParent = parentWidget();
+ if ( aParent ) {
+ resize( (int)(0.8 * aParent->width()), (int)(0.8 * aParent->height()) );
}
QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
}
myPlot->canvas()->installEventFilter( this );
}
-/*!
- Destructor
-*/
-Plot2d_ViewFrame::~Plot2d_ViewFrame()
+void Plot2d_ViewFrame::SetPreference()
{
+ readPreferences();
+ setBackgroundColor( myBackground );
+ setSelectionColor( mySelectionColor );
+ setCurveType( myCurveType, true );
+ setMarkerSize( myMarkerSize, true );
+ showLegend( myShowLegend, true );
+ setLegendPos( myLegendPos );
+ setLegendSymbolType( myLegendSymbolType );
+ setLegendFont( myLegendFont );
+ setLegendFontColor( myLegendColor );
+ setSelectedLegendFontColor( mySelectedLegendFontColor );
+ myPlot->replot();
}
/*!
Gets window's central widget
/*!
Removes all curves from the view
*/
-void Plot2d_ViewFrame::EraseAll()
+void Plot2d_ViewFrame::EraseAll()
{
objectList anObjects;
getObjects( anObjects );
myIntermittentSegmentList.clear();
}
- // 2)- Erase all curves points markers
-
- int nbMark = myMarkerList.size();
- if (nbMark > 0)
- {
- for (int imar=0; imar < nbMark; imar++)
- {
- QwtPlotMarker *marker = myMarkerList[imar];
-
- marker->detach(); // erase in QwtPlot window
- delete marker;
- }
- myMarkerList.clear();
- }
-
- // The graphic view's picker
- Plot2d_QwtPlotPicker *picker = myPlot->getPicker();
-
- // Clear points markers list and associations (marker,tooltip)
- if ( picker ) {
- picker->pMarkers.clear(); // QList<QwtPlotMarker*>
- picker->pMarkersToolTip.clear(); // QMap<QwtPlotMarker*, QwtText>
- }
-
// 3)- Erase all QwtPlotCurve associated with the Plot2d_Curve
int nbCur1 = myQwtPlotCurveList.size();
*/
void Plot2d_ViewFrame::readPreferences()
{
+#ifndef NO_SUIT
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
+ myLegendSymbolType = resMgr->integerValue( "Plot2d", "LegendSymbolType", myLegendSymbolType );
myLegendFont = resMgr->fontValue( "Plot2d", "LegendFont", myLegendFont );
myLegendColor = resMgr->colorValue( "Plot2d", "LegendFontColor", myLegendColor );
+ mySelectedLegendFontColor = resMgr->colorValue( "Plot2d", "SelectedLegendFontColor", mySelectedLegendFontColor );
myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
+ mySelectionColor = resMgr->colorValue( "Plot2d", "SelectionColor", mySelectionColor );
myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
setNormRMaxMode( resMgr->booleanValue( "Plot2d", "VerNormRMaxMode", myNormRMax ) );
QColor c = resMgr->colorValue( "Plot2d", "DeviationMarkerColor", QColor(255,0,0));
myPlot->setProperty(PLOT2D_DEVIATION_COLOR, c);
- myPlot->setProperty(PLOT2D_DEVIATION_LW,
+ myPlot->setProperty(PLOT2D_DEVIATION_LW,
resMgr->integerValue( "Plot2d", "DeviationMarkerLineWidth", 1));
- myPlot->setProperty(PLOT2D_DEVIATION_TS,
+ myPlot->setProperty(PLOT2D_DEVIATION_TS,
resMgr->integerValue( "Plot2d", "DeviationMarkerTickSize", 2));
-
+#endif
}
/*!
*/
void Plot2d_ViewFrame::writePreferences()
{
+#ifndef NO_SUIT
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
resMgr->setValue( "Plot2d", "CurveType", myCurveType );
resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
+ resMgr->setValue( "Plot2d", "LegendSymbolType", myLegendSymbolType );
resMgr->setValue( "Plot2d", "LegendFont", myLegendFont );
resMgr->setValue( "Plot2d", "LegendFontColor", myLegendColor );
+ resMgr->setValue( "Plot2d", "SelectedLegendFontColor", mySelectedLegendFontColor );
resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
resMgr->setValue( "Plot2d", "Background", myBackground );
+ resMgr->setValue( "Plot2d", "SelectionColor", mySelectionColor );
resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
+ resMgr->setValue( "Plot2d", "DeviationMarkerColor", myPlot->property(PLOT2D_DEVIATION_COLOR).value<QColor>() );
+ resMgr->setValue( "Plot2d", "DeviationMarkerLineWidth", myPlot->property(PLOT2D_DEVIATION_LW).toInt() );
+ resMgr->setValue( "Plot2d", "DeviationMarkerTickSize", myPlot->property(PLOT2D_DEVIATION_TS).toInt() );
if ( mySecondY )
resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
resMgr->setValue( "Plot2d", "VerNormLMaxMode", myNormLMax );
resMgr->setValue( "Plot2d", "VerNormRMinMode", myNormRMin );
resMgr->setValue( "Plot2d", "VerNormRMaxMode", myNormRMax );
+#endif
}
/*!
Prints mouse cursor coordinates into string
*/
-QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
+QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
{
int i;
QwtValueList aTicks;
bool xFound = false, yFound = false;
double xCoord, yCoord;
- const QwtScaleDiv* aXscale = myPlot->axisScaleDiv( QwtPlot::xBottom );
- aTicks = aXscale->ticks( QwtScaleDiv::MajorTick );
+ const QwtScaleDiv& aXscale = myPlot->axisScaleDiv( QwtPlot::xBottom );
+ aTicks = aXscale.ticks( QwtScaleDiv::MajorTick );
for ( i = 0; i < aTicks.count(); i++ ) {
double majXmark = aTicks[i];
int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
if ( xmark-2 == pnt.x() ) {
- xCoord = majXmark;
+ xCoord = majXmark;
xFound = true;
break;
}
}
if ( !xFound ) {
- aTicks = aXscale->ticks( QwtScaleDiv::MinorTick );
+ aTicks = aXscale.ticks( QwtScaleDiv::MinorTick );
for ( i = 0; i < aTicks.count(); i++ ) {
double minXmark = aTicks[i];
int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
if ( xmark-2 == pnt.x() ) {
- xCoord = minXmark;
+ xCoord = minXmark;
xFound = true;
break;
}
}
- }
- const QwtScaleDiv* aYscale = myPlot->axisScaleDiv( QwtPlot::yLeft );
- aTicks = aYscale->ticks( QwtScaleDiv::MajorTick );
+ }
+ const QwtScaleDiv& aYscale = myPlot->axisScaleDiv( QwtPlot::yLeft );
+ aTicks = aYscale.ticks( QwtScaleDiv::MajorTick );
for ( i = 0; i < aTicks.count(); i++ ) {
double majYmark = aTicks[i];
int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
if ( ymark-2 == pnt.y() ) {
- yCoord = majYmark;
+ yCoord = majYmark;
yFound = true;
break;
}
}
if ( !yFound ) {
- aTicks = aYscale->ticks( QwtScaleDiv::MinorTick );
+ aTicks = aYscale.ticks( QwtScaleDiv::MinorTick );
for ( i = 0; i < aTicks.count(); i++ ) {
double minYmark = aTicks[i];
int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
if ( ymark-2 == pnt.y() ) {
- yCoord = minYmark;
+ yCoord = minYmark;
yFound = true;
break;
}
}
- }
+ }
QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).trimmed();
if ( strX == "-0" )
bool yFound2 = false;
double yCoord2;
- const QwtScaleDiv* aYscale2 = myPlot->axisScaleDiv( QwtPlot::yRight );
- aTicks = aYscale2->ticks( QwtScaleDiv::MajorTick );
+ const QwtScaleDiv& aYscale2 = myPlot->axisScaleDiv( QwtPlot::yRight );
+ aTicks = aYscale2.ticks( QwtScaleDiv::MajorTick );
for ( i = 0; i < aTicks.count(); i++ ) {
double majYmark = aTicks[i];
int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
if ( ymark-2 == pnt.y() ) {
- yCoord2 = majYmark;
+ yCoord2 = majYmark;
yFound2 = true;
break;
}
}
if ( !yFound2 ) {
- aTicks = aYscale2->ticks( QwtScaleDiv::MinorTick );
+ aTicks = aYscale2.ticks( QwtScaleDiv::MinorTick );
for ( i = 0; i < aTicks.count(); i++ ) {
double minYmark = aTicks[i];
int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
if ( ymark-2 == pnt.y() ) {
- yCoord2 = minYmark;
+ yCoord2 = minYmark;
yFound2 = true;
break;
}
}
}
- QString strY2 = QString::number( yFound2 ? yCoord2 :
+ QString strY2 = QString::number( yFound2 ? yCoord2 :
myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).trimmed();
if ( strY2 == "-0" )
strY2 = "0";
// Total number of curves
// 1)- Construction of a list by component and by system
-
+
// | component 1 | component 2 | ..... | component M |
// | syst1 syst2 ... systN | syst1 syst2 ... systN | ..... | syst1 syst2 ... systN |
QwtScaleWidget *wid = myPlot->axisWidget( QwtPlot::xBottom);
wid->setTitle(" "); // to make the names readable under X axis.
QFont xFont = myPlot->axisFont(QwtPlot::xBottom);
- xFont.setPointSize(8);
+ xFont.setPointSize(8);
myPlot->setAxisFont(QwtPlot::xBottom, xFont);
return ret;
}
bool displayLegend, const QList< bool >& sides)
{
// Consider the new legend's entries
- // (PB: to update the legend we must remove it and put a new QwtLegend in the QwtPlot)
- myPlot->insertLegend( (QwtLegend*)NULL); // we remove here, we shall put at the end
+ // (PB: to update the legend we must remove it and put a new QwtAbstractLegend in the QwtPlot)
+ myPlot->insertLegend( (QwtAbstractLegend*)NULL); // we remove here, we shall put at the end
int nbAllCurves = curveList.size();
int nbGroups = nbAllCurves / groupSize;
icur2 = icur1 + groupSize -1;
// For all curves in one group
- double XgroupMin, XgroupMax;
- double YgroupMin, YgroupMax;
+ double XgroupMin = 0., XgroupMax = 0.;
+ double YgroupMin = 0., YgroupMax = 0.;
// For one curve
- double XcurveMin, XcurveMax;
- double YcurveMin, YcurveMax;
+ double XcurveMin = 0., XcurveMax = 0.;
+ double YcurveMin = 0., YcurveMax = 0.;
double *Xval;
double *Yval;
int nbPoints;
QwtSymbol::Style symbolStyle1 = plot2dCurve1->getMarkerStyle();
// We attribute to the current group's curve, the color, the line's kind
// and the marker's kind of the first group's curve
-
+
for (icur=icur1+1; icur<icur1+groupSize; icur++)
{
Plot2d_Curve *plot2dCurve = curveList.at(icur);
QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>(getPlotObject(plot2dCurve));
vectCurve[ig].push_back(plotCurve);
// Modify the points' markers
- QwtSymbol symbol(plotCurve->symbol()) ;
- symbol.setStyle(symbolStyle1);
- symbol.setPen(QPen(color1,lineWidth1));
+ QwtSymbol* symbol = new QwtSymbol(plotCurve->symbol()->style(), plotCurve->symbol()->brush(),
+ plotCurve->symbol()->pen(), plotCurve->symbol()->size()) ;
+ symbol->setStyle(symbolStyle1);
+ symbol->setPen(QPen(color1,lineWidth1));
//symbol.setBrush( QBrush( color1));
//QSize size = 0.5*(symbol.size());
//symbol.setSize(size);
int lineWidth,
QColor & lineColor,
QwtSymbol::Style markerKind,
- Plot2d_QwtPlotPicker* picker,
+ Plot2d_QwtPlotPicker* /*picker*/,
bool toDraw,
bool displayLegend)
{
{
if (!displayLegend)
{
- myPlot->insertLegend( (QwtLegend*)NULL);
+ myPlot->insertLegend( (QwtAbstractLegend*)NULL);
}
displayCurve( plot2dCurve);
}
// Modify points' markers
- QwtSymbol symbol (plotCurve->symbol()) ;
- symbol.setStyle( markerKind);
+ QwtSymbol* symbol = new QwtSymbol( plotCurve->symbol()->style(), plotCurve->symbol()->brush(),
+ plotCurve->symbol()->pen(), plotCurve->symbol()->size() ) ;
+ symbol->setStyle( markerKind );
//
if (markerKind != QwtSymbol::NoSymbol)
{
- symbol.setPen( QPen( theColor, lineWidth));
- symbol.setBrush( QBrush( theColor));
- QSize size = 2.0*(symbol.size()); //0.5
- symbol.setSize(size);
+ symbol->setPen( QPen( theColor, lineWidth));
+ symbol->setBrush( QBrush( theColor));
+ QSize size = 2.0*(symbol->size()); //0.5
+ symbol->setSize(size);
}
plotCurve->setSymbol( symbol);
QColor & lineColor,
QwtSymbol::Style markerKind, bool side)
{
- QwtPlotCurve* aPCurve = new QwtPlotCurve();
+ QwtPlotCurve* aPCurve = new QwtPlotCurve( QString::null );
- aPCurve->setData( X, Y, nbPoint);
+ aPCurve->setSamples( X, Y, nbPoint);
aPCurve->setPen( QPen( lineColor, lineWidth, lineKind));
- QwtSymbol aSymbol;
- aSymbol.setStyle( markerKind);
- aPCurve->setSymbol( aSymbol);
+ QwtSymbol* aSymbol = new QwtSymbol();
+ aSymbol->setStyle( markerKind );
+ aPCurve->setSymbol( aSymbol );
// The segment must not have legend's entry
aPCurve->setItemAttribute( QwtPlotItem::Legend, false);
updateObject( curve, update );
}
-void Plot2d_ViewFrame::processFiltering(bool update)
+void Plot2d_ViewFrame::processFiltering(bool update)
{
CurveDict aCurves = getCurves();
AlgoPlot2dInputData aLData, aRData;
// Normalization by left Y axis
if (!myNormLMin && !myNormLMax)
myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
- if(myNormLMin && myNormLMax)
+ if(myNormLMin && myNormLMax)
myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
else if(myNormLMin)
myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
// Normalization by right Y axis
if (!myNormRMin && !myNormRMax)
myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
- if(myNormRMin && myNormRMax)
+ if(myNormRMin && myNormRMax)
myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
else if(myNormRMin)
myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
QwtPlotItem* anItem = 0;
if ( !object )
return anItem;
-
+
if ( object->getYAxis() == QwtPlot::yRight )
mySecondY = true;
- // san -- Protection against QwtCurve bug in Qwt 0.4.x:
+ // san -- Protection against QwtCurve bug in Qwt 0.4.x:
// it crashes if switched to X/Y logarithmic mode, when one or more points have
// non-positive X/Y coordinate
if ( myXMode && object->getMinX() <= 0. )
if ( object->isAutoAssign() )
object->autoFill( myPlot );
-
+
if ( hasPlotObject( object ) ) {
processFiltering(update);
updateObject( object, update );
Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( object );
if ( aCurve )
{
- //myMarkerSize = 1;
- //aCurve->setMarkerSize( myMarkerSize );
-
- if (aCurve->getMarkerSize() == 0)
- {
- aCurve->setMarkerSize( myMarkerSize );
- }
+ if ( aCurve->getMarkerSize() == 0 )
+ aCurve->setMarkerSize( myMarkerSize );
processFiltering(update);
updatePlotItem( aCurve, anItem );
}
}
}
- updateTitles();
+ updateTitles( false );
myPlot->updateYAxisIdentifiers();
- if ( update )
+ if ( update ) {
myPlot->replot();
- if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
+ if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
+ }
return anItem;
}
QwtPlotItem* anObject = getPlotObject( object );
eraseBasicObject(anObject,update);
}
- if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
+ if (update) {
+ if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
+ }
}
void Plot2d_ViewFrame::eraseBasicObject( QwtPlotItem *object, bool update )
object->hide();
object->detach();
myObjects.remove(object);
- updateTitles();
+ updateTitles(update);
myPlot->updateYAxisIdentifiers();
if ( update )
myPlot->replot();
return;
updatePlotItem(object, anItem );
anItem->setVisible( true );
- if ( update )
+ if ( update ) {
myPlot->replot();
- if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
+ if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
+ }
}
}
bool Plot2d_ViewFrame::isVisible( Plot2d_Object* object ) const
{
return object && hasPlotObject( object ) && getPlotObject( object )->isVisible();
-}
+}
/*!
update legend
update legend
*/
void Plot2d_ViewFrame::updateLegend() {
- if ( myPlot->getLegend() ) {
- ObjectDict::iterator it = myObjects.begin();
- for( ; it != myObjects.end(); ++it )
- it.key()->updateLegend(myPlot->getLegend());
+ const QwtPlotItemList& items = myPlot->itemList();
+ QwtPlotItemIterator it;
+ for ( it = items.begin(); it != items.end(); it++ ) {
+ QwtPlotItem* item = *it;
+ if ( item )
+ item->updateLegend( item, item->legendData() );
}
}
*/
void Plot2d_ViewFrame::fitAll()
{
- // Postpone fitAll operation until QwtPlot geometry
- // has been fully defined
- if ( !myPlot->polished() ){
- QApplication::postEvent( this, new QEvent( (QEvent::Type)FITALL_EVENT ) );
- return;
- }
-
- myPlot->setAxisAutoScale( QwtPlot::yLeft );
- myPlot->setAxisAutoScale( QwtPlot::xBottom );
- myPlot->replot();
+ // no need to set auto scaling, it will be disabled by setAxisScale() method call
+ // myPlot->setAxisAutoScale( QwtPlot::yLeft );
+ // myPlot->setAxisAutoScale( QwtPlot::xBottom );
+ // myPlot->replot();
double xmin, xmax, y1min, y1max, y2min, y2max;
getFitRangeByCurves(xmin, xmax, y1min, y1max, y2min, y2max);
+ getFitRangeByMarkers(xmin, xmax, y1min, y1max, y2min, y2max);
myPlot->setAxisScale( QwtPlot::xBottom, xmin, xmax );
myPlot->setAxisScale( QwtPlot::yLeft, y1min, y1max );
myPlot->setAxisScale( QwtPlot::yRight, y2min, y2max );
}
myPlot->replot();
- if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
+ if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
}
/*!
rect.setHeight( MIN_RECT_SIZE );
rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
}
- myPlot->setAxisScale( QwtPlot::yLeft,
- myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
+ myPlot->setAxisScale( QwtPlot::yLeft,
+ myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
if (mySecondY)
- myPlot->setAxisScale( QwtPlot::yRight,
- myPlot->invTransform( QwtPlot::yRight, rect.top() ),
+ myPlot->setAxisScale( QwtPlot::yRight,
+ myPlot->invTransform( QwtPlot::yRight, rect.top() ),
myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
- myPlot->setAxisScale( QwtPlot::xBottom,
- myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
+ myPlot->setAxisScale( QwtPlot::xBottom,
+ myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
myPlot->replot();
if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
if (mySecondY)
myPlot->setAxisScale( QwtPlot::yRight, y2Min, y2Max );
}
- if ( mode == 0 || mode == 1 )
- myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
+ if ( mode == 0 || mode == 1 )
+ myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
myPlot->replot();
if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
}
}
}
+/*!
+ Gets current fit ranges by Markers
+ All parameters are inout.
+*/
+void Plot2d_ViewFrame::getFitRangeByMarkers(double& xMin, double& xMax,
+ double& yMin, double& yMax,
+ double& y2Min, double& y2Max)
+{
+ Plot2d_QwtPlotPicker *picker=myPlot->getPicker();
+ if(!picker)
+ return;
+ if(picker->pMarkers.empty())
+ return;
+ foreach(QwtPlotMarker *mrker,picker->pMarkers)
+ {
+ bool isV2 = mrker->yAxis() == QwtPlot::yRight;
+ xMin = qMin( xMin, mrker->xValue() );
+ xMax = qMax( xMax, mrker->xValue() );
+ if ( isV2 ) {
+ y2Min = qMin( y2Min, mrker->yValue() );
+ y2Max = qMax( y2Max, mrker->yValue() );
+ }
+ else {
+ yMin = qMin( yMin, mrker->yValue() );
+ yMax = qMax( yMax, mrker->yValue() );
+ }
+ if ( xMin == xMax ) {
+ xMin = xMin == 0. ? -1. : xMin - xMin/10.;
+ xMax = xMax == 0. ? 1. : xMax + xMax/10.;
+ }
+ if ( yMin == yMax ) {
+ yMin = yMin == 0. ? -1. : yMin - yMin/10.;
+ yMax = yMax == 0. ? 1 : yMax + yMax/10.;
+ }
+ if ( y2Min == y2Max ) {
+ y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
+ y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
+ }
+ }
+}
+
/*!
Tests if it is necessary to start operation on mouse action
*/
int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
{
- int btn = me.button() | me.modifiers();
- const int zoomBtn = Qt::ControlModifier | Qt::LeftButton;
- const int panBtn = Qt::ControlModifier | Qt::MidButton;
- const int fitBtn = Qt::ControlModifier | Qt::RightButton;
+ int btn = (int)me.button() | (int)me.modifiers();
+ const int zoomBtn = (int)Qt::ControlModifier | (int)Qt::LeftButton;
+ const int panBtn = (int)Qt::ControlModifier | (int)Qt::MidButton;
+ const int fitBtn = (int)Qt::ControlModifier | (int)Qt::RightButton;
int op = NoOpId;
if ( btn == zoomBtn ) {
cols[ "blue-min" ] = color.blue();
}
#endif
-
+
Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
dlg->setMainTitle( myTitleEnabled, myTitle );
dlg->setXTitle( myXTitleEnabled, myXTitle );
if (mySecondY)
dlg->setY2Title( myY2TitleEnabled, myY2Title );
dlg->setCurveType( myCurveType );
- dlg->setLegend( myShowLegend, myLegendPos, myLegendFont, myLegendColor );
+ dlg->setLegend( myShowLegend, myLegendPos, myLegendSymbolType, myLegendFont,
+ myLegendColor, mySelectedLegendFontColor );
dlg->setMarkerSize( myMarkerSize );
dlg->setBackgroundColor( myBackground );
+ dlg->setSelectionColor( mySelectionColor );
dlg->setScaleMode(myXMode, myYMode);
dlg->setLMinNormMode(myNormLMin);
dlg->setLMaxNormMode(myNormLMax);
setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
// main title
- if( dlg->isMainTitleEnabled() && myTitle != dlg->getMainTitle() )
+ if( dlg->isMainTitleEnabled() && myTitle != dlg->getMainTitle() )
myIsDefTitle = false;
setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
// curve type
}
if ( myLegendPos != dlg->getLegendPos() ) {
setLegendPos( dlg->getLegendPos() );
+ }
+ if ( myLegendSymbolType != dlg->getLegendSymbolType() ) {
+ setLegendSymbolType( dlg->getLegendSymbolType() );
}
if ( myLegendFont != dlg->getLegendFont() ) {
setLegendFont( dlg->getLegendFont() );
if ( myLegendColor != dlg->getLegendColor() ) {
setLegendFontColor( dlg->getLegendColor() );
}
+ if ( mySelectedLegendFontColor != dlg->getSelectedLegendColor() ) {
+ setSelectedLegendFontColor( dlg->getSelectedLegendColor() );
+ }
// marker size
if ( myMarkerSize != dlg->getMarkerSize() ) {
if ( myBackground != dlg->getBackgroundColor() ) {
setBackgroundColor( dlg->getBackgroundColor() );
}
+ // selection color
+ if ( mySelectionColor != dlg->getSelectionColor() ) {
+ setSelectionColor( dlg->getSelectionColor() );
+ }
// grid
bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
aY2GridMajorEnabled, aY2GridMinorEnabled;
setNormRMaxMode( dlg->getRMaxNormMode() );
}
- myPlot->setProperty(PLOT2D_DEVIATION_COLOR,
+ myPlot->setProperty(PLOT2D_DEVIATION_COLOR,
dlg->getDeviationMarkerCl());
- myPlot->setProperty(PLOT2D_DEVIATION_LW,
+ myPlot->setProperty(PLOT2D_DEVIATION_LW,
dlg->getDeviationMarkerLw());
- myPlot->setProperty(PLOT2D_DEVIATION_TS,
+ myPlot->setProperty(PLOT2D_DEVIATION_TS,
dlg->getDeviationMarkerTs());
// update view
myPlot->replot();
// update preferences
- if ( dlg->isSetAsDefault() )
+ if ( dlg->isSetAsDefault() )
writePreferences();
}
delete dlg;
}
+#ifndef NO_ANALYTICAL_CURVES
/*!
"Analytical Curves" toolbar action slot
*/
void Plot2d_ViewFrame::onAnalyticalCurve()
{
-#ifndef DISABLE_PYCONSOLE
Plot2d_AnalyticalCurveDlg dlg( this, this );
dlg.exec();
updateAnalyticalCurves();
-#endif
}
void Plot2d_ViewFrame::addAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
{
-#ifndef DISABLE_PYCONSOLE
- myAnalyticalCurves.append(theCurve);
-#endif
+ myAnalyticalCurves.append(theCurve);
}
void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
{
-#ifndef DISABLE_PYCONSOLE
- theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
-#endif
+ theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
}
/*
*/
void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool updateView)
{
-#ifndef DISABLE_PYCONSOLE
if(!c) return;
- QwtScaleDiv* div = myPlot->axisScaleDiv(QwtPlot::xBottom);
- c->setRangeBegin(div->lowerBound());
- c->setRangeEnd(div->upperBound());
+ QwtScaleDiv div = myPlot->axisScaleDiv(QwtPlot::xBottom);
+ c->setRangeBegin(div.lowerBound());
+ c->setRangeEnd(div.upperBound());
c->calculate();
c->setMarkerSize(myMarkerSize);
QwtPlotItem* item = c->plotItem();
-
+
switch( c->getAction() ) {
case Plot2d_AnalyticalCurve::ActAddInView:
if( c->isActive() ) {
c->updatePlotItem();
item->attach( myPlot );
+ item->itemChanged();
item->show();
}
c->setAction(Plot2d_AnalyticalCurve::ActNothing);
break;
-
+
case Plot2d_AnalyticalCurve::ActUpdateInView:
if(c->isActive()) {
c->updatePlotItem();
item->show();
- } else {
+ } else {
item->hide();
item->detach();
}
-
+
c->setAction(Plot2d_AnalyticalCurve::ActNothing);
- break;
+ break;
case Plot2d_AnalyticalCurve::ActRemoveFromView:
item->hide();
item->detach();
- myAnalyticalCurves.removeAll(c);
- delete c;
break;
}
if(updateView)
myPlot->replot();
-#endif
}
/*
*/
void Plot2d_ViewFrame::updateAnalyticalCurves()
{
-#ifndef DISABLE_PYCONSOLE
AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
+ AnalyticalCurveList toDelete;
for( ; it != myAnalyticalCurves.end(); it++) {
- updateAnalyticalCurve(*it);
+ Plot2d_AnalyticalCurve* c = (*it);
+ updateAnalyticalCurve(c);
+ if(c && c->getAction() == Plot2d_AnalyticalCurve::ActRemoveFromView)
+ toDelete.push_back(c);
+ }
+ it = toDelete.begin();
+ for( ; it != toDelete.end(); it++) {
+ Plot2d_AnalyticalCurve* c = (*it);
+ myAnalyticalCurves.removeAll(c);
+ delete c;
+ c = NULL;
}
myPlot->replot();
-#endif
}
/*!
*/
AnalyticalCurveList Plot2d_ViewFrame::getAnalyticalCurves() const
{
- return myAnalyticalCurves;
+ return myAnalyticalCurves ;
}
/*!
Get analytical curve by plot item.
*/
Plot2d_AnalyticalCurve* Plot2d_ViewFrame::getAnalyticalCurve(QwtPlotItem * theItem) {
-#ifndef DISABLE_PYCONSOLE
AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
for( ; it != myAnalyticalCurves.end(); it++) {
- if((*it)->plotItem() == theItem);
- return (*it);
+ if((*it)->plotItem() == theItem)
+ return (*it);
}
return 0;
-#endif
}
+#endif
/*!
"Fit Data" command slot
Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
double xMin,xMax,yMin,yMax,y2Min,y2Max;
getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
-
+
dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
if ( dlg->exec() == QDialog::Accepted ) {
int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max);
}
delete dlg;
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
*/
void Plot2d_ViewFrame::onChangeBackground()
{
- QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
+ QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
if ( selColor.isValid() ) {
setBackgroundColor( selColor );
}
if ( crv )
setCurveType( crv, myCurveType );
}
+ for(int i=0 ; i < myAnalyticalCurves.count(); i++) {
+ QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( myAnalyticalCurves[i]->plotItem() );
+ Plot2d_AnalyticalCurve* aCurve = dynamic_cast<Plot2d_AnalyticalCurve*>( myAnalyticalCurves[i] );
+ if ( aPCurve && aCurve ) {
+ setCurveType( aPCurve, myCurveType );
+ }
+ }
if ( update )
myPlot->replot();
emit vpCurveChanged();
\param curveKey - curve id
\param title - new title
*/
-void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title )
+void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title )
{
setObjectTitle( curve, title );
}
\param object - object id
\param title - new title
*/
-void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title )
-{
+void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title )
+{
if ( object && hasPlotObject( object ) )
getPlotObject( object )->setTitle( title );
-}
+}
/*!
Shows/hides legend
{
myShowLegend = show;
if ( myShowLegend ) {
- QwtLegend* legend = myPlot->legend();
- if ( !legend ) {
- legend = new QwtLegend( myPlot );
- legend->setFrameStyle( QFrame::Box | QFrame::Sunken );
+ QwtAbstractLegend* absLegend = myPlot->legend();
+ QwtLegend* legend = 0;
+ if ( !absLegend ) {
+ legend = new Plot2d_QwtLegend( myPlot );
+ legend->setDefaultItemMode(QwtLegendData::Clickable);
+ connect( legend, SIGNAL( clicked (const QVariant&, int) ),
+ this, SIGNAL( clicked (const QVariant&, int) ) );
+ legend->setFrameStyle( QFrame::Box | QFrame::Sunken );
+ }
+ else {
+ legend = dynamic_cast<QwtLegend*>(absLegend);
+ }
+ if(legend) {
+ myPlot->insertLegend( legend );
+ setLegendPos( myLegendPos );
+ setLegendFont( myLegendFont );
+ setLegendFontColor( myLegendColor );
}
- legend->setItemMode( QwtLegend::ClickableItem );
- myPlot->insertLegend( legend );
- setLegendPos( myLegendPos );
- setLegendFont( myLegendFont );
- setLegendFontColor( myLegendColor );
}
else
myPlot->insertLegend( 0 );
+
+ if( show && update )
+ updateLegend();
+
if ( update )
myPlot->replot();
}
void Plot2d_ViewFrame::setLegendPos( int pos )
{
myLegendPos = pos;
- QwtLegend* legend = myPlot->legend();
+ QwtAbstractLegend* legend = myPlot->legend();
if ( legend ) {
switch( pos ) {
case 0:
return myLegendPos;
}
+/*!
+ Sets legend symbol type : 0 - marker on line, 1 - marker above line
+*/
+void Plot2d_ViewFrame::setLegendSymbolType( int type )
+{
+ myLegendSymbolType = type;
+ myPlot->setLegendSymbolType( type );
+ updateLegend();
+}
+
+/*!
+ Gets legend symbol type : 0 - marker on line, 1 - marker above line
+*/
+int Plot2d_ViewFrame::getLegendSymbolType() const
+{
+ return myLegendSymbolType;
+}
+
/*!
Sets legend font
*/
void Plot2d_ViewFrame::setLegendFont( const QFont& fnt )
{
myLegendFont = fnt;
- QwtLegend* legend = myPlot->legend();
+ QwtAbstractLegend* legend = myPlot->legend();
if ( legend ) {
legend->setFont(fnt);
}
return myLegendFont;
}
-/*!
- Gets legend font color
-*/
-QColor Plot2d_ViewFrame::getLegendFontColor() const
-{
- return myLegendColor;
-}
-
/*!
Sets legend font color
*/
void Plot2d_ViewFrame::setLegendFontColor( const QColor& col )
{
myLegendColor = col;
- QwtLegend* legend = myPlot->legend();
+ QwtAbstractLegend* legend = myPlot->legend();
if ( legend ) {
QPalette pal = legend->palette();
pal.setColor( QPalette::Text, col );
}
}
+/*!
+ Gets legend font color
+*/
+QColor Plot2d_ViewFrame::getLegendFontColor() const
+{
+ return myLegendColor;
+}
+
+/*!
+ Sets selected legend font color
+*/
+void Plot2d_ViewFrame::setSelectedLegendFontColor( const QColor& col )
+{
+ mySelectedLegendFontColor = col;
+ Plot2d_Object::setHighlightedLegendTextColor( col );
+}
+
+/*!
+ Gets selected legend font color
+*/
+QColor Plot2d_ViewFrame::getSelectedLegendFontColor() const
+{
+ return mySelectedLegendFontColor;
+}
+
/*!
Sets new marker size
*/
QwtPlotCurve* crv = it.key();
if ( crv )
{
- QwtSymbol aSymbol = crv->symbol();
- aSymbol.setSize( myMarkerSize, myMarkerSize );
+ QwtSymbol* aSymbol = new QwtSymbol( crv->symbol()->style(), crv->symbol()->brush(),
+ crv->symbol()->pen(), QSize( myMarkerSize, myMarkerSize ) );
crv->setSymbol( aSymbol );
- if(it.value())
- it.value()->setMarkerSize( myMarkerSize );
+ if( it.value() )
+ it.value()->setMarkerSize( myMarkerSize );
}
}
if ( update )
}
Repaint();
}
+
/*!
Gets background color
*/
{
return myBackground;
}
+
+/*!
+ Sets selection color
+*/
+void Plot2d_ViewFrame::setSelectionColor( const QColor& color )
+{
+ mySelectionColor = color;
+ Plot2d_Object::setSelectionColor( color );
+}
+
+/*!
+ Gets selection color
+*/
+QColor Plot2d_ViewFrame::selectionColor() const
+{
+ return mySelectionColor;
+}
+
/*!
Sets hor.axis grid parameters
*/
-void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
- bool xMinorEnabled, const int xMinorMax,
+void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
+ bool xMinorEnabled, const int xMinorMax,
bool update )
{
myXGridMajorEnabled = xMajorEnabled;
myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
QwtPlotGrid* grid = myPlot->grid();
- if ( myPlot->axisScaleDiv( QwtPlot::xBottom ) )
- grid->setXDiv( *myPlot->axisScaleDiv( QwtPlot::xBottom ) );
+ if ( !myPlot->axisScaleDiv( QwtPlot::xBottom ).isEmpty() )
+ grid->setXDiv( myPlot->axisScaleDiv( QwtPlot::xBottom ) );
grid->enableX( myXGridMajorEnabled );
grid->enableXMin( myXGridMinorEnabled );
/*!
Sets ver.axis grid parameters
*/
-void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
+void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
bool yMinorEnabled, const int yMinorMax,
- bool y2MajorEnabled, const int y2MajorMax,
- bool y2MinorEnabled, const int y2MinorMax,
+ bool y2MajorEnabled, const int y2MajorMax,
+ bool y2MinorEnabled, const int y2MinorMax,
bool update )
{
myYGridMajorEnabled = yMajorEnabled;
}
QwtPlotGrid* grid = myPlot->grid();
- if ( myPlot->axisScaleDiv( QwtPlot::yLeft ) )
- grid->setYDiv( *myPlot->axisScaleDiv( QwtPlot::yLeft ) );
+ if ( !myPlot->axisScaleDiv( QwtPlot::yLeft ).isEmpty() )
+ grid->setYDiv( myPlot->axisScaleDiv( QwtPlot::yLeft ) );
if (mySecondY) {
if (myYGridMajorEnabled) {
grid->enableYMin( myYGridMinorEnabled );
}
else if (myY2GridMajorEnabled) {
- if ( myPlot->axisScaleDiv( QwtPlot::yRight ) )
- grid->setYDiv( *myPlot->axisScaleDiv( QwtPlot::yRight ) );
+ if ( !myPlot->axisScaleDiv( QwtPlot::yRight ).isEmpty() )
+ grid->setYDiv( myPlot->axisScaleDiv( QwtPlot::yRight ) );
grid->enableY( myY2GridMajorEnabled );
grid->enableYMin( myY2GridMinorEnabled );
}
if ( myXMode == mode )
return;
- // san -- Protection against QwtCurve bug in Qwt 0.4.x:
+ // san -- Protection against QwtCurve bug in Qwt 0.4.x:
// it crashes if switched to X/Y logarithmic mode, when one or more points have
// non-positive X/Y coordinate
if ( mode && !isXLogEnabled() ){
- SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
+#ifndef NO_SUIT
+ SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
+#else
+ QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
+#endif
return;
}
myXMode = mode;
+ // set bounds of logarithmic scale
+ if( myXMode != 0 ) {
+ myPlot->setAxisScale( QwtPlot::xBottom, 1.0, 1e5 );
+ myPlot->updateAxes();
+ }
+
myPlot->setLogScale(QwtPlot::xBottom, myXMode != 0);
if ( update )
if ( myYMode == mode )
return;
- // san -- Protection against QwtCurve bug in Qwt 0.4.x:
+ // san -- Protection against QwtCurve bug in Qwt 0.4.x:
// it crashes if switched to X/Y logarithmic mode, when one or more points have
// non-positive X/Y coordinate
if ( mode && !isYLogEnabled() ){
- SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
+#ifndef NO_SUIT
+ SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
+#else
+ QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
+#endif
return;
}
myYMode = mode;
+
+ // set bounds of logarithmic scale
+ if( myYMode != 0 ){
+ myPlot->setAxisScale( QwtPlot::yLeft, 1.0, 1e5 );
+ myPlot->updateAxes();
+ }
+
myPlot->setLogScale(QwtPlot::yLeft, myYMode != 0);
- if (mySecondY)
+ if (mySecondY) {
+ if( myYMode != 0 ){
+ myPlot->setAxisScale( QwtPlot::yRight, 1.0, 1e5 );
+ myPlot->updateAxes();
+ }
myPlot->setLogScale( QwtPlot::yRight, myYMode != 0 );
+ }
if ( update )
fitAll();
*/
void Plot2d_ViewFrame::plotMousePressed( const QMouseEvent& me )
{
+#ifndef NO_SUIT
Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
if (aParent)
aParent->putInfo(getInfo(me.pos()));
+#endif
if ( myOperation == NoOpId )
myOperation = testOperation( me );
if ( myOperation != NoOpId ) {
myPnt = me.pos();
if ( myOperation == GlPanId ) {
myPlot->setAxisScale( QwtPlot::yLeft,
- myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2,
+ myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2,
myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2 );
- myPlot->setAxisScale( QwtPlot::xBottom,
- myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
+ myPlot->setAxisScale( QwtPlot::xBottom,
+ myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
if (mySecondY)
myPlot->setAxisScale( QwtPlot::yRight,
- myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2,
+ myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2,
myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2 );
myPlot->replot();
}
}
else {
- int btn = me.button() | me.modifiers();
+ int btn = (int)me.button() | (int)me.modifiers();
if (btn == Qt::RightButton) {
QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
me.pos(), me.button(), me.buttons(), me.modifiers() );
parent()->eventFilter(this, aEvent);
}
}
- setFocus();
+ setFocus();
}
/*!
Slot, called when user moves mouse
bool aRes = false;
if ( myOperation != NoOpId) {
if ( myOperation == ZoomId ) {
- this->incrementalZoom( dx, dy );
+ this->incrementalZoom( dx, dy );
myPnt = me.pos();
aRes = true;
}
}
}
else {
+#ifndef NO_SUIT
Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
if (aParent)
aParent->putInfo(getInfo(me.pos()));
+#endif
}
return aRes;
}
QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
me.pos(), me.globalPos() );
emit contextMenuRequested( &aEvent );
- }
+ }
else {
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
myPlot->defaultPicker();
+#ifndef NO_SUIT
Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
if (aParent)
aParent->putInfo(tr("INF_READY"));
+#endif
myOperation = NoOpId;
}
/*!
Slot, called when user wheeling mouse
*/
void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
-{
+{
QwtPlotLayout* pl = myPlot->plotLayout();
// compute zooming factor
double aDelta = event->delta();
- double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
+ double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
- bool scaleXBottom = pl->scaleRect(QwtPlot::xBottom).contains( event->pos() ) ||
+ bool scaleXBottom = pl->scaleRect(QwtPlot::xBottom).contains( event->pos() ) ||
pl->canvasRect().contains( event->pos() );
- bool scaleYLeft = pl->scaleRect(QwtPlot::yLeft).contains( event->pos() ) ||
+ bool scaleYLeft = pl->scaleRect(QwtPlot::yLeft).contains( event->pos() ) ||
pl->canvasRect().contains( event->pos() );
- bool scaleYRight = mySecondY && ( pl->scaleRect(QwtPlot::yRight).contains( event->pos() ) ||
+ bool scaleYRight = mySecondY && ( pl->scaleRect(QwtPlot::yRight).contains( event->pos() ) ||
pl->canvasRect().contains( event->pos() ) );
// scale x bottom axis
- if ( scaleXBottom ) {
+ if ( scaleXBottom ) {
QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
if ( xMap.s2() - xMap.s1() > 1.0e-12 || aScale > 1 )
myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s1() + aScale*(xMap.s2() - xMap.s1()) );
}
-
+
// scale y left axis
if ( scaleYLeft ) {
QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
if ( yMap.s2() - yMap.s1() > 10e-12 || aScale > 1 )
myPlot->setAxisScale( QwtPlot::yRight, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
}
-
+
// redraw
myPlot->replot();
// update zoomer
if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
// store current mouse position
myPnt = event->pos();
+#ifndef NO_ANALYTICAL_CURVES
// update analytical curves
updateAnalyticalCurves();
+#endif
}
/*!
/*!
Sets curve type
*/
-void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int curveType )
+void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int /*curveType*/ )
{
if ( !curve )
return;
View operations : Pan view
*/
void Plot2d_ViewFrame::onViewPan()
-{
+{
+ // reset the previous operation
+ myPlot->defaultPicker();
+
QCursor panCursor (Qt::SizeAllCursor);
myPlot->canvas()->setCursor( panCursor );
myOperation = PanId;
/*!
View operations : Zoom view
*/
-void Plot2d_ViewFrame::onViewZoom()
+void Plot2d_ViewFrame::onViewZoom()
{
+ // reset the previous operation
+ myPlot->defaultPicker();
+
QPixmap zoomPixmap (imageZoomCursor);
QCursor zoomCursor (zoomPixmap);
myPlot->canvas()->setCursor( zoomCursor );
myOperation = ZoomId;
}
/*!
- View operations : Fot All
+ View operations : Fit All
*/
-void Plot2d_ViewFrame::onViewFitAll()
-{
+void Plot2d_ViewFrame::onViewFitAll()
+{
fitAll();
+
+ // reset the previous operation
+ myPlot->defaultPicker();
+ myPlot->canvas()->setCursor( QCursor(Qt::CrossCursor) );
+ myOperation = NoOpId;
}
/*!
View operations : Fit Area
*/
-void Plot2d_ViewFrame::onViewFitArea()
+void Plot2d_ViewFrame::onViewFitArea()
{
myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
myOperation = FitAreaId;
/*!
View operations : Global panning
*/
-void Plot2d_ViewFrame::onViewGlobalPan()
+void Plot2d_ViewFrame::onViewGlobalPan()
{
+ // reset the previous operation
+ myPlot->defaultPicker();
+
QPixmap globalPanPixmap (imageCrossCursor);
QCursor glPanCursor (globalPanPixmap);
myPlot->canvas()->setCursor( glPanCursor );
QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
myYDistance2 = yMap2.s2() - yMap2.s1();
}
- fitAll();
+ // don't make fit all
+ // fitAll();
myOperation = GlPanId;
}
class Plot2d_QwtPlotZoomer : public QwtPlotZoomer
{
public:
- Plot2d_QwtPlotZoomer( int xAxis, int yAxis, QwtPlotCanvas* canvas )
+ Plot2d_QwtPlotZoomer( int xAxis, int yAxis, QWidget* canvas )
: QwtPlotZoomer( xAxis, yAxis, canvas )
{
qApp->installEventFilter( this );
*/
Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
: QwtPlot( parent ),
- myIsPolished( false )
+ myPicker( 0 )
{
// Create alternative scales
setAxisScaleDraw( QwtPlot::yLeft, new Plot2d_ScaleDraw() );
setAxisScaleDraw( QwtPlot::yRight, new Plot2d_ScaleDraw() );
myPlotZoomer = new Plot2d_QwtPlotZoomer( QwtPlot::xBottom, QwtPlot::yLeft, canvas() );
- myPlotZoomer->setSelectionFlags( QwtPicker::DragSelection | QwtPicker::CornerToCorner );
myPlotZoomer->setTrackerMode( QwtPicker::AlwaysOff );
myPlotZoomer->setRubberBand( QwtPicker::RectRubberBand );
myPlotZoomer->setRubberBandPen( QColor( Qt::green ) );
setAxisAutoScale( QwtPlot::yLeft );
setAxisAutoScale( QwtPlot::yRight );
setAxisAutoScale( QwtPlot::xBottom );
-
+
myScaleDraw = NULL;
// grid
myGrid = new QwtPlotGrid();
- QPen aMajPen = myGrid->majPen();
+ QPen aMajPen = myGrid->majorPen();
aMajPen.setStyle( Qt::DashLine );
myGrid->setPen( aMajPen );
void Plot2d_Plot2d::setLogScale( int axisId, bool log10 )
{
if ( log10 )
- setAxisScaleEngine( axisId, new QwtLog10ScaleEngine() );
+ setAxisScaleEngine( axisId, new QwtLogScaleEngine() );
else
setAxisScaleEngine( axisId, new QwtLinearScaleEngine() );
}
/*!
- Recalculates and redraws Plot 2d view
+ Recalculates and redraws Plot 2d view
*/
void Plot2d_Plot2d::replot()
{
enableAxis( QwtPlot::yRight, enableYRight );
updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
- QwtPlot::replot();
+ QwtPlot::replot();
}
/*!
Get legend
*/
-QwtLegend* Plot2d_Plot2d::getLegend()
+QwtAbstractLegend* Plot2d_Plot2d::getLegend()
{
#if QWT_VERSION < 0x040200
return d_legend;
-#else
+#else
return legend(); /* mpv: porting to the Qwt 4.2.0 */
#endif
}
myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1,
Qt::RightButton, Qt::ControlModifier ); // zooming button
for ( int i = QwtEventPattern::MouseSelect2; i < QwtEventPattern::MouseSelect6; i++ )
- myPlotZoomer->setMousePattern( i, Qt::NoButton, Qt::NoButton );
+ myPlotZoomer->setMousePattern( (QwtEventPattern::MousePatternCode)i, Qt::NoButton,
+ Qt::NoModifier );
}
void Plot2d_Plot2d::setPickerMousePattern( int button, int state )
{
- myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, button, state );
+ myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, (Qt::MouseButton)button,
+ (Qt::KeyboardModifiers)state );
}
/*!
/*!
* Create marker and tooltip associed with a point
*/
-QwtPlotMarker* Plot2d_Plot2d::createMarkerAndTooltip( QwtSymbol symbol,
- double X,
- double Y,
- QString & tooltip,
- Plot2d_QwtPlotPicker *picker)
+QwtPlotMarker* Plot2d_Plot2d::createMarkerAndTooltip( QwtSymbol* symbol,
+ double X,
+ double Y,
+ QString & tooltip,
+ Plot2d_QwtPlotPicker *picker)
{
QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
aPlotMarker->setYValue(Y);
//
aPlotMarker->attach(this);
-
+
// Associate a tooltip with the point's marker
// PB: how to obtain a tooltip with a rectangular frame ?
//QwtText tooltip ("X=" + QString::number(X) + " Y=" + QString::number(Y) );
text.setBackgroundBrush( QBrush(tooltipColor)); //, Qt::SolidPattern));
//
if ( picker ) {
- picker->pMarkers.append( aPlotMarker);
+ picker->pMarkers.append( aPlotMarker);
picker->pMarkersToolTip[ aPlotMarker] = text;
}
return aPlotMarker;
}
-bool Plot2d_Plot2d::polished() const
-{
- return myIsPolished;
-}
-
QwtPlotGrid* Plot2d_Plot2d::grid() const
{
return myGrid;
-};
+}
QwtPlotZoomer* Plot2d_Plot2d::zoomer() const
{
return myPlotZoomer;
}
-/*!
- Slot: checks the current labels format and change it if needed
-*/
-void Plot2d_Plot2d::onScaleDivChanged()
-{
- QwtScaleWidget* aSW = 0;
- if ( ( aSW = dynamic_cast<QwtScaleWidget*>(sender()) ) ) {
- int axisId = -1;
- switch ( aSW->alignment() ) {
- case QwtScaleDraw::BottomScale:
- axisId = QwtPlot::xBottom;
- break;
- case QwtScaleDraw::LeftScale:
- axisId = QwtPlot::yLeft;
- break;
- case QwtScaleDraw::RightScale:
- axisId = QwtPlot::yRight;
- break;
- default:
- break;
- }
-
- if ( axisId >= 0 ) {
- QwtScaleMap map = canvasMap(axisId);
- double aDist = fabs(map.s2()-map.s1()) / (axisMaxMajor(axisId)*axisMaxMinor(axisId));
-
- QString aDistStr;
- aDistStr.sprintf("%e",aDist);
- int aPrecision = aDistStr.right(aDistStr.length()-aDistStr.indexOf('e')-2).toInt();
-
- QwtScaleDraw* aQwtSD = axisScaleDraw(axisId);
- Plot2d_ScaleDraw* aPlot2dSD = dynamic_cast<Plot2d_ScaleDraw*>(aQwtSD);
- if ( ( !aPlot2dSD && aPrecision > 6 ) || ( aPlot2dSD && aPlot2dSD->precision() != aPrecision ) )
- setAxisScaleDraw( axisId, new Plot2d_ScaleDraw(*aQwtSD, 'f', aPrecision) );
- }
- }
-}
-
/*!
Updates identifiers of Y axis type in the legend.
*/
if ( Plot2d_QwtPlotCurve* aPCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( item ) )
aPCurve->setYAxisIdentifierEnabled( enableYLeft && enableYRight );
if ( item && item->isVisible() && legend() )
- item->updateLegend( legend() );
+ item->updateLegend( item, item->legendData() );
}
}
-/*!
- Sets the flag saying that QwtPlot geometry has been fully defined.
-*/
-void Plot2d_Plot2d::polish()
-{
- QwtPlot::polish();
- myIsPolished = true;
-}
-
// Methods to manage axis graduations
/* Create definition and graduations of axes
QList<double> allTicks;
double devXmin, devXmax; // X interval of a system
- double gapXmin, gapXmax; // X interval between two systems
+ double gapXmin = 0., gapXmax = 0.; // X interval between two systems
double devLabPos; // Label's position of a system
double segmentPos; // Position of the vertical segment between current system and the next
mySeparationLineList.clear();
}
+/* Set type of legend symbol
+ */
+void Plot2d_Plot2d::setLegendSymbolType( const int type )
+{
+ myLegendSymbolType = type;
+}
+
+/* Get type of legend symbol
+ */
+int Plot2d_Plot2d::getLegendSymbolType()
+{
+ return myLegendSymbolType;
+}
+
/*!
Creates presentation of object
Default implementation is empty
myCurveType = vf->myCurveType;
myShowLegend = vf->myShowLegend;
myLegendPos = vf->myLegendPos;
+ myLegendSymbolType = vf->myLegendSymbolType;
+ myLegendFont = vf->myLegendFont;
+ mySelectedLegendFontColor = vf->mySelectedLegendFontColor;
myMarkerSize = vf->myMarkerSize;
myBackground = vf->myBackground;
- myTitle = vf->myTitle;
+ mySelectionColor = vf->mySelectionColor;
+ myTitle = vf->myTitle;
myXTitle = vf->myXTitle;
myYTitle = vf->myYTitle;
myY2Title = vf->myY2Title;
Updates titles according to curves
*/
#define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
-void Plot2d_ViewFrame::updateTitles()
+void Plot2d_ViewFrame::updateTitles( const bool update )
{
ObjectDict::iterator it = myObjects.begin();
QStringList aXTitles;
QString yTitle = anObject->getVerTitle().trimmed();
QString xUnits = anObject->getHorUnits().trimmed();
QString yUnits = anObject->getVerUnits().trimmed();
-
+
if ( anObject->getYAxis() == QwtPlot::yLeft ) {
if ( !aYTitles.contains( yTitle ) )
aYTitles.append( yTitle );
if ( !y2Title.isEmpty() && !y2Units.isEmpty() )
y2Title += " ";
- setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, true );
- setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, true );
+ setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, false );
+ setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, false );
if ( mySecondY )
- setTitle( myY2TitleEnabled, y2Title + y2Units, Y2Title, true );
- if( myIsDefTitle )
- setTitle( true, aTables.join("; "), MainTitle, true );
+ setTitle( myY2TitleEnabled, y2Title + y2Units, Y2Title, false );
+ if( myIsDefTitle )
+ setTitle( true, aTables.join("; "), MainTitle, false );
+
+ // do update if necessary
+ if ( update ) {
+ myPlot->replot();
+ }
}
/*!
if( myPlot )
{
QPaintDevice* pd = 0;
- if( format=="PS" || format=="EPS" )
+ if( format=="PS" || format=="EPS" || format == "PDF" )
{
QPrinter* pr = new QPrinter( QPrinter::HighResolution );
+ if(format == "PDF")
+ pr->setOutputFormat(QPrinter::PdfFormat);
pr->setPageSize( QPrinter::A4 );
pr->setOutputFileName( file );
pr->setPrintProgram( "" );
if( pd )
{
- myPlot->print( *pd );
+ QwtPlotRenderer* pr = new QwtPlotRenderer();
+ pr->renderTo( myPlot, *pd );
res = true;
delete pd;
}
}
return res;
#endif
+
}
/**
* Print Plot2d window
*/
-void Plot2d_ViewFrame::printPlot( QPainter* p, const QRect& rect,
- const QwtPlotPrintFilter& filter ) const
+void Plot2d_ViewFrame::printPlot( QPainter* p, const QRectF& rect) const
{
- myPlot->print( p, rect, filter );
+ QwtPlotRenderer* pr = new QwtPlotRenderer();
+ pr->render( myPlot, p, rect );
}
/*!
getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
QString retStr;
//Store font in the visual parameters string as:
- //
+ //
// ...*FontFamily|FontSize|B|I|U|r:g:b*...
-
+
retStr.sprintf( "%d*%d*%d*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%s|%i|%i|%i|%i|%i:%i:%i",
myXMode, myYMode, mySecondY, xmin, xmax, ymin, ymax, y2min, y2max,
qPrintable(myLegendFont.family()), myLegendFont.pointSize(),myLegendFont.bold(),
myLegendFont.italic(), myLegendFont.underline(),myLegendColor.red(),
myLegendColor.green(), myLegendColor.blue());
-
+
//store all Analytical curves
//store each curve in the following format
// ...*Name|isActive|Expresion|NbInervals|isAutoAssign[|MarkerType|LineType|LineWidth|r:g:b]
// parameters in the [ ] is optional in case if isAutoAssign == true
AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
Plot2d_AnalyticalCurve* c = 0;
- bool isAuto;
+ bool isAuto;
for( ; it != myAnalyticalCurves.end(); it++) {
c = (*it);
if(!c) continue;
}
}
retStr += QString( "*%1" ).arg( Qtx::colorToString( backgroundColor() ) );
- return retStr;
+ return retStr;
*/
}
setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
setHorScaleMode( myXMode, /*update=*/false );
setVerScaleMode( myYMode, /*update=*/false );
-
+
if (mySecondY) {
QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
myYDistance2 = yMap2.s2() - yMap2.s1();
}
-
+
fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
}
colorList[2].toInt());
setLegendFontColor( myLegendColor );
}
- }
+ }
}
+#ifndef NO_ANALYTICAL_CURVES
//Restore all Analytical curves
int startCurveIndex = 10;
if( paramsLst.size() >= startCurveIndex+1 ) {
}
myPlot->replot();
}
+#endif
}
/*!
aWriter.writeEndElement();
aWriter.writeEndElement();
+#ifndef NO_ANALYTICAL_CURVES
//AnalyticalCurve
- aWriter.writeStartElement("AnalyticalCurves");
+ aWriter.writeStartElement("AnalyticalCurves");
AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
Plot2d_AnalyticalCurve* c = 0;
- bool isAuto;
+ bool isAuto;
int id = 1;
for( ; it != myAnalyticalCurves.end(); it++) {
c = (*it);
aWriter.writeAttribute("Name",c->getName());
aWriter.writeAttribute("IsActive", QString("").sprintf("%d", c->isActive()));
aWriter.writeAttribute("Expression", c->getExpression());
- aWriter.writeAttribute("NbIntervals", QString("").sprintf("%d", c->getNbIntervals()));
+ aWriter.writeAttribute("NbIntervals", QString("").sprintf("%ld", c->getNbIntervals()));
aWriter.writeAttribute("isAuto", QString("").sprintf("%d",isAuto));
if(!isAuto) {
aWriter.writeAttribute("Marker", QString("").sprintf("%d",(int)c->getMarker()));
id++;
}
aWriter.writeEndElement(); //AnalyticalCurve
+#endif
//Background
- aWriter.writeStartElement(QString("Background").arg(id));
- aWriter.writeStartElement(QString("BackgroundColor").arg(id));
+ aWriter.writeStartElement(QString("Background"));
+ aWriter.writeStartElement(QString("BackgroundColor"));
aWriter.writeAttribute("R", QString("").sprintf("%d",backgroundColor().red()));
aWriter.writeAttribute("G", QString("").sprintf("%d",backgroundColor().green()));
aWriter.writeAttribute("B", QString("").sprintf("%d",backgroundColor().blue()));
*/
bool Plot2d_ViewFrame::setXmlVisualParameters(const QString& parameters) {
QXmlStreamReader aReader(parameters);
- double xmin, xmax, ymin, ymax, y2min, y2max;
+ double xmin = 0., xmax = 0., ymin = 0., ymax = 0., y2min = 0., y2max = 0.;
bool leftMin,leftMax,rightMin,rightMax;
leftMin = leftMax = rightMin = rightMax = false;
while(!aReader.atEnd()) {
setLegendFontColor( myLegendColor );
setLegendFont(myLegendFont);
} else if(aReader.name().toString().indexOf("AnalyticalCurve_") >= 0) {
+#ifndef NO_ANALYTICAL_CURVES
Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
c->setName(aAttr.value("Name").toString());
c->setActive((bool)aAttr.value("IsActive").toString().toInt());
if( !c->isAutoAssign() ) {
c->setMarker((Plot2d::MarkerType)aAttr.value("Marker").toString().toInt());
c->setLine((Plot2d::LineType)aAttr.value("Line").toString().toInt());
- c->setLineWidth(aAttr.value("LineWidth").toString().toInt());
+ c->setLineWidth(aAttr.value("LineWidth").toString().toInt());
c->setColor(QColor(aAttr.value("R").toString().toInt(),
aAttr.value("G").toString().toInt(),
aAttr.value("B").toString().toInt()));
}
addAnalyticalCurve(c);
updateAnalyticalCurve(c);
+#endif
} else if(aReader.name().toString() == "BackgroundColor") {
setBackgroundColor(QColor(aAttr.value("R").toString().toInt(),
aAttr.value("G").toString().toInt(),
if (mySecondY)
setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
setHorScaleMode( myXMode, /*update=*/false );
- setVerScaleMode( myYMode, /*update=*/false );
+ setVerScaleMode( myYMode, /*update=*/false );
if (mySecondY) {
QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
myYDistance2 = yMap2.s2() - yMap2.s1();
- }
+ }
setNormLMinMode(leftMin);
setNormLMaxMode(leftMax);
setNormRMinMode(rightMin);
showLegend( myShowLegend, false );
- fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
+ fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
return true;
}
void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) {
QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
-
- myPlot->setAxisScale( QwtPlot::yLeft,
- myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s1() )-incrY ),
+
+ myPlot->setAxisScale( QwtPlot::yLeft,
+ myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s1() )-incrY ),
myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() )-incrY ) );
- myPlot->setAxisScale( QwtPlot::xBottom,
+ myPlot->setAxisScale( QwtPlot::xBottom,
myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s1() )-incrX ),
- myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() )-incrX ) );
+ myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() )-incrX ) );
if (mySecondY) {
QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
myPlot->setAxisScale( QwtPlot::yRight,
- myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s1() )-incrY ),
+ myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s1() )-incrY ),
myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() )-incrY ) );
}
myPlot->replot();
void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) {
QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
-
- myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(),
+
+ myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(),
myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() ) + incrY ) );
- myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(),
+ myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(),
myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() ) - incrX ) );
if (mySecondY) {
QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
}
/*
- Update plot item
+ Update plot item
*/
void Plot2d_ViewFrame::updatePlotItem(Plot2d_Object* theObject, QwtPlotItem* theItem) {
theObject->updatePlotItem( theItem );
xNew[j] = itTmp.value().at(j).first;
yNew[j] = itTmp.value().at(j).second;
}
- cu->setData(xNew, yNew,j);
+ cu->setSamples(xNew, yNew,j);
delete [] xNew;
delete [] yNew;
if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
*/
QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas() const
{
- return myPlot ? myPlot->canvas() : 0;
+ return myPlot ? (QwtPlotCanvas*)myPlot->canvas() : 0;
}
/*!
continue;
double d;
int i = aCurve->closestPoint( p, &d );
- if ( index > -1 && ( distance < 0 || d < distance ) ) {
+ if ( i > -1 && ( distance < 0 || d < distance ) ) {
pCurve = it.value();
distance = d;
index = i;
return pCurve;
}
+#ifndef NO_ANALYTICAL_CURVES
/*!
\brief Deselect all analytical curves.
*/
c->setSelected(false);
}
}
+#endif
/*!
\brief Deselect all objects, except analytical curves.
void Plot2d_ViewFrame::onPanLeft()
{
this->incrementalPan( -INCREMENT_FOR_OP, 0 );
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
void Plot2d_ViewFrame::onPanRight()
{
this->incrementalPan( INCREMENT_FOR_OP, 0 );
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
void Plot2d_ViewFrame::onPanUp()
{
this->incrementalPan( 0, -INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
void Plot2d_ViewFrame::onPanDown()
{
this->incrementalPan( 0, INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
void Plot2d_ViewFrame::onZoomIn()
{
this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
void Plot2d_ViewFrame::onZoomOut()
{
this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
updateAnalyticalCurves();
+#endif
}
/*!
*
*/
Plot2d_Object* Plot2d_ViewFrame::getPlotObject( QwtPlotItem* plotItem ) const {
-
+
ObjectDict::const_iterator it = myObjects.begin();
for( ; it != myObjects.end(); ++it ) {
if ( it.key() == plotItem ) {
invalidateCache();
}
-Plot2d_ScaleDraw::Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f, int prec )
- : QwtScaleDraw(scaleDraw),
- myFormat(f),
- myPrecision(prec)
-{
- invalidateCache();
-}
-
QwtText Plot2d_ScaleDraw::label( double value ) const
{
- QwtScaleMap m = map();
+ QwtScaleMap m = scaleMap();
QString str1 = QwtScaleDraw::label( m.s1() ).text();
QString str2 = QwtScaleDraw::label( m.s2() ).text();
if ( str1 == str2 ) {
- double aDist = fabs(map().s2()-map().s1())/5;
+ double aDist = fabs(scaleMap().s2()-scaleMap().s1())/5;
int precision = 0;
while (aDist < 1 ) {
- precision++;
- aDist *= 10.;
+ precision++;
+ aDist *= 10.;
}
if ( precision > 0 && value > 0 )
return QLocale::system().toString( value,'f', precision );
major_ticks.clear();
major_ticks.append( myTicks);
- myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MajorTick, major_ticks);
- myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
- myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
+
+ QwtScaleDiv aScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
+ aScaleDiv.setTicks( QwtScaleDiv::MajorTick, major_ticks );
+ aScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
+ aScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
+ myPlot->setAxisScaleDiv( QwtPlot::xBottom, aScaleDiv );
+
QwtScaleDraw *scale = myPlot->axisScaleDraw(QwtPlot::xBottom);
((Plot2d_AxisScaleDraw*)(scale))->applyTicks();
for (int i = 0; i < myTicks.size(); i++)
{
- drawLabel( painter, myTicks[i]);
- }
-
+ drawLabel( painter, myTicks[i]);
+ }
+
//std::cout << "Ok for Plot2d_AxisScaleDraw::draw()" << std::endl;
}
+double Plot2d_AxisScaleDraw::extent( const QFont &font ) const
+{
+ QFontMetrics fm( font );
+ return QwtScaleDraw::extent( font ) + fm.height() * 2;
+}
+
QwtText Plot2d_AxisScaleDraw::label( double value) const
{
if (myLabelX.contains(value))
medium_ticks.clear();
minor_ticks.clear();
- myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MajorTick, myTicks);
- myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
- myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
+ QwtScaleDiv aQwtScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
+ aQwtScaleDiv.setTicks( QwtScaleDiv::MajorTick, myTicks );
+ aQwtScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
+ aQwtScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
+ myPlot->setAxisScaleDiv( QwtPlot::xBottom, aQwtScaleDiv );
QwtScaleDiv* aScaleDiv = (QwtScaleDiv*) &scaleDiv();
if (myLowerBound != -1 && myUpperBound != -1)
aScaleDiv->setInterval(myLowerBound, myUpperBound);
-
+
//for (int i = 0; i < myTicks.size(); i++){
// QPoint p = labelPosition( i );
// qDebug() << i<< ") applyTicks -> LABEL" <<p;
//const char *c_label = std_label.c_str();
//std::cout << " deviceLabel= |" << c_label << "|" << std::endl;
- QPoint p = labelPosition( value );
+ QPointF p = labelPosition( value );
p += QPoint(0, DEVICE_BY);
QFont prevf = painter->font();
//QColor prevc = (painter->pen()).color();
-
+
QFont devicef( DEVICE_FONT, DEVICE_FONT_SIZE, QFont::Bold);
//
//painter->setPen( QColor("blue") );
QwtScaleDraw::drawLabel( painter, value );
}
}
-
+
void Plot2d_AxisScaleDraw::drawTick( QPainter* painter, double value, int len) const
{
if ( myLabelX.contains(value) )
{
QwtScaleDraw::drawTick( painter, value, len);
- }
+ }
}
/* Management of tooltips associated with markers for curves points or others points
*/
const double Plot2d_QwtPlotPicker::BOUND_HV_SIZE = 0.2;
-
+
Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
int yAxis,
- int selectionFlags,
RubberBand rubberBand,
DisplayMode trackerMode,
QwtPlotCanvas *canvas)
: QwtPlotPicker( xAxis,
yAxis,
- selectionFlags,
rubberBand,
trackerMode,
canvas) // of drawing zone QwtPlot
{
}
-
+
Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
int yAxis,
QwtPlotCanvas *canvas)
/* Return the tooltip associated with a point when the mouse cursor pass near
*/
-QwtText Plot2d_QwtPlotPicker::trackerText( const QwtDoublePoint & pos ) const
+QwtText Plot2d_QwtPlotPicker::trackerText( const QPoint & pos ) const
{
- for (QList<QwtPlotMarker* >::const_iterator pMarkerIt = pMarkers.begin();
- pMarkerIt != pMarkers.end();
- ++pMarkerIt )
- {
+ for (QList<QwtPlotMarker* >::const_iterator pMarkerIt = pMarkers.begin();pMarkerIt != pMarkers.end(); ++pMarkerIt )
+ {
QwtPlotMarker* pMarker = *pMarkerIt;
if ( pMarker != NULL )
- {
- QwtDoubleRect bound0 = pMarker->boundingRect();
- QwtDoublePoint center_bound0 = bound0.center();
- double left = center_bound0.x()-(BOUND_HV_SIZE/2.);
- double top = center_bound0.y()-(BOUND_HV_SIZE/2.);
+ {
+ const QwtSymbol* symb=pMarker->symbol();
+ const QSize& sz=symb->size();
+ const QwtScaleMap yMapRef=plot()->canvasMap(QwtPlot::yLeft);
+ const QwtScaleMap xMap=plot()->canvasMap(pMarker->xAxis());
+ const QwtScaleMap yMap=plot()->canvasMap(pMarker->yAxis());
+ QwtDoubleRect bound0=pMarker->boundingRect();
+ int x1 = qRound(xMap.transform(bound0.left()));
+ int x2 = qRound(xMap.transform(bound0.right()));
+ int y1 = qRound(yMap.transform(bound0.top()));
+ int y2 = qRound(yMap.transform(bound0.bottom()));
- QwtDoubleRect bound( left, top , BOUND_HV_SIZE, BOUND_HV_SIZE);
+ if ( x2 < x1 )
+ qSwap(x1, x2);
+ if ( y2 < y1 )
+ qSwap(y1, y2);
- if( bound.contains(pos) )
- {
- //QString toolTip = "X=" + QString::number( pMarker->xValue() )
- // + " Y=" + QString::number( pMarker->yValue() );
- return pMarkersToolTip[pMarker];
- }
- }
+ QRect bound00=QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
+ QPoint toto(xMap.transform(pos.x()),yMapRef.transform(pos.y()));
+ bound00.setX(bound00.x()-sz.width());
+ bound00.setY(bound00.y()-sz.height());
+ bound00.setWidth(bound00.width()+sz.width());
+ bound00.setHeight(bound00.height()+sz.height());
+ if( bound00.contains(toto) )
+ {
+ return pMarkersToolTip[pMarker];
+ }
+ }
}
-
- return QwtText();
+ return QwtText();
}