//
#include "Plot2d_Curve.h"
-#include <QColor>
+
+#define DEFAULT_LINE_WIDTH 0 // (default) line width
+#define DEFAULT_MARKER_SIZE 9 // default marker size
/*!
Constructor
*/
Plot2d_Curve::Plot2d_Curve()
-: myHorTitle( "" ), myVerTitle( "" ),
- myHorUnits( "" ), myVerUnits( "" ),
- myName( "" ),
- myAutoAssign( true ),
- myColor( 0,0,0 ),
+: Plot2d_Object(),
+ myColor( 0,0,0 ),
+ myMarkerSize( 0 ),
myMarker( Plot2d::Circle ),
myLine( Plot2d::Solid ),
- myLineWidth( 0 ),
- myYAxis( QwtPlot::yLeft )
-{
-}
-
-/*!
- Destructor
-*/
-Plot2d_Curve::~Plot2d_Curve()
+ myLineWidth( 0 )
{
}
Copy constructor. Makes deep copy of data.
*/
Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
+: Plot2d_Object( curve )
{
- myAutoAssign = curve.isAutoAssign();
- myHorTitle = curve.getHorTitle();
- myVerTitle = curve.getVerTitle();
- myHorUnits = curve.getHorUnits();
- myVerUnits = curve.getVerUnits();
- myName = curve.getName();
myColor = curve.getColor();
myMarker = curve.getMarker();
myLine = curve.getLine();
myLineWidth = curve.getLineWidth();
- myPoints = curve.getPointList();
}
/*!
return *this;
}
-/*!
- \return title of table
-*/
-QString Plot2d_Curve::getTableTitle() const
-{
- return QString();
-}
-
-/*!
- Sets curve's horizontal title
-*/
-void Plot2d_Curve::setHorTitle( const QString& title )
-{
- myHorTitle = title;
-}
-
-/*!
- Gets curve's horizontal title
-*/
-QString Plot2d_Curve::getHorTitle() const
-{
- return myHorTitle;
-}
-
-/*!
- Sets curve's vertical title
-*/
-void Plot2d_Curve::setVerTitle( const QString& title )
-{
- myVerTitle = title;
-}
-
-/*!
- Gets curve's vertical title
-*/
-QString Plot2d_Curve::getVerTitle() const
-{
- return myVerTitle;
-}
-
-/*!
- Sets curve's horizontal units
-*/
-void Plot2d_Curve::setHorUnits( const QString& units )
-{
- myHorUnits = units;
-}
-
-/*!
- Gets curve's horizontal units
-*/
-QString Plot2d_Curve::getHorUnits() const
-{
- return myHorUnits;
-}
-
-/*!
- Sets curve's vertical units
-*/
-void Plot2d_Curve::setVerUnits( const QString& units )
-{
- myVerUnits = units;
-}
-
-/*!
- Gets curve's vertical units
-*/
-QString Plot2d_Curve::getVerUnits() const
-{
- return myVerUnits;
-}
-
-/*!
- Sets curve's name
+/**
+ *
*/
-void Plot2d_Curve::setName( const QString& theName )
-{
- myName = theName;
-}
-/*!
- Gets curve's name
- */
-QString Plot2d_Curve::getName() const
-{
- return myName;
-}
-
-/*!
- Adds one point for curve.
-*/
-void Plot2d_Curve::addPoint(double theX, double theY, const QString& txt )
+int Plot2d_Curve::rtti()
{
- Plot2d_Point aPoint;
- aPoint.x = theX;
- aPoint.y = theY;
- aPoint.text = txt;
- myPoints.append(aPoint);
+ return QwtPlotItem::Rtti_PlotCurve;
}
/*!
- Insert one point for curve on some position.
+ Displays curve in the given plot.
*/
-void Plot2d_Curve::insertPoint(int thePos, double theX, double theY, const QString& txt)
+QwtPlotItem* Plot2d_Curve::createPlotItem()
{
- Plot2d_Point aPoint;
- aPoint.x = theX;
- aPoint.y = theY;
- aPoint.text = txt;
-
- QList<Plot2d_Point>::iterator aIt;
- int aCurrent = 0;
- for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
- if (thePos == aCurrent) {
- myPoints.insert(aIt, aPoint);
- return;
- }
- aCurrent++;
- }
- myPoints.append(aPoint);
+ QwtPlotCurve* aCurve = new QwtPlotCurve();
+ updatePlotItem( aCurve );
+ return aCurve;
}
-/*!
- Delete one point for curve on some position.
-*/
-void Plot2d_Curve::deletePoint(int thePos)
-{
- if ( thePos >= 0 && thePos < myPoints.count() )
- myPoints.removeAt( thePos );
-}
-
-/*!
- Remove all points for curve.
-*/
-void Plot2d_Curve::clearAllPoints()
+/**
+ * Auto fill parameters of object by plot view
+ */
+void Plot2d_Curve::autoFill( const QwtPlot* thePlot )
{
- myPoints.clear();
-}
+ QwtSymbol::Style typeMarker;
+ QColor color;
+ Qt::PenStyle typeLine;
+ getNextMarker( thePlot, typeMarker, color, typeLine );
-/*!
- Gets curve's data : abscissas of points
-*/
-pointList Plot2d_Curve::getPointList() const
-{
- return myPoints;
+ setColor( color );
+ setLine( Plot2d::qwt2plotLine( typeLine ), DEFAULT_LINE_WIDTH );
+ setMarker( Plot2d::qwt2plotMarker( typeMarker ) );
}
/*!
- Sets curve's data.
-*/
-void Plot2d_Curve::setData( const double* hData, const double* vData, long size, const QStringList& lst )
-{
- clearAllPoints();
- QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
- for( long i = 0; i < size; i++, anIt++ )
- addPoint( hData[i], vData[i], anIt==aLast ? QString() : *anIt );
-}
-
-/*!
- Gets curve's data : abscissas of points
-*/
-double* Plot2d_Curve::horData() const
-{
- int aNPoints = nbPoints();
- double* aX = new double[aNPoints];
- for (int i = 0; i < aNPoints; i++) {
- aX[i] = myPoints[i].x;
- }
- return aX;
-}
-
-/*!
- Gets curve's data : ordinates of points
-*/
-double* Plot2d_Curve::verData() const
+ * Updates curve fields
+ */
+void Plot2d_Curve::updatePlotItem( QwtPlotItem* theItem )
{
- int aNPoints = nbPoints();
- double* aY = new double[aNPoints];
- for (int i = 0; i < aNPoints; i++) {
- aY[i] = myPoints[i].y;
- }
- return aY;
-}
+ if ( theItem->rtti() != rtti() )
+ return;
+ QwtPlotCurve* aCurve = dynamic_cast<QwtPlotCurve*>( theItem );
+ if ( !aCurve )
+ return;
-/*!
- Gets curve's data : number of points
-*/
-int Plot2d_Curve::nbPoints() const
-{
- return myPoints.count();
-}
+ Qt::PenStyle ps = Plot2d::plot2qwtLine( getLine() );
+ QwtSymbol::Style ms = Plot2d::plot2qwtMarker( getMarker() );
-/*!
- Returns true if curve has no data
-*/
-bool Plot2d_Curve::isEmpty() const
-{
- return myPoints.isEmpty();
-}
-
-/*!
- Sets curve's AutoAssign flag - in this case attributes will be set automatically
-*/
-void Plot2d_Curve::setAutoAssign( bool on )
-{
- myAutoAssign = on;
-}
-
-/*!
- Gets curve's AutoAssign flag state
-*/
-bool Plot2d_Curve::isAutoAssign() const
-{
- return myAutoAssign;
+ aCurve->setPen( QPen( getColor(), getLineWidth(), ps ) );
+ aCurve->setSymbol( QwtSymbol( ms, QBrush( getColor() ),
+ QPen( getColor() ),
+ QSize( myMarkerSize, myMarkerSize ) ) );
+ aCurve->setData( horData(), verData(), nbPoints() );
+ aCurve->setTitle( !getName().isEmpty() ? getName() : getVerTitle() );
}
/*!
return myColor;
}
+/*!
+ Sets new marker size
+*/
+void Plot2d_Curve::setMarkerSize( const int theSize )
+{
+ myMarkerSize = theSize;
+}
+
/*!
Sets curve's marker ( and resets AutoAssign flag )
*/
{
return myMarker;
}
-
/*!
Sets curve's line type and width ( and resets AutoAssign flag )
NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals.
}
/*!
- Sets curve's y axis
+ Gets new unique marker for item if possible
*/
-void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis)
+const int MAX_ATTEMPTS = 10;
+void Plot2d_Curve::getNextMarker( const QwtPlot* thePlot, QwtSymbol::Style& typeMarker,
+ QColor& color, Qt::PenStyle& typeLine )
{
- if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
- myYAxis = theYAxis;
-}
+ bool bOk = false;
+ int cnt = 1;
+ while ( !bOk ) {
+ int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
+ int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
+ int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
+ int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1;// 9 markers types( not including empty )
+ int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1;// 5 line types ( not including empty )
-/*!
- Gets curve's y axis
-*/
-QwtPlot::Axis Plot2d_Curve::getYAxis() const
-{
- return myYAxis;
-}
+ typeMarker = ( QwtSymbol::Style )aMarker;
+ color = QColor( aRed, aGreen, aBlue );
+ typeLine = ( Qt::PenStyle )aLine;
-/*!
- Gets curve's minimal abscissa
-*/
-double Plot2d_Curve::getMinX() const
-{
- QList<Plot2d_Point>::const_iterator aIt;
- double aMinX = 1e150;
- //int aCurrent = 0;
- for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
- if ( (*aIt).x < aMinX )
- aMinX = (*aIt).x;
+ cnt++;
+ if ( cnt == MAX_ATTEMPTS )
+ bOk = true;
+ else
+ bOk = !existMarker( thePlot, typeMarker, color, typeLine );
}
- return aMinX;
-}
-
-/*!
- Gets curve's minimal ordinate
-*/
-double Plot2d_Curve::getMinY() const
-{
- QList<Plot2d_Point>::const_iterator aIt;
- double aMinY = 1e150;
- //int aCurrent = 0;
- for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
- if ( (*aIt).y < aMinY )
- aMinY = (*aIt).y;
+/*
+ static int aMarker = -1;
+ static int aColor = -1;
+ static int aLine = -1;
+
+ if ( myColors.isEmpty() ) {
+ // creating colors list
+ myColors.append( Qt::white );
+ myColors.append( Qt::blue );
+ myColors.append( Qt::gray );
+ myColors.append( Qt::darkGreen );
+ myColors.append( Qt::magenta );
+ myColors.append( Qt::darkGray );
+ myColors.append( Qt::red );
+ myColors.append( Qt::darkBlue );
+ myColors.append( Qt::darkYellow );
+ myColors.append( Qt::cyan );
+ myColors.append( Qt::darkRed );
+ myColors.append( Qt::darkCyan );
+ myColors.append( Qt::yellow );
+ myColors.append( Qt::darkMagenta );
+ myColors.append( Qt::green );
+ myColors.append( Qt::black );
}
- return aMinY;
-}
-/*!
- Changes text assigned to point of curve
- \param ind -- index of point
- \param txt -- new text
-*/
-void Plot2d_Curve::setText( const int ind, const QString& txt )
-{
- if( ind<0 || ind>=myPoints.count() )
+ int nbMarkers = 11; // QwtSymbol supports 11 marker types
+ int nbLines = 6; // Qt supports 6 line types
+ int nbColors = myColors.count(); // number of default colors supported
+
+ aMarker = ( aMarker + 1 ) % nbMarkers;
+ if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
+ aColor = ( aColor + 1 ) % nbColors;
+ aLine = ( aLine + 1 ) % nbLines;
+ if ( aLine == Qt::NoPen ) aLine++;
+
+ typeMarker = ( QwtSymbol::Style )aMarker;
+ color = myColors[ aColor ];
+ typeLine = ( Qt::PenStyle )aLine;
+ if ( !existMarker( thePlot, typeMarker, color, typeLine ) )
return;
- myPoints[ind].text = txt;
+ int i, j, k;
+ for ( i = 0; i < nbMarkers; i++ ) {
+ aMarker = ( aMarker + 1 ) % nbMarkers;
+ if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
+ for ( j = 0; j < nbColors; j++ ) {
+ aColor = ( aColor + 1 ) % nbColors;
+ for ( k = 0; k < nbLines; k++ ) {
+ aLine = ( aLine + 1 ) % nbLines;
+ if ( aLine == Qt::NoPen ) aLine++;
+ if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
+ typeMarker = ( QwtSymbol::Style )aMarker;
+ color = myColors[ aColor ];
+ typeLine = ( Qt::PenStyle )aLine;
+ return;
+ }
+ }
+ }
+ }
+*/
}
/*!
- \return text assigned to point
- \param ind -- index of point
+ Checks if marker belongs to any enitity
*/
-QString Plot2d_Curve::text( const int ind ) const
+bool Plot2d_Curve::existMarker( const QwtPlot* thePlot, const QwtSymbol::Style typeMarker,
+ const QColor& color, const Qt::PenStyle typeLine )
{
- if( ind<0 || ind>=myPoints.count() )
- return QString();
- else
- return myPoints[ind].text;
+ QColor aColor = thePlot->palette().color( QPalette::Background );
+ if ( closeColors( color, aColor ) )
+ return true;
+ QwtPlotItemList anItems = thePlot->itemList();
+ QwtPlotItemIterator anIt = anItems.begin(), aLast = anItems.end();
+ QwtPlotItem* anItem;
+ for( ; anIt != aLast; anIt++ ) {
+ anItem = *anIt;
+ if( anItem && anItem->rtti() == rtti() ) {
+ QwtPlotCurve* crv = dynamic_cast<QwtPlotCurve*>( anItem );
+ if ( crv ) {
+ QwtSymbol::Style aStyle = crv->symbol().style();
+ QColor aColor = crv->pen().color();
+ Qt::PenStyle aLine = crv->pen().style();
+ if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
+ return true;
+ }
+ }
+ }
+ return false;
}
#define PLOT2D_CURVE_H
#include "Plot2d.h"
+#include <Plot2d_Object.h>
-#include <QList>
-#include <qwt_plot.h>
+#include <qwt_plot_curve.h>
-class QColor;
-
-typedef struct
-{
- double x;
- double y;
- QString text;
-} Plot2d_Point;
-
-typedef QList<Plot2d_Point> pointList;
-
-class PLOT2D_EXPORT Plot2d_Curve
+class PLOT2D_EXPORT Plot2d_Curve : public Plot2d_Object
{
public:
Plot2d_Curve();
- virtual ~Plot2d_Curve();
Plot2d_Curve( const Plot2d_Curve& );
- Plot2d_Curve& operator= ( const Plot2d_Curve& );
-
- virtual QString getTableTitle() const;
-
- void setHorTitle( const QString& );
- QString getHorTitle() const;
- void setVerTitle( const QString& );
- QString getVerTitle() const;
-
- void setHorUnits( const QString& );
- QString getHorUnits() const;
- void setVerUnits( const QString& );
- QString getVerUnits() const;
-
- void setName( const QString& );
- QString getName() const;
- void addPoint( double, double, const QString& = QString() );
- void insertPoint( int, double, double, const QString& = QString() );
- void deletePoint( int );
- void clearAllPoints();
- pointList getPointList() const;
-
- void setData( const double*, const double*,
- long, const QStringList& = QStringList() );
- double* horData() const;
- double* verData() const;
-
- void setText( const int, const QString& );
- QString text( const int ) const;
-
- int nbPoints() const;
- bool isEmpty() const;
+ virtual ~Plot2d_Curve() {};
+ Plot2d_Curve& operator= ( const Plot2d_Curve& );
- void setAutoAssign( bool );
- bool isAutoAssign() const;
+ virtual int rtti();
+ virtual QwtPlotItem* createPlotItem();
+ virtual void autoFill( const QwtPlot* );
+ virtual void updatePlotItem( QwtPlotItem* );
void setColor( const QColor& );
QColor getColor() const;
+ void setMarkerSize( const int );
+
void setMarker( Plot2d::MarkerType );
Plot2d::MarkerType getMarker() const;
Plot2d::LineType getLine() const;
int getLineWidth() const;
- void setYAxis( QwtPlot::Axis );
- QwtPlot::Axis getYAxis() const;
-
- // Protection against QwtCurve::drawLines() 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
- double getMinX() const;
- double getMinY() const;
+protected:
+ void getNextMarker( const QwtPlot*, QwtSymbol::Style&,
+ QColor&, Qt::PenStyle& );
+ bool existMarker( const QwtPlot*, const QwtSymbol::Style,
+ const QColor&, const Qt::PenStyle );
protected:
- bool myAutoAssign;
- QString myHorTitle;
- QString myVerTitle;
- QString myHorUnits;
- QString myVerUnits;
- QString myName;
QColor myColor;
+ int myMarkerSize;
Plot2d::MarkerType myMarker;
Plot2d::LineType myLine;
int myLineWidth;
- QwtPlot::Axis myYAxis;
-
- pointList myPoints;
};
typedef QList<Plot2d_Curve*> curveList;
/*!
Standard constructor
*/
-Plot2d_Prs::Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete )
+Plot2d_Prs::Plot2d_Prs( const Plot2d_Object* obj, bool theDelete )
: mySecondY( false), myIsAutoDel( theDelete )
{
AddObject( obj );
Plot2d_Prs::~Plot2d_Prs()
{
if ( myIsAutoDel )
- qDeleteAll( myCurves );
+ qDeleteAll( myObjects );
}
/*!
*/
curveList Plot2d_Prs::getCurves() const
{
- return myCurves;
+ curveList aCurves;
+
+ QList<Plot2d_Object*>::const_iterator it = myObjects.begin();
+ Plot2d_Object* anObj;
+ Plot2d_Curve* aCurve;
+ for ( ; it != myObjects.end(); ++it ) {
+ anObj = *it;
+ if ( anObj && anObj->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
+ aCurve = dynamic_cast<Plot2d_Curve*>( anObj );
+ aCurves.append( aCurve );
+ }
+ }
+ return aCurves;
+}
+
+/*!
+ Get objects list
+*/
+objectList Plot2d_Prs::getObjects() const
+{
+ return myObjects;
}
/*!
Add curve
*/
-void Plot2d_Prs::AddObject( const Plot2d_Curve* obj )
+void Plot2d_Prs::AddObject( const Plot2d_Object* obj )
{
- myCurves.append((Plot2d_Curve*)obj);
+ myObjects.append((Plot2d_Object*)obj);
if (obj->getYAxis() == QwtPlot::yRight)
mySecondY = true;
*/
bool Plot2d_Prs::IsNull() const
{
- return myCurves.isEmpty();
+ return myObjects.isEmpty();
}
/*!
#include "Plot2d.h"
#include "Plot2d_Curve.h"
+#include "Plot2d_Object.h"
class PLOT2D_EXPORT Plot2d_Prs
{
public:
Plot2d_Prs( bool theDelete = false );
- Plot2d_Prs( const Plot2d_Curve* obj, bool theDelete = false );
+ Plot2d_Prs( const Plot2d_Object* obj, bool theDelete = false );
~Plot2d_Prs();
- curveList getCurves() const;
- void AddObject( const Plot2d_Curve* obj );
+ curveList getCurves() const; // obsolete
+ objectList getObjects() const;
+ void AddObject( const Plot2d_Object* obj );
- bool IsNull() const;
+ bool IsNull() const;
- bool isSecondY() const;
+ bool isSecondY() const;
- void setAutoDel(bool theDel);
+ void setAutoDel(bool theDel);
protected:
- curveList myCurves;
- bool mySecondY;
- bool myIsAutoDel;
+ objectList myObjects;
+ bool mySecondY;
+ bool myIsAutoDel;
};
#endif
const int maxDist = 3, tip_margin = 10;
-Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame, Plot2d_Plot2d* plot )
-: QtxToolTip( plot->canvas() ),
- myFrame( frame ),
- myPlot( plot )
+Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame )
+: QtxToolTip( frame->getPlotCanvas() ),
+ myFrame( frame )
{
connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
int pInd;
double dist;
- Plot2d_Curve* c = myPlot->getClosestCurve( p, dist, pInd );
+ Plot2d_Curve* c = myFrame->getClosestCurve( p, dist, pInd );
if( !c || dist>maxDist )
return;
#include <QtxToolTip.h>
class Plot2d_ViewFrame;
-class Plot2d_Plot2d;
class PLOT2D_EXPORT Plot2d_ToolTip : public QtxToolTip
{
Q_OBJECT
public:
- Plot2d_ToolTip( Plot2d_ViewFrame*, Plot2d_Plot2d* );
+ Plot2d_ToolTip( Plot2d_ViewFrame* );
virtual ~Plot2d_ToolTip();
virtual bool eventFilter( QObject*, QEvent* );
private:
Plot2d_ViewFrame* myFrame;
- Plot2d_Plot2d* myPlot;
};
#endif
#include <qwt_legend.h>
-#define DEFAULT_LINE_WIDTH 0 // (default) line width
+//#define DEFAULT_LINE_WIDTH 0 // (default) line width
#define DEFAULT_MARKER_SIZE 9 // default marker size
#define MIN_RECT_SIZE 11 // min sensibility area size
myCurveType( 1 ),
myShowLegend( true ), myLegendPos( 1 ),
myMarkerSize( DEFAULT_MARKER_SIZE ),
- myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
myBackground( Qt::white ),
+ myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
myTitleEnabled( true ), myXTitleEnabled( true ),
myYTitleEnabled( true ), myY2TitleEnabled (true),
myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
/* Plot 2d View */
QVBoxLayout* aLayout = new QVBoxLayout( this );
myPlot = new Plot2d_Plot2d( this );
- new Plot2d_ToolTip( this, myPlot );
+ new Plot2d_ToolTip( this );
aLayout->addWidget( myPlot );
*/
void Plot2d_ViewFrame::DisplayAll()
{
- QList<Plot2d_Curve*> clist;
- getCurves( clist );
- for ( int i = 0; i < (int)clist.count(); i++ ) {
- updateCurve( clist.at( i ), false );
+ QList<Plot2d_Object*> olist;
+ getObjects( olist );
+ for ( int i = 0; i < (int)olist.count(); i++ ) {
+ updateObject( olist.at( i ), false );
}
myPlot->replot();
}
void Plot2d_ViewFrame::EraseAll()
{
myPlot->clear();
- myPlot->getCurves().clear();
+ myObjects.clear();
myPlot->replot();
}
/*!
}
// display all curves from presentation
- curveList aCurves = prs->getCurves();
- displayCurves( aCurves );
+ objectList anObjects = prs->getObjects();
+ displayObjects( anObjects );
setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
return;
// erase all curves from presentation
- curveList aCurves = prs->getCurves();
- eraseCurves( aCurves );
+ objectList anObjects = prs->getObjects();
+ eraseObjects( anObjects );
}
bool Plot2d_ViewFrame::eventFilter( QObject* watched, QEvent* e )
*/
void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
{
- if ( !curve )
- return;
+ displayObject( curve, update );
+}
- // san -- Protection against QwtCurve bug in Qwt 0.4.x:
+/*!
+ Adds curves into view
+*/
+void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
+{
+ objectList olist;
+ QList<Plot2d_Curve*>::const_iterator it = curves.begin();
+ for ( ; it != curves.end(); it++ )
+ olist.append( *it );
+
+ displayObjects( olist, update );
+}
+
+/*!
+ Erases curve
+*/
+void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
+{
+ eraseObject( curve, update );
+}
+
+/*!
+ Erases curves
+*/
+void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
+{
+ objectList olist;
+ QList<Plot2d_Curve*>::const_iterator it = curves.begin();
+ for ( ; it != curves.end(); it++ )
+ olist.append( *it );
+
+ eraseObjects( olist, update );
+}
+
+/*!
+ Updates curves attributes
+*/
+void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
+{
+ updateObject( curve, update );
+}
+
+/*!
+ Gets lsit of displayed curves
+*/
+int Plot2d_ViewFrame::getCurves( curveList& clist )
+{
+ clist.clear();
+
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ for ( ; it != aCurves.end(); it++ )
+ clist.append( it.value() );
+ return clist.count();
+}
+
+/*!
+ Gets lsit of displayed curves
+*/
+int Plot2d_ViewFrame::getObjects( objectList& olist )
+{
+ olist.clear();
+
+ ObjectDict::iterator it = myObjects.begin();
+ for ( ; it != myObjects.end(); it++ )
+ olist.append( it.value() );
+ return olist.count();
+}
+
+CurveDict Plot2d_ViewFrame::getCurves()
+{
+ ObjectDict::iterator it = myObjects.begin(), aLast = myObjects.end();
+ CurveDict aCurves;
+ QwtPlotItem* anItem;
+ for ( ; it != aLast; it++ ) {
+ anItem = it.key();
+ if ( anItem && anItem->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
+ QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( anItem );
+ Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( it.value() );
+ if ( aPCurve && aCurve )
+ aCurves.insert( aPCurve, aCurve );
+ }
+ }
+ return aCurves;
+}
+
+/*!
+ Adds object into view
+*/
+void Plot2d_ViewFrame::displayObject( Plot2d_Object* object, bool update )
+{
+ if ( !object )
+ return;
+ // san -- Protection against QwtObject 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 && curve->getMinX() <= 0. )
+ if ( myXMode && object->getMinX() <= 0. )
setHorScaleMode( 0, false );
- if ( myYMode && curve->getMinY() <= 0. )
+ if ( myYMode && object->getMinY() <= 0. )
setVerScaleMode( 0, false );
- if ( hasPlotCurve( curve ) ) {
- updateCurve( curve, update );
+ if ( hasPlotObject( object ) ) {
+ updateObject( object, update );
}
else {
- QwtPlotCurve* aPCurve = new QwtPlotCurve( !curve->getName().isEmpty() ?
- curve->getName() : curve->getVerTitle() );
- aPCurve->attach( myPlot );
+ if ( object->isAutoAssign() )
+ object->autoFill( myPlot );
+ QwtPlotItem* anItem = object->createPlotItem();
+ anItem->attach( myPlot );
+ myObjects.insert( anItem, object );
//myPlot->setCurveYAxis(curveKey, curve->getYAxis());
- myPlot->getCurves().insert( aPCurve, curve );
- if ( curve->isAutoAssign() ) {
- QwtSymbol::Style typeMarker;
- QColor color;
- Qt::PenStyle typeLine;
-
- myPlot->getNextMarker( typeMarker, color, typeLine );
- aPCurve->setPen( QPen( color, DEFAULT_LINE_WIDTH, typeLine ) );
- aPCurve->setSymbol( QwtSymbol( typeMarker,
- QBrush( color ),
- QPen( color ),
- QSize( myMarkerSize, myMarkerSize ) ) );
- curve->setColor( color );
- curve->setLine( Plot2d::qwt2plotLine( typeLine ) );
- curve->setMarker( Plot2d::qwt2plotMarker( typeMarker ) );
- }
- else {
- Qt::PenStyle ps = Plot2d::plot2qwtLine( curve->getLine() );
- QwtSymbol::Style ms = Plot2d::plot2qwtMarker( curve->getMarker() );
- aPCurve->setPen( QPen( curve->getColor(), curve->getLineWidth(), ps ) );
- aPCurve->setSymbol( QwtSymbol( ms,
- QBrush( curve->getColor() ),
- QPen( curve->getColor() ),
- QSize( myMarkerSize, myMarkerSize ) ) );
+ if ( object->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
+ Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( object );
+ if ( aCurve ) {
+ aCurve->setMarkerSize( myMarkerSize );
+ aCurve->updatePlotItem( anItem );
+ setCurveType( getPlotCurve( aCurve ), myCurveType );
+ }
}
- setCurveType( aPCurve, myCurveType );
- aPCurve->setData( curve->horData(), curve->verData(), curve->nbPoints() );
}
updateTitles();
if ( update )
}
/*!
- Adds curves into view
+ Adds objects into view
*/
-void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
+void Plot2d_ViewFrame::displayObjects( const objectList& objects, bool update )
{
//myPlot->setUpdatesEnabled( false ); // call this function deprecate update of legend
- QList<Plot2d_Curve*>::const_iterator it = curves.begin();
- Plot2d_Curve* aCurve;
- for (; it != curves.end(); ++it ) {
- aCurve = *it;
- displayCurve( aCurve, false );
+ QList<Plot2d_Object*>::const_iterator it = objects.begin();
+ Plot2d_Object* anObject;
+ for (; it != objects.end(); ++it ) {
+ anObject = *it;
+ displayObject( anObject, false );
}
fitAll();
//myPlot->setUpdatesEnabled( true );
}
/*!
- Erases curve
+ Erases object
*/
-void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
+void Plot2d_ViewFrame::eraseObject( Plot2d_Object* object, bool update )
{
- if ( !curve )
+ if ( !object )
return;
- if ( hasPlotCurve( curve ) ) {
- QwtPlotCurve* aPCurve = getPlotCurve( curve );
- aPCurve->hide();
- aPCurve->detach();
- myPlot->getCurves().remove( aPCurve );
+ if ( hasPlotObject( object ) ) {
+ QwtPlotItem* anObject = getPlotObject( object );
+ anObject->hide();
+ anObject->detach();
+ myObjects.remove( anObject );
updateTitles();
if ( update )
myPlot->replot();
}
/*!
- Erases curves
+ Erases objects
*/
-void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
+void Plot2d_ViewFrame::eraseObjects( const objectList& objects, bool update )
{
- QList<Plot2d_Curve*>::const_iterator it = curves.begin();
- Plot2d_Curve* aCurve;
- for (; it != curves.end(); ++it ) {
- aCurve = *it;
- eraseCurve( aCurve, false );
+ QList<Plot2d_Object*>::const_iterator it = objects.begin();
+ Plot2d_Object* anObject;
+ for (; it != objects.end(); ++it ) {
+ anObject = *it;
+ eraseObject( anObject, false );
}
// fitAll();
if ( update )
}
/*!
- Updates curves attributes
+ Updates objects attributes
*/
-void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
+void Plot2d_ViewFrame::updateObject( Plot2d_Object* object, bool update )
{
- if ( !curve )
+ if ( !object )
return;
- if ( hasPlotCurve( curve ) ) {
- QwtPlotCurve* aPCurve = getPlotCurve( curve );
- if ( !curve->isAutoAssign() ) {
- Qt::PenStyle ps = Plot2d::plot2qwtLine( curve->getLine() );
- QwtSymbol::Style ms = Plot2d::plot2qwtMarker( curve->getMarker() );
- aPCurve->setPen ( QPen( curve->getColor(), curve->getLineWidth(), ps ) );
- aPCurve->setSymbol( QwtSymbol( ms,
- QBrush( curve->getColor() ),
- QPen( curve->getColor() ),
- QSize( myMarkerSize, myMarkerSize ) ) );
- aPCurve->setData( curve->horData(), curve->verData(), curve->nbPoints() );
- }
- aPCurve->setTitle( !curve->getName().isEmpty() ? curve->getName() :
- curve->getVerTitle() );
- aPCurve->setVisible( true );
+ if ( hasPlotObject( object ) ) {
+ QwtPlotItem* anItem = getPlotObject( object );
+ if ( !anItem )
+ return;
+ object->updatePlotItem( anItem );
+ anItem->setVisible( true );
if ( update )
myPlot->replot();
}
}
/*!
- Gets lsit of displayed curves
+ Returns true if the curve is visible
*/
-int Plot2d_ViewFrame::getCurves( curveList& clist )
-{
- clist.clear();
-
- CurveDict::iterator it = myPlot->getCurves().begin();
- for ( ; it != myPlot->getCurves().end(); it++ )
- clist.append( it.value() );
- return clist.count();
-}
-
-const CurveDict& Plot2d_ViewFrame::getCurves()
+bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve )
{
- return myPlot->getCurves();
+ return isVisible( dynamic_cast<Plot2d_Object*>( curve ) );
}
/*!
Returns true if the curve is visible
*/
-bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve )
+bool Plot2d_ViewFrame::isVisible( Plot2d_Object* object )
{
- if(curve) {
- if ( hasPlotCurve( curve ) ) {
- return getPlotCurve( curve )->isVisible();
+ if ( object ) {
+ if ( hasPlotObject( object ) ) {
+ return getPlotObject( object )->isVisible();
}
}
return false;
{
if ( !prs || prs->IsNull() )
return;
- curveList aCurves = prs->getCurves();
-
- QList<Plot2d_Curve*>::iterator it = aCurves.begin();
- Plot2d_Curve* aCurve;
- for (; it != aCurves.end(); ++it ) {
- aCurve = *it;
- if ( hasPlotCurve( aCurve ) )
- getPlotCurve( aCurve )->setTitle( !aCurve->getName().isEmpty() ?
- aCurve->getName() : aCurve->getVerTitle() );
+
+ ObjectDict::iterator it = myObjects.begin();
+ Plot2d_Object* anObj;
+ for (; it != myObjects.end(); ++it ) {
+ anObj = *it;
+ if ( hasPlotObject( anObj ) )
+ getPlotObject( anObj )->setTitle( !anObj->getName().isEmpty() ?
+ anObj->getName() : anObj->getVerTitle() );
}
}
QwtSymbol::Style typeMarker;
QColor color;
Qt::PenStyle typeLine;
- myPlot->getNextMarker( typeMarker, color, typeLine );
+ ///myPlot->getNextMarker( typeMarker, color, typeLine );
if ( mars.contains(typeMarker) )
mars[ typeMarker ] = mars[ typeMarker ]+1;
else
void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
{
myCurveType = curveType;
- CurveDict::iterator it = myPlot->getCurves().begin();
- for ( ; it != myPlot->getCurves().end(); it++ ) {
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ for ( ; it != aCurves.end(); it++ ) {
QwtPlotCurve* crv = it.key();
if ( crv )
setCurveType( crv, myCurveType );
\param title - new title
*/
void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title )
+{
+ setObjectTitle( curve, title );
+}
+
+/*!
+ Sets object title
+ \param object - object id
+ \param title - new title
+*/
+void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title )
{
- if ( curve && hasPlotCurve( curve ) )
- getPlotCurve( curve )->setTitle( title );
+ if ( object && hasPlotObject( object ) )
+ getPlotObject( object )->setTitle( title );
}
/*!
if ( myMarkerSize != size )
{
myMarkerSize = size;
- CurveDict::iterator it = myPlot->getCurves().begin();
- for ( ; it != myPlot->getCurves().end(); it++ ) {
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ for ( ; it != aCurves.end(); it++ ) {
QwtPlotCurve* crv = it.key();
if ( crv )
{
myY2Title = title;
myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString() );
break;
+ default:
+ break;
}
if ( update )
myPlot->replot();
title = myYTitle; break;
case Y2Title:
title = myY2Title; break;
+ default:
+ break;
}
return title;
}
*/
QwtPlotCurve* Plot2d_ViewFrame::getPlotCurve( Plot2d_Curve* curve )
{
- CurveDict::iterator it = myPlot->getCurves().begin();
- for ( ; it != myPlot->getCurves().end(); it++ ) {
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ for ( ; it != aCurves.end(); it++ ) {
if ( it.value() == curve )
return it.key();
}
*/
bool Plot2d_ViewFrame::hasPlotCurve( Plot2d_Curve* curve )
{
- CurveDict::iterator it = myPlot->getCurves().begin();
- for ( ; it != myPlot->getCurves().end(); it++ ) {
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ for ( ; it != aCurves.end(); it++ ) {
if ( it.value() == curve )
return true;
}
return false;
}
+/*!
+ Returns qwt plot curve if it is existed in map of curves and 0 otherwise
+*/
+QwtPlotItem* Plot2d_ViewFrame::getPlotObject( Plot2d_Object* object )
+{
+ ObjectDict::iterator it = myObjects.begin();
+ for ( ; it != myObjects.end(); it++ ) {
+ if ( it.value() == object )
+ return it.key();
+ }
+ return 0;
+}
+/*!
+ Returns true if qwt plot curve is existed in map of curves and false otherwise
+*/
+bool Plot2d_ViewFrame::hasPlotObject( Plot2d_Object* object )
+{
+ ObjectDict::iterator it = myObjects.begin();
+ for ( ; it != myObjects.end(); it++ ) {
+ if ( it.value() == object )
+ return true;
+ }
+ return false;
+}
+
/*!
Sets curve type
*/
bool Plot2d_ViewFrame::isXLogEnabled() const
{
bool allPositive = true;
- CurveDict::const_iterator it = myPlot->getCurves().begin();
- for ( ; allPositive && it != myPlot->getCurves().end(); it++ )
+ ObjectDict::const_iterator it = myObjects.begin();
+ for ( ; allPositive && it != myObjects.end(); it++ )
allPositive = ( it.value()->getMinX() > 0. );
return allPositive;
}
bool Plot2d_ViewFrame::isYLogEnabled() const
{
bool allPositive = true;
- CurveDict::const_iterator it = myPlot->getCurves().begin();
- for ( ; allPositive && it != myPlot->getCurves().end(); it++ )
+ ObjectDict::const_iterator it = myObjects.begin();
+ for ( ; allPositive && it != myObjects.end(); it++ )
allPositive = ( it.value()->getMinY() > 0. );
return allPositive;
}
QwtPlot::replot();
}
-/*!
- Checks if two colors are close to each other [ static ]
- uses COLOR_DISTANCE variable as max tolerance for comparing of colors
-*/
-const long COLOR_DISTANCE = 100;
-const int MAX_ATTEMPTS = 10;
-static bool closeColors( const QColor& color1, const QColor& color2 )
-{
- long tol = abs( color2.red() - color1.red() ) +
- abs( color2.green() - color1.green() ) +
- abs( color2.blue() - color1.blue() );
-
- return ( tol <= COLOR_DISTANCE );
-}
-/*!
- Gets new unique marker for item if possible
-*/
-void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
-{
- bool bOk = false;
- int cnt = 1;
- while ( !bOk ) {
- int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
- int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
- int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
- int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty )
- int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty )
-
- typeMarker = ( QwtSymbol::Style )aMarker;
- color = QColor( aRed, aGreen, aBlue );
- typeLine = ( Qt::PenStyle )aLine;
-
- cnt++;
- if ( cnt == MAX_ATTEMPTS )
- bOk = true;
- else
- bOk = !existMarker( typeMarker, color, typeLine );
- }
-/*
- static int aMarker = -1;
- static int aColor = -1;
- static int aLine = -1;
-
- if ( myColors.isEmpty() ) {
- // creating colors list
- myColors.append( Qt::white );
- myColors.append( Qt::blue );
- myColors.append( Qt::gray );
- myColors.append( Qt::darkGreen );
- myColors.append( Qt::magenta );
- myColors.append( Qt::darkGray );
- myColors.append( Qt::red );
- myColors.append( Qt::darkBlue );
- myColors.append( Qt::darkYellow );
- myColors.append( Qt::cyan );
- myColors.append( Qt::darkRed );
- myColors.append( Qt::darkCyan );
- myColors.append( Qt::yellow );
- myColors.append( Qt::darkMagenta );
- myColors.append( Qt::green );
- myColors.append( Qt::black );
- }
-
- int nbMarkers = 11; // QwtSymbol supports 11 marker types
- int nbLines = 6; // Qt supports 6 line types
- int nbColors = myColors.count(); // number of default colors supported
-
- aMarker = ( aMarker + 1 ) % nbMarkers;
- if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
- aColor = ( aColor + 1 ) % nbColors;
- aLine = ( aLine + 1 ) % nbLines;
- if ( aLine == Qt::NoPen ) aLine++;
-
- typeMarker = ( QwtSymbol::Style )aMarker;
- color = myColors[ aColor ];
- typeLine = ( Qt::PenStyle )aLine;
- if ( !existMarker( typeMarker, color, typeLine ) )
- return;
-
- int i, j, k;
- for ( i = 0; i < nbMarkers; i++ ) {
- aMarker = ( aMarker + 1 ) % nbMarkers;
- if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
- for ( j = 0; j < nbColors; j++ ) {
- aColor = ( aColor + 1 ) % nbColors;
- for ( k = 0; k < nbLines; k++ ) {
- aLine = ( aLine + 1 ) % nbLines;
- if ( aLine == Qt::NoPen ) aLine++;
- if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
- typeMarker = ( QwtSymbol::Style )aMarker;
- color = myColors[ aColor ];
- typeLine = ( Qt::PenStyle )aLine;
- return;
- }
- }
- }
- }
-*/
-}
-
/*!
\return the default layout behavior of the widget
*/
myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, button, state );
}
-/*!
- return closest curve if it exist, else 0
-*/
-Plot2d_Curve* Plot2d_Plot2d::getClosestCurve( QPoint p, double& distance, int& index )
-{
- CurveDict::iterator it = getCurves().begin();
- QwtPlotCurve* aCurve;
- for ( ; it != getCurves().end(); it++ ) {
- aCurve = it.key();
- if ( !aCurve )
- continue;
- index = aCurve->closestPoint( p, &distance );
- if ( index > -1 )
- return it.value();
- }
- return 0;
-}
-
-/*!
- Checks if marker belongs to any enitity
-*/
-bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
-{
- QColor aColor = palette().color( QPalette::Background );
- if ( closeColors( color, aColor ) )
- return true;
-
- CurveDict::iterator it = myCurves.begin();
- for ( ; it != myCurves.end(); it++ ) {
- QwtPlotCurve* crv = it.key();
- if ( crv ) {
- QwtSymbol::Style aStyle = crv->symbol().style();
- QColor aColor = crv->pen().color();
- Qt::PenStyle aLine = crv->pen().style();
-// if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
- if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
- return true;
- }
- }
- return false;
-}
-
/*!
Sets the flag saying that QwtPlot geometry has been fully defined.
*/
#define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
void Plot2d_ViewFrame::updateTitles()
{
- CurveDict::iterator it = myPlot->getCurves().begin();
- //QIntDictIterator<Plot2d_Curve> it( myCurves );
+ ObjectDict::iterator it = myObjects.begin();
QStringList aXTitles;
QStringList aYTitles;
QStringList aXUnits;
QStringList aTables;
int i = 0;
- Plot2d_Curve* aCurve;
- for ( ; it != myPlot->getCurves().end(); it++ ) {
+ Plot2d_Object* anObject;
+ for ( ; it != myObjects.end(); it++ ) {
// collect titles and units from all curves...
- aCurve = it.value();
- QString xTitle = aCurve->getHorTitle().trimmed();
- QString yTitle = aCurve->getVerTitle().trimmed();
- QString xUnits = aCurve->getHorUnits().trimmed();
- QString yUnits = aCurve->getVerUnits().trimmed();
+ anObject = it.value();
+ QString xTitle = anObject->getHorTitle().trimmed();
+ QString yTitle = anObject->getVerTitle().trimmed();
+ QString xUnits = anObject->getHorUnits().trimmed();
+ QString yUnits = anObject->getVerUnits().trimmed();
aYTitles.append( yTitle );
if ( !aXTitles.contains( xTitle ) )
if ( !aYUnits.contains( yUnits ) )
aYUnits.append( yUnits );
- QString aName = aCurve->getTableTitle();
+ QString aName = anObject->getTableTitle();
if( !aName.isEmpty() && !aTables.contains( aName ) )
aTables.append( aName );
++i;
#endif
}
+/**
+ * Print Plot2d window
+ */
+void Plot2d_ViewFrame::printPlot( QPainter* p, const QRect& rect,
+ const QwtPlotPrintFilter& filter ) const
+{
+ myPlot->print( p, rect, filter );
+}
+
/*!
\return string with all visual parameters
*/
myPlot->replot();
}
+/**
+ *
+ */
+QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas()
+{
+ return myPlot ? myPlot->canvas() : 0;
+}
+
+/*!
+ return closest curve if it exist, else 0
+*/
+Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance,
+ int& index )
+{
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ QwtPlotCurve* aCurve;
+ for ( ; it != aCurves.end(); it++ ) {
+ aCurve = it.key();
+ if ( !aCurve )
+ continue;
+ index = aCurve->closestPoint( p, &distance );
+ if ( index > -1 )
+ return it.value();
+ }
+ return 0;
+}
+
#define INCREMENT_FOR_OP 10
/*!
if ( ce->type() == FITALL_EVENT )
fitAll();
}
-
-/*!
- Gets plot
-*/
-Plot2d_Plot2d* Plot2d_ViewFrame::getPlot() const
-{
- return myPlot;
-}
-
-
class QwtPlotGrid;
class QwtPlotZoomer;
-typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
+typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict; // obsolete
+typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
{
void updateTitles();
void setTitle( const QString& title );
QString getTitle() const { return myTitle; }
- void displayCurve( Plot2d_Curve* curve, bool update = false );
- void displayCurves( const curveList& curves, bool update = false );
- void eraseCurve( Plot2d_Curve* curve, bool update = false );
- void eraseCurves( const curveList& curves, bool update = false );
- int getCurves( curveList& clist );
- const CurveDict& getCurves();
- bool isVisible( Plot2d_Curve* curve );
- void updateCurve( Plot2d_Curve* curve, bool update = false );
+
+ // obsolete operation on curves
+ void displayCurve( Plot2d_Curve* curve, bool update = false ); // obsolete
+ void displayCurves( const curveList& curves, bool update = false ); // obsolete
+ void eraseCurve( Plot2d_Curve* curve, bool update = false ); // obsolete
+ void eraseCurves( const curveList& curves, bool update = false ); // obsolete
+ int getCurves( curveList& clist ); // obsolete
+ CurveDict getCurves(); // osolete
+ bool isVisible( Plot2d_Curve* curve ); // obsolete
+ void updateCurve( Plot2d_Curve* curve, bool update = false ); // osolete
+
+ // operations on objects
+ void displayObject( Plot2d_Object* curve, bool update = false );
+ void displayObjects( const objectList& objects, bool update = false );
+ void eraseObject( Plot2d_Object* object, bool update = false );
+ void eraseObjects( const objectList& objects, bool update = false );
+
+ int getObjects( objectList& clist );
+ bool isVisible( Plot2d_Object* curve );
+ void updateObject( Plot2d_Object* object, bool update = false );
+
+
+ // operations on view frame
void updateLegend( const Plot2d_Prs* prs );
void fitAll();
void fitArea( const QRect& area );
void copyPreferences( Plot2d_ViewFrame* );
void setCurveType( int curveType, bool update = true );
int getCurveType() const { return myCurveType; }
- void setCurveTitle( Plot2d_Curve* curve, const QString& title );
+ void setCurveTitle( Plot2d_Curve* curve, const QString& title ); // obsolete
+ void setObjectTitle( Plot2d_Object* curve, const QString& title );
void showLegend( bool show, bool update = true );
void setLegendPos( int pos );
int getLegendPos() const { return myLegendPos; }
bool isYLogEnabled() const;
virtual bool print( const QString& file, const QString& format ) const;
+ void printPlot( QPainter* p, const QRect& rect,
+ const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const;
QString getVisualParameters();
void setVisualParameters( const QString& parameters );
void incrementalPan ( const int incrX, const int incrY );
void incrementalZoom( const int incrX, const int incrY );
+ QwtPlotCanvas* getPlotCanvas();
+ Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index );
+
protected:
int testOperation( const QMouseEvent& );
void readPreferences();
void writePreferences();
QString getInfo( const QPoint& pnt );
virtual void wheelEvent( QWheelEvent* );
- QwtPlotCurve* getPlotCurve( Plot2d_Curve* curve );
- bool hasPlotCurve( Plot2d_Curve* curve );
+ // obsolete methods on curves
+ QwtPlotCurve* getPlotCurve( Plot2d_Curve* curve ); // obsolete
+ bool hasPlotCurve( Plot2d_Curve* curve ); // obsolete
+ // methods on objects
+ QwtPlotItem* getPlotObject( Plot2d_Object* object );
+ bool hasPlotObject( Plot2d_Object* object );
+
void setCurveType( QwtPlotCurve* curve, int curveType );
public slots:
int myXMode, myYMode;
double myXDistance, myYDistance, myYDistance2;
bool mySecondY;
+ ObjectDict myObjects;
};
class Plot2d_Plot2d : public QwtPlot
void setLogScale( int axisId, bool log10 );
void replot();
- void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
QwtLegend* getLegend() {
#if QWT_VERSION < 0x040200
return d_legend;
bool polished() const { return myIsPolished; }
QwtPlotGrid* grid() { return myGrid; };
- CurveDict& getCurves() { return myCurves; }
- Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index );
public slots:
virtual void polish();
protected:
- bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
-
-protected:
- CurveDict myCurves;
QwtPlotGrid* myGrid;
QList<QColor> myColors;
bool myIsPolished;
if ( !myViewFrame )
return;
- Plot2d_Plot2d* aPlot = myViewFrame->getPlot();
- if ( !aPlot )
- return;
-
// stored settings for further starts
static QString aPrinterName;
static int aColorMode = -1;
// Iterate through, store temporary their parameters and assign
// parameters proper for printing
- CurveDict& aCurveDict = aPlot->getCurves();
+ CurveDict aCurveDict = myViewFrame->getCurves();
CurveDict::iterator it;
for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ )
{
}
}
- aPlot->print( &aPainter, QRect( 0, 0, W, H ) );
+ myViewFrame->printPlot( &aPainter, QRect( 0, 0, W, H ) );
aPainter.end();
// restore old pens and symbols
if ( needColorCorrection && !aCurvToPen.isEmpty() )
{
- CurveDict& aCurveDict = aPlot->getCurves();
+ CurveDict aCurveDict = myViewFrame->getCurves();
CurveDict::iterator it;
for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ )
{