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

Brief description of class still missing. More...

#include <ColumnTextParser.h>

Inheritance diagram for QGpCoreTools::ColumnTextParser:
QGpCoreTools::Thread QGpCoreTools::XMLClass

List of all members.

Signals

void dataAvailable ()

Public Member Functions

bool acceptNullColumns () const
QString acceptPattern () const
int columnCount () const
 ColumnTextParser (QObject *parent=0)
 ColumnTextParser (const ColumnTextParser &o)
QString columnWidths () const
QString delimiters () const
int endLine () const
double factor (int column) const
bool hasComments () const
bool isFixedWidth () const
bool isSectionCellPattern () const
bool isSectionLineCount () const
bool isSectionLinePattern () const
bool isSectionRowCount () const
int lineNumber (int row) const
int maximumColumnCount () const
QString rejectPattern () const
QString replaceAfter (int column) const
QString replaceRx (int column) const
int rowCount () const
int sectionBeginRow (int index) const
int sectionCellColumn () const
QString sectionCellPattern () const
const QString & sectionComments (int index) const
int sectionEndRow (int index) const
int sectionIndexOf (int row) const
int sectionLineCount () const
QString sectionLinePattern () const
int sectionRowCount () const
void setAcceptNullColumns (bool a)
void setAcceptPattern (QString a)
void setColumnWidths (QString w)
void setDelimiters (QString d)
void setEndLine (int e)
void setFactor (int column, double f)
void setFixedWidth (bool f)
void setHasComments (bool c)
void setMaximumColumnCount (int m)
void setRejectPattern (QString r)
void setReplaceAfter (int column, QString after)
void setReplaceRx (int column, QString rx)
void setSectionCellColumn (int s)
void setSectionCellPattern (bool b)
void setSectionCellPattern (QString s)
void setSectionLineCount (bool b)
void setSectionLineCount (int s)
void setSectionLinePattern (bool b)
void setSectionLinePattern (QString s)
void setSectionRowCount (bool b)
void setSectionRowCount (int s)
void setStandardTypes (const QStringList &standardTypes)
void setStartLine (int s)
void setText (QTextStream *s)
void setType (int column, int type)
void setTypeName (int column, QString type)
const QStringList & standardTypes () const
int startLine () const
void startUpdates ()
void stopUpdates ()
const QString & text (int row, int column) const
int type (int column) const
QString typeName (int column) const
virtual const QString & xml_tagName () const
 ~ColumnTextParser ()

Static Public Attributes

static const QString xmlColumnTextParserTag = "ColumnTextParser"

Protected Member Functions

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

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

Description of constructor still missing

References setStandardTypes(), and TRACE.

      : Thread(parent)
  {
    TRACE;
    setObjectName("ColumnTextParser");
    _text=0;
    _terminate=false;

    // Init at least one standard type
    setStandardTypes(QStringList());

    _startLine=0;
    _endLine=0;
    _acceptPattern="";
    _rejectPattern="^#";
    _hasComments=true;

    _delimiters=" \t";
    _maximumColumnCount=99;
    _columnCount=-1;
    _acceptNullColumns=false;
    _fixedWidth=false;
    _columnDescriptions.resize(1); // At least one default column is mandatory

    _isSectionLinePattern=true;
    _sectionLinePattern="^#";
    _isSectionLineCount=false;
    _sectionLineCount=0;
    _isSectionRowCount=false;
    _sectionRowCount=0;
    _isSectionCellPattern=false;
    _sectionCellColumn=0;
    _sectionCellPattern="";
  }

Copy constructor, constructed without parent. Keep only properties to run on another file.

      : Thread(), XMLClass()
  {
    setObjectName("ColumnTextParser");
    _text=0;
    _terminate=false;

    _standardTypes=o._standardTypes;
    _columnDescriptions=o._columnDescriptions;

    _startLine=o._startLine;
    _endLine=o._endLine;
    _acceptPattern=o._acceptPattern;
    _rejectPattern=o._rejectPattern;
    _hasComments=o._hasComments;

    _delimiters=o._delimiters;
    _maximumColumnCount=o._maximumColumnCount;
    _columnWidths=o._columnWidths;
    _fixedWidth=o._fixedWidth;
    _acceptNullColumns=o._acceptNullColumns;

    _isSectionLinePattern=o._isSectionLinePattern;
    _sectionLinePattern=o._sectionLinePattern;
    _isSectionLineCount=o._isSectionLineCount;
    _sectionLineCount=o._sectionLineCount;
    _isSectionRowCount=o._isSectionRowCount;
    _sectionRowCount=o._sectionRowCount;
    _isSectionCellPattern=o._isSectionCellPattern;
    _sectionCellColumn=o._sectionCellColumn;
    _sectionCellPattern=o._sectionCellPattern;
  }

Description of destructor still missing

