All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Slots | Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
SciFigs::XYValueLines Class Reference

A XYValueLines is a layer to draw polylines of color (static) More...

#include <XYValueLines.h>

Inheritance diagram for SciFigs::XYValueLines:
SciFigs::XYColorLines SciFigs::GraphContentLayer QGpGuiTools::PropertyItem QGpCoreTools::XMLClass

List of all members.

Public Slots

void setPalette (const ColorPalette &pal)

Signals

void paletteChanged (const ColorPalette &pal)

Public Member Functions

virtual void addProperties (PropertyProxy *pp)
virtual bool hasProperties ()
const ColorPalettepalette () const
virtual void properties (PropertyWidget *w) const
virtual void removeProperties (PropertyProxy *pp)
void setLinearPalette (double minVal, double maxVal)
virtual void setProperty (uint wid, int pid, QVariant val)
void setValues (double *values)
double * setValues (const QVector< double > &values)
void valueRange (double &min, double &max) const
double * values ()
virtual const QString & xml_tagName () const
 XYValueLines (AxisWindow *parent=0, bool autoDelete=false)
 ~XYValueLines ()

Static Public Attributes

static const QString xmlXYValueLinesTag = "XYValueLines"

Protected Member Functions

virtual void paintData (const LayerPainterRequest &lp, QPainter &p, double dotpercm) const
virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual void xml_polishChild (XML_POLISHCHILD_ARGS)
virtual bool xml_setBinaryData (XML_SETBINARYDATA_ARGS)
virtual void xml_writeBinaryData (XML_WRITEBINARYDATA_ARGS) const
virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const

Protected Attributes

ColorPalette _pal
double * _values

Static Protected Attributes

static uint _tabPalette = PropertyProxy::uniqueId()

Detailed Description

A XYValueLines is a layer to draw polylines of color (static)


Constructor & Destructor Documentation

SciFigs::XYValueLines::XYValueLines ( AxisWindow parent = 0,
bool  autoDelete = false 
)

References TRACE.

                                                               :
    XYColorLines(parent, autoDelete)
{
  TRACE;
  _values=0;
  _pal.defaultColors(20);
}

References SciFigs::XYColorLines::_autoDelete, _values, and TRACE.

{
  TRACE;
  if(_autoDelete) {
    delete [] _values;
  }
}

Member Function Documentation

Setup property editor

Reimplemented from SciFigs::XYColorLines.

References _tabPalette, QGpGuiTools::PropertyProxy::addReference(), QGpGuiTools::PropertyProxy::addTab(), QGpGuiTools::PropertyProxy::setCurrentTab(), QGpCoreTools::tr(), TRACE, and w.

{
  TRACE;
  XYColorLines::addProperties(pp);
  if(pp->setCurrentTab(_tabPalette)) {
    pp->addReference(this);
  } else {
    PaletteProperties * w=new PaletteProperties;
    pp->addTab(_tabPalette, tr("Palette"), w, this);
  }
}
virtual bool SciFigs::XYValueLines::hasProperties ( ) [inline, virtual]

Reimplemented from SciFigs::XYColorLines.

{return true;}
void SciFigs::XYValueLines::paintData ( const LayerPainterRequest lp,
QPainter &  p,
double  dotpercm 
) const [protected, virtual]

Reimplemented from SciFigs::XYColorLines.

References SciFigs::XYColorLines::_curveCount, SciFigs::XYColorLines::_lineWeight, _pal, SciFigs::XYColorLines::_pointCounts, SciFigs::XYColorLines::_points, _values, SciFigs::GraphContentOptions::checkOrigin(), QGpGuiTools::ColorPalette::color(), SciFigs::LayerPainterRequest::graphContent(), SciFigs::XYColorLines::lineWeight(), SciFigs::LayerPainterRequest::options(), SciFigs::GraphContentOptions::r2s(), SciFigs::GraphContent::setProgressMaximum(), SciFigs::GraphContent::setProgressValue(), SciFigs::LayerPainterRequest::size(), SciFigs::LayerPainterRequest::terminated(), and TRACE.

