Source Code (Use browser search to find items of interest.)

Class Index

kdelibs'ParseContext (./kdelibs/kio/ktraderparsetree.h:78)

class ParseContext
{
public:
  /**
   * This is NOT a copy constructor.
   */
  ParseContext( const ParseContext* _ctx ) : service( _ctx->service ), maxima( _ctx->maxima ),
    offers( _ctx->offers ) {}
  ParseContext( const KService* _service, const KServiceTypeProfile::OfferList& _offers,
		QMap<QString,PreferencesMaxima>& _m )
    : service( _service ), maxima( _m ), offers( _offers ) {}

  bool initMaxima( const QString& _prop);

  enum Type { T_STRING = 1, T_DOUBLE = 2, T_NUM = 3, T_BOOL = 4,
	      T_STR_SEQ = 5, T_SEQ = 6 };

  QString str;
  int i;
  double f;
  bool b;
  QValueList<QVariant> seq;
  QStringList strSeq;
  Type type;

  const KService* service;

  QMap<QString,PreferencesMaxima>& maxima;
  const KServiceTypeProfile::OfferList& offers;
};


kdelibs'ParseContext::initMaxima() (./kdelibs/kio/ktraderparsetree.cpp:628)

bool ParseContext::initMaxima( const QString& _prop )
{
  // Is the property known ?
  QVariant prop = service->property( _prop );
  if ( !prop.isValid() )
    return false;

  // Numeric ?
  if ( prop.type() != QVariant::Int && prop.type() != QVariant::Double )
    return false;

  // Did we cache the result ?
  QMap<QString,PreferencesMaxima>::Iterator it = maxima.find( _prop );
  if ( it != maxima.end() )
    return ( it.data().type == PreferencesMaxima::PM_DOUBLE ||
	     it.data().type == PreferencesMaxima::PM_INT );

  // Double or Int ?
  PreferencesMaxima extrema;
  if ( prop.type() != QVariant::Int )
    extrema.type = PreferencesMaxima::PM_INVALID_INT;
  else
    extrema.type = PreferencesMaxima::PM_INVALID_DOUBLE;

  // Iterate over all offers
  KServiceTypeProfile::OfferList::ConstIterator oit = offers.begin();
  for( ; oit != offers.end(); ++it )
  {
    QVariant p = (*oit).service()->property( _prop );
    if ( p.isValid() )
    {
      // Determine new maximum/minimum
      if ( extrema.type == PreferencesMaxima::PM_INVALID_INT )
      {
	extrema.type = PreferencesMaxima::PM_INT;
	extrema.iMin = p.toInt();
	extrema.iMax = p.toInt();
      }
      // Correct existing extrema
      else if ( extrema.type == PreferencesMaxima::PM_INT )
      {
	if ( p.toInt() < extrema.iMin )
	  extrema.iMin = p.toInt();
	if ( p.toInt() > extrema.iMax )
	  extrema.iMax = p.toInt();
      }
      // Determine new maximum/minimum
      else if ( extrema.type == PreferencesMaxima::PM_INVALID_DOUBLE )
      {
	extrema.type = PreferencesMaxima::PM_DOUBLE;
	extrema.fMin = p.toDouble();
	extrema.fMax = p.toDouble();
      }
      // Correct existing extrema
      else if ( extrema.type == PreferencesMaxima::PM_DOUBLE )
      {
	if ( p.toDouble() < it.data().fMin )
	  it.data().fMin = p.toDouble();
	if ( p.toDouble() > it.data().fMax )
	  it.data().fMax = p.toDouble();
      }
    }
  }

  // Cache the result
  maxima.insert( _prop, extrema );

  // Did we succeed ?
  return ( extrema.type == PreferencesMaxima::PM_DOUBLE ||
	   extrema.type == PreferencesMaxima::PM_INT );
}