summaryrefslogtreecommitdiffstats
path: root/src/datablocks
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2024-10-13 11:56:14 +0900
committerMichele Calgaro <[email protected]>2024-10-29 21:58:42 +0900
commit2879ff70be9271550477982a1a6371714db38562 (patch)
treec2054149dba923ab080fe7093432c7663a990111 /src/datablocks
parent3eb38d2556f676d1027746f20bf12a1dd74451ef (diff)
downloadkrecipes-2879ff70be9271550477982a1a6371714db38562.tar.gz
krecipes-2879ff70be9271550477982a1a6371714db38562.zip
Rearrange folders structure to remove unnecessary 'krecipes' second level subfolder
Signed-off-by: Michele Calgaro <[email protected]> (cherry picked from commit 0c8ed6c9a4000af8f48581a81c4b5c2f5b9fd502)
Diffstat (limited to 'src/datablocks')
-rw-r--r--src/datablocks/Makefile.am20
-rw-r--r--src/datablocks/categorytree.cpp133
-rw-r--r--src/datablocks/categorytree.h61
-rw-r--r--src/datablocks/constraintlist.cpp11
-rw-r--r--src/datablocks/constraintlist.h47
-rw-r--r--src/datablocks/element.cpp43
-rw-r--r--src/datablocks/element.h41
-rw-r--r--src/datablocks/elementlist.cpp102
-rw-r--r--src/datablocks/elementlist.h43
-rw-r--r--src/datablocks/ingredient.cpp95
-rw-r--r--src/datablocks/ingredient.h63
-rw-r--r--src/datablocks/ingredientlist.cpp272
-rw-r--r--src/datablocks/ingredientlist.h61
-rw-r--r--src/datablocks/ingredientproperty.cpp32
-rw-r--r--src/datablocks/ingredientproperty.h37
-rw-r--r--src/datablocks/ingredientpropertylist.cpp53
-rw-r--r--src/datablocks/ingredientpropertylist.h30
-rw-r--r--src/datablocks/kreborder.cpp17
-rw-r--r--src/datablocks/kreborder.h29
-rw-r--r--src/datablocks/mixednumber.cpp289
-rw-r--r--src/datablocks/mixednumber.h126
-rw-r--r--src/datablocks/rating.cpp86
-rw-r--r--src/datablocks/rating.h55
-rw-r--r--src/datablocks/recipe.cpp53
-rw-r--r--src/datablocks/recipe.h71
-rw-r--r--src/datablocks/recipelist.cpp18
-rw-r--r--src/datablocks/recipelist.h28
-rw-r--r--src/datablocks/unit.cpp75
-rw-r--r--src/datablocks/unit.h45
-rw-r--r--src/datablocks/unitratio.cpp30
-rw-r--r--src/datablocks/unitratio.h37
-rw-r--r--src/datablocks/unitratiolist.cpp34
-rw-r--r--src/datablocks/unitratiolist.h33
-rw-r--r--src/datablocks/weight.cpp14
-rw-r--r--src/datablocks/weight.h41
35 files changed, 2225 insertions, 0 deletions
diff --git a/src/datablocks/Makefile.am b/src/datablocks/Makefile.am
new file mode 100644
index 0000000..e6161f7
--- /dev/null
+++ b/src/datablocks/Makefile.am
@@ -0,0 +1,20 @@
+## Makefile.am for krecipes
+
+# this is the program that gets installed. it's name is used for all
+# of the other Makefile.am variables
+
+# set the include path for X, tqt and TDE
+INCLUDES = -I$(srcdir)/.. $(all_includes)
+
+noinst_LTLIBRARIES=libdatablocks.la
+libdatablocks_la_SOURCES= \
+ recipelist.cpp constraintlist.cpp categorytree.cpp kreborder.cpp \
+ recipe.cpp ingredient.cpp ingredientlist.cpp elementlist.cpp \
+ element.cpp ingredientproperty.cpp ingredientpropertylist.cpp \
+ unit.cpp unitratio.cpp unitratiolist.cpp mixednumber.cpp rating.cpp \
+ weight.cpp
+
+libdatablocks_la_METASOURCES=AUTO
+
+#the library search path.
+libdatablocks_la_LDFLAGS = $(KDE_RPATH) $(all_libraries)
diff --git a/src/datablocks/categorytree.cpp b/src/datablocks/categorytree.cpp
new file mode 100644
index 0000000..bb61de6
--- /dev/null
+++ b/src/datablocks/categorytree.cpp
@@ -0,0 +1,133 @@
+/***************************************************************************
+* Copyright (C) 2004 by Jason Kivlighn *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "categorytree.h"
+
+#include <kdebug.h>
+
+#include "element.h"
+
+CategoryTree::CategoryTree( CategoryTree *parent ) :
+ m_parent( 0 ), m_child( 0 ), m_sibling( 0 ), m_last(0), m_count(0)
+{
+ if ( parent )
+ parent->insertItem( this );
+}
+
+CategoryTree::~CategoryTree()
+{
+ if ( m_parent )
+ m_parent->takeItem( this );
+
+ CategoryTree * i = m_child;
+ m_child = 0;
+ while ( i ) {
+ i->m_parent = 0;
+ CategoryTree * n = i->m_sibling;
+ delete i;
+ i = n;
+ }
+}
+
+CategoryTree *CategoryTree::add
+ ( const Element &cat )
+{
+ CategoryTree * new_child = new CategoryTree( this );
+ new_child->category = cat;
+
+ m_count++;
+
+ return new_child;
+}
+
+void CategoryTree::insertItem( CategoryTree *newChild )
+{
+ newChild->m_parent = this;
+ if ( m_child && m_child->m_last )
+ m_child->m_last->m_sibling = newChild;
+ else
+ m_child = newChild;
+
+ m_child->m_last = newChild;
+ m_count++;
+}
+
+void CategoryTree::takeItem( CategoryTree *tree )
+{
+ kdError()<< "Both these methods seem to be broken... don't use this function!" << endl;
+
+ CategoryTree *lastItem = m_child->m_last;
+#if 0
+ CategoryTree ** nextChild = &m_child;
+ while( nextChild && *nextChild && tree != *nextChild )
+ nextChild = &((*nextChild)->m_sibling);
+
+ if ( nextChild && tree == *nextChild ) {
+ *nextChild = (*nextChild)->m_sibling;
+ }
+ tree->m_parent = 0;
+ tree->m_sibling = 0;
+#else
+ for ( CategoryTree *it = firstChild(); it; it = it->nextSibling() ) {
+ if ( it->nextSibling() == tree ) {
+ it->m_sibling = tree->nextSibling();
+ break;
+ }
+ }
+ tree->m_parent = 0;
+ tree->m_sibling = 0;
+#endif
+ if ( tree != m_last )
+ m_child->m_last = lastItem;
+ else //FIXME: unstable behavior if this is the case
+ kdDebug()<<"CategoryTree::takeItem: warning - unstable behavior expected"<<endl;
+ m_count--;
+}
+
+void CategoryTree::clear()
+{
+ CategoryTree *c = m_child;
+ CategoryTree *n;
+ while( c ) {
+ n = c->m_sibling;
+ delete c;
+ c = n;
+ }
+}
+
+bool CategoryTree::contains( int id ) const
+{
+ bool result = false;
+
+ for ( CategoryTree * child_it = firstChild(); child_it; child_it = child_it->nextSibling() ) {
+ if ( child_it->category.id == id )
+ return true;
+
+ result = child_it->contains( id );
+ }
+
+ return result;
+}
+
+CategoryTree* CategoryTree::find( int id ) const
+{
+ CategoryTree *result = 0;
+
+ for ( CategoryTree * child_it = firstChild(); child_it; child_it = child_it->nextSibling() ) {
+ if ( child_it->category.id == id )
+ return child_it;
+
+ result = child_it->find( id );
+ }
+
+ return result;
+}
+
+
diff --git a/src/datablocks/categorytree.h b/src/datablocks/categorytree.h
new file mode 100644
index 0000000..e5668e4
--- /dev/null
+++ b/src/datablocks/categorytree.h
@@ -0,0 +1,61 @@
+/***************************************************************************
+* Copyright (C) 2004 by Jason Kivlighn *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef CATEGORYTREE_H
+#define CATEGORYTREE_H
+
+#include "element.h"
+
+class CategoryTree
+{
+public:
+ CategoryTree( CategoryTree *parent = 0 );
+
+ ~CategoryTree();
+
+ Element category;
+
+ CategoryTree *add
+ ( const Element &cat );
+ void clear();
+
+ bool contains( int id ) const;
+ CategoryTree* find( int id ) const;
+
+ CategoryTree *parent() const
+ {
+ return m_parent;
+ }
+ CategoryTree *firstChild() const
+ {
+ return m_child;
+ }
+ CategoryTree *nextSibling() const
+ {
+ return m_sibling;
+ }
+
+ void takeItem( CategoryTree * );
+ void insertItem( CategoryTree * );
+
+ int count() const { return m_count; }
+
+private:
+ CategoryTree( const CategoryTree & );
+ CategoryTree &operator=( const CategoryTree & );
+
+ CategoryTree *m_parent;
+ CategoryTree *m_child;
+ CategoryTree *m_sibling;
+ CategoryTree *m_last;
+
+ int m_count;
+};
+
+#endif
diff --git a/src/datablocks/constraintlist.cpp b/src/datablocks/constraintlist.cpp
new file mode 100644
index 0000000..f96ffc9
--- /dev/null
+++ b/src/datablocks/constraintlist.cpp
@@ -0,0 +1,11 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "constraintlist.h"
+
diff --git a/src/datablocks/constraintlist.h b/src/datablocks/constraintlist.h
new file mode 100644
index 0000000..2a75470
--- /dev/null
+++ b/src/datablocks/constraintlist.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef CONSTRAINTLIST_H
+#define CONSTRAINTLIST_H
+
+#include <tqstring.h>
+
+#include "unit.h"
+
+/**
+@author Unai Garro
+*/
+
+class IngredientProperty;
+
+class Constraint
+{
+public:
+ Constraint()
+ {
+ max = 0.0;
+ min = 0.0;
+ id = -1;
+ enabled = false;
+ }
+
+ ~Constraint(){}
+
+ int id;
+ TQString name;
+ TQString units;
+ Unit perUnit; // stores the unit ID, name, and type
+ double max;
+ double min;
+ bool enabled;
+};
+
+typedef TQValueList< Constraint > ConstraintList;
+
+#endif
diff --git a/src/datablocks/element.cpp b/src/datablocks/element.cpp
new file mode 100644
index 0000000..18c2b7f
--- /dev/null
+++ b/src/datablocks/element.cpp
@@ -0,0 +1,43 @@
+/***************************************************************************
+* Copyright (C) 2003 by *
+* Unai Garro ([email protected]) *
+* Cyril Bosselut ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "element.h"
+
+Element::Element() :
+ id( -1 )
+{}
+
+Element::Element( const TQString &_name, int _id ) :
+ name( _name ),
+ id( _id )
+{}
+
+Element::Element( const Element &el )
+{
+ id = el.id;
+ name = el.name;
+}
+
+Element::~Element()
+{}
+
+Element& Element::operator=( const Element &el )
+{
+ id = el.id;
+ name = el.name;
+ return *this;
+}
+
+bool Element::operator==( const Element &el ) const
+{
+ return ( el.id == id );
+}
diff --git a/src/datablocks/element.h b/src/datablocks/element.h
new file mode 100644
index 0000000..6324719
--- /dev/null
+++ b/src/datablocks/element.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+* Copyright (C) 2003 by *
+* Unai Garro ([email protected]) *
+* Cyril Bosselut ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef ELEMENT_H
+#define ELEMENT_H
+#include <tqstring.h>
+/**
+@author Unai Garro
+*/
+class Element
+{
+public:
+ Element();
+ Element( const TQString &name, int id = -1 );
+ Element( const Element &el );
+
+ ~Element();
+ TQString name;
+ int id;
+ Element& operator=( const Element &el );
+
+ /** Compare two elements by their id */
+ bool operator==( const Element & ) const;
+
+ /** Compare (sort) by name */
+ bool operator<( const Element &e ) const
+ {
+ return name < e.name;
+ }
+};
+
+#endif
diff --git a/src/datablocks/elementlist.cpp b/src/datablocks/elementlist.cpp
new file mode 100644
index 0000000..7eca42d
--- /dev/null
+++ b/src/datablocks/elementlist.cpp
@@ -0,0 +1,102 @@
+/***************************************************************************
+* Copyright (C) 2003-2004 by *
+* Unai Garro ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "datablocks/elementlist.h"
+
+ElementList::ElementList() : TQValueList <Element>()
+{}
+
+ElementList::~ElementList()
+{}
+
+Element ElementList::getElement( int index ) const
+{
+ return * ( at( index ) );
+}
+
+Element ElementList::findByName( const TQString &name ) const
+{
+ ElementList::const_iterator it_end = end();
+ for ( ElementList::const_iterator it = begin(); it != it_end; ++it ) {
+ if ( ( *it ).name == name )
+ return * it;
+ }
+
+ Element el;
+ el.id = -1;
+ return el;
+}
+
+Element ElementList::findByName( const TQRegExp &rx ) const
+{
+ ElementList::const_iterator it_end = end();
+ for ( ElementList::const_iterator it = begin(); it != it_end; ++it ) {
+ if ( ( *it ).name.find(rx) != -1 )
+ return * it;
+ }
+
+ Element el;
+ el.id = -1;
+ return el;
+}
+
+bool ElementList::containsId( int id ) const // Search by id (which uses search by item, with comparison defined on header)
+{
+ if ( id == -1 ) {
+ return count() == 0;
+ }
+
+ Element i;
+ i.id = id;
+ return ( find( i ) != end() );
+}
+
+bool ElementList::containsSubSet( ElementList &el )
+{
+ ElementList::const_iterator it_end = el.end();
+ ElementList::const_iterator it;
+
+ for ( it = el.begin(); it != it_end; ++it ) {
+ if ( !containsId( ( *it ).id ) )
+ return false;
+ }
+ return true;
+}
+
+TQString ElementList::join( const TQString &sep ) const
+{
+ TQString ret;
+
+ ElementList::const_iterator it_end = end();
+ ElementList::const_iterator it;
+
+ for ( it = begin(); it != it_end; ++it ) {
+ if ( it != begin() )
+ ret += sep;
+ ret += (*it).name;
+ }
+
+ return ret;
+}
+
+ElementList ElementList::split( const TQString &sep, const TQString &str )
+{
+ ElementList ret;
+ TQStringList list = TQStringList::split(sep,str);
+
+ TQStringList::const_iterator it_end = list.end();
+ TQStringList::const_iterator it;
+
+ for ( it = list.begin(); it != it_end; ++it ) {
+ ret.append( Element((*it).stripWhiteSpace()) );
+ }
+
+ return ret;
+}
diff --git a/src/datablocks/elementlist.h b/src/datablocks/elementlist.h
new file mode 100644
index 0000000..58d5bca
--- /dev/null
+++ b/src/datablocks/elementlist.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+* Copyright (C) 2003-2004 by *
+* Unai Garro ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef ELEMENTLIST_H
+#define ELEMENTLIST_H
+
+#include <tqvaluelist.h>
+#include <tqregexp.h>
+
+#include "element.h"
+
+/**
+@author Unai Garro
+*/
+class ElementList: public TQValueList<Element>
+{
+public:
+ ElementList();
+ ~ElementList();
+
+ bool containsId( int id ) const;
+ bool containsSubSet( ElementList &el );
+
+ Element findByName( const TQString & ) const;
+ Element findByName( const TQRegExp & ) const;
+
+ Element getElement( int index ) const;
+
+ TQString join( const TQString &sep ) const;
+
+ static ElementList split( const TQString &sep, const TQString &str );
+};
+
+typedef TQValueList<int> IDList;
+
+#endif
diff --git a/src/datablocks/ingredient.cpp b/src/datablocks/ingredient.cpp
new file mode 100644
index 0000000..a17beda
--- /dev/null
+++ b/src/datablocks/ingredient.cpp
@@ -0,0 +1,95 @@
+/***************************************************************************
+* Copyright (C) 2003 by *
+* Unai Garro ([email protected]) *
+* Cyril Bosselut ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "datablocks/ingredient.h"
+
+#include <tqstringlist.h>
+
+#include "mixednumber.h"
+
+IngredientData::IngredientData() : amount( 0 ), amount_offset( 0 ), groupID( -1 )
+{}
+
+IngredientData::IngredientData( const TQString &_name, double _amount, const Unit &_units, int _unitID, int _ingredientID ) :
+ ingredientID( _ingredientID ),
+ name( _name ),
+ amount( _amount ),
+ amount_offset( 0 ),
+ units( _units ),
+ groupID( -1 )
+{
+units.id=_unitID;
+}
+
+//compare also using the group id because there may be the same ingredient in a list multiple times, but each in a different group
+bool IngredientData::operator==( const IngredientData &ing ) const
+{
+ return ( ( ing.ingredientID == ingredientID ) && ( ing.groupID == groupID ) );
+}
+
+Ingredient::Ingredient() : IngredientData()
+{}
+
+Ingredient::Ingredient( const TQString &_name, double _amount, const Unit &_units, int _unitID, int _ingredientID ) :
+ IngredientData(_name,_amount,_units,_unitID,_ingredientID)
+{}
+
+Ingredient::Ingredient( const IngredientData &d ) : IngredientData(d)
+{}
+
+void Ingredient::setAmount( const TQString &range, bool *ok )
+{
+ if ( range.isEmpty() ) {
+ if ( ok ) *ok = true;
+ return;
+ }
+
+ TQStringList ranges = TQStringList::split('-',range);
+
+ TQString amount_min = ranges[0];
+ if ( amount_min.isEmpty() ) {
+ if ( ok ) *ok = false;
+ return;
+ }
+
+ TQString amount_max;
+ switch ( ranges.count() ) {
+ case 0:
+ case 1: break;
+ case 2: amount_max = ranges[1];
+ break;
+ default:
+ if ( ok ) *ok = false;
+ return;
+ }
+
+ MixedNumber nm_min = MixedNumber::fromString( amount_min, ok );
+ if ( ok && *ok == false ) return;
+
+ MixedNumber nm_max = MixedNumber::fromString( amount_max, ok );
+ if ( ok && *ok == false ) return;
+
+ amount = nm_min.toDouble();
+ if ( nm_max > 0 )
+ amount_offset = nm_max.toDouble() - amount;
+}
+
+//compare also using the group id because there may be the same ingredient in a list multiple times, but each in a different group
+bool Ingredient::operator==( const Ingredient &ing ) const
+{
+ return ( ( ing.ingredientID == ingredientID ) && ( ing.groupID == groupID ) );
+}
+
+bool Ingredient::operator<( const Ingredient &ing ) const
+{
+ return ( TQString::localeAwareCompare( name, ing.name ) < 0 );
+}
diff --git a/src/datablocks/ingredient.h b/src/datablocks/ingredient.h
new file mode 100644
index 0000000..bdc20d4
--- /dev/null
+++ b/src/datablocks/ingredient.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* Copyright (C) 2006 Jason Kivlighn <[email protected]> *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef INGREDIENT_H
+#define INGREDIENT_H
+
+#include <tqstring.h>
+#include <tqvaluelist.h>
+
+#include "datablocks/unit.h"
+#include "datablocks/elementlist.h"
+
+//###: Is there a better way to get the behavior of a list of Ingredient
+// objects as a data member of Ingredient?
+class IngredientData
+{
+public:
+ IngredientData();
+ IngredientData( const TQString &name, double amount, const Unit &units, int unitID = -1, int ingredientID = -1 );
+
+ int ingredientID;
+ TQString name;
+ double amount;
+ double amount_offset;
+ Unit units;
+ int groupID;
+ TQString group;
+ ElementList prepMethodList;
+
+ /** Compare two elements by their id */
+ bool operator==( const IngredientData & ) const;
+};
+
+/**
+@author Unai Garro
+*/
+class Ingredient : public IngredientData
+{
+public:
+ Ingredient();
+ Ingredient( const TQString &name, double amount, const Unit &units, int unitID = -1, int ingredientID = -1 );
+ Ingredient( const IngredientData& );
+
+ TQValueList<IngredientData> substitutes;
+
+ void setAmount( const TQString &range, bool *ok = 0 );
+
+ /** Compare two elements by their id and groupID */
+ bool operator==( const Ingredient & ) const;
+
+ /** This is used for sorting, and so we compare by name */
+ bool operator<( const Ingredient & ) const;
+};
+
+#endif
diff --git a/src/datablocks/ingredientlist.cpp b/src/datablocks/ingredientlist.cpp
new file mode 100644
index 0000000..7156a48
--- /dev/null
+++ b/src/datablocks/ingredientlist.cpp
@@ -0,0 +1,272 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* Unai Garro ([email protected]) *
+* Cyril Bosselut ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "ingredientlist.h"
+
+#include "backends/recipedb.h"
+
+IngredientList::IngredientList() : TQValueList<Ingredient>()
+{}
+
+IngredientList::~IngredientList()
+{}
+
+bool IngredientList::contains( const Ingredient &ing, bool compareAmount, RecipeDB *database ) const
+{
+ bool ret = false;
+ for ( IngredientList::const_iterator it = begin(); it != end(); ++it ) {
+ if ( (*it).ingredientID == ing.ingredientID ) {
+ //see if we have enough of the ingredient
+ //(only if an amount was specified for both)
+ if ( compareAmount && (*it).amount > 0 && ing.amount > 0 ) {
+ Ingredient convertedIng;
+ if ( database->convertIngredientUnits( ing, (*it).units, convertedIng ) )
+ ret = (*it).amount >= convertedIng.amount;
+ else //we couldn't do the conversion
+ ret = true;
+ }
+ else
+ ret = true;
+ }
+ }
+ if ( !ret ) {
+ for ( TQValueList<IngredientData>::const_iterator it = ing.substitutes.begin(); it != ing.substitutes.end(); ++it ) {
+ ret = contains(*it, compareAmount, database);
+ if ( ret ) break;
+ }
+ }
+ return ret;
+}
+
+bool IngredientList::containsSubSet( IngredientList &il, IngredientList &missing, bool compareAmount, RecipeDB *database )
+{
+ missing.empty();
+ bool contained = true;
+ IngredientList::const_iterator it;
+
+ for ( it = il.begin();it != il.end();++it ) {
+ if ( !contains( *it, compareAmount, database ) ) {
+ contained = false;
+ missing.append( *it );
+ }
+ }
+
+ return contained;
+}
+
+bool IngredientList::containsSubSet( IngredientList &il ) const
+{
+ IngredientList::const_iterator it;
+
+ for ( it = il.begin();it != il.end();++it ) {
+ if ( !contains( *it ) ) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool IngredientList::containsAny( const IngredientList &list, bool compareAmount, RecipeDB *database )
+{
+ for ( IngredientList::const_iterator this_list_it = begin(); this_list_it != end(); ++this_list_it ) {
+ for ( IngredientList::const_iterator contains_list_it = list.begin(); contains_list_it != list.end(); ++contains_list_it ) {
+ if ( contains( *contains_list_it, compareAmount, database ) )
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void IngredientList::empty( void )
+{
+ clear();
+}
+
+int IngredientList::find( int id ) const // Search by id (which uses search by item, with comparison defined on header)
+{
+ Ingredient i;
+ i.ingredientID = id;
+ return findIndex( i );
+}
+
+Ingredient IngredientList::findByName( const TQString &ing ) const
+{
+ IngredientList::const_iterator it_end = end();
+ for ( IngredientList::const_iterator it = begin(); it != it_end; ++it ) {
+ if ( ( *it ).name == ing )
+ return *it;
+
+ for ( TQValueList<IngredientData>::const_iterator sub_it = ( *it ).substitutes.begin(); sub_it != ( *it ).substitutes.end(); ++sub_it ) {
+ if ( ( *sub_it ).name == ing )
+ return *sub_it;
+ }
+ }
+
+ Ingredient el;
+ el.ingredientID = -1;
+ return el;
+}
+
+Ingredient IngredientList::findByName( const TQRegExp &rx ) const
+{
+ IngredientList::const_iterator it_end = end();
+ for ( IngredientList::const_iterator it = begin(); it != it_end; ++it ) {
+ if ( ( *it ).name.find(rx) != -1 )
+ return *it;
+
+ for ( TQValueList<IngredientData>::const_iterator sub_it = ( *it ).substitutes.begin(); sub_it != ( *it ).substitutes.end(); ++sub_it ) {
+ if ( ( *sub_it ).name.find(rx) != -1 )
+ return *sub_it;
+ }
+ }
+
+ Ingredient el;
+ el.ingredientID = -1;
+ return el;
+}
+
+IngredientList::const_iterator IngredientList::find( IngredientList::const_iterator it, int id ) const // Search by id (which uses search by item, with comparison defined on header)
+{
+ Ingredient i;
+ i.ingredientID = id;
+ return TQValueList<Ingredient>::find( it, i );
+}
+
+IngredientList::iterator IngredientList::find( IngredientList::iterator it, int id ) // Search by id (which uses search by item, with comparison defined on header)
+{
+ Ingredient i;
+ i.ingredientID = id;
+ return TQValueList<Ingredient>::find( it, i );
+}
+
+IngredientData& IngredientList::findSubstitute( const Ingredient &i ) // Search by id (which uses search by item, with comparison defined on header)
+{
+ TQValueList<Ingredient>::iterator result = TQValueList<Ingredient>::find(i);
+ if ( result == end() ) {
+ for ( IngredientList::iterator it = begin(); it != end(); ++it ) {
+ TQValueList<IngredientData>::iterator result = (*it).substitutes.find(i);
+ if ( result != (*it).substitutes.end() )
+ return *result;
+ }
+ }
+ return *result;
+}
+
+void IngredientList::removeSubstitute( const Ingredient &i )
+{
+ TQValueList<Ingredient>::iterator result = TQValueList<Ingredient>::find(i);
+ if ( result == end() ) {
+ for ( IngredientList::iterator it = begin(); it != end(); ++it ) {
+ TQValueList<IngredientData>::iterator result = (*it).substitutes.find(i);
+ if ( result != (*it).substitutes.end() ) {
+ (*it).substitutes.remove(result);
+ return;
+ }
+ }
+ }
+ remove(result);
+}
+
+void IngredientList::move( int index1, int index2 ) //moves element in pos index1, to pos after index2
+{
+ IngredientList::iterator tmp_it = at( index1 );
+ Ingredient tmp_ing( *tmp_it );
+
+ remove
+ ( tmp_it );
+
+ tmp_it = at( index2 );
+ insert( tmp_it, tmp_ing );
+}
+
+void IngredientList::move( int index1, int count1, int index2 ) //moves element in pos index1 and the following count1 items, to pos after index2
+{
+ IngredientList::iterator tmp_it = at( index1 );
+ IngredientList::iterator after_it = at( index2 + 1 );
+
+ for ( int i = 0; i < count1; ++i )
+ {
+ Ingredient tmp_ing( *tmp_it );
+
+ IngredientList::iterator remove_me_it = tmp_it;
+ ++tmp_it;
+ remove
+ ( remove_me_it );
+
+ insert( after_it, tmp_ing );
+ }
+}
+
+IngredientList IngredientList::groupMembers( int id, IngredientList::const_iterator begin ) const
+{
+ bool first_found = false;
+
+ IngredientList matches;
+ for ( IngredientList::const_iterator it = begin; it != end(); ++it ) {
+ if ( ( *it ).groupID == id ) {
+ matches.append( *it );
+ first_found = true;
+ }
+ else if ( first_found ) //this is the end of this group... there may be more later though
+ break;
+ }
+
+ return matches;
+}
+
+TQValueList<IngredientList::const_iterator> IngredientList::_groupMembers( int id, IngredientList::const_iterator begin ) const
+{
+ bool first_found = false;
+
+ TQValueList<IngredientList::const_iterator> matches;
+ for ( IngredientList::const_iterator it = begin; it != end(); ++it ) {
+ if ( ( *it ).groupID == id ) {
+ matches << it;
+ first_found = true;
+ }
+ else if ( first_found ) //this is the end of this group... there may be more later though
+ break;
+ }
+
+ return matches;
+}
+
+IngredientList IngredientList::firstGroup()
+{
+ usedGroups.clear();
+
+ TQValueList<IngredientList::const_iterator> members = _groupMembers( ( *begin() ).groupID, begin() );
+
+ for ( TQValueList<IngredientList::const_iterator>::const_iterator members_it = members.begin(); members_it != members.end(); ++members_it ) {
+ usedGroups << *members_it;
+ }
+
+ return groupMembers( ( *begin() ).groupID, begin() );
+}
+
+IngredientList IngredientList::nextGroup()
+{
+ for ( IngredientList::const_iterator it = begin(); it != end(); ++it ) {
+ if ( usedGroups.find( it ) == usedGroups.end() ) {
+ TQValueList<IngredientList::const_iterator> members = _groupMembers( ( *it ).groupID, it );
+
+ for ( TQValueList<IngredientList::const_iterator>::const_iterator members_it = members.begin(); members_it != members.end(); ++members_it ) {
+ usedGroups << *members_it;
+ }
+
+ return groupMembers( ( *it ).groupID, it );
+ }
+ }
+ return IngredientList();
+}
diff --git a/src/datablocks/ingredientlist.h b/src/datablocks/ingredientlist.h
new file mode 100644
index 0000000..bfd07db
--- /dev/null
+++ b/src/datablocks/ingredientlist.h
@@ -0,0 +1,61 @@
+/***************************************************************************
+* Copyright (C) 2003 by *
+* *
+* Unai Garro ([email protected]) *
+* Cyril Bosselut ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef INGREDIENTLIST_H
+#define INGREDIENTLIST_H
+
+#include <tqvaluelist.h>
+#include <tqregexp.h>
+
+#include "datablocks/ingredient.h"
+
+class RecipeDB;
+
+/**
+@author Unai Garro
+*/
+class IngredientList: public TQValueList <Ingredient>
+{
+public:
+ IngredientList();
+ ~IngredientList();
+ bool contains( const Ingredient &ing, bool compareAmount = false, RecipeDB *database = 0 ) const;
+ bool containsSubSet( IngredientList &il, IngredientList &missing, bool compareAmount = false, RecipeDB *database = 0 );
+ bool containsSubSet( IngredientList &il ) const;
+ bool containsAny( const IngredientList &, bool compareAmount = false, RecipeDB *database = 0 );
+
+ IngredientList groupMembers( int id, IngredientList::const_iterator begin ) const;
+
+ void move( int index1, int index2 );
+ void move( int index1, int count, int index2 );
+ void empty( void );
+ int find( int id ) const;
+ Ingredient findByName( const TQString & ) const;
+ Ingredient findByName( const TQRegExp & ) const;
+ IngredientList::const_iterator find( IngredientList::const_iterator, int id ) const;
+ IngredientList::iterator find( IngredientList::iterator, int id );
+
+ /** Warning, returns an invalid reference if no ingredient is found. Must check prior
+ * to calling this function if the ingredient exists.
+ */
+ IngredientData& findSubstitute( const Ingredient & );
+ void removeSubstitute( const Ingredient & );
+
+ IngredientList firstGroup();
+ IngredientList nextGroup();
+
+private:
+ TQValueList<IngredientList::const_iterator> _groupMembers( int id, IngredientList::const_iterator begin ) const;
+ TQValueList<IngredientList::const_iterator> usedGroups;
+};
+
+#endif
diff --git a/src/datablocks/ingredientproperty.cpp b/src/datablocks/ingredientproperty.cpp
new file mode 100644
index 0000000..d8c621e
--- /dev/null
+++ b/src/datablocks/ingredientproperty.cpp
@@ -0,0 +1,32 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "datablocks/ingredientproperty.h"
+
+IngredientProperty::IngredientProperty()
+{
+ id = -1;
+ ingredientID = -1;
+ amount = 0.0;
+}
+
+IngredientProperty::IngredientProperty( const TQString &_name, const TQString &_units, int _id ) :
+ id( _id ),
+ name( _name ),
+ units( _units )
+{}
+
+IngredientProperty::~IngredientProperty()
+{}
+
+bool IngredientProperty::operator==( const IngredientProperty &prop ) const
+{
+ return ( prop.id == id );
+}
+
diff --git a/src/datablocks/ingredientproperty.h b/src/datablocks/ingredientproperty.h
new file mode 100644
index 0000000..5b5fd55
--- /dev/null
+++ b/src/datablocks/ingredientproperty.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef INGREDIENTPROPERTY_H
+#define INGREDIENTPROPERTY_H
+
+#include <tqstring.h>
+
+#include "unit.h"
+
+/**
+@author Unai Garro
+*/
+class IngredientProperty
+{
+public:
+ IngredientProperty();
+ IngredientProperty( const TQString &name, const TQString &units, int id = -1 );
+ ~IngredientProperty();
+ int id; // The property's id
+ int ingredientID; // (Optional) reference to the ingredient to which is attached
+ TQString name; // Name of the property
+ TQString units; // The units that the property uses
+ Unit perUnit; // stores the unit ID, name, and type of the per units.
+ double amount; // Stores the amount, in the case of being attached to an ingredient. If not attached to any, you can set it to -1 preferably. That's the case in which the property is treated as a characteristic any without value (amount).
+
+ /** Compare two elements by their id */
+ bool operator==( const IngredientProperty & ) const;
+};
+
+#endif
diff --git a/src/datablocks/ingredientpropertylist.cpp b/src/datablocks/ingredientpropertylist.cpp
new file mode 100644
index 0000000..40d63be
--- /dev/null
+++ b/src/datablocks/ingredientpropertylist.cpp
@@ -0,0 +1,53 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "datablocks/ingredientpropertylist.h"
+
+IngredientPropertyList::IngredientPropertyList()
+{}
+
+
+IngredientPropertyList::~IngredientPropertyList()
+{}
+
+IngredientPropertyList::const_iterator IngredientPropertyList::find( int id )
+{
+ IngredientProperty ip;
+ ip.id = id;
+ return TQValueList<IngredientProperty>::find( ip );
+}
+
+int IngredientPropertyList::findByName( const TQString &name )
+{
+ IngredientPropertyList::const_iterator prop_it;
+ for ( prop_it = begin(); prop_it != end(); ++prop_it ) {
+ if ( (*prop_it).name == name )
+ return (*prop_it).id;
+ }
+
+ return -1;
+}
+
+void IngredientPropertyList::divide( double units_of_yield_type )
+{
+ IngredientPropertyList::iterator prop_it;
+ for ( prop_it = begin(); prop_it != end(); ++prop_it )
+ (*prop_it).amount /= units_of_yield_type;
+}
+
+void IngredientPropertyList::filter( int ingredientID, IngredientPropertyList *filteredList )
+{
+ filteredList->clear();
+ IngredientPropertyList::const_iterator prop_it;
+ for ( prop_it = begin(); prop_it != end(); ++prop_it ) {
+ if ( (*prop_it).ingredientID == ingredientID )
+ filteredList->append( *prop_it );
+ }
+}
diff --git a/src/datablocks/ingredientpropertylist.h b/src/datablocks/ingredientpropertylist.h
new file mode 100644
index 0000000..5a8811d
--- /dev/null
+++ b/src/datablocks/ingredientpropertylist.h
@@ -0,0 +1,30 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef INGREDIENTPROPERTYLIST_H
+#define INGREDIENTPROPERTYLIST_H
+
+#include <tqvaluelist.h>
+
+#include "datablocks/ingredientproperty.h"
+
+class IngredientPropertyList : public TQValueList<IngredientProperty>
+{
+public:
+ IngredientPropertyList();
+
+ ~IngredientPropertyList();
+
+ void divide( double units_of_yield_type );
+ IngredientPropertyList::const_iterator find( int id );
+ int findByName( const TQString & );
+ void filter( int ingredientID, IngredientPropertyList *filteredList );
+};
+
+#endif
diff --git a/src/datablocks/kreborder.cpp b/src/datablocks/kreborder.cpp
new file mode 100644
index 0000000..4109f1e
--- /dev/null
+++ b/src/datablocks/kreborder.cpp
@@ -0,0 +1,17 @@
+/***************************************************************************
+* Copyright (C) 2004 by *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "kreborder.h"
+
+//typedef enum KreBorderStyle { None = 0, Dotted, Dashed, Solid, Double, Groove, Ridge, Inset, Outset };
+
+KreBorder::KreBorder( int w, const TQString & s, const TQColor &c ) : width( w ), style( s ), color( c )
+{
+}
diff --git a/src/datablocks/kreborder.h b/src/datablocks/kreborder.h
new file mode 100644
index 0000000..0e535b6
--- /dev/null
+++ b/src/datablocks/kreborder.h
@@ -0,0 +1,29 @@
+/***************************************************************************
+* Copyright (C) 2004 by *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef KREBORDER_H
+#define KREBORDER_H
+
+#include <tqcolor.h>
+#include <tqstring.h>
+
+//typedef enum KreBorderStyle { None = 0, Dotted, Dashed, Solid, Double, Groove, Ridge, Inset, Outset };
+
+class KreBorder
+{
+public:
+ KreBorder( int w = 1, const TQString & s = "none", const TQColor &c = TQt::black );
+
+ int width;
+ TQString style;
+ TQColor color;
+};
+
+#endif //KREBORDER_H
diff --git a/src/datablocks/mixednumber.cpp b/src/datablocks/mixednumber.cpp
new file mode 100644
index 0000000..17a9047
--- /dev/null
+++ b/src/datablocks/mixednumber.cpp
@@ -0,0 +1,289 @@
+/***************************************************************************
+* Copyright (C) 2003 by krecipes.sourceforge.net authors *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "mixednumber.h"
+
+#include <tqregexp.h>
+
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <kdebug.h>
+
+TQString beautify( const TQString &num )
+{
+ TQString copy( num );
+ copy.remove( TQRegExp( TQString( "(%1){0,1}0+$" ).arg( TQRegExp::escape( TDEGlobal::locale() ->decimalSymbol() ) ) ) );
+ return copy;
+}
+
+MixedNumber::MixedNumber() :
+ m_whole( 0 ),
+ m_numerator( 0 ),
+ m_denominator( 1 ),
+ locale( TDEGlobal::locale() )
+{}
+
+MixedNumber::MixedNumber( int whole, int numerator, int denominator ) :
+ m_whole( whole ),
+ m_numerator( numerator ),
+ m_denominator( denominator ),
+ locale( TDEGlobal::locale() )
+{}
+
+MixedNumber::MixedNumber( double decimal, double precision ) :
+ locale( TDEGlobal::locale() )
+{
+ // find nearest fraction
+ int intPart = static_cast<int>( decimal );
+ decimal -= static_cast<double>( intPart );
+
+ MixedNumber low( 0, 0, 1 ); // "A" = 0/1
+ MixedNumber high( 0, 1, 1 ); // "B" = 1/1
+
+ for ( int i = 0; i < 100; ++i ) {
+ double testLow = low.denominator() * decimal - low.numerator();
+ double testHigh = high.numerator() - high.denominator() * decimal;
+
+ if ( testHigh < precision * high.denominator() )
+ break; // high is answer
+ if ( testLow < precision * low.denominator() ) { // low is answer
+ high = low;
+ break;
+ }
+
+ if ( i & 1 ) { // odd step: add multiple of low to high
+ double test = testHigh / testLow;
+ int count = ( int ) test; // "N"
+ int num = ( count + 1 ) * low.numerator() + high.numerator();
+ int denom = ( count + 1 ) * low.denominator() + high.denominator();
+
+ if ( ( num > 0x8000 ) || ( denom > 0x10000 ) )
+ break;
+
+ high.setNumerator( num - low.numerator() ); // new "A"
+ high.setDenominator( denom - low.denominator() );
+ low.setNumerator( num ); // new "B"
+ low.setDenominator( denom );
+ }
+ else { // even step: add multiple of high to low
+ double test = testLow / testHigh;
+ int count = ( int ) test; // "N"
+ int num = low.numerator() + ( count + 1 ) * high.numerator();
+ int denom = low.denominator() + ( count + 1 ) * high.denominator();
+
+ if ( ( num > 0x10000 ) || ( denom > 0x10000 ) )
+ break;
+
+ low.setNumerator( num - high.numerator() ); // new "A"
+ low.setDenominator( denom - high.denominator() );
+ high.setNumerator( num ); // new "B"
+ high.setDenominator( denom );
+ }
+ }
+
+ m_numerator = high.numerator();
+ m_denominator = high.denominator();
+ m_whole = intPart;
+}
+
+MixedNumber::~MixedNumber()
+{}
+
+int MixedNumber::getNumerator( const TQString &input, int space_index, int slash_index, bool *ok )
+{
+ return input.mid( space_index + 1, slash_index - space_index - 1 ).toInt( ok );
+}
+
+int MixedNumber::getDenominator( const TQString &input, int slash_index, bool *ok )
+{
+ return input.mid( slash_index + 1, input.length() ).toInt( ok );
+}
+
+MixedNumber MixedNumber::fromString( const TQString &str, bool *ok, bool locale_aware )
+{
+ TQString input = str.stripWhiteSpace();
+ if ( input.isEmpty() ) {
+ if ( ok ) {
+ *ok = true;
+ }
+ return MixedNumber();
+ }
+
+ TDELocale *locale = TDEGlobal::locale();
+
+ bool num_ok;
+
+ int whole;
+ int numerator;
+ int denominator;
+
+ int space_index = input.find( " " );
+ int slash_index = input.find( "/" );
+
+ if ( space_index == -1 ) {
+ if ( slash_index == -1 ) //input contains no fractional part
+ {
+ TQString decimal_symbol = ( locale_aware ) ? locale->decimalSymbol() : ".";
+ if ( input.endsWith( decimal_symbol ) )
+ {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ double decimal = ( locale_aware ) ? locale->readNumber( input, &num_ok ) : input.toDouble( &num_ok );
+
+ if ( !num_ok )
+ {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ if ( ok )
+ {
+ *ok = true;
+ }
+ return MixedNumber( decimal );
+ }
+ else //input just contains a fraction
+ {
+ whole = 0;
+
+ numerator = MixedNumber::getNumerator( input, space_index, slash_index, &num_ok );
+ if ( !num_ok ) {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ denominator = MixedNumber::getDenominator( input, slash_index, &num_ok );
+ if ( !num_ok || denominator == 0 ) {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ if ( ok ) {
+ *ok = true;
+ }
+ return MixedNumber( whole, numerator, denominator );
+ }
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ whole = input.mid( 0, space_index ).toInt( &num_ok );
+ if ( !num_ok ) {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ numerator = MixedNumber::getNumerator( input, space_index, slash_index, &num_ok );
+ if ( !num_ok ) {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ denominator = MixedNumber::getDenominator( input, slash_index, &num_ok );
+ if ( !num_ok || denominator == 0 ) {
+ if ( ok ) {
+ *ok = false;
+ }
+ return MixedNumber();
+ }
+
+ if ( ok ) {
+ *ok = true;
+ }
+ return MixedNumber( whole, numerator, denominator );
+}
+
+TQString MixedNumber::toString( Format format, bool locale_aware ) const
+{
+ if ( format == DecimalFormat ) {
+ if ( locale_aware )
+ return beautify( locale->formatNumber( toDouble(), 5 ) );
+ else
+ return TQString::number( toDouble() );
+ }
+
+ if ( m_numerator == 0 && m_whole == 0 )
+ return TQString( "0" );
+
+
+ TQString result;
+
+ if ( m_whole != 0 ) {
+ result += TQString::number( m_whole );
+ if ( m_numerator != 0 )
+ result += " ";
+ }
+
+ if ( m_numerator != 0 )
+ result += TQString::number( m_numerator ) + "/" + TQString::number( m_denominator );
+
+ return result;
+}
+
+bool MixedNumber::operator!=( const MixedNumber &fraction )
+{
+ return ( fraction.toDouble() != toDouble() );
+}
+
+MixedNumber& MixedNumber::operator+=( const MixedNumber &fraction )
+{
+ m_numerator = ( m_numerator * fraction.m_denominator ) + ( m_denominator * fraction.m_numerator );
+ m_denominator = m_denominator * fraction.m_denominator;
+ m_whole += fraction.m_whole;
+ simplify();
+
+ return *this;
+}
+
+MixedNumber& MixedNumber::operator+=( double d )
+{
+ MixedNumber mn(d);
+ *this += mn;
+ return *this;
+}
+
+void MixedNumber::simplify()
+{
+ int divisor = gcd( m_numerator, m_denominator );
+ m_numerator /= divisor;
+ m_denominator /= divisor;
+}
+
+double MixedNumber::toDouble() const
+{
+ return static_cast<double>( m_whole ) + ( static_cast<double>( m_numerator ) / static_cast<double>( m_denominator ) );
+}
+
+int MixedNumber::gcd( int n, int m )
+{
+ int r;
+ while ( n != 0 ) {
+ r = m % n;
+ m = n;
+ n = r;
+ }
+
+ return m;
+}
diff --git a/src/datablocks/mixednumber.h b/src/datablocks/mixednumber.h
new file mode 100644
index 0000000..34a0f8b
--- /dev/null
+++ b/src/datablocks/mixednumber.h
@@ -0,0 +1,126 @@
+/***************************************************************************
+* Copyright (C) 2003 by *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef MIXEDNUMBER_H
+#define MIXEDNUMBER_H
+
+#include <tqstring.h>
+
+/** remove any extra zeros on the end of the string and the decimal if a whole number */
+TQString beautify( const TQString &num );
+
+class TDELocale;
+
+/** A class to hold and manipulate a mixed number.
+ * @author Jason Kivlighn
+ */
+class MixedNumber
+{
+public:
+ MixedNumber( int whole, int numerator, int denominator );
+
+ /** Create a mixed number from the given @param decimal. This uses a method that will
+ * approximate the actual fraction with precision equal to @param precision.
+ * The closer @param precision is to zero without being zero, the more precisely
+ * it will try to approximate the fraction.
+ */
+ MixedNumber( double decimal, double precision = 1e-6 );
+
+ /** Creates a mixed number with an initial value of zero. */
+ MixedNumber();
+
+ ~MixedNumber();
+
+ MixedNumber& operator+=( const MixedNumber & );
+ MixedNumber& operator+=( double );
+ bool operator!=( const MixedNumber &fraction );
+ bool operator>( double d )
+ {
+ return ( toDouble() > d );
+ }
+
+ enum Format { DecimalFormat, MixedNumberFormat };
+
+ /** The input as a decimal. */
+ double toDouble() const;
+
+ /** Returns the fraction as a string */
+ TQString toString( Format = MixedNumberFormat, bool locale_aware = true ) const;
+
+ /** The whole part of the input */
+ int whole() const
+ {
+ return m_whole;
+ }
+
+ /** The numerator of the fractional part of the input. */
+ int numerator() const
+ {
+ return m_numerator;
+ }
+
+ /** The denominator of the fractional part of the input. */
+ int denominator() const
+ {
+ return m_denominator;
+ }
+
+ void setNumerator( int n )
+ {
+ m_numerator = n;
+ }
+ void setDenominator( int d )
+ {
+ m_denominator = d;
+ }
+
+ /** Ensure that the fraction is simplified to its lowest terms. */
+ void simplify();
+
+ /** Parses the given TQString as a mixed number. The input can be
+ * expressed as a mixed number in the form "a b/c", or as a decimal.
+ */
+ static MixedNumber fromString( const TQString &input, bool *ok = 0, bool locale_aware = true );
+
+private:
+ static int getNumerator( const TQString &input, int space_index, int slash_index, bool *ok );
+ static int getDenominator( const TQString &input, int slash_index, bool *ok );
+
+ int gcd( int, int );
+
+ int m_whole;
+ int m_numerator;
+ int m_denominator;
+
+ TDELocale *locale;
+};
+
+inline const MixedNumber operator+( const MixedNumber &mn1, const MixedNumber &mn2 )
+{
+ MixedNumber tmp = mn1;
+ tmp += mn2;
+ return tmp;
+}
+
+
+inline const MixedNumber operator+( double d, const MixedNumber &mn )
+{
+ MixedNumber tmp = mn;
+ tmp += d;
+ return tmp;
+}
+
+inline const MixedNumber operator+( const MixedNumber &mn, double d )
+{
+ return operator+(d,mn);
+}
+
+
+#endif //MIXEDNUMBER_H
diff --git a/src/datablocks/rating.cpp b/src/datablocks/rating.cpp
new file mode 100644
index 0000000..83f0d9b
--- /dev/null
+++ b/src/datablocks/rating.cpp
@@ -0,0 +1,86 @@
+/***************************************************************************
+* Copyright (C) 2005 by Jason Kivlighn *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "rating.h"
+
+#include <tqpainter.h>
+#include <tqbitmap.h>
+
+#include <kiconloader.h>
+
+TQPixmap Rating::starsPixmap( double stars_d, bool include_empty )
+{
+ int stars = tqRound(stars_d * 2); //multiply by two to make it easier to work with half-stars
+
+ TQPixmap star = UserIcon(TQString::fromLatin1("star_on"));
+ TQPixmap star_off;
+ if ( include_empty )
+ star_off = UserIcon(TQString::fromLatin1("star_off"));
+
+ int pixmapWidth;
+ if ( include_empty )
+ pixmapWidth = 18*5;
+ else
+ pixmapWidth = 18*(stars/2)+((stars%2==1)?9:0);
+
+ TQPixmap generatedPixmap(pixmapWidth,18);
+
+ if ( !generatedPixmap.isNull() ) { //there aren't zero stars
+ generatedPixmap.fill();
+ TQPainter painter( &generatedPixmap );
+
+ int pixmapWidth = 18*(stars/2)+((stars%2==1)?9:0);
+ if ( include_empty )
+ painter.drawTiledPixmap(0,0,18*5,18,star_off); //fill with empty stars
+ painter.drawTiledPixmap(0,0,pixmapWidth,18,star); //write over the empty stars to show the rating
+ }
+
+ generatedPixmap.setMask( generatedPixmap.createHeuristicMask() );
+
+ return generatedPixmap;
+}
+
+void Rating::append( const RatingCriteria &rc )
+{
+ ratingCriteriaList.append( rc );
+}
+
+double Rating::average() const
+{
+ double sum = 0;
+ int count = 0;
+ for ( RatingCriteriaList::const_iterator rc_it = ratingCriteriaList.begin(); rc_it != ratingCriteriaList.end(); ++rc_it ) {
+ count++;
+ sum += (*rc_it).stars;
+ }
+
+ if ( count > 0 )
+ return sum/count;
+ else
+ return -1;
+}
+
+
+double RatingList::average()
+{
+ int rating_total = 0;
+ double rating_sum = 0;
+ for ( RatingList::const_iterator rating_it = begin(); rating_it != end(); ++rating_it ) {
+ for ( RatingCriteriaList::const_iterator rc_it = (*rating_it).ratingCriteriaList.begin(); rc_it != (*rating_it).ratingCriteriaList.end(); ++rc_it ) {
+ rating_total++;
+ rating_sum += (*rc_it).stars;
+ }
+ }
+
+ if ( rating_total > 0 )
+ return rating_sum/rating_total;
+ else
+ return -1;
+}
diff --git a/src/datablocks/rating.h b/src/datablocks/rating.h
new file mode 100644
index 0000000..60e7693
--- /dev/null
+++ b/src/datablocks/rating.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+* Copyright (C) 2005 by Jason Kivlighn *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef RATING_H
+#define RATING_H
+
+#include <tqvaluelist.h>
+#include <tqstring.h>
+
+#include <tqpixmap.h>
+
+class RatingCriteria
+{
+public:
+ RatingCriteria() : id(-1), stars(0.0){}
+
+ int id;
+ TQString name;
+ double stars;
+};
+
+typedef TQValueList< RatingCriteria > RatingCriteriaList;
+
+class Rating
+{
+public:
+ Rating() : id(-1){}
+
+ static TQPixmap starsPixmap( double stars_d, bool include_empty = false );
+
+ void append( const RatingCriteria & );
+
+ double average() const;
+
+ int id;
+ TQString comment;
+ TQString rater;
+
+ RatingCriteriaList ratingCriteriaList;
+};
+
+class RatingList : public TQValueList< Rating >
+{
+public:
+ double average();
+};
+
+#endif
diff --git a/src/datablocks/recipe.cpp b/src/datablocks/recipe.cpp
new file mode 100644
index 0000000..dd00f07
--- /dev/null
+++ b/src/datablocks/recipe.cpp
@@ -0,0 +1,53 @@
+/***************************************************************************
+* Copyright (C) 2003-2004 by *
+* Unai Garro ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "datablocks/recipe.h"
+
+Recipe::Recipe()
+{
+ empty(); //Create & initialize the recipe empty originally
+}
+
+Recipe::~Recipe()
+{}
+
+void Recipe::empty( void )
+{
+ recipeID = -1;
+
+ yield.amount = 1;
+ yield.amount_offset = 0;
+ yield.type = TQString::null;
+
+ title = TQString::null;
+ instructions = TQString::null;
+ photo = TQPixmap();
+ ingList.empty();
+ categoryList.clear();
+ authorList.clear();
+ ratingList.clear();
+ prepTime = TQTime( 0, 0 );
+}
+
+
+TQString Yield::amountToString() const
+{
+ TQString ret = TQString::number(amount);
+ if ( amount_offset > 0 )
+ ret += "-"+TQString::number(amount+amount_offset);
+
+ return ret;
+}
+
+TQString Yield::toString() const
+{
+ return amountToString() + " " + type;
+}
+
diff --git a/src/datablocks/recipe.h b/src/datablocks/recipe.h
new file mode 100644
index 0000000..c1c8aab
--- /dev/null
+++ b/src/datablocks/recipe.h
@@ -0,0 +1,71 @@
+/***************************************************************************
+* Copyright (C) 2003-2004 by *
+* Unai Garro ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef RECIPE_H
+#define RECIPE_H
+
+#include <tqstring.h>
+#include <tqpixmap.h>
+#include <tqdatetime.h>
+
+#include "ingredientlist.h"
+#include "datablocks/rating.h"
+#include "datablocks/elementlist.h"
+#include "datablocks/ingredientpropertylist.h"
+
+class Yield
+{
+public:
+ Yield() : amount(1), amount_offset(0), type(TQString::null), type_id(-1){}
+
+ TQString amountToString() const;
+ TQString toString() const;
+
+ double amount;
+ double amount_offset;
+ TQString type;
+ int type_id;
+};
+
+/**
+@author Unai Garro
+*/
+class Recipe
+{
+public:
+ Recipe();
+ ~Recipe();
+ // Public variables
+
+ int recipeID;
+ Yield yield;
+ TQString title;
+ TQString instructions;
+ TQPixmap photo;
+ IngredientList ingList;
+ ElementList categoryList; // id+name
+ ElementList authorList; //authors' id+name
+ TQTime prepTime;
+
+ TQDateTime ctime;
+ TQDateTime mtime;
+ TQDateTime atime;
+
+ RatingList ratingList;
+ IngredientPropertyList properties;
+
+ // Public methods
+ void empty( void );
+
+
+
+};
+
+#endif
diff --git a/src/datablocks/recipelist.cpp b/src/datablocks/recipelist.cpp
new file mode 100644
index 0000000..5a7d583
--- /dev/null
+++ b/src/datablocks/recipelist.cpp
@@ -0,0 +1,18 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro ([email protected]) *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "recipelist.h"
+
+RecipeList::RecipeList() : TQValueList <Recipe>()
+{}
+
+RecipeList::~RecipeList()
+{}
+
diff --git a/src/datablocks/recipelist.h b/src/datablocks/recipelist.h
new file mode 100644
index 0000000..ac8cc99
--- /dev/null
+++ b/src/datablocks/recipelist.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro [email protected] *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef RECIPELIST_H
+#define RECIPELIST_H
+
+#include "datablocks/recipe.h"
+
+#include <tqvaluelist.h>
+
+/**
+@author Unai Garro
+*/
+class RecipeList: public TQValueList <Recipe>
+{
+public:
+ RecipeList();
+ ~RecipeList();
+};
+
+#endif
diff --git a/src/datablocks/unit.cpp b/src/datablocks/unit.cpp
new file mode 100644
index 0000000..ab670f3
--- /dev/null
+++ b/src/datablocks/unit.cpp
@@ -0,0 +1,75 @@
+/***************************************************************************
+* Copyright (C) 2004 by *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "unit.h"
+
+Unit::Unit() : type(Unit::Other), id( -1 )
+{}
+
+Unit::Unit( const TQString &_name, const TQString &_plural, int _id ) :
+ type(Unit::Other),
+ id( _id ),
+ name( _name ),
+ plural( _plural )
+{}
+
+Unit::Unit( const TQString &_name, double amount ) : type(Unit::Other)
+{
+ if ( amount > 1 )
+ plural = _name;
+ else
+ name = _name;
+}
+
+TQString Unit::determineName( double amount, bool useAbbrev ) const
+{
+ if ( useAbbrev ) {
+ TQString unit = ( amount > 1 ) ? plural_abbrev : name_abbrev;
+ if ( unit.isEmpty() )
+ unit = ( amount > 1 ) ? plural : name;
+ return unit;
+ }
+ else
+ return ( amount > 1 ) ? plural : name;
+}
+
+bool Unit::operator==( const Unit &u ) const
+{
+ //treat TQString::null and "" as the same
+ TQString plural_test1 = u.plural.lower();
+ if ( plural_test1.isNull() )
+ plural_test1 = "";
+
+ TQString plural_test2 = plural.lower();
+ if ( plural_test2.isNull() )
+ plural_test2 = "";
+
+ TQString single_test1 = u.name.lower();
+ if ( single_test1.isNull() )
+ single_test1 = "";
+
+ TQString single_test2 = name.lower();
+ if ( single_test2.isNull() )
+ single_test2 = "";
+
+ if ( plural_test1.isEmpty() && plural_test2.isEmpty() && single_test1.isEmpty() && single_test2.isEmpty() )
+ return true;
+ else if ( plural_test1.isEmpty() && plural_test2.isEmpty() )
+ return single_test1 == single_test2;
+ else if ( single_test1.isEmpty() && single_test2.isEmpty() )
+ return plural_test1 == plural_test2;
+ else
+ return ( plural_test1 == plural_test2 || single_test1 == single_test2 );
+}
+
+bool Unit::operator<( const Unit &u ) const
+{
+ return ( TQString::localeAwareCompare( name.lower(), u.name.lower() ) < 0 );
+}
diff --git a/src/datablocks/unit.h b/src/datablocks/unit.h
new file mode 100644
index 0000000..f948cf8
--- /dev/null
+++ b/src/datablocks/unit.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+* Copyright (C) 2004-2006 by *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef UNIT_H
+#define UNIT_H
+
+#include <tqstring.h>
+#include <tqvaluelist.h>
+
+class Unit
+{
+public:
+ Unit();
+ Unit( const TQString &name, const TQString &plural, int id = -1 );
+
+ typedef enum { All = -1, Other = 0, Mass, Volume } Type;
+
+ /** Use @param amount to determine whether to use @param name as the plural or singlular form */
+ Unit( const TQString &name, double amount );
+
+ bool operator==( const Unit &u ) const;
+ bool operator<( const Unit &u ) const;
+
+ TQString determineName( double amount, bool useAbbrev ) const;
+
+ Type type;
+
+ int id;
+ TQString name;
+ TQString plural;
+
+ TQString name_abbrev;
+ TQString plural_abbrev;
+};
+
+typedef TQValueList< Unit > UnitList;
+
+#endif //UNIT_H
diff --git a/src/datablocks/unitratio.cpp b/src/datablocks/unitratio.cpp
new file mode 100644
index 0000000..fb531cd
--- /dev/null
+++ b/src/datablocks/unitratio.cpp
@@ -0,0 +1,30 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "unitratio.h"
+#include "tdelocale.h"
+
+UnitRatio::UnitRatio()
+{
+ uID1 = -1;
+ uID2 = -1;
+ ratio = -1;
+}
+
+UnitRatio::UnitRatio( const UnitRatio &ur )
+{
+ uID1 = ur.uID1;
+ uID2 = ur.uID2;
+ ratio = ur.ratio;
+}
+
+UnitRatio::~UnitRatio()
+{}
+
+
diff --git a/src/datablocks/unitratio.h b/src/datablocks/unitratio.h
new file mode 100644
index 0000000..dd327f1
--- /dev/null
+++ b/src/datablocks/unitratio.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef UNITRATIO_H
+#define UNITRATIO_H
+
+/**
+@author Unai Garro
+*/
+class UnitRatio
+{
+public:
+
+ UnitRatio();
+ UnitRatio( const UnitRatio &ur );
+ ~UnitRatio();
+
+ bool operator!=( const UnitRatio &r ) const
+ {
+ return !( r.uID1 == uID1 && r.uID2 == uID2 );
+ }
+ bool operator==( const UnitRatio &r ) const
+ {
+ return ( r.uID1 == uID1 && r.uID2 == uID2 );
+ }
+
+ int uID1, uID2;
+ double ratio;
+};
+
+#endif
diff --git a/src/datablocks/unitratiolist.cpp b/src/datablocks/unitratiolist.cpp
new file mode 100644
index 0000000..6955005
--- /dev/null
+++ b/src/datablocks/unitratiolist.cpp
@@ -0,0 +1,34 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "unitratiolist.h"
+#include "tdelocale.h"
+
+
+UnitRatioList::UnitRatioList()
+{}
+
+
+UnitRatioList::~UnitRatioList()
+{}
+
+double UnitRatioList::getRatio( int uid1, int uid2 )
+{
+ if ( uid1 == uid2 )
+ return ( 1.0 );
+ else {
+ for ( UnitRatioList::const_iterator ur_it = begin();ur_it != end(); ++ur_it ) {
+ if ( ( *ur_it ).uID1 == uid1 && ( *ur_it ).uID2 == uid2 )
+ return ( ( *ur_it ).ratio );
+ else if ( ( *ur_it ).uID1 == uid2 && ( *ur_it ).uID2 == uid1 )
+ return ( 1.0 / ( *ur_it ).ratio );
+ }
+ return ( -1.0 );
+ }
+}
diff --git a/src/datablocks/unitratiolist.h b/src/datablocks/unitratiolist.h
new file mode 100644
index 0000000..9b74e0a
--- /dev/null
+++ b/src/datablocks/unitratiolist.h
@@ -0,0 +1,33 @@
+/***************************************************************************
+* Copyright (C) 2003 by Unai Garro *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef UNITRATIOLIST_H
+#define UNITRATIOLIST_H
+#include <tqvaluelist.h>
+#include "unitratio.h"
+
+
+/**
+@author Unai Garro
+*/
+class UnitRatioList : public TQValueList <UnitRatio>
+{
+public:
+ UnitRatioList();
+ ~UnitRatioList();
+
+ void add
+ ( const UnitRatio &r )
+ {
+ append( r );
+ }
+ double getRatio( int uid1, int uid2 );
+};
+
+#endif
diff --git a/src/datablocks/weight.cpp b/src/datablocks/weight.cpp
new file mode 100644
index 0000000..08ba695
--- /dev/null
+++ b/src/datablocks/weight.cpp
@@ -0,0 +1,14 @@
+/***************************************************************************
+* Copyright (C) 2006 Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "weight.h"
+
+Weight::Weight() : id(-1), prepMethodID(-1)
+{}
+
diff --git a/src/datablocks/weight.h b/src/datablocks/weight.h
new file mode 100644
index 0000000..c5042bd
--- /dev/null
+++ b/src/datablocks/weight.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+* Copyright (C) 2006 Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef WEIGHT_H
+#define WEIGHT_H
+
+#include <tqstring.h>
+#include <tqvaluelist.h>
+
+#include "datablocks/elementlist.h"
+
+class Weight
+{
+public:
+ Weight();
+
+ int id;
+ int ingredientID;
+ int perAmountUnitID;
+ TQString perAmountUnit;
+ double perAmount;
+ int weightUnitID;
+ double weight;
+ TQString weightUnit;
+ int prepMethodID;
+ TQString prepMethod;
+};
+
+class WeightList : public TQValueList<Weight>
+{
+public:
+ WeightList() : TQValueList<Weight>(){}
+};
+
+#endif