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

A graphic symbol. More...

#include <Symbol.h>

Inheritance diagram for SciFigs::Symbol:
QGpCoreTools::XMLClass

List of all members.

Public Types

enum  Type {
  NoSymbol, Cross, Square, Circle,
  TriangleUp, TriangleDown, Losange, Star
}

Public Member Functions

const Brushbrush () const
void fromStream (QTextStream &s)
Symboloperator= (const Symbol &o)
bool operator== (const Symbol &o) const
void paint (QPainter &p, const QPointF &center, double dotpercm=28.346457) const
const Penpen () const
void setBrush (const Brush &b)
void setPen (const Pen &p)
void setSize (double s)
void setType (Type t)
double size () const
 Symbol (Type type=NoSymbol, double size=1.2, Pen pen=Pen(Qt::black), Brush brush=Brush(Qt::NoBrush))
 Symbol (const Symbol &s)
Type type () const
virtual const QString & xml_tagName () const
virtual ~Symbol ()

Static Public Member Functions

static void paint (Type type, QPainter &p, QPointF center, double size, double halfSize)
static QString symbolName (Type s)
static Type symbolValue (QString s)

Static Public Attributes

static const Symbol null
static const QString xmlSymbolTag = "Symbol"

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Protected Attributes

Brush _brush
Pen _pen
double _size
Type _type

Detailed Description

A graphic symbol.


Member Enumeration Documentation

Enumerator:
NoSymbol 
Cross 
Square 
Circle 
TriangleUp 
TriangleDown 
Losange 
Star 

Constructor & Destructor Documentation

SciFigs::Symbol::Symbol ( Type  type = NoSymbol,
double  size = 1.2,
Pen  pen = Pen(Qt::black),
Brush  brush = Brush(Qt::NoBrush) 
)

References _brush, _pen, _size, and _type.

                              : XMLClass()
{
  _type=s._type;
  _size=s._size;
  _pen=s._pen;
  _brush=s._brush;
}
virtual SciFigs::Symbol::~Symbol ( ) [inline, virtual]
{}

Member Function Documentation

const Brush& SciFigs::Symbol::brush ( ) const [inline]
void SciFigs::Symbol::fromStream ( QTextStream &  s)
Symbol & SciFigs::Symbol::operator= ( const Symbol o)

References _brush, _pen, _size, and _type.

{
  _type=o._type;
  _size=o._size;
  _pen=o._pen;
  _brush=o._brush;
  return *this;
}
bool SciFigs::Symbol::operator== ( const Symbol o) const

References _brush, _pen, _size, _type, and TRACE.

{
  TRACE;
  return _type==o._type
      && _size==o._size
      && _pen==o._pen
      && _brush==o._brush;
}
void SciFigs::Symbol::paint ( QPainter &  p,
const QPointF &  center,
double  dotpercm = 28.346457 
) const

References _brush, _pen, _size, _type, SciFigs::Brush::qbrush(), SciFigs::Pen::qpen(), size(), and TRACE.

Referenced by SciFigs::LegendItemDisplay::paint(), SciFigs::LegendTableDelegate::paint(), and SciFigs::LegendWidget::paint().

{
  TRACE;
  double size=_size*dotpercm*0.1;
  p.save();
  p.setRenderHints(QPainter::Antialiasing, true);
  p.setBrush(_brush.qbrush(dotpercm) );
  p.setPen(_pen.qpen(dotpercm));
  paint(_type, p, center, size, 0.5*size);
  p.restore();
}
void SciFigs::Symbol::paint ( Type  type,
QPainter &  p,
QPointF  center,
double  size,
double  halfSize 
) [inline, static]

References Cross, Losange, size(), Square, Star, TRACE, TriangleDown, and TriangleUp.

  {
    TRACE;
    switch(type) {
    case Cross: {
        QPointF h1(halfSize, halfSize);
        QPointF h2(halfSize, -halfSize);
        p.drawLine(center-h1, center+h1);
        p.drawLine(center-h2, center+h2);
      }
      break;
    case Square: {
        p.drawRect(QRectF(center-QPointF(halfSize, halfSize),QSizeF(size,size)));
      }
      break;
    case Circle: {
        p.drawEllipse(center, halfSize, halfSize);
      }
      break;
    case TriangleUp: {
        QPolygonF points(4);
        double halfSize=0.5*0.866025403784439*size;
        center+=QPointF(-halfSize, 0.25*size);
        points[0]=center;
        points[1]=center+QPointF(0.866025403784439*size, 0);
        points[2]=center+QPointF(halfSize, -0.75*size);
        points[3]=points[0];
        p.drawPolygon(points);
      }
      break;
    case TriangleDown: {
        QPolygonF points(4);
        double halfSize=0.5*0.866025403784439*size;
        center+=QPointF(-halfSize, -0.25*size);
        points[0]=center;
        points[1]=center+QPointF(0.866025403784439*size, 0);
        points[2]=center+QPointF(halfSize, 0.75*size);
        points[3]=points[0];
        p.drawPolygon(points);
      }
      break;
    case Losange: {
        QPolygonF points(5);
        double quarterSize=size*0.25;
        points[0]=center-QPointF(0.0, halfSize);
        points[1]=center+QPointF(quarterSize, 0.0);
        points[2]=center+QPointF(0.0, halfSize);
        points[3]=center-QPointF(quarterSize, 0.0);
        points[4]=points[0];
        p.drawPolygon (points);
      }
      break;
    case Star: {
        QPointF h1(halfSize, halfSize);
        QPointF h2(halfSize, -halfSize);
        QPointF h3(halfSize, 0.0);
        QPointF h4(0.0, halfSize);
        p.drawLine(center-h1, center+h1);
        p.drawLine(center-h2, center+h2);
        p.drawLine(center-h3, center+h3);
        p.drawLine(center-h4, center+h4);
      }
      break;
    default:
      break;
    }
  }
