Back to index

salome-gui  6.5.0
Public Slots | Public Member Functions | Protected Slots | Protected Attributes
Plot2d_Plot2d Class Reference

#include <Plot2d_ViewFrame.h>

Collaboration diagram for Plot2d_Plot2d:
Collaboration graph
[legend]

List of all members.

Public Slots

virtual void polish ()
 Sets the flag saying that QwtPlot geometry has been fully defined.

Public Member Functions

 Plot2d_Plot2d (QWidget *)
 Constructor.
virtual ~Plot2d_Plot2d ()
void setLogScale (int, bool)
 axis scale engine - linear or log10
void replot ()
 Recalculates and redraws Plot 2d view.
QwtLegend * getLegend ()
 Get legend.
QSize sizeHint () const
QSize minimumSizeHint () const
 return minimum size for qwt plot
void defaultPicker ()
void setPickerMousePattern (int, int=Qt::NoButton)
void createMarkerAndTooltip (QwtSymbol symbol, double X, double Y, QString &tooltip, Plot2d_QwtPlotPicker *picker)
 Create marker and tooltip associed with a point.
bool polished () const
QwtPlotGrid * grid () const
QwtPlotZoomer * zoomer () const
virtual void updateYAxisIdentifiers ()
 Updates identifiers of Y axis type in the legend.
void createAxisScaleDraw ()
void applyTicks ()
void unactivAxisScaleDraw (int numcall)
void displayXTicksAndLabels (double XLeftmargin, double XRightMargin, const QList< QPair< QString, QMap< double, QString > > > &devicesPosLabelTicks)
void createSeparationLine (double Xpos)

Protected Slots

void onScaleDivChanged ()
 Slot: checks the current labels format and change it if needed.

Protected Attributes

QwtPlotGrid * myGrid
QList< QColor > myColors
bool myIsPolished
QwtPlotZoomer * myPlotZoomer
Plot2d_AxisScaleDrawmyScaleDraw

Detailed Description

Definition at line 322 of file Plot2d_ViewFrame.h.


Constructor & Destructor Documentation

Plot2d_Plot2d::Plot2d_Plot2d ( QWidget *  parent)

Constructor.

Definition at line 2677 of file Plot2d_ViewFrame.cxx.

  : QwtPlot( parent ),
    myIsPolished( false )
{
  // Create alternative scales
  setAxisScaleDraw( QwtPlot::yLeft,   new Plot2d_ScaleDraw() );
  setAxisScaleDraw( QwtPlot::xBottom, 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 ) );

  defaultPicker();

  // auto scaling by default
  setAxisAutoScale( QwtPlot::yLeft );
  setAxisAutoScale( QwtPlot::yRight );
  setAxisAutoScale( QwtPlot::xBottom );

// grid
  myGrid = new QwtPlotGrid();
  QPen aMajPen = myGrid->majPen();
  aMajPen.setStyle( Qt::DashLine );
  myGrid->setPen( aMajPen );

  myGrid->enableX( false );
  myGrid->enableXMin( false );
  myGrid->enableY( false );
  myGrid->enableYMin( false );

  myGrid->attach( this );

  setMouseTracking( false );
  canvas()->setMouseTracking( true );

  myPlotZoomer->setEnabled( true );
  myPlotZoomer->setZoomBase();

  setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
}

Here is the call graph for this function:

Definition at line 2721 of file Plot2d_ViewFrame.cxx.

{
}

Member Function Documentation

Definition at line 2941 of file Plot2d_ViewFrame.cxx.

Here is the call graph for this function:

Definition at line 2933 of file Plot2d_ViewFrame.cxx.

void Plot2d_Plot2d::createMarkerAndTooltip ( QwtSymbol  symbol,
double  X,
double  Y,
QString &  tooltip,
Plot2d_QwtPlotPicker picker 
)

Create marker and tooltip associed with a point.

Definition at line 2811 of file Plot2d_ViewFrame.cxx.

{
  QwtPlotMarker* aPlotMarker = new QwtPlotMarker();

  aPlotMarker->setSymbol( symbol );  // symbol must have a color
  aPlotMarker->setLabelAlignment( Qt::AlignTop);
  aPlotMarker->setXValue(X);
  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) );

  QwtText text (tooltip);
  //QColor tooltipColor( 245, 222, 179);            // Wheat  -RGB (0 a 255)
  QColor tooltipColor( 253, 245, 230);            // OldLace
  text.setBackgroundBrush( QBrush(tooltipColor)); //, Qt::SolidPattern));
  //
  picker->pMarkers.append( aPlotMarker); 
  picker->pMarkersToolTip[ aPlotMarker] = text;
}

Definition at line 3116 of file Plot2d_ViewFrame.cxx.

{
  QwtPlotMarker* aPlotMarker = new QwtPlotMarker();

  aPlotMarker->setLineStyle( QwtPlotMarker::VLine);
  aPlotMarker->setXValue( Xpos);
  aPlotMarker->setLinePen( QPen(Qt::black));
  aPlotMarker->attach(this);  // Add to drawing zone
}

