Plot2d_ViewManager.h \
Plot2d_ViewModel.h \
Plot2d_ViewWindow.h \
- Plot2d_SetupCurveDlg.h
+ Plot2d_SetupCurveDlg.h \
+ Plot2d_ToolTip.h
# .po files to transform in .qm
PO_FILES = Plot2d_images.po \
Plot2d_ViewManager.cxx \
Plot2d_ViewModel.cxx \
Plot2d_ViewWindow.cxx \
- Plot2d_SetupCurveDlg.cxx
+ Plot2d_SetupCurveDlg.cxx \
+ Plot2d_ToolTip.cxx
LIB_MOC = \
Plot2d_FitDataDlg.h \
Plot2d_ViewManager.h \
Plot2d_ViewModel.h \
Plot2d_ViewWindow.h \
- Plot2d_SetupCurveDlg.h
+ Plot2d_SetupCurveDlg.h \
+ Plot2d_ToolTip.h
RESOURCES_FILES = \
plot2d_clone.png \
/*!
Adds one point for curve.
*/
-void Plot2d_Curve::addPoint(double theX, double theY)
+void Plot2d_Curve::addPoint(double theX, double theY, const QString& txt )
{
Plot2d_Point aPoint;
aPoint.x = theX;
aPoint.y = theY;
+ aPoint.text = txt;
myPoints.append(aPoint);
}
/*!
Insert one point for curve on some position.
*/
-void Plot2d_Curve::insertPoint(int thePos, double theX, double theY)
+void Plot2d_Curve::insertPoint(int thePos, double theX, double theY, const QString& txt)
{
Plot2d_Point aPoint;
aPoint.x = theX;
aPoint.y = theY;
+ aPoint.text = txt;
QValueList<Plot2d_Point>::iterator aIt;
int aCurrent = 0;
/*!
Sets curve's data.
*/
-void Plot2d_Curve::setData( const double* hData, const double* vData, long size )
+void Plot2d_Curve::setData( const double* hData, const double* vData, long size, const QStringList& lst )
{
clearAllPoints();
- for(long i = 0; i < size; i++) addPoint(hData[i], vData[i]);
+ 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::null : *anIt );
}
/*!
{
QValueList<Plot2d_Point>::const_iterator aIt;
double aMinX = 1e150;
- int aCurrent = 0;
+ //int aCurrent = 0;
for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
if ( (*aIt).x < aMinX )
aMinX = (*aIt).x;
{
QValueList<Plot2d_Point>::const_iterator aIt;
double aMinY = 1e150;
- int aCurrent = 0;
+ //int aCurrent = 0;
for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
if ( (*aIt).y < aMinY )
aMinY = (*aIt).y;
}
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() )
+ return;
+
+ myPoints[ind].text = txt;
+}
+
+/*!
+ \return text assigned to point
+ \param ind -- index of point
+*/
+QString Plot2d_Curve::text( const int ind ) const
+{
+ if( ind<0 || ind>=myPoints.count() )
+ return QString::null;
+ else
+ return myPoints[ind].text;
+}
{
double x;
double y;
+ QString text;
} Plot2d_Point;
typedef QValueList<Plot2d_Point> pointList;
QString getHorUnits() const;
void setVerUnits( const QString& units );
QString getVerUnits() const;
- void addPoint(double theX, double theY);
- void insertPoint(int thePos, double theX, double theY);
+ void addPoint(double theX, double theY, const QString& = QString::null );
+ void insertPoint(int thePos, double theX, double theY, const QString& = QString::null );
void deletePoint(int thePos);
void clearAllPoints();
pointList getPointList() const;
- void setData( const double* hData, const double* vData, long size );
+ void setData( const double* hData, const double* vData, long size, 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;
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: Plot2d_ToolTip.cxx
+// Author: Alexandre SOLOVYOV
+
+#include <Plot2d_ToolTip.h>
+#include <Plot2d_ViewFrame.h>
+#include <Plot2d_Curve.h>
+
+#include <qfontmetrics.h>
+
+#include <qwt_plot.h>
+#include <qwt_plot_canvas.h>
+
+const int maxDist = 3, tip_margin = 10;
+
+
+Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame, Plot2d_Plot2d* plot )
+: QtxToolTip( plot->canvas() ),
+ myFrame( frame ),
+ myPlot( plot )
+{
+ connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
+ this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
+}
+
+Plot2d_ToolTip::~Plot2d_ToolTip()
+{
+}
+
+void Plot2d_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
+{
+ int curInd, pInd, dist;
+ double x, y;
+ curInd = myPlot->closestCurve( p.x(), p.y(), dist, x, y, pInd );
+
+ if( dist>maxDist )
+ return;
+
+ Plot2d_Curve* c = myFrame->getCurves().find( curInd );
+ if( !c )
+ return;
+
+ str = c->text( pInd );
+ if( !str )
+ return;
+
+ QFontMetrics m( f );
+ QStringList lst = QStringList::split( "\n", str );
+ QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
+ int w = 0, h = 0;
+ for( ; anIt!=aLast; anIt++ )
+ {
+ if( h>0 )
+ h+= m.lineSpacing();
+
+ QRect r = m.boundingRect( *anIt );
+ if( r.width()>w )
+ w = r.width();
+ h+=r.height();
+ }
+
+ txtRect = QRect( p.x(), p.y(), w, h );
+ rect = txtRect;
+}
+
+bool Plot2d_ToolTip::eventFilter( QObject* o, QEvent* e )
+{
+ bool res = QtxToolTip::eventFilter( o, e );
+ if( e && e->type() == QEvent::MouseMove )
+ {
+ QMouseEvent* me = ( QMouseEvent* )e;
+ if( me->state()==0 )
+ return true;
+ }
+ return res;
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: Plot2d_ToolTip.h
+// Author: Alexandre SOLOVYOV
+
+#ifndef PLOT2D_TOOLTIP_H
+#define PLOT2D_TOOLTIP_H
+
+#include <Plot2d.h>
+#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* );
+ virtual ~Plot2d_ToolTip();
+
+public slots:
+ void onToolTip( QPoint, QString&, QFont&, QRect&, QRect& );
+
+protected:
+ virtual bool eventFilter( QObject*, QEvent* );
+
+private:
+ Plot2d_ViewFrame* myFrame;
+ Plot2d_Plot2d* myPlot;
+};
+
+#endif
#include "Plot2d_FitDataDlg.h"
#include "Plot2d_ViewWindow.h"
#include "Plot2d_SetupViewDlg.h"
+#include "Plot2d_ToolTip.h"
#include "SUIT_Tools.h"
#include "SUIT_Session.h"
/* Plot 2d View */
QVBoxLayout* aLayout = new QVBoxLayout( this );
myPlot = new Plot2d_Plot2d( this );
+ new Plot2d_ToolTip( this, myPlot );
+
aLayout->addWidget( myPlot );
// createActions();