References TRACE.

  {
    TRACE;
    delete _text;
  }

Member Function Documentation

{return _acceptNullColumns;}
{return _acceptPattern;}

References columnWidths().

Referenced by columnWidths(), xml_setProperty(), and xml_writeProperties().

{return columnWidths(_columnWidths);}
QString QGpCoreTools::ColumnTextParser::delimiters ( ) const [inline]
{return _delimiters;}
{return _endLine;}
double QGpCoreTools::ColumnTextParser::factor ( int  column) const [inline]

Returns the factor of column column.

Referenced by QGpGuiTools::ColumnTextItem::data().

{return columnDescription(column).factor();}
{return _hasComments;}
{return _fixedWidth;}
{return _isSectionCellPattern;}
{return _isSectionLineCount;}
{return _isSectionLinePattern;}
{return _isSectionRowCount;}

Referenced by QGpGuiTools::ColumnTextItem::headerData().

  {
    QMutexLocker ml(&_mutex);
    if(row<_cells.count()) {
      return _lines2rows[row];
    } else {
      return 0;
    }
  }
{return _maximumColumnCount;}
{return _rejectPattern;}
QString QGpCoreTools::ColumnTextParser::replaceAfter ( int  column) const [inline]

Returns the replacement string of column column.

Referenced by QGpGuiTools::ColumnTextItem::data().

{return columnDescription(column).replaceAfter();}
QString QGpCoreTools::ColumnTextParser::replaceRx ( int  column) const [inline]

Returns the regular expression of column column.

Referenced by QGpGuiTools::ColumnTextItem::data().

{return columnDescription(column).replaceRx();}

References TRACE.

Referenced by QGpGuiTools::ColumnTextItem::rowCount().

  {
    TRACE;
    QMutexLocker ml(&_mutex);
    return _cells.count();
  }

Referenced by QGpGuiTools::ColumnTextItem::data(), and QGpCoreTools::ColumnTextIterator::setCurrentSection().

  {
    QMutexLocker ml(&_mutex);
    if(index<_sectionMarkers.count()) {
      return _sectionMarkers.at(index);
    } else {
      return 0;
    }
  }
{return _sectionCellColumn;}
{return _sectionCellPattern;}
const QString & QGpCoreTools::ColumnTextParser::sectionComments ( int  index) const

Referenced by QGpGuiTools::ColumnTextItem::data().

  {
    QMutexLocker ml(&_mutex);
    if(index<_sectionComments.count()) {
      return _sectionComments.at(index);
    } else {
      return _nullCell;
    }
  }

Referenced by QGpCoreTools::ColumnTextIterator::atSectionEnd(), QGpCoreTools::ColumnTextIterator::ColumnTextIterator(), and QGpCoreTools::ColumnTextIterator::setCurrentSection().

  {
    QMutexLocker ml(&_mutex);
    index++;
    if(index<_sectionMarkers.count()) {
      return _sectionMarkers.at(index);
    } else {
      return _cells.count();
    }

  }

Referenced by QGpGuiTools::ColumnTextItem::data().

  {
    QMutexLocker ml(&_mutex);
    QList<int>::const_iterator it=qLowerBound(_sectionMarkers.begin(), _sectionMarkers.end(), row);
    return it-_sectionMarkers.begin();
  }
{return _sectionLineCount;}
{return _sectionLinePattern;}
{return _sectionRowCount;}
{_acceptNullColumns=a;}
{_acceptPattern=a;}
{_columnWidths=columnWidths(w);}
void QGpCoreTools::ColumnTextParser::setDelimiters ( QString  d) [inline]
{_delimiters=d;}

Lines start at 1, If i is 0, no limit on end line is set.

{_endLine=e<0 ? 0 : e;}
void QGpCoreTools::ColumnTextParser::setFactor ( int  column,
double  f 
) [inline]

Referenced by QGpGuiTools::ColumnTextItem::setData().

{columnDescription(column).setFactor(f);}
{_fixedWidth=f;}
{_hasComments=c;}
{_maximumColumnCount=m;}
{_rejectPattern=r;}
void QGpCoreTools::ColumnTextParser::setReplaceAfter ( int  column,
QString  after 
) [inline]

Referenced by QGpGuiTools::ColumnTextItem::setData().

{columnDescription(column).setReplaceAfter(after);}
void QGpCoreTools::ColumnTextParser::setReplaceRx ( int  column,
QString  rx 
) [inline]

Referenced by QGpGuiTools::ColumnTextItem::setData().

{columnDescription(column).setReplaceRx(rx);}
{_sectionCellColumn=s;}
{_isSectionCellPattern=b;}
{_sectionCellPattern=s;}
{_isSectionLineCount=b;}
{_sectionLineCount=s;}
{_isSectionLinePattern=b;}
{_sectionLinePattern=s;}
{_isSectionRowCount=b;}
{_sectionRowCount=s;}
void QGpCoreTools::ColumnTextParser::setStandardTypes ( const QStringList &  standardTypes)

