Exemple #1
0
void Particle::update(float timeElapsed) {
   setTimeElapsed(timeElapsed);
   interpolateLifeTime();
   interpolateSize();
   interpolateColor();
   calculatePhysics();
}
int QgsDiagramRenderer::calculateDiagramSize( const QgsFeature& f, int& size ) const
{
  //find out value for classificationAttribute
  QVariant value;
  if ( classificationValue( f, value ) != 0 )
  {
    return 1;
  }

  if ( mItemInterpretation == ATTRIBUTE )
  {
    size = ( int )( value.toDouble() * mScaleFactor );
    return 0;
  }

  if ( mItems.size() < 1 )
  {
    return 2;
  }

  if ( mItemInterpretation == CONSTANT )
  {
    size = ( int )( mItems.constBegin()->size * mScaleFactor );
    return 0;
  }

  //find out size
  bool sizeAssigned = false;

  QList<QgsDiagramItem>::const_iterator current_it = mItems.constBegin();
  QList<QgsDiagramItem>::const_iterator last_it = mItems.constEnd();

  if ( value.type() == QVariant::String ) //string types are handled differently
  {
    for ( ; current_it != mItems.constEnd(); ++current_it )
    {
      if ( current_it->value.toString() == value.toString() )
      {
        size = ( int )( current_it->size * mScaleFactor );
        sizeAssigned = true;
      }
    }
    if ( !sizeAssigned )
    {
      return 3;
    }
  }
  else //numerical types
  {
    for ( ; current_it != mItems.constEnd(); ++current_it )
    {
      if ( value.toDouble() < current_it->value.toDouble() )
      {
        if ( last_it == mItems.constEnd() ) //values below classifications receive first items size
        {
          size = ( int )( current_it->size * mScaleFactor );
        }
        else
        {
          size = ( int )( interpolateSize( value.toDouble(), last_it->value.toDouble(), current_it->value.toDouble(), last_it->size, current_it->size ) * mScaleFactor );

        }
        sizeAssigned = true;
        break;
      }
      last_it = current_it;
    }

    if ( !sizeAssigned )//values above classification receive last items size
    {
      size = ( int )( last_it->size * mScaleFactor );
    }
  }

  return 0;
}