Here is the caller graph for this function:

Definition at line 2795 of file Plot2d_ViewFrame.cxx.

{
  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 );
}

Here is the caller graph for this function:

void Plot2d_Plot2d::displayXTicksAndLabels ( double  XLeftmargin,
double  XRightMargin,
const QList< QPair< QString, QMap< double, QString > > > &  devicesPosLabelTicks 
)

Definition at line 2971 of file Plot2d_ViewFrame.cxx.

{
  //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;

  int nbDevices = devicesPosLabelTicks.size();
  //
  //std::cout << "  Nombre de systemes = " << nbDevices << std::endl;
  if (nbDevices == 0)  return;

  // For drawing systems' names, their positions must be in the allTicks list
  // (cf class Plot2d_AxisScaleDraw)

  // Liste of ticks' positions and systems' names
  QList<double> allTicks;

  double devXmin, devXmax;  // X interval of a system
  double gapXmin, gapXmax;  // 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

  // 1)- Search for the system whose X interval is the most to the left

  int ileftDev = 0;
  double XminMin = 1.e+12;

  if (nbDevices > 1)
  {
      for (int idev=0; idev < nbDevices; idev++)
      {
          QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);

          QString deviceLabel = paire.first;

          // Ticks' map of the system
          QMap<double,QString> devPosLabelTicks = paire.second;

          QList<double> posTicks = devPosLabelTicks.keys();

          // List's items increasing sorting
          qSort( posTicks.begin(), posTicks.end() );  // iterators

          // X interval for the system
          devXmin = posTicks.first();
          devXmax = posTicks.last();

          if (devXmin < XminMin)
          {
              XminMin = devXmin;
              ileftDev = idev;
          }
      }
  }

  // 2)- Ticks, systems' names, verticals segments

  for (int idev=0; idev < nbDevices; idev++)
  {
      QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);

      QString deviceLabel = paire.first;

      std::string std_label = deviceLabel.toStdString();
      //const char *c_label = std_label.c_str();
      //std::cout << "  deviceLabel: |" << c_label << "|" << std::endl;

      // Ticks' map of the system
      QMap<double,QString> devPosLabelTicks = paire.second;

      int nbTicks = devPosLabelTicks.size();

      QList<double> posTicks = devPosLabelTicks.keys();

      // List's items increasing sorting
      qSort( posTicks.begin(), posTicks.end() );  // iterators

      // X interval for the system
      devXmin = posTicks.first();
      devXmax = posTicks.last();

      // Stock ticks' positions and labels on X axis
      double pos;
      QString label;
      //
      for (int itic=0; itic < nbTicks; itic++)
      {
          pos   = posTicks.at(itic);
          label = devPosLabelTicks[pos];

          myScaleDraw->setLabelTick( pos, label, false);

          std::string std_label = label.toStdString();
          //const char *c_label = std_label.c_str();
          //std::cout << "    tick " << itic << " : pos= " << pos << ", label= |" << c_label << "|" << std::endl;
      }
      allTicks.append( posTicks);

      // Compute the position of the system's label
      if (idev == ileftDev)
      {
          devLabPos = devXmin + 0.25*(devXmax - devXmin);
      }
      else
      {
          devLabPos = devXmin + 0.50*(devXmax - devXmin);
      }
      allTicks.append( devLabPos);

      // Stock position and name of the system under X axis
      myScaleDraw->setLabelTick( devLabPos, deviceLabel, true);

      if (idev > 0)
      {
          // Create the vertical segment between the current system and the next
          gapXmax = devXmin;
          segmentPos = gapXmin + 0.5*(gapXmax - gapXmin);

          createSeparationLine( segmentPos);
      }
      gapXmin = devXmax;
  }

  // List's items increasing sorting
  qSort( allTicks.begin(), allTicks.end() );  // iterators

  // Stock the interval of X's values
  double lowerBound = allTicks.first() - XLeftMargin;
  double upperBound = allTicks.last() + XRightMargin;
  myScaleDraw->setInterval( lowerBound, upperBound);

  // For each system, stock the position of the X's ticks and those of the name
  myScaleDraw->setTicks( allTicks);  // do not draw the ticks

  // Memorize the X axis in the drawing zone
  setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw);  // heritage of QwtPlot

  //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
}

Here is the call graph for this function:

QwtLegend * Plot2d_Plot2d::getLegend ( )

Get legend.

Definition at line 2768 of file Plot2d_ViewFrame.cxx.

{
#if QWT_VERSION < 0x040200
  return d_legend;
#else  
  return legend(); /* mpv: porting to the Qwt 4.2.0 */
#endif
}
QwtPlotGrid * Plot2d_Plot2d::grid ( ) const

Definition at line 2844 of file Plot2d_ViewFrame.cxx.

{
  return myGrid;
};

return minimum size for qwt plot

Definition at line 2788 of file Plot2d_ViewFrame.cxx.

{
  return QSize( 0, 0 );
//  QSize aSize = QwtPlot::minimumSizeHint();
//  return QSize(aSize.width()*3/4, aSize.height());
}