Set the list of standard types. Used when restoring from an xml stream and by setType(). The first item of standardTypes has type index 1. A default "Skipped" type is always prepended, hence there is no need to include one in standardTypes.

References standardTypes(), QGpCoreTools::tr(), and TRACE.

Referenced by ColumnTextParser(), and QGpGuiTools::ColumnTextWidget::setStandardTypes().

  {
    TRACE;
    _standardTypes=standardTypes;
    _standardTypes.prepend(tr("Skipped"));
  }

Lines start at 1, If i is 0, no limit on start line is set.

{_startLine=s<0 ? 0 : s;  }
void QGpCoreTools::ColumnTextParser::setText ( QTextStream *  s)

Set test stream to parse. s is deleted by the destructor or when calling this function several times. It is safe to call this function even when the parser is running. In this case it is forced to stop updates before switching to the new stream.

References stopUpdates(), and TRACE.

Referenced by SciFigs::CurveBrowser::loadMultiColumns(), QGpGuiTools::ColumnTextWidget::setBuffer(), and QGpGuiTools::ColumnTextWidget::setFile().

  {
    TRACE;
    if(isRunning()) {
      stopUpdates();
    }
    delete _text;
    _text=s;
  }
void QGpCoreTools::ColumnTextParser::setType ( int  column,
int  type 
) [inline]

Referenced by QGpGuiTools::ColumnTextWidget::setTypes().

{return columnDescription(column).setType(type);}
void QGpCoreTools::ColumnTextParser::setTypeName ( int  column,
QString  type 
)

Sets type of column index column to type.

setTypeName() is called only from ColumnTextItem, in response to user action. The list of standard type is never huge, hence we search in a QStringList.

References QGpCoreTools::ColumnTextDescription::setType().

Referenced by QGpGuiTools::ColumnTextItem::setData().

  {
    int i=_standardTypes.indexOf(type);
    if(i>-1) {
      columnDescription(column).setType(i);
    }
  }
const QStringList& QGpCoreTools::ColumnTextParser::standardTypes ( ) const [inline]
{return _startLine;}

References TRACE.

Referenced by QGpGuiTools::ColumnTextWidget::parse(), QGpGuiTools::ColumnTextItem::setData(), QGpGuiTools::ColumnTextWidget::setParserFile(), and setText().

  {
    TRACE;
    if(isRunning()) {
      _terminate.fetchAndStoreOrdered(true);
      wait();
    }
  }
const QString & QGpCoreTools::ColumnTextParser::text ( int  row,
int  column 
) const

Referenced by QGpGuiTools::ColumnTextItem::data(), QGpGuiWave::DispersionProxy::parse(), QGpGuiWave::AutocorrProxy::parse(), QGpGuiWave::EllipticityProxy::parse(), SciFigs::ComplexStatisticalProxy::parse(), SciFigs::RealStatisticalProxy::parse(), and QGpGuiWave::RefractionProxy::parse().

  {
    QMutexLocker ml(&_mutex);
    if(row<_cells.count()) {
      const QStringList& cols=_cells.at(row);
      if(column<cols.count()) {
        return cols.at(column);
      }
    }
    return _nullCell;
  }
QString QGpCoreTools::ColumnTextParser::type ( int  column) const [inline]
QString QGpCoreTools::ColumnTextParser::typeName ( int  column) const [inline]

Returns the type of column column.

Referenced by QGpGuiTools::ColumnTextItem::data().