{
  TRACE;
  if( !_curveCount) return ;
  ColorPalette pal=_pal; // Copy to avoid distrubance during paint.
  const GraphContentOptions& gc=lp.options();
  int h=lp.size().height();
  Point2D *p1=_points - 1, *p2;
  QPoint pscreen1, pscreen2;
  int lineWeight=(int) floor(_lineWeight * dotpercm + 0.5);
  if(lineWeight<1) lineWeight=1;
  QPen currentPen(Qt::black, lineWeight, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
  lp.graphContent()->setProgressMaximum(_curveCount);
  for(int i=0;i < _curveCount;i++ ) {
    if(lp.terminated()) return;
    lp.graphContent()->setProgressValue(i);
    int countPoints=_pointCounts[ i ];
    if(countPoints > 0) {
      QPolygon ap(countPoints);
      if(_values) currentPen.setColor(pal.color(_values[ i ] ));
      p.setPen(currentPen);
      p1++;
      int subCurveCount=0;
      for(int j=1;j < countPoints;j++ ) {
        p2=p1 + 1;
        if(gc.r2s( *p1, *p2, pscreen1, pscreen2) ) {
          gc.checkOrigin(pscreen1, pscreen2, h);
          if(subCurveCount==0) {
            ap.setPoint(0, pscreen1);
            subCurveCount=1;
          } else {
            if(ap.point(subCurveCount - 1)!=pscreen1) {
              p.drawPolyline (ap.data(), subCurveCount);
              ap.setPoint(0, pscreen1);
              subCurveCount=1;
            }
          }
          ap.setPoint(subCurveCount, pscreen2);
          subCurveCount++;
        } else if(subCurveCount > 1) {
          p.drawPolyline (ap.data(), subCurveCount);
          subCurveCount=0;
        }
        p1=p2;
      }
      if(subCurveCount > 1) p.drawPolyline (ap.data(), subCurveCount);
    }
  }
  lp.graphContent()->setProgressValue(_curveCount);
}
const ColorPalette& SciFigs::XYValueLines::palette ( ) const [inline]

Referenced by properties(), and setLinearPalette().

{return _pal;}
void SciFigs::XYValueLines::paletteChanged ( const ColorPalette pal) [signal]

Referenced by setLinearPalette(), and setPalette().

void SciFigs::XYValueLines::properties ( PropertyWidget w) const [virtual]

Clean property editor

Reimplemented from SciFigs::XYColorLines.

References _tabPalette, QGpGuiTools::PropertyProxy::removeTab(), and TRACE.

void SciFigs::XYValueLines::setLinearPalette ( double  minVal,
double  maxVal 
)

Set a linear scale on palette. Safe for painting threads. For other modification of the palette see setPalette().

References _pal, SciFigs::GraphContent::deepUpdate(), SciFigs::GraphContentLayer::graphContent(), palette(), paletteChanged(), QGpGuiTools::ColorPalette::setVLinear(), and TRACE.

Referenced by addManyCurvePlot().

{
  TRACE;
  LayerLocker ll(this);
  _pal.setVLinear(minVal, maxVal);
  // This layer takes generally time to repaint (useless to repaint only this layer) 
  graphContent()->deepUpdate();
  emit paletteChanged(palette());
}
void SciFigs::XYValueLines::setPalette ( const ColorPalette pal) [slot]

Set the palette. Safe for painting threads.

References _pal, SciFigs::GraphContent::deepUpdate(), SciFigs::GraphContentLayer::graphContent(), paletteChanged(), and TRACE.

Referenced by createManyCurvesPlot(), DinverDCGui::DCModelViewer::initGraphs(), setProperty(), and xml_polishChild().

{
  TRACE;
  // Avoid recurrent loop
  static bool locked=false;
  if(!locked) {
    locked=true;
    LayerLocker ll(this);
    _pal=pal;
    // This layer takes generally time to repaint (useless to repaint only this layer) 
    graphContent()->deepUpdate();
    emit paletteChanged(pal);
    locked=false;
  }
}
void SciFigs::XYValueLines::setProperty ( uint  wid,
int  pid,
QVariant  val 
) [virtual]

Reimplemented from SciFigs::XYColorLines.

References _tabPalette, SciFigs::PaletteProperties::Palette, and setPalette().

{
  if(wid==_tabPalette) {
    switch(pid) {
    case PaletteProperties::Palette:
      setPalette(val.value<ColorPalette>());
      break;
    default:
      break;
    }
  } else {
    XYColorLines::setProperty(wid, pid, val);
  }
}
void SciFigs::XYValueLines::setValues ( double *  values)

Set the internal list of values to values. If the object has been created with autodelete, this object takes the ownership of values.

References SciFigs::XYColorLines::_autoDelete, _values, TRACE, and values().

Referenced by addManyCurvePlot(), DinverDCGui::DCModelViewer::loadModels(), and DinverDCGui::DCModelViewer::~DCModelViewer().

{
  TRACE;
  LayerLocker ll(this);
  if(_autoDelete) {
    delete [] _values;
  }
  _values=values;
}
double * SciFigs::XYValueLines::setValues ( const QVector< double > &  values)

Convenience function to set the internal list of values from a dynamic vector of values. Returns the internal allocated list of values. Ownership depends upon the constructor of this object.

References SciFigs::XYColorLines::_autoDelete, SciFigs::XYColorLines::_curveCount, _values, and TRACE.

{
  TRACE;
  LayerLocker ll(this);
  if(_autoDelete) {
    delete [] _values;
  }
  ASSERT(_curveCount==values.count());
  _values=new double[_curveCount];
  for(int i=0; i<_curveCount; i++) {
    _values[i]=values[i];
  }
  return _values;
}
void SciFigs::XYValueLines::valueRange ( double &  min,
double &  max 
) const

Get min and maximum of values (usually to adjust the palette). It is the responsability of the caller to initialize min and max to 1e99 and -1e99 respectively

References SciFigs::XYColorLines::_curveCount, _values, and TRACE.

Referenced by addManyCurvePlot(), and DinverDCGui::DCModelViewer::setLimits().

{
  TRACE;
  if(_curveCount==0) return;
  if(_values[ 0 ] < min) min=_values[ 0 ];
  if(_values[ 0 ] > max) max=_values[ 0 ];
  for(int i=1;i < _curveCount;i++ ) {
    if(_values[ i ] < min) min=_values[ i ];
    else if(_values[ i ] > max) max=_values[ i ];
  }
}
double* SciFigs::XYValueLines::values ( ) [inline]

Referenced by setValues().

{return _values;}

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from SciFigs::GraphContentLayer.

References SciFigs::XMLSciFigs::data(), and TRACE.

{
  TRACE;
  XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context);
  if(scifigsContext->data()) {
    if(tag=="ColorPalette") return XMLMember(new ColorPalette, true);
  }
  return XYColorLines::xml_member(tag, attributes, context);
}

