#include <ingredientViewItem.hpp>
Public Member Functions | |
| IngredientViewItem (QListViewItem *parent, const QString &_amount1, const QString &_amount2, const QString &_amount3, const QString &_unit, const QString &_name, const QString &_prep) | |
| IngredientViewItem (QListViewItem *parent, QListViewItem *after, const QString &_amount1, const QString &_amount2, const QString &_amount3, const QString &_unit, const QString &_name, const QString &_prep) | |
| void | setAmount (double _amountDouble=0.0) |
| void | setAmount (int _amountNominator, int _amountDenominator) |
| bool | isNull (void) const |
| bool | isFraction (void) const |
| void | setFraction (bool _fraction) |
| double | getAmountDouble (void) const |
| int | getAmountNumber (void) const |
| int | getAmountNominator (void) const |
| int | getAmountDenominator (void) const |
Protected Attributes | |
| double | amountDouble |
| int | amountNominator |
| int | amountDenominator |
Definition at line 25 of file ingredientViewItem.hpp.
| IngredientViewItem::IngredientViewItem | ( | QListViewItem * | parent, | |
| const QString & | _amount1, | |||
| const QString & | _amount2, | |||
| const QString & | _amount3, | |||
| const QString & | _unit, | |||
| const QString & | _name, | |||
| const QString & | _prep | |||
| ) |
Definition at line 26 of file ingredientViewItem.cpp.
References setAmount().
00032 : 00033 QListViewItem( parent, "", _unit, _name, _prep ) 00034 { 00035 if ( !_amount1.isEmpty() ) 00036 setAmount( atof( _amount1 ) ); 00037 else 00038 setAmount( atoi( _amount2 ), atoi( _amount3 ) ); 00039 }
| IngredientViewItem::IngredientViewItem | ( | QListViewItem * | parent, | |
| QListViewItem * | after, | |||
| const QString & | _amount1, | |||
| const QString & | _amount2, | |||
| const QString & | _amount3, | |||
| const QString & | _unit, | |||
| const QString & | _name, | |||
| const QString & | _prep | |||
| ) |
Definition at line 41 of file ingredientViewItem.cpp.
References setAmount().
00048 : 00049 QListViewItem( parent, after, "", _unit, _name, _prep ) 00050 { 00051 if ( !_amount1.isEmpty() ) 00052 setAmount( atof( _amount1 ) ); 00053 else 00054 setAmount( atoi( _amount2 ), atoi( _amount3 ) ); 00055 }
| void IngredientViewItem::setAmount | ( | double | _amountDouble = 0.0 |
) |
Definition at line 57 of file ingredientViewItem.cpp.
References amountDenominator, amountDouble, and amountNominator.
Referenced by IngredientViewItem(), and setFraction().
00058 { 00059 assert( _amountDouble >= 0.0 ); 00060 00061 amountDouble = _amountDouble; 00062 amountNominator = 0; 00063 amountDenominator = 0; 00064 00065 if ( amountDouble != 0.0 ) 00066 setText( 0, QString( "%1" ).arg( amountDouble ) ); 00067 else 00068 setText( 0, "" ); 00069 }
| void IngredientViewItem::setAmount | ( | int | _amountNominator, | |
| int | _amountDenominator | |||
| ) |
Definition at line 71 of file ingredientViewItem.cpp.
References amountDenominator, amountDouble, amountNominator, and gcd().
00073 { 00074 assert( _amountNominator >= 0 ); 00075 assert( _amountDenominator >= 0 ); 00076 00077 amountDouble = 0.0; 00078 amountNominator = _amountNominator; 00079 amountDenominator = _amountDenominator; 00080 00081 if ( amountDenominator == 0 ) amountDenominator = 1; 00082 00083 if ( amountNominator > 0 ) { 00084 00085 int greatestCommonDivisor = gcd( amountNominator, amountDenominator ); 00086 amountNominator /= greatestCommonDivisor; 00087 amountDenominator /= greatestCommonDivisor; 00088 00089 if ( amountDenominator > 1 ) { 00090 if ( amountNominator >= amountDenominator ) 00091 setText( 0, QString( "%1 %2/%3" ). 00092 arg( amountNominator / amountDenominator ). 00093 arg( amountNominator % amountDenominator ). 00094 arg( amountDenominator ) ); 00095 else 00096 setText( 0, QString( "%1/%2" ). 00097 arg( amountNominator ). 00098 arg( amountDenominator ) ); 00099 } else 00100 setText( 0, QString( "%1" ).arg( amountNominator ) ); 00101 00102 } else 00103 setText( 0, "" ); 00104 }
| bool IngredientViewItem::isNull | ( | void | ) | const [inline] |
Definition at line 44 of file ingredientViewItem.hpp.
References amountDouble, and amountNominator.
00045 { return amountNominator == 0 && amountDouble == 0.0; }
| bool IngredientViewItem::isFraction | ( | void | ) | const [inline] |
Definition at line 47 of file ingredientViewItem.hpp.
References amountDenominator.
Referenced by setFraction().
00047 { return amountDenominator > 0; }
| void IngredientViewItem::setFraction | ( | bool | _fraction | ) |
Definition at line 106 of file ingredientViewItem.cpp.
References amountDenominator, amountDouble, amountNominator, isFraction(), and setAmount().
00107 { 00108 if ( _fraction != isFraction() ) { 00109 if ( _fraction ) { 00110 setAmount( (int)( amountDouble * 1000 ), 1000 ); 00111 } else { 00112 assert( amountDenominator > 0 ); 00113 setAmount( (double)amountNominator / amountDenominator ); 00114 }; 00115 }; 00116 }
| double IngredientViewItem::getAmountDouble | ( | void | ) | const [inline] |
Definition at line 51 of file ingredientViewItem.hpp.
References amountDouble.
00051 { return amountDouble; }
| int IngredientViewItem::getAmountNumber | ( | void | ) | const |
Definition at line 118 of file ingredientViewItem.cpp.
References amountDenominator, and amountNominator.
00119 { 00120 assert( amountDenominator > 0 ); 00121 return amountNominator / amountDenominator; 00122 }
| int IngredientViewItem::getAmountNominator | ( | void | ) | const |
Definition at line 124 of file ingredientViewItem.cpp.
References amountDenominator, and amountNominator.
00125 { 00126 assert( amountDenominator > 0 ); 00127 return amountNominator % amountDenominator; 00128 }
| int IngredientViewItem::getAmountDenominator | ( | void | ) | const [inline] |
Definition at line 57 of file ingredientViewItem.hpp.
References amountDenominator.
00058 { return amountDenominator; }
double IngredientViewItem::amountDouble [protected] |
Definition at line 61 of file ingredientViewItem.hpp.
Referenced by getAmountDouble(), isNull(), setAmount(), and setFraction().
int IngredientViewItem::amountNominator [protected] |
Definition at line 63 of file ingredientViewItem.hpp.
Referenced by getAmountNominator(), getAmountNumber(), isNull(), setAmount(), and setFraction().
int IngredientViewItem::amountDenominator [protected] |
Definition at line 65 of file ingredientViewItem.hpp.
Referenced by getAmountDenominator(), getAmountNominator(), getAmountNumber(), isFraction(), setAmount(), and setFraction().