{return _standardTypes[columnDescription(column).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 QGpCoreTools::endl(), QGpCoreTools::App::stream(), QGpCoreTools::tr(), TRACE, and QGpCoreTools::XMLMember::Unknown.

  {
    TRACE;
    Q_UNUSED(context);
    if(tag=="ColumnTextDescription") {
      static const QString tmp("column");
      XMLRestoreAttributeIterator it=attributes.find(tmp);
      if(it!=attributes.end()) {
        return XMLMember(&columnDescription(it.value().toInt()));
      } else {
        App::stream() << tr("No column index defined for description") << endl;
        return XMLMember(XMLMember::Unknown);
      }
    } else if(tag=="startLine") return XMLMember(0);
    else if(tag=="endLine") return XMLMember(1);
    else if(tag=="acceptPattern") return XMLMember(2);
    else if(tag=="rejectPattern") return XMLMember(3);
    else if(tag=="hasComments") return XMLMember(4);

    else if(tag=="fixedWidth") return XMLMember(5);
    else if(tag=="acceptNullColumns") return XMLMember(6);
    else if(tag=="delimiters") return XMLMember(7);
    else if(tag=="maximumColumnCount") return XMLMember(8);
    else if(tag=="columnWidths") return XMLMember(9);

    else if(tag=="isSectionLinePattern") return XMLMember(10);
    else if(tag=="sectionLinePattern") return XMLMember(11);
    else if(tag=="isSectionLineCount") return XMLMember(12);
    else if(tag=="sectionLineCount") return XMLMember(13);
    else if(tag=="isSectionRowCount") return XMLMember(14);
    else if(tag=="sectionRowCount") return XMLMember(15);
    else if(tag=="isSectionCellPattern") return XMLMember(16);
    else if(tag=="sectionCellColumn") return XMLMember(17);
    else if(tag=="sectionCellPattern") return XMLMember(18);
    return XMLMember(XMLMember::Unknown);
  }

After restoring from an xml stream there might be some non-standard column types, remove them.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE, and type().

  {
    TRACE;
    Q_UNUSED(context);
    int standardTypeCount=_standardTypes.count();
    int nColumns=_columnDescriptions.count();
    for(int i=0;i<nColumns;i++) {
      if(_columnDescriptions[i].type()>=standardTypeCount) {
        _columnDescriptions[i].setType(0);
      }
    }
  }

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 columnWidths(), and TRACE.

  {
    TRACE;
    Q_UNUSED(tag);
    Q_UNUSED(attributes);
    Q_UNUSED(context);
    switch (memberID) {
    case 0: _startLine=content.toInt(); return true;
    case 1: _endLine=content.toInt(); return true;
    case 2: _acceptPattern=content.toString(); return true;
    case 3: _rejectPattern=content.toString(); return true;
    case 4: _hasComments=content.toBool(); return true;

    case 5: _fixedWidth=content.toBool(); return true;
    case 6: _acceptNullColumns=content.toBool(); return true;
    case 7: _delimiters=content.toString(); return true;
    case 8: _maximumColumnCount=content.toInt(); return true;
    case 9: _columnWidths=columnWidths(content.toString()); return true;

    case 10: _isSectionLinePattern=content.toBool(); return true;
    case 11: _sectionLinePattern=content.toString(); return true;
    case 12: _isSectionLineCount=content.toBool(); return true;
    case 13: _sectionLineCount=content.toInt(); return true;
    case 14: _isSectionRowCount=content.toBool(); return true;
    case 15: _sectionRowCount=content.toInt(); return true;
    case 16: _isSectionCellPattern=content.toBool(); return true;
    case 17: _sectionCellColumn=content.toInt(); return true;
    case 18: _sectionCellPattern=content.toString(); return true;
    default: return false;
    }
  }
virtual const QString& QGpCoreTools::ColumnTextParser::xml_tagName ( ) const [inline, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References QGpCoreTools::XMLSaveAttributes::add(), and TRACE.

  {
    TRACE;
    Q_UNUSED(context);
    static const QString key("column");
    XMLSaveAttributes att;
    QString& value=att.add(key);
    int n=_columnDescriptions.count();
    for(int i=0;i<n;i++) {
      value=QString::number(i);
      _columnDescriptions[i].xml_save(s, context, att);
    }
  }

Reimplemented from QGpCoreTools::XMLClass.

References columnWidths(), TRACE, and QGpCoreTools::XMLClass::writeProperty().

  {
    TRACE;
    Q_UNUSED(context);
    writeProperty(s, "startLine", _startLine);
    writeProperty(s, "endLine", _endLine);
    writeProperty(s, "acceptPattern", _acceptPattern);
    writeProperty(s, "rejectPattern", _rejectPattern);
    writeProperty(s, "hasComments", (bool)_hasComments);

    writeProperty(s, "fixedWidth", (bool)_fixedWidth);
    writeProperty(s, "acceptNullColumns", (bool)_acceptNullColumns);
    writeProperty(s, "delimiters", _delimiters);
    writeProperty(s, "maximumColumnCount", _maximumColumnCount);
    writeProperty(s, "columnWidths", columnWidths(_columnWidths));

    writeProperty(s, "isSectionLinePattern", (bool)_isSectionLinePattern);
    writeProperty(s, "sectionLinePattern", _sectionLinePattern);
    writeProperty(s, "isSectionLineCount", (bool)_isSectionLineCount);
    writeProperty(s, "sectionLineCount", _sectionLineCount);
    writeProperty(s, "isSectionRowCount", (bool)_isSectionRowCount);
    writeProperty(s, "sectionRowCount", _sectionRowCount);
    writeProperty(s, "isSectionCellPattern", (bool)_isSectionCellPattern);
    writeProperty(s, "sectionCellColumn", _sectionCellColumn);
    writeProperty(s, "sectionCellPattern", _sectionCellPattern);
  }

Member Data Documentation

const QString QGpCoreTools::ColumnTextParser::xmlColumnTextParserTag = "ColumnTextParser" [static]

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