diff --git a/RecipeDB.pro b/RecipeDB.pro index 2c957a5..0153b2b 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -25,7 +25,8 @@ SOURCES += model/recipe/instruction.cpp \ SQLite/sqlite3.c \ model/database/resulttable.cpp \ model/database/recipedatabase.cpp \ - utils/fileutils.cpp + utils/fileutils.cpp \ + gui/newrecipedialog.cpp HEADERS += model/recipe/instruction.h \ model/recipe/recipe.h \ @@ -40,11 +41,13 @@ HEADERS += model/recipe/instruction.h \ SQLite/sqlite3ext.h \ model/database/resulttable.h \ model/database/recipedatabase.h \ - utils/fileutils.h + utils/fileutils.h \ + gui/newrecipedialog.h LIBS += -ldl \ -FORMS += gui/mainwindow.ui +FORMS += gui/mainwindow.ui \ + gui/newrecipedialog.ui DISTFILES += \ .gitignore diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 1db1cc9..267cc6b 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -109,12 +109,25 @@ - Source Sans Pro Light + Noto Sans CJK KR Light 20 + PreferAntialias + + false + - background-color: rgb(83, 75, 255); + QPushButton#newButton { + background-color: rgb(235, 235, 255); + border: 0px; +} +QPushButton#newButton:hover{ + background-color: rgb(245, 245, 255); +} +QPushButton#newButton:pressed{ + background-color: rgb(255, 255, 255); +} New @@ -134,12 +147,22 @@ - Source Sans Pro Light + Noto Sans CJK KR Light 20 + PreferAntialias - background-color: rgb(112, 105, 255); + QPushButton#openButton { + background-color: rgb(222, 226, 255); + border: 0px; +} +QPushButton#openButton:hover{ + background-color: rgb(232, 236, 255); +} +QPushButton#openButton:pressed{ + background-color: rgb(255, 255, 255); +} Open @@ -156,16 +179,32 @@ - Source Sans Pro Light + Noto Sans CJK KR Light 20 + PreferAntialias + + false + - background-color: rgb(137, 131, 255); + QPushButton#browseButton { + background-color: rgb(215, 215, 255); + border: 0px; +} +QPushButton#browseButton:hover{ + background-color: rgb(225, 225, 255); +} +QPushButton#browseButton:pressed{ + background-color: rgb(255, 255, 255); +} Browse + + false + @@ -214,8 +253,13 @@ - Source Sans Pro Light + Noto Sans CJK KR Light 24 + 50 + false + false + PreferAntialias + true @@ -299,7 +343,7 @@ - Source Sans Pro Light + Noto Sans CJK KR Thin 18 @@ -324,8 +368,9 @@ - Source Sans Pro Light - 16 + Noto Sans CJK KR Light + 12 + PreferAntialias @@ -343,6 +388,9 @@ Qt::ScrollBarAlwaysOff + + QAbstractItemView::NoSelection + true @@ -397,7 +445,7 @@ - Source Sans Pro Light + Noto Sans CJK KR Thin 18 @@ -445,11 +493,11 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#00ff40;">This is some </span><span style=" font-size:16pt; color:#a33c3e;">colored text and </span><a href="https://www.google.com"><span style=" font-size:8pt; text-decoration: underline; color:#0000ff;">link</span></a></p></body></html> +</style></head><body style=" font-family:'Liberation Serif Bold'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; color:#00ff40;">This is some </span><span style=" font-family:'MS Shell Dlg 2'; font-size:16pt; color:#a33c3e;">colored text and </span><a href="https://www.google.com"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt; text-decoration: underline; color:#0000ff;">link</span></a></p></body></html> - Qt::LinksAccessibleByMouse + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp new file mode 100644 index 0000000..818f180 --- /dev/null +++ b/gui/newrecipedialog.cpp @@ -0,0 +1,14 @@ +#include "newrecipedialog.h" +#include "ui_newrecipedialog.h" + +NewRecipeDialog::NewRecipeDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewRecipeDialog) +{ + ui->setupUi(this); +} + +NewRecipeDialog::~NewRecipeDialog() +{ + delete ui; +} diff --git a/gui/newrecipedialog.h b/gui/newrecipedialog.h new file mode 100644 index 0000000..30c34a2 --- /dev/null +++ b/gui/newrecipedialog.h @@ -0,0 +1,22 @@ +#ifndef NEWRECIPEDIALOG_H +#define NEWRECIPEDIALOG_H + +#include + +namespace Ui { +class NewRecipeDialog; +} + +class NewRecipeDialog : public QDialog +{ + Q_OBJECT + + public: + explicit NewRecipeDialog(QWidget *parent = 0); + ~NewRecipeDialog(); + + private: + Ui::NewRecipeDialog *ui; +}; + +#endif // NEWRECIPEDIALOG_H diff --git a/gui/newrecipedialog.ui b/gui/newrecipedialog.ui new file mode 100644 index 0000000..5248942 --- /dev/null +++ b/gui/newrecipedialog.ui @@ -0,0 +1,19 @@ + + + NewRecipeDialog + + + + 0 + 0 + 640 + 480 + + + + Dialog + + + + + diff --git a/main.cpp b/main.cpp index d67a414..1cadc3c 100644 --- a/main.cpp +++ b/main.cpp @@ -13,22 +13,16 @@ int main(int argc, char *argv[]) //TESTING CODE RecipeDatabase recipeDB("recipes"); -// recipeDB.storeIngredient(Ingredient("Apple", "Fruit")); -// recipeDB.storeIngredient(Ingredient("Corn", "Vegetable")); -// recipeDB.storeIngredient(Ingredient("Lettuce", "Vegetable")); -// recipeDB.storeIngredient(Ingredient("Carrot", "Vegetable")); - -// recipeDB.executeSQL("SELECT * FROM ingredient;").printData(); //TESTING CODE - vector ri; - ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c"))); - ri.push_back(RecipeIngredient("Baking Powder", "Additives", 1.0f, UnitOfMeasure("Teaspoon", "Teaspoons", "Tsp"))); +// vector ri; +// ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c"))); +// ri.push_back(RecipeIngredient("Baking Powder", "Additives", 1.0f, UnitOfMeasure("Teaspoon", "Teaspoons", "Tsp"))); - Recipe rec("Example", ri, Instruction("BOLDiTaLiCs"), QImage(), vector(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f); +// Recipe rec("Example", ri, Instruction("BOLDiTaLiCs"), QImage(), vector(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f); - bool success = recipeDB.storeRecipe(rec); - printf("Storage successful: %d\n", success); +// bool success = recipeDB.storeRecipe(rec); +// printf("Storage successful: %d\n", success); Recipe reloadRec = recipeDB.retrieveRecipe("Example"); reloadRec.print(); diff --git a/model/database/recipedatabase.cpp b/model/database/recipedatabase.cpp index 4c991da..bc23000 100644 --- a/model/database/recipedatabase.cpp +++ b/model/database/recipedatabase.cpp @@ -117,7 +117,6 @@ Recipe RecipeDatabase::retrieveRecipe(string name){ fprintf(stderr, "Error: No recipe with name %s found!\n", name.c_str()); return Recipe(); } - t.printData(); Recipe r; int id = std::stoi(t.valueAt(0, 0)); r.setName(t.valueAt(0, 1)); @@ -137,7 +136,6 @@ vector RecipeDatabase::retrieveRecipeIngredients(int recipeId) "INNER JOIN recipeIngredient " "ON ingredient.ingredientId = recipeIngredient.ingredientId " "AND recipeIngredient.recipeId = "+std::to_string(recipeId)+";"); - t.printData(); vector ings; for (unsigned int row = 0; row < t.rowCount(); row++){ RecipeIngredient r(t.valueAt(row, 0), t.valueAt(row, 1), std::stof(t.valueAt(row, 2)), UnitOfMeasure(t.valueAt(row, 3))); diff --git a/model/recipe/ingredients/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp index de88da5..bd1a41e 100644 --- a/model/recipe/ingredients/ingredientlistmodel.cpp +++ b/model/recipe/ingredients/ingredientlistmodel.cpp @@ -10,10 +10,22 @@ int IngredientListModel::rowCount(const QModelIndex &parent) const{ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{ int row = index.row(); + RecipeIngredient i = this->ingredients[row]; + + string displayStr; + + if (std::ceil(i.getQuantity()) == i.getQuantity()){ + //The quantity is an integer and should be casted. + displayStr += std::to_string((int)i.getQuantity()); + } else { + displayStr += std::to_string(i.getQuantity()); + } + + displayStr += " " + i.getUnit().getAbbreviation() + " " + i.getName(); switch(role){ case Qt::DisplayRole: - return QString::fromStdString(ingredients[row].getName()); + return QString::fromStdString(displayStr); } return QVariant(); diff --git a/model/recipe/ingredients/unitofmeasure.cpp b/model/recipe/ingredients/unitofmeasure.cpp index ddf62c8..7b4a0f8 100644 --- a/model/recipe/ingredients/unitofmeasure.cpp +++ b/model/recipe/ingredients/unitofmeasure.cpp @@ -1,19 +1,21 @@ #include "unitofmeasure.h" -UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation){ +UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation, int type){ this->name = name; this->plural = plural; this->abbreviation = abbreviation; + this->type = type; } UnitOfMeasure::UnitOfMeasure(string name){ this->name = name; this->plural = name + "s"; this->abbreviation = "NULL"; + this->type = MISC; ///TODO: Make actual guessing of this stuff. } -UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){ +UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", "", MISC){ //Default constructor initializes all fields to empty strings. } @@ -26,5 +28,9 @@ string UnitOfMeasure::getNamePlural() const{ } string UnitOfMeasure::getAbbreviation() const{ - return this->abbreviation; + return this->abbreviation; +} + +int UnitOfMeasure::getType() const{ + return this->type; } diff --git a/model/recipe/ingredients/unitofmeasure.h b/model/recipe/ingredients/unitofmeasure.h index 1787f14..1197089 100644 --- a/model/recipe/ingredients/unitofmeasure.h +++ b/model/recipe/ingredients/unitofmeasure.h @@ -12,8 +12,14 @@ using namespace std; class UnitOfMeasure { public: + //Constants Declarations. + static const int MASS = 1; + static const int VOLUME = 2; + static const int LENGTH = 3; + static const int MISC = 4; + //Full constructor. - UnitOfMeasure(string name, string plural, string abbreviation); + UnitOfMeasure(string name, string plural, string abbreviation, int type); //Attempt to guess unit from just a string. UnitOfMeasure(string name); //Constructor with default values. @@ -23,10 +29,13 @@ public: string getName() const; string getNamePlural() const; string getAbbreviation() const; + int getType() const; private: string name; //The name of the unit of measure. string plural; //The plural name. string abbreviation; //A short version of the unit. + int type; //The type of unit, as one of the constants above. + double metricCoefficient; //The conversion from this unit to the standard metric unit. }; #endif // UNITOFMEASURE_H