const Pen& SciFigs::Symbol::pen ( ) const [inline]
void SciFigs::Symbol::setBrush ( const Brush b) [inline]
void SciFigs::Symbol::setPen ( const Pen p) [inline]
void SciFigs::Symbol::setSize ( double  s) [inline]
void SciFigs::Symbol::setType ( Type  t) [inline]
double SciFigs::Symbol::size ( ) const [inline]
QString SciFigs::Symbol::symbolName ( Type  s) [static]

References Cross, Losange, Square, Star, TRACE, TriangleDown, and TriangleUp.

Referenced by SciFigs::XYPlot::symbolString(), and xml_writeProperties().

{
  TRACE;
  switch (s) {
  case Cross: return "Cross";
  case Square: return "Square";
  case Circle: return "Circle";
  case TriangleUp: return "TriangleUp";
  case TriangleDown: return "TriangleDown";
  case Losange: return "Losange";
  case Star: return "Star";
  default: return "NoSymbol";
  }
}
Symbol::Type SciFigs::Symbol::symbolValue ( QString  s) [static]

References Circle, Cross, Losange, NoSymbol, Square, Star, TriangleDown, and TriangleUp.

Referenced by SciFigs::XYPlot::setSymbol(), SciFigs::LineLayer::setSymType(), and xml_setProperty().

{
  if(s.count()>=4) {
    switch(s[2].unicode()) {
    case 'o':
      if(s=="Cross") return Cross;
      break;
    case 'u':
      if(s=="Square") return Square;
      break;
    case 'i':
      if(s=="TriangleUp") return TriangleUp;
      else if(s=="TriangleDown") return TriangleDown;
      else if(s=="Triangle") return TriangleDown;    // For compatibility
      break;
    case 'r':
      if(s=="Circle") return Circle;
      break;
    case 's':
      if(s=="Losange") return Losange;
      break;
    case 'a':
      if(s=="Star") return Star;
      break;
    default:
      break;
    }
  }
  return NoSymbol;
}
Type SciFigs::Symbol::type ( ) const [inline]

Referenced by SciFigs::LegendTableItem::data(), and Symbol().

{return _type;}

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 QGpCoreTools::XMLClass.

References _brush, _pen, and TRACE.

{
  TRACE;
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  if(tag=="type") return XMLMember(0);
  else if(tag=="size") return XMLMember(1);
  else if(tag=="Pen") return XMLMember(&_pen);
  else if(tag=="Brush") return XMLMember(&_brush);
  return XMLMember(XMLMember::Unknown);
}
bool SciFigs::Symbol::xml_setProperty ( XML_SETPROPERTY_ARGS  ) [protected, virtual]

Re-implement this function to offer XML restore properties support to your class.

From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).

For a general case:

  Q_UNUSED(attributes);
  double val=content.toDouble();
  switch (memberID) {
  case 0:
    _x1=val;
    return true;
  case 1:
    _y1=val;
    return true;
  case 2:
    _x2=val;
    return true;
  case 3:
    _y2=val;
    return true;
  default:
    return false;
  }

For classes inheriting other classes (see also xml_member())

  switch (memberID) {
  case 0:
    _anInteger=content.toString();
    return true;
  case 1:
    _aString=content.toInt();
    return true;
  case 2:
    _aDouble=content.toDouble();
    return true;
  default:
    return AbstractLine::xml_setProperty(memberID-3, map, content);

For the arguments of this function use Macro XML_SETPROPERTY_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References _size, _type, symbolValue(), and TRACE.

{
  TRACE;
  Q_UNUSED(tag);
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  switch (memberID) {
  case 0:
    _type=symbolValue(content.toString());
    return true;
  case 1:
    _size=content.toDouble();
    return true;
  default:
    return false;
  }
}
virtual const QString& SciFigs::Symbol::xml_tagName ( ) const [inline, virtual]

Implements QGpCoreTools::XMLClass.

{return xmlSymbolTag;}
void SciFigs::Symbol::xml_writeChildren ( XML_WRITECHILDREN_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References _brush, _pen, TRACE, and QGpCoreTools::XMLClass::xml_save().

{
  TRACE;
  _pen.xml_save(s, context);
  _brush.xml_save(s, context);
}
void SciFigs::Symbol::xml_writeProperties ( XML_WRITEPROPERTIES_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References _size, _type, symbolName(), TRACE, and QGpCoreTools::XMLClass::writeProperty().

{
  TRACE;
  Q_UNUSED(context);
  writeProperty(s, "type",symbolName(_type));
  writeProperty(s, "size",_size);
}

Member Data Documentation

double SciFigs::Symbol::_size [protected]
const Symbol SciFigs::Symbol::null [static]

Referenced by SciFigs::Legend::symbol().

const QString SciFigs::Symbol::xmlSymbolTag = "Symbol" [static]

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