Ejemplo n.º 1
0
void BtLineEdit::lineChanged(Unit::unitDisplay oldUnit, Unit::unitScale oldScale)
{
   // This is where it gets hard
   double val = -1.0;
   QString amt;
   bool force = Brewtarget::hasUnits(text());
   bool ok = false;
   bool wasChanged = sender() == this;

   // editingFinished happens on focus being lost, regardless of anything
   // being changed. I am hoping this short circuits properly and we do
   // nothing if nothing changed.
   if ( sender() == this && ! isModified() )
   {
      return;
   }

   if (text().isEmpty())
   {
      return;
   }

   // The idea here is we need to first translate the field into a known
   // amount (aka to SI) and then into the unit we want.
   switch( _type )
   {
      case Unit::Mass:
      case Unit::Volume:
      case Unit::Temp:
      case Unit::Time:
      case Unit::Density:
         val = toSI(oldUnit,oldScale,force);
         amt = displayAmount(val,3);
         break;
      case Unit::Color:
         val = toSI(oldUnit,oldScale,force);
         amt = displayAmount(val,0);
         break;
      case Unit::String:
         amt = text();
         break;
      case Unit::None:
      default:
         val = Brewtarget::toDouble(text(),&ok);
         if ( ! ok )
            Brewtarget::logW( QString("%1: failed to convert %2 (%3:%4) to double").arg(Q_FUNC_INFO).arg(text()).arg(_section).arg(_editField) );
         amt = displayAmount(val);
   }
   QLineEdit::setText(amt);

   if ( wasChanged ) {
      emit textModified();
   }
}
Ejemplo n.º 2
0
void BtLineEdit::setText( BeerXMLElement* element, int precision )
{
   double amount = 0.0;
   QString display;

   if ( _section.isEmpty() )
      initializeSection();
   if ( _property.isEmpty() )
      initializeProperties();

   if ( _type == STRING )
      display = element->property(_property.toLatin1().constData()).toString();
   else if ( element->property(_property.toLatin1().constData()).canConvert(QVariant::Double) )
   {
      // Get the amount
      bool ok = false;
      QString tmp = element->property(_property.toLatin1().constData()).toString();
      amount = Brewtarget::toDouble(tmp, &ok);
      if ( !ok )
         Brewtarget::logW( QString("BtLineEdit::setText(BeerXMLElement*,int) could not convert %1 to double").arg(tmp) );

      display = displayAmount(amount, precision);
   }
   else
   {
      display = "?";
   }

   QLineEdit::setText(display);
}
Ejemplo n.º 3
0
void BtLineEdit::setText( BeerXMLElement* element, int precision )
{
   double amount = 0.0;
   QString display;

   if ( _type == Unit::String )
      display = element->property(_editField.toLatin1().constData()).toString();
   else if ( element->property(_editField.toLatin1().constData()).canConvert(QVariant::Double) )
   {
      // Get the amount
      bool ok = false;
      QString tmp = element->property(_editField.toLatin1().constData()).toString();
      amount = Brewtarget::toDouble(tmp, &ok);
      if ( !ok )
         Brewtarget::logW( QString("%1 could not convert %2 (%3:%4) to double").arg(Q_FUNC_INFO).arg(tmp).arg(_section).arg(_editField) );

      display = displayAmount(amount, precision);
   }
   else
   {
      display = "?";
   }

   QLineEdit::setText(display);
}
Ejemplo n.º 4
0
void tableDisplay(My570List *list) {

/*
    +-----------------+--------------------------+----------------+----------------+
    |       Date      | Description              |         Amount |        Balance |
    +-----------------+--------------------------+----------------+----------------+
    | Thu Aug 21 2008 | ...                      |      1,723.00  |      1,723.00  |
    | Wed Dec 31 2008 | ...                      | (       45.33) |      1,677.67  |
    | Mon Jul 13 2009 | ...                      |     10,388.07  |     12,065.74  |
    | Sun Jan 10 2010 | ...                      | (      654.32) |     11,411.42  |
    +-----------------+--------------------------+----------------+----------------+
Each line is exactly 80 characters long (followed by a single "\n" character).
The Date field spans characters 3 through 17. Please use ctime() to format the timestamp 
and remove unnecessary characters to make it look like what's in the table above. 
The Description field spans characters 21 through 44. (If a description is too long,
you must truncate it.) The Amount field spans characters 48 through 61. For a withdrawal,
a pair of paranthesis must be used as indicated. If the amount of a transaction
is more than or equal to 10 million, please print ?,???,???.?? (or (?,???,???.??))
in the Amount field. The Balance field spans characters 65 through 78.
If a balance is negative, a pair of paranthesis must be used.
If the absolute value of a balance is more than or equal to 10 million, please print ?,???,???.?? (or (?,???,???.??)) in the Balance field.
 */
	double balance = 0;
 	fprintf(stdout,"+-----------------+--------------------------+----------------+----------------+\n");
	fprintf(stdout,"|       Date      | Description              |         Amount |        Balance |\n");
	fprintf(stdout,"+-----------------+--------------------------+----------------+----------------+\n");
	My570ListElem *elem=NULL;
	int recnum = 0;
	for (elem=list->First(); elem != NULL; elem=list->Next(elem)) {
        struct record *temp =(struct record*)(elem->Obj());
		temp->recordnum =recnum;
		recnum++;

		fprintf(stdout,"| ");
		displayDate(temp->timestamp); 		///<will add a space at the end ---TIMESTAMP
		
		fprintf(stdout,"| ");				///< add a | on same line		---DESCRIPTION
		displayDescription(temp->description);
		
		fprintf(stdout,"| ");				///< add a | on same line		---AMOUNT
		displayAmount(temp);
		
		fprintf(stdout,"| ");				///< add a | on same line		---AMOUNT
		balance = displayBalance(balance,temp);
		
		fprintf(stdout,"|");
		fprintf(stdout,"\n");
    }
	fprintf(stdout,"+-----------------+--------------------------+----------------+----------------+\n");	
}
Ejemplo n.º 5
0
void BtLineEdit::setText( QString amount, int precision)
{
   double amt;
   bool ok = false;

   if ( _type == STRING )
      QLineEdit::setText(amount);
   else
   {
      amt = Brewtarget::toDouble(amount,&ok);
      if ( !ok )
         Brewtarget::logW( QString("BtLineEdit::setText(QString,int) could not conver %1 to double").arg(amount) );
      QLineEdit::setText(displayAmount(amt, precision));
   }
}
Ejemplo n.º 6
0
void BtLineEdit::setText( QString amount, int precision)
{
   double amt;
   bool ok = false;

   if ( _type == Unit::String )
      QLineEdit::setText(amount);
   else
   {
      amt = Brewtarget::toDouble(amount,&ok);
      if ( !ok )
         Brewtarget::logW( QString("%1 could not convert %2 (%3:%4) to double").arg(Q_FUNC_INFO).arg(amount).arg(_section).arg(_editField) );
      QLineEdit::setText(displayAmount(amt, precision));
   }
}
Ejemplo n.º 7
0
void BtLineEdit::setText( double amount, int precision)
{
   QLineEdit::setText( displayAmount(amount,precision) );
}
Ejemplo n.º 8
0
void BtLineEdit::lineChanged(Unit::unitDisplay oldUnit, Unit::unitScale oldScale)
{
   // This is where it gets hard
   double val = -1.0;
   QString amt;
   bool force = false;
   bool ok = false;

   // editingFinished happens on focus being lost, regardless of anything
   // being changed. I am hoping this short circuits properly and we do
   // nothing if nothing changed.
   if ( sender() == this && ! isModified() )
   {
      return;
   }

   // If we are here because somebody else sent the signal (ie, a label) or we
   // generated the signal but nothing has changed then don't try to guess the
   // units.
   if ( sender() != this )
   {
      force = true;
   }

   if ( _section.isEmpty() )
      initializeSection();

   if ( _property.isEmpty() )
      initializeProperties();

   if (text().isEmpty())
   {
      return;
   }

   // The idea here is we need to first translate the field into a known
   // amount (aka to SI) and then into the unit we want.
   switch( _type )
   {
      case MASS:
      case VOLUME:
      case TEMPERATURE:
      case TIME:
         val = toSI(oldUnit,oldScale,force);
         amt = displayAmount(val,3);
         break;
      case DENSITY:
      case COLOR:
         val = toSI(oldUnit,oldScale,force);
         amt = displayAmount(val,0);
         break;
      case STRING:
         amt = text();
         break;
      case GENERIC:
      default:
         val = Brewtarget::toDouble(text(),&ok);
         if ( ! ok )
            Brewtarget::logW( QString("BtLineEdit::lineChanged: failed to convert %1 toDouble").arg(text()) );
         amt = displayAmount(val);
   }
   QLineEdit::setText(amt);

   if ( ! force )
   {
      emit textModified();
   }
}