Reimplemented from QGpCoreTools::XMLClass.

References setPalette().

{
  Q_UNUSED(context);
  if(child->xml_tagName()=="ColorPalette") {
    ColorPalette * pal=static_cast<ColorPalette *>(child);
    setPalette( *pal);
  }
}

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

See also xml_writeBinaryData().

The difference between xml_setBinaryData() and xml_setBinaryData200410() is detected by the type of tag at the beginning of each block if it can be read with QString ==> 200510, else try with a normal C string, if it match the current tag then execute xml_setBinaryData200411().

See also xml_setBinaryData200411() to maintain compatibility with previous versions of xml storages.

For the arguments of this function use Macro XML_SETBINARYDATA_ARGS.

Reimplemented from SciFigs::XYColorLines.

References SciFigs::XYColorLines::_autoDelete, SciFigs::XYColorLines::_curveCount, SciFigs::XYColorLines::_pointCounts, SciFigs::XYColorLines::_points, _values, SciFigs::XMLSciFigs::currentFileVersion(), and TRACE.

{
  TRACE;
  s >> _curveCount;
  if(_curveCount > 0) {
    _autoDelete=true;
    bool hasColor;
    XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context);
    Version v(scifigsContext->currentFileVersion());
    static const Version vRef(1, 0, 99);
    if(v>vRef) {
      s >> hasColor;
    } else {
      hasColor=false;
    }
    _pointCounts=new int[ _curveCount ];
    s.readRawData(( char * ) _pointCounts, sizeof(int) * _curveCount);
    // Count number of points
    int n=0;
    for(int i=0;i < _curveCount;i++ ) {
      if(_pointCounts[ i ]<0) _pointCounts[ i ]=0;
      n += _pointCounts[ i ];
    }
    if(n>0) {
      _points=new Point2D [ n ];
      s.readRawData(( char * ) _points, sizeof(Point2D) * n);
      _values=new double[ _curveCount ];
      s.readRawData(( char * ) _values, sizeof(double) * _curveCount);
    }
  }
  return true;
}
virtual const QString& SciFigs::XYValueLines::xml_tagName ( ) const [inline, virtual]

Reimplemented from SciFigs::XYColorLines.

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

The way binary data is stored drastically changed in November 2006 with the introduction of tar.gz structures for xml files. Each class willing to store binary data can automatically generate a new file (with an automatic file name) in the .tar.gz structure by sending bytes to s.

See also xml_setBinaryData().

For the arguments of this function use Macro XML_WRITEBINARYDATA_ARGS.

Reimplemented from SciFigs::XYColorLines.

References SciFigs::XYColorLines::_curveCount, _values, and TRACE.

{
  TRACE;
  XYColorLines::xml_writeBinaryData(s, context);
  s.writeRawData(( const char * ) _values, sizeof(double) * _curveCount);
}

Reimplemented from QGpCoreTools::XMLClass.

References _pal, SciFigs::XMLSciFigs::data(), TRACE, and QGpCoreTools::XMLClass::xml_save().

{
  TRACE;
  XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context);
  if(scifigsContext->data()) {
    _pal.xml_save(s, context);
  }
}

Member Data Documentation

uint SciFigs::XYValueLines::_tabPalette = PropertyProxy::uniqueId() [static, protected]
double* SciFigs::XYValueLines::_values [protected]
const QString SciFigs::XYValueLines::xmlXYValueLinesTag = "XYValueLines" [static]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines