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

A group is a list of signals. More...

#include <SignalGroup.h>

Inheritance diagram for GeopsyCore::SignalGroup:
GeopsyCore::AbstractSignalGroup QGpCoreTools::TreeContainer QGpCoreTools::TreeItem QGpCoreTools::XMLClass GeopsyCore::AbstractSignalResults GeopsyCore::StationGroup

List of all members.

Public Member Functions

virtual void addSignals (const SubSignalPool &subPool)
virtual bool convertIds (const QHash< int, Signal * > &ids)
virtual bool directlyContains (const Signal *sig) const
bool hasIds () const
virtual bool hasOwnSignal () const
void openV12 (int dbVersion, const QDir &dbPath)
virtual void removeSignal (Signal *sig)
virtual void setName (const QString &n)
virtual void setSignals (const SubSignalPool &subPool)
virtual int signalCount () const
 SignalGroup (AbstractSignalGroup *parent=0)
virtual SubSignalPool subPool () const
virtual bool xml_inherits (const QString &tagName) const
virtual const QString & xml_tagName () const
virtual ~SignalGroup ()

Static Public Attributes

static const QString xmlSignalGroupTag = "Group"

Protected Member Functions

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

Detailed Description

A group is a list of signals.

A list of ids is temporarily allocated for loading groups from an XML buffer.


Constructor & Destructor Documentation

References TRACE.

    : AbstractSignalGroup(parent)
  {
    TRACE;
    _ids=0;
  }

References TRACE.

  {
    TRACE;
    delete _ids;
  }

Member Function Documentation

void GeopsyCore::SignalGroup::addSignals ( const SubSignalPool subPool) [virtual]
bool GeopsyCore::SignalGroup::convertIds ( const QHash< int, Signal * > &  ids) [virtual]

Converts ID values according to ids.

Reimplemented from GeopsyCore::AbstractSignalGroup.

References GeopsyCore::SubSignalPool::addSignal(), QGpCoreTools::endl(), GeopsyCore::AbstractSignalGroup::name(), GeopsyCore::AbstractSignalGroup::pathName(), GeopsyCore::SubSignalPool::removeAll(), GeopsyCore::SubSignalPool::setName(), QGpCoreTools::tr(), and TRACE.

  {
    TRACE;
    if(_ids) {
      _signals.removeAll();
      for(QVector<int>::iterator it=_ids->begin(); it!=_ids->end(); it++) {
        QHash<int, Signal *>::const_iterator itHash=ids.find(*it);
        if(itHash==ids.end()) {
          App::stream() << tr("Group '%1': unknow signal ID %2").arg(pathName()).arg(*it) << endl;
          return false;
        } else {
          _signals.addSignal(itHash.value());
        }
      }
      delete _ids;
      _ids=0;
      _signals.setName(name());
    }
    return AbstractSignalGroup::convertIds(ids);
  }
bool GeopsyCore::SignalGroup::directlyContains ( const Signal sig) const [inline, virtual]

Returns true if it directly contains signal with id.

Reimplemented from GeopsyCore::AbstractSignalGroup.

{return _signals.contains(sig);}
bool GeopsyCore::SignalGroup::hasIds ( ) const [inline]
virtual bool GeopsyCore::SignalGroup::hasOwnSignal ( ) const [inline, virtual]

Returns true if there are signals owned only by this group.

Returns true.

Reimplemented from GeopsyCore::AbstractSignalGroup.

{return true;}
void GeopsyCore::SignalGroup::openV12 ( int  dbVersion,
const QDir &  dbPath 
)

Loads group from database path of db and eventually translate loaded IDs using the translation map translateID (if not null).

This function is used for compatibility with databases version<3. For these versions, the groups were saved in the same directory as the .sdb file.

References QGpCoreTools::endl(), GeopsyCore::AbstractSignalGroup::name(), GeopsyCore::AbstractSignalGroup::setModified(), QGpCoreTools::tr(), and TRACE.

  {
    TRACE;
    QFile f(dbPath.absoluteFilePath(name()+".group"));
    if(f.open(QIODevice::ReadOnly)) {
      if(!_ids) {
        _ids=new QVector<int>;
      }
      QDataStream s(&f);
      if(dbVersion==1) {
        s.setByteOrder(QDataStream::LittleEndian); // To read file from YACL
      }
      int id;
      while(!s.atEnd()) {
        s >> id;
        (*_ids) << id;
      }
    } else {
      App::stream() << tr("Unable to open %1.group for reading" ).
                       arg(dbPath.absoluteFilePath(name()) ) << endl;
    }
    setModified(true);
  }
void GeopsyCore::SignalGroup::removeSignal ( Signal sig) [virtual]

Removes one signal sig from group.

Reimplemented from GeopsyCore::AbstractSignalGroup.

References GeopsyCore::SubSignalPool::indexOf(), GeopsyCore::SubSignalPool::removeAt(), GeopsyCore::AbstractSignalGroup::setModified(), and TRACE.

  {
    TRACE;
    int index=_signals.indexOf(sig);
    if(index<0) return;
    _signals.removeAt(index);
    setModified(true);
  }
void GeopsyCore::SignalGroup::setName ( const QString &  n) [virtual]

Sets group's name.

Reimplemented from GeopsyCore::AbstractSignalGroup.

Reimplemented in GeopsyCore::StationGroup.

References GeopsyCore::SubSignalPool::setName().

Referenced by addSignals(), and setSignals().

  {
    AbstractSignalGroup::setName(n);
    _signals.setName(n);
  }
void GeopsyCore::SignalGroup::setSignals ( const SubSignalPool subPool) [virtual]
int GeopsyCore::SignalGroup::signalCount ( ) const [inline, virtual]

Returns the number of signals.

Reimplemented from GeopsyCore::AbstractSignalGroup.

{return _signals.count();}
virtual SubSignalPool GeopsyCore::SignalGroup::subPool ( ) const [inline, virtual]

Returns the list of signals contained in all its children.

Returns the list of signals of this group.

Reimplemented from GeopsyCore::AbstractSignalGroup.

Referenced by GeopsyCore::StationGroup::name(), and setSignals().

{return _signals;}
bool GeopsyCore::SignalGroup::xml_inherits ( const QString &  tagName) const [virtual]

May be useful for classes that do not inherit QObject. Must be re-implemented in sub-classes

Reimplemented from QGpCoreTools::XMLClass.

Reimplemented in GeopsyCore::StationGroup.

References xmlSignalGroupTag.

  {
    if(tagName==xmlSignalGroupTag) {
      return true;
    } else {
      return AbstractSignalGroup::xml_inherits(tagName);
    }
  }

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 GeopsyCore::AbstractSignalGroup.

References TRACE.

  {
    TRACE;
    if(tag=="ids") return XMLMember(0);
    return AbstractSignalGroup::xml_member(tag, attributes, context)+1;
  }

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 GeopsyCore::AbstractSignalGroup.

References QGpCoreTools::StringSection::isValid(), QGpCoreTools::StringSection::nextField(), QGpCoreTools::StringSection::toInt(), and TRACE.

  {
    TRACE;
    switch (memberID) {
    case 0: {
        if(!_ids) {   // Multiple <ids> tags are merge together
          _ids=new QVector<int>;
        }
        static const QString sep=" \n\t\r";
        const QChar * ptr=0;
        StringSection f=content.nextField(ptr, sep, true);
        while(f.isValid()) {
          _ids->append(f.toInt());
          f=content.nextField(ptr, sep, true);
        }
        return true;
      }
    default:
      return AbstractSignalGroup::xml_setProperty(memberID-1, tag, attributes, content, context);
    }
  }
virtual const QString& GeopsyCore::SignalGroup::xml_tagName ( ) const [inline, virtual]

Reimplemented from QGpCoreTools::TreeItem.

Reimplemented in GeopsyCore::StationGroup.

Reimplemented from GeopsyCore::AbstractSignalGroup.

References GeopsyCore::SubSignalPool::begin(), GeopsyCore::SubSignalPool::end(), str, TRACE, and QGpCoreTools::XMLClass::writeProperty().

  {
    TRACE;
    AbstractSignalGroup::xml_writeProperties(s, context);
    QString str;
    for(SubSignalPool::const_iterator it=_signals.begin(); it!=_signals.end(); ++it) {
      str+=QString::number((*it)->id())+" ";
    }
    writeProperty(s, "ids", str);
  }

Member Data Documentation

const QString GeopsyCore::SignalGroup::xmlSignalGroupTag = "Group" [static]

Referenced by xml_inherits().


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