Here is the caller graph for this function:

void Plot2d_Plot2d::onScaleDivChanged ( ) [protected, slot]

Slot: checks the current labels format and change it if needed.

Definition at line 2857 of file Plot2d_ViewFrame.cxx.

{
  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) );
    }
  }
}

Here is the call graph for this function:

void Plot2d_Plot2d::polish ( ) [virtual, slot]

Sets the flag saying that QwtPlot geometry has been fully defined.

Definition at line 2923 of file Plot2d_ViewFrame.cxx.

bool Plot2d_Plot2d::polished ( ) const

Definition at line 2839 of file Plot2d_ViewFrame.cxx.

{
  return myIsPolished;
}

Recalculates and redraws Plot 2d view.

Definition at line 2739 of file Plot2d_ViewFrame.cxx.

{
  // the following code is intended to enable only axes
  // that are really used by displayed objects
  bool enableXBottom = false, enableXTop   = false;
  bool enableYLeft   = false, enableYRight = false;
  const QwtPlotItemList& items = itemList();
  QwtPlotItemIterator it;
  for ( it = items.begin(); it != items.end(); it++ ) {
    QwtPlotItem* item = *it;
    if ( item ) {
      enableXBottom |= item->xAxis() == QwtPlot::xBottom;
      enableXTop    |= item->xAxis() == QwtPlot::xTop;
      enableYLeft   |= item->yAxis() == QwtPlot::yLeft;
      enableYRight  |= item->yAxis() == QwtPlot::yRight;
    }
  }
  enableAxis( QwtPlot::xBottom, enableXBottom );
  enableAxis( QwtPlot::xTop,    enableXTop );
  enableAxis( QwtPlot::yLeft,   enableYLeft );
  enableAxis( QwtPlot::yRight,  enableYRight );

  updateLayout();  // to fix bug(?) of Qwt - view is not updated when title is changed
  QwtPlot::replot(); 
}
void Plot2d_Plot2d::setLogScale ( int  axisId,
bool  log10 
)

axis scale engine - linear or log10

Definition at line 2728 of file Plot2d_ViewFrame.cxx.

{
  if ( log10 )
    setAxisScaleEngine( axisId, new QwtLog10ScaleEngine() );
  else
    setAxisScaleEngine( axisId, new QwtLinearScaleEngine() );
}
void Plot2d_Plot2d::setPickerMousePattern ( int  button,
int  state = Qt::NoButton 
)

Definition at line 2803 of file Plot2d_ViewFrame.cxx.

{
  myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, button, state );
}
QSize Plot2d_Plot2d::sizeHint ( ) const
Returns:
the recommended size for the widget

Definition at line 2780 of file Plot2d_ViewFrame.cxx.

Here is the call graph for this function:

Definition at line 2951 of file Plot2d_ViewFrame.cxx.

{
  // Memorize X axis (myScaleDraw already exists) in the drawing zone
  //setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw);  // heritage of QwtPlot

  myScaleDraw->unactivTicksDrawing( numcall);
}

Here is the call graph for this function:

Updates identifiers of Y axis type in the legend.

Definition at line 2895 of file Plot2d_ViewFrame.cxx.

{
  bool enableYLeft = false, enableYRight = false;
  const QwtPlotItemList& items = itemList();
  QwtPlotItemIterator it;
  for ( it = items.begin(); it != items.end(); it++ ) {
    QwtPlotItem* item = *it;
    if ( item ) {
      enableYLeft  |= item->yAxis() == QwtPlot::yLeft;
      enableYRight |= item->yAxis() == QwtPlot::yRight;
    }
  }

  // if several curves are attached to different axes
  // display corresponding identifiers in the legend,
  // otherwise hide them
  for ( it = items.begin(); it != items.end(); it++ ) {
    QwtPlotItem* item = *it;
    if ( Plot2d_QwtPlotCurve* aPCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( item ) )
      aPCurve->setYAxisIdentifierEnabled( enableYLeft && enableYRight );
    if ( item && item->isVisible() && legend() )
      item->updateLegend( legend() );
  }
}
QwtPlotZoomer * Plot2d_Plot2d::zoomer ( ) const

Definition at line 2849 of file Plot2d_ViewFrame.cxx.

{
  return myPlotZoomer;
}

Member Data Documentation

QList<QColor> Plot2d_Plot2d::myColors [protected]

Definition at line 371 of file Plot2d_ViewFrame.h.

QwtPlotGrid* Plot2d_Plot2d::myGrid [protected]

Definition at line 370 of file Plot2d_ViewFrame.h.

bool Plot2d_Plot2d::myIsPolished [protected]

Definition at line 372 of file Plot2d_ViewFrame.h.

QwtPlotZoomer* Plot2d_Plot2d::myPlotZoomer [protected]

Definition at line 373 of file Plot2d_ViewFrame.h.

Definition at line 374 of file Plot2d_ViewFrame.h.


The documentation for this class was generated from the following files: