Esempio n. 1
0
QValidator::State MapimgValidator::validate( QString & input, int & ) const
{
   if( input.upper() == "UNDEFINED" && m_allowUndefined )
   {
       input = "Undefined";
       return Acceptable;
   }

   QRegExp empty( QString::fromLatin1(" *-?\\.? *") );
   if ( m_bottom >= 0 &&
      input.stripWhiteSpace().startsWith(QString::fromLatin1("-")) )
        return Invalid;
   if ( empty.exactMatch(input) )
      return Intermediate;
   bool ok = TRUE;
   double entered = input.toDouble( &ok );
   int nume = input.contains( 'e', FALSE );
   if ( !ok ) {
      // explicit exponent regexp
      QRegExp expexpexp( QString::fromLatin1("[Ee][+-]?\\d*$") );
      int eeePos = expexpexp.search( input );
      if ( eeePos > 0 && nume == 1 ) {
         QString mantissa = input.left( eeePos );
         entered = mantissa.toDouble( &ok );
         if ( !ok )
            return Invalid;
      } else if ( eeePos == 0 ) {
         return Intermediate;
      } else {
         return Invalid;
      }
   }

   QString tempInput = QString::number( entered );

   int tempj = tempInput.find( '.' );
   int i = input.find( '.' );

   if( (i >= 0 || tempj >= 0 || input.contains("e-", FALSE)) && m_decimals == 0 )
   {
      return Invalid;
   }

   if ( i >= 0 && nume == 0 ) {
      // has decimal point (but no E), now count digits after that
      i++;
      int j = i;
      while( input[j].isDigit() )
         j++;
      if ( j - i > m_decimals )
         return Invalid; //Intermediate;
   }

   if( entered > m_top )
      return Invalid;
   else if ( entered < m_bottom )
      return Intermediate;
   else
      return Acceptable;
}
QValidator::State QDoubleValidator::validate( QString & input, int & ) const
{
    QRegExp empty( QString::fromLatin1(" *-?\\.? *") );
    if ( b >= 0 &&
	 input.stripWhiteSpace().startsWith(QString::fromLatin1("-")) )
	return Invalid;
    if ( empty.exactMatch(input) )
	return Intermediate;
    bool ok = TRUE;
    double entered = input.toDouble( &ok );
    int nume = input.contains( 'e', FALSE );
    if ( !ok ) {
	// explicit exponent regexp
	QRegExp expexpexp( QString::fromLatin1("[Ee][+-]?\\d*$") );
	int eeePos = expexpexp.search( input );
	if ( eeePos > 0 && nume == 1 ) {
	    QString mantissa = input.left( eeePos );
	    entered = mantissa.toDouble( &ok );
	    if ( !ok )
		return Invalid;
	} else if ( eeePos == 0 ) {
	    return Intermediate;
	} else {
	    return Invalid;
	}
    }

    int i = input.find( '.' );
    if ( i >= 0 && nume == 0 ) {
	// has decimal point (but no E), now count digits after that
	i++;
	int j = i;
	while( input[j].isDigit() )
	    j++;
	if ( j - i > d )
	    return Intermediate;
    }

    if ( entered < b || entered > t )
	return Intermediate;
    else
	return Acceptable;
}