Added query counter, list of all tags, ingredients to open recipe view.
This commit is contained in:
		
							parent
							
								
									9065df521a
								
							
						
					
					
						commit
						844c558726
					
				
							
								
								
									
										11
									
								
								RecipeDB.pro
								
								
								
								
							
							
						
						
									
										11
									
								
								RecipeDB.pro
								
								
								
								
							| 
						 | 
					@ -34,7 +34,9 @@ SOURCES += model/recipe/instruction.cpp \
 | 
				
			||||||
    utils/stringutils.cpp \
 | 
					    utils/stringutils.cpp \
 | 
				
			||||||
    gui/openrecipedialog.cpp \
 | 
					    gui/openrecipedialog.cpp \
 | 
				
			||||||
    model/recipe/recipetablemodel.cpp \
 | 
					    model/recipe/recipetablemodel.cpp \
 | 
				
			||||||
    gui/mainwindow.cpp
 | 
					    gui/mainwindow.cpp \
 | 
				
			||||||
 | 
					    gui/newDialogs/newfoodgroupdialog.cpp \
 | 
				
			||||||
 | 
					    model/recipe/ingredients/recipeingredientlistmodel.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HEADERS  += model/recipe/instruction.h \
 | 
					HEADERS  += model/recipe/instruction.h \
 | 
				
			||||||
    model/recipe/recipe.h \
 | 
					    model/recipe/recipe.h \
 | 
				
			||||||
| 
						 | 
					@ -58,7 +60,9 @@ HEADERS  += model/recipe/instruction.h \
 | 
				
			||||||
    utils/stringutils.h \
 | 
					    utils/stringutils.h \
 | 
				
			||||||
    gui/openrecipedialog.h \
 | 
					    gui/openrecipedialog.h \
 | 
				
			||||||
    model/recipe/recipetablemodel.h \
 | 
					    model/recipe/recipetablemodel.h \
 | 
				
			||||||
    gui/mainwindow.h
 | 
					    gui/mainwindow.h \
 | 
				
			||||||
 | 
					    gui/newDialogs/newfoodgroupdialog.h \
 | 
				
			||||||
 | 
					    model/recipe/ingredients/recipeingredientlistmodel.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LIBS += -ldl \
 | 
					LIBS += -ldl \
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +72,8 @@ FORMS    += gui/mainwindow.ui \
 | 
				
			||||||
    gui/newDialogs/newtagdialog.ui \
 | 
					    gui/newDialogs/newtagdialog.ui \
 | 
				
			||||||
    gui/newDialogs/newunitdialog.ui \
 | 
					    gui/newDialogs/newunitdialog.ui \
 | 
				
			||||||
    gui/openrecipedialog.ui \
 | 
					    gui/openrecipedialog.ui \
 | 
				
			||||||
    gui/mainwindow.ui
 | 
					    gui/mainwindow.ui \
 | 
				
			||||||
 | 
					    gui/newDialogs/newfoodgroupdialog.ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DISTFILES += \
 | 
					DISTFILES += \
 | 
				
			||||||
    .gitignore
 | 
					    .gitignore
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
#include <QAbstractListModel>
 | 
					#include <QAbstractListModel>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "model/recipe/recipe.h"
 | 
					#include "model/recipe/recipe.h"
 | 
				
			||||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
					#include "model/recipe/ingredients/recipeingredientlistmodel.h"
 | 
				
			||||||
#include "gui/newrecipedialog.h"
 | 
					#include "gui/newrecipedialog.h"
 | 
				
			||||||
#include "gui/openrecipedialog.h"
 | 
					#include "gui/openrecipedialog.h"
 | 
				
			||||||
#include "utils/stringutils.h"
 | 
					#include "utils/stringutils.h"
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ public:
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
    Ui::MainWindow *ui;
 | 
					    Ui::MainWindow *ui;
 | 
				
			||||||
	RecipeDatabase *recipeDB;
 | 
						RecipeDatabase *recipeDB;
 | 
				
			||||||
    IngredientListModel ingredientModel;
 | 
						RecipeIngredientListModel ingredientModel;
 | 
				
			||||||
	TagListModel tagsListModel;
 | 
						TagListModel tagsListModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Hidden manipulation methods.
 | 
					    //Hidden manipulation methods.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -604,6 +604,9 @@ font: "Noto Sans CJK KR";</string>
 | 
				
			||||||
                  <property name="horizontalScrollBarPolicy">
 | 
					                  <property name="horizontalScrollBarPolicy">
 | 
				
			||||||
                   <enum>Qt::ScrollBarAlwaysOff</enum>
 | 
					                   <enum>Qt::ScrollBarAlwaysOff</enum>
 | 
				
			||||||
                  </property>
 | 
					                  </property>
 | 
				
			||||||
 | 
					                  <property name="editTriggers">
 | 
				
			||||||
 | 
					                   <set>QAbstractItemView::NoEditTriggers</set>
 | 
				
			||||||
 | 
					                  </property>
 | 
				
			||||||
                  <property name="selectionMode">
 | 
					                  <property name="selectionMode">
 | 
				
			||||||
                   <enum>QAbstractItemView::ExtendedSelection</enum>
 | 
					                   <enum>QAbstractItemView::ExtendedSelection</enum>
 | 
				
			||||||
                  </property>
 | 
					                  </property>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					#include "newfoodgroupdialog.h"
 | 
				
			||||||
 | 
					#include "ui_newfoodgroupdialog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					newFoodGroupDialog::newFoodGroupDialog(QWidget *parent) :
 | 
				
			||||||
 | 
						QDialog(parent),
 | 
				
			||||||
 | 
						ui(new Ui::newFoodGroupDialog)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						ui->setupUi(this);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					newFoodGroupDialog::~newFoodGroupDialog()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						delete ui;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					string newFoodGroupDialog::getFoodGroup() const{
 | 
				
			||||||
 | 
						return ui->lineEdit->text().toStdString();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,27 @@
 | 
				
			||||||
 | 
					#ifndef NEWFOODGROUPDIALOG_H
 | 
				
			||||||
 | 
					#define NEWFOODGROUPDIALOG_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QDialog>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui {
 | 
				
			||||||
 | 
					class newFoodGroupDialog;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class newFoodGroupDialog : public QDialog
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
							Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public:
 | 
				
			||||||
 | 
							explicit newFoodGroupDialog(QWidget *parent = 0);
 | 
				
			||||||
 | 
							~newFoodGroupDialog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							string getFoodGroup() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private:
 | 
				
			||||||
 | 
							Ui::newFoodGroupDialog *ui;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // NEWFOODGROUPDIALOG_H
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,101 @@
 | 
				
			||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<ui version="4.0">
 | 
				
			||||||
 | 
					 <class>newFoodGroupDialog</class>
 | 
				
			||||||
 | 
					 <widget class="QDialog" name="newFoodGroupDialog">
 | 
				
			||||||
 | 
					  <property name="geometry">
 | 
				
			||||||
 | 
					   <rect>
 | 
				
			||||||
 | 
					    <x>0</x>
 | 
				
			||||||
 | 
					    <y>0</y>
 | 
				
			||||||
 | 
					    <width>240</width>
 | 
				
			||||||
 | 
					    <height>114</height>
 | 
				
			||||||
 | 
					   </rect>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="font">
 | 
				
			||||||
 | 
					   <font>
 | 
				
			||||||
 | 
					    <pointsize>11</pointsize>
 | 
				
			||||||
 | 
					   </font>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="windowTitle">
 | 
				
			||||||
 | 
					   <string>New Food Group</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="windowIcon">
 | 
				
			||||||
 | 
					   <iconset resource="../../images.qrc">
 | 
				
			||||||
 | 
					    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
 | 
					  <layout class="QVBoxLayout" name="verticalLayout">
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QLabel" name="label">
 | 
				
			||||||
 | 
					     <property name="font">
 | 
				
			||||||
 | 
					      <font>
 | 
				
			||||||
 | 
					       <family>Noto Sans CJK KR Light</family>
 | 
				
			||||||
 | 
					       <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					      </font>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="text">
 | 
				
			||||||
 | 
					      <string>Add New Food Group</string>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="alignment">
 | 
				
			||||||
 | 
					      <set>Qt::AlignCenter</set>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QLineEdit" name="lineEdit">
 | 
				
			||||||
 | 
					     <property name="font">
 | 
				
			||||||
 | 
					      <font>
 | 
				
			||||||
 | 
					       <family>Noto Sans CJK KR Light</family>
 | 
				
			||||||
 | 
					       <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					      </font>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					   <item>
 | 
				
			||||||
 | 
					    <widget class="QDialogButtonBox" name="buttonBox">
 | 
				
			||||||
 | 
					     <property name="orientation">
 | 
				
			||||||
 | 
					      <enum>Qt::Horizontal</enum>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					     <property name="standardButtons">
 | 
				
			||||||
 | 
					      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
				
			||||||
 | 
					     </property>
 | 
				
			||||||
 | 
					    </widget>
 | 
				
			||||||
 | 
					   </item>
 | 
				
			||||||
 | 
					  </layout>
 | 
				
			||||||
 | 
					 </widget>
 | 
				
			||||||
 | 
					 <resources>
 | 
				
			||||||
 | 
					  <include location="../../images.qrc"/>
 | 
				
			||||||
 | 
					 </resources>
 | 
				
			||||||
 | 
					 <connections>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>accepted()</signal>
 | 
				
			||||||
 | 
					   <receiver>newFoodGroupDialog</receiver>
 | 
				
			||||||
 | 
					   <slot>accept()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>248</x>
 | 
				
			||||||
 | 
					     <y>254</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>157</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					  <connection>
 | 
				
			||||||
 | 
					   <sender>buttonBox</sender>
 | 
				
			||||||
 | 
					   <signal>rejected()</signal>
 | 
				
			||||||
 | 
					   <receiver>newFoodGroupDialog</receiver>
 | 
				
			||||||
 | 
					   <slot>reject()</slot>
 | 
				
			||||||
 | 
					   <hints>
 | 
				
			||||||
 | 
					    <hint type="sourcelabel">
 | 
				
			||||||
 | 
					     <x>316</x>
 | 
				
			||||||
 | 
					     <y>260</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					    <hint type="destinationlabel">
 | 
				
			||||||
 | 
					     <x>286</x>
 | 
				
			||||||
 | 
					     <y>274</y>
 | 
				
			||||||
 | 
					    </hint>
 | 
				
			||||||
 | 
					   </hints>
 | 
				
			||||||
 | 
					  </connection>
 | 
				
			||||||
 | 
					 </connections>
 | 
				
			||||||
 | 
					</ui>
 | 
				
			||||||
| 
						 | 
					@ -24,10 +24,26 @@ Ingredient NewIngredientDialog::getIngredient(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NewIngredientDialog::populateFoodGroupBox(){
 | 
					void NewIngredientDialog::populateFoodGroupBox(){
 | 
				
			||||||
	vector<string> foodGroups = this->recipeDB->retrieveAllFoodGroups();
 | 
						vector<string> foodGroups = this->recipeDB->retrieveAllFoodGroups();
 | 
				
			||||||
	printf("Found %ld food Groups.\n", foodGroups.size());
 | 
					 | 
				
			||||||
	ui->foodGroupBox->clear();
 | 
						ui->foodGroupBox->clear();
 | 
				
			||||||
	for (unsigned int i = 0; i < foodGroups.size(); i++){
 | 
						for (unsigned int i = 0; i < foodGroups.size(); i++){
 | 
				
			||||||
		QString s = QString::fromStdString(foodGroups[i]);
 | 
							QString s = QString::fromStdString(foodGroups[i]);
 | 
				
			||||||
		ui->foodGroupBox->insertItem(i, s);
 | 
							ui->foodGroupBox->insertItem(i, s);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void NewIngredientDialog::on_addFoodGroupButton_clicked(){
 | 
				
			||||||
 | 
						newFoodGroupDialog d(this);
 | 
				
			||||||
 | 
						if (d.exec() == QDialog::Accepted){
 | 
				
			||||||
 | 
							string s = d.getFoodGroup();
 | 
				
			||||||
 | 
							if (!s.empty()){
 | 
				
			||||||
 | 
								ui->foodGroupBox->addItem(QString::fromStdString(s));
 | 
				
			||||||
 | 
								ui->foodGroupBox->setCurrentText(QString::fromStdString(s));
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								QMessageBox::warning(this, "Empty Food Group", "The food group you entered is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void NewIngredientDialog::on_deleteFoodGroupButton_clicked(){
 | 
				
			||||||
 | 
						ui->foodGroupBox->removeItem(ui->foodGroupBox->currentIndex());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,8 +2,11 @@
 | 
				
			||||||
#define NEWINGREDIENTDIALOG_H
 | 
					#define NEWINGREDIENTDIALOG_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDialog>
 | 
					#include <QDialog>
 | 
				
			||||||
 | 
					#include <QMessageBox>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "model/recipe/ingredients/ingredient.h"
 | 
					#include "model/recipe/ingredients/ingredient.h"
 | 
				
			||||||
#include "model/database/recipedatabase.h"
 | 
					#include "model/database/recipedatabase.h"
 | 
				
			||||||
 | 
					#include "gui/newDialogs/newfoodgroupdialog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Ui {
 | 
					namespace Ui {
 | 
				
			||||||
class NewIngredientDialog;
 | 
					class NewIngredientDialog;
 | 
				
			||||||
| 
						 | 
					@ -21,6 +24,11 @@ class NewIngredientDialog : public QDialog
 | 
				
			||||||
		//Access values.
 | 
							//Access values.
 | 
				
			||||||
		Ingredient getIngredient();
 | 
							Ingredient getIngredient();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private slots:
 | 
				
			||||||
 | 
							void on_addFoodGroupButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_deleteFoodGroupButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		Ui::NewIngredientDialog *ui;
 | 
							Ui::NewIngredientDialog *ui;
 | 
				
			||||||
		RecipeDatabase *recipeDB;
 | 
							RecipeDatabase *recipeDB;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,6 +70,9 @@
 | 
				
			||||||
                <verstretch>0</verstretch>
 | 
					                <verstretch>0</verstretch>
 | 
				
			||||||
               </sizepolicy>
 | 
					               </sizepolicy>
 | 
				
			||||||
              </property>
 | 
					              </property>
 | 
				
			||||||
 | 
					              <property name="insertPolicy">
 | 
				
			||||||
 | 
					               <enum>QComboBox::InsertAlphabetically</enum>
 | 
				
			||||||
 | 
					              </property>
 | 
				
			||||||
             </widget>
 | 
					             </widget>
 | 
				
			||||||
            </item>
 | 
					            </item>
 | 
				
			||||||
            <item alignment="Qt::AlignRight">
 | 
					            <item alignment="Qt::AlignRight">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,16 +7,19 @@
 | 
				
			||||||
    <x>0</x>
 | 
					    <x>0</x>
 | 
				
			||||||
    <y>0</y>
 | 
					    <y>0</y>
 | 
				
			||||||
    <width>240</width>
 | 
					    <width>240</width>
 | 
				
			||||||
    <height>320</height>
 | 
					    <height>121</height>
 | 
				
			||||||
   </rect>
 | 
					   </rect>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
  <property name="windowTitle">
 | 
					  <property name="windowTitle">
 | 
				
			||||||
   <string>Dialog</string>
 | 
					   <string>New Tag</string>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
  <property name="windowIcon">
 | 
					  <property name="windowIcon">
 | 
				
			||||||
   <iconset resource="../../images.qrc">
 | 
					   <iconset resource="../../images.qrc">
 | 
				
			||||||
    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
					    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="styleSheet">
 | 
				
			||||||
 | 
					   <string notr="true">font: 25 "Noto Sans CJK KR Light";</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
  <property name="modal">
 | 
					  <property name="modal">
 | 
				
			||||||
   <bool>true</bool>
 | 
					   <bool>true</bool>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
| 
						 | 
					@ -26,6 +29,14 @@
 | 
				
			||||||
     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
					     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QLabel" name="tagLabel">
 | 
					       <widget class="QLabel" name="tagLabel">
 | 
				
			||||||
 | 
					        <property name="font">
 | 
				
			||||||
 | 
					         <font>
 | 
				
			||||||
 | 
					          <pointsize>13</pointsize>
 | 
				
			||||||
 | 
					          <weight>3</weight>
 | 
				
			||||||
 | 
					          <italic>false</italic>
 | 
				
			||||||
 | 
					          <bold>false</bold>
 | 
				
			||||||
 | 
					         </font>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>New Tag</string>
 | 
					         <string>New Tag</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
| 
						 | 
					@ -35,7 +46,16 @@
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QLineEdit" name="tagEdit"/>
 | 
					       <widget class="QLineEdit" name="tagEdit">
 | 
				
			||||||
 | 
					        <property name="font">
 | 
				
			||||||
 | 
					         <font>
 | 
				
			||||||
 | 
					          <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					          <weight>3</weight>
 | 
				
			||||||
 | 
					          <italic>false</italic>
 | 
				
			||||||
 | 
					          <bold>false</bold>
 | 
				
			||||||
 | 
					         </font>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
     </layout>
 | 
					     </layout>
 | 
				
			||||||
    </widget>
 | 
					    </widget>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,8 @@
 | 
				
			||||||
   <rect>
 | 
					   <rect>
 | 
				
			||||||
    <x>0</x>
 | 
					    <x>0</x>
 | 
				
			||||||
    <y>0</y>
 | 
					    <y>0</y>
 | 
				
			||||||
    <width>240</width>
 | 
					    <width>195</width>
 | 
				
			||||||
    <height>350</height>
 | 
					    <height>340</height>
 | 
				
			||||||
   </rect>
 | 
					   </rect>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
  <property name="windowTitle">
 | 
					  <property name="windowTitle">
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,9 @@
 | 
				
			||||||
   <iconset resource="../../images.qrc">
 | 
					   <iconset resource="../../images.qrc">
 | 
				
			||||||
    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
					    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
 | 
					  <property name="styleSheet">
 | 
				
			||||||
 | 
					   <string notr="true">font: 25 "Noto Sans CJK KR Light";</string>
 | 
				
			||||||
 | 
					  </property>
 | 
				
			||||||
  <property name="modal">
 | 
					  <property name="modal">
 | 
				
			||||||
   <bool>true</bool>
 | 
					   <bool>true</bool>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
| 
						 | 
					@ -26,6 +29,14 @@
 | 
				
			||||||
     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
					     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QLabel" name="label">
 | 
					       <widget class="QLabel" name="label">
 | 
				
			||||||
 | 
					        <property name="font">
 | 
				
			||||||
 | 
					         <font>
 | 
				
			||||||
 | 
					          <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					          <weight>3</weight>
 | 
				
			||||||
 | 
					          <italic>false</italic>
 | 
				
			||||||
 | 
					          <bold>false</bold>
 | 
				
			||||||
 | 
					         </font>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Unit Name</string>
 | 
					         <string>Unit Name</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
| 
						 | 
					@ -39,6 +50,14 @@
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QLabel" name="label_2">
 | 
					       <widget class="QLabel" name="label_2">
 | 
				
			||||||
 | 
					        <property name="font">
 | 
				
			||||||
 | 
					         <font>
 | 
				
			||||||
 | 
					          <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					          <weight>3</weight>
 | 
				
			||||||
 | 
					          <italic>false</italic>
 | 
				
			||||||
 | 
					          <bold>false</bold>
 | 
				
			||||||
 | 
					         </font>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Plural Name</string>
 | 
					         <string>Plural Name</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
| 
						 | 
					@ -52,6 +71,14 @@
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QLabel" name="label_3">
 | 
					       <widget class="QLabel" name="label_3">
 | 
				
			||||||
 | 
					        <property name="font">
 | 
				
			||||||
 | 
					         <font>
 | 
				
			||||||
 | 
					          <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					          <weight>3</weight>
 | 
				
			||||||
 | 
					          <italic>false</italic>
 | 
				
			||||||
 | 
					          <bold>false</bold>
 | 
				
			||||||
 | 
					         </font>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Abbreviation</string>
 | 
					         <string>Abbreviation</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
| 
						 | 
					@ -86,6 +113,14 @@
 | 
				
			||||||
             <verstretch>0</verstretch>
 | 
					             <verstretch>0</verstretch>
 | 
				
			||||||
            </sizepolicy>
 | 
					            </sizepolicy>
 | 
				
			||||||
           </property>
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="font">
 | 
				
			||||||
 | 
					            <font>
 | 
				
			||||||
 | 
					             <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					             <weight>3</weight>
 | 
				
			||||||
 | 
					             <italic>false</italic>
 | 
				
			||||||
 | 
					             <bold>false</bold>
 | 
				
			||||||
 | 
					            </font>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
           <property name="text">
 | 
					           <property name="text">
 | 
				
			||||||
            <string>Type:</string>
 | 
					            <string>Type:</string>
 | 
				
			||||||
           </property>
 | 
					           </property>
 | 
				
			||||||
| 
						 | 
					@ -109,6 +144,14 @@
 | 
				
			||||||
        <layout class="QVBoxLayout" name="verticalLayout_3">
 | 
					        <layout class="QVBoxLayout" name="verticalLayout_3">
 | 
				
			||||||
         <item>
 | 
					         <item>
 | 
				
			||||||
          <widget class="QLabel" name="label_5">
 | 
					          <widget class="QLabel" name="label_5">
 | 
				
			||||||
 | 
					           <property name="font">
 | 
				
			||||||
 | 
					            <font>
 | 
				
			||||||
 | 
					             <pointsize>12</pointsize>
 | 
				
			||||||
 | 
					             <weight>3</weight>
 | 
				
			||||||
 | 
					             <italic>false</italic>
 | 
				
			||||||
 | 
					             <bold>false</bold>
 | 
				
			||||||
 | 
					            </font>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
           <property name="text">
 | 
					           <property name="text">
 | 
				
			||||||
            <string>Metric Coefficient</string>
 | 
					            <string>Metric Coefficient</string>
 | 
				
			||||||
           </property>
 | 
					           </property>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -199,8 +199,8 @@ void NewRecipeDialog::on_newUnitButton_clicked(){
 | 
				
			||||||
	d.show();
 | 
						d.show();
 | 
				
			||||||
	if (d.exec() == QDialog::Accepted){
 | 
						if (d.exec() == QDialog::Accepted){
 | 
				
			||||||
		UnitOfMeasure u = d.getUnit();
 | 
							UnitOfMeasure u = d.getUnit();
 | 
				
			||||||
		if (!this->recipeDB->storeUnitOfMeasure(u) || u.getName().empty() || u.getNamePlural().empty() || u.getAbbreviation().empty()){
 | 
							if (u.getName().empty() || u.getNamePlural().empty() || u.getAbbreviation().empty() || !this->recipeDB->storeUnitOfMeasure(u)){
 | 
				
			||||||
			QMessageBox::critical(this, "Error", "Unable to store new unit.");
 | 
								QMessageBox::critical(this, "Error", "Unable to store new unit. Make sure all the information is filled in!");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			this->populateUnitsBox();
 | 
								this->populateUnitsBox();
 | 
				
			||||||
			ui->unitComboBox->setCurrentText(QString::fromStdString(u.getName()));
 | 
								ui->unitComboBox->setCurrentText(QString::fromStdString(u.getName()));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@
 | 
				
			||||||
#include <QMessageBox>
 | 
					#include <QMessageBox>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "model/database/recipedatabase.h"
 | 
					#include "model/database/recipedatabase.h"
 | 
				
			||||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
					#include "model/recipe/ingredients/recipeingredientlistmodel.h"
 | 
				
			||||||
#include "model/recipe/tags/taglistmodel.h"
 | 
					#include "model/recipe/tags/taglistmodel.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gui/newDialogs/newingredientdialog.h"
 | 
					#include "gui/newDialogs/newingredientdialog.h"
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ class NewRecipeDialog : public QDialog
 | 
				
			||||||
		vector<Ingredient> ingredients;
 | 
							vector<Ingredient> ingredients;
 | 
				
			||||||
		vector<UnitOfMeasure> units;
 | 
							vector<UnitOfMeasure> units;
 | 
				
			||||||
		vector<RecipeTag> tags;
 | 
							vector<RecipeTag> tags;
 | 
				
			||||||
		IngredientListModel ingredientListModel;
 | 
							RecipeIngredientListModel ingredientListModel;
 | 
				
			||||||
		TagListModel tagsListModel;
 | 
							TagListModel tagsListModel;
 | 
				
			||||||
		QImage img;
 | 
							QImage img;
 | 
				
			||||||
		bool accepted = false;
 | 
							bool accepted = false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -273,6 +273,12 @@
 | 
				
			||||||
                   <verstretch>0</verstretch>
 | 
					                   <verstretch>0</verstretch>
 | 
				
			||||||
                  </sizepolicy>
 | 
					                  </sizepolicy>
 | 
				
			||||||
                 </property>
 | 
					                 </property>
 | 
				
			||||||
 | 
					                 <property name="styleSheet">
 | 
				
			||||||
 | 
					                  <string notr="true">background-color: rgb(113, 119, 255);</string>
 | 
				
			||||||
 | 
					                 </property>
 | 
				
			||||||
 | 
					                 <property name="insertPolicy">
 | 
				
			||||||
 | 
					                  <enum>QComboBox::InsertAlphabetically</enum>
 | 
				
			||||||
 | 
					                 </property>
 | 
				
			||||||
                </widget>
 | 
					                </widget>
 | 
				
			||||||
               </item>
 | 
					               </item>
 | 
				
			||||||
               <item alignment="Qt::AlignRight">
 | 
					               <item alignment="Qt::AlignRight">
 | 
				
			||||||
| 
						 | 
					@ -459,12 +465,21 @@
 | 
				
			||||||
                         <verstretch>0</verstretch>
 | 
					                         <verstretch>0</verstretch>
 | 
				
			||||||
                        </sizepolicy>
 | 
					                        </sizepolicy>
 | 
				
			||||||
                       </property>
 | 
					                       </property>
 | 
				
			||||||
 | 
					                       <property name="styleSheet">
 | 
				
			||||||
 | 
					                        <string notr="true">background-color: rgb(113, 119, 255);</string>
 | 
				
			||||||
 | 
					                       </property>
 | 
				
			||||||
                       <property name="editable">
 | 
					                       <property name="editable">
 | 
				
			||||||
                        <bool>false</bool>
 | 
					                        <bool>false</bool>
 | 
				
			||||||
                       </property>
 | 
					                       </property>
 | 
				
			||||||
                       <property name="currentText">
 | 
					                       <property name="currentText">
 | 
				
			||||||
                        <string/>
 | 
					                        <string/>
 | 
				
			||||||
                       </property>
 | 
					                       </property>
 | 
				
			||||||
 | 
					                       <property name="insertPolicy">
 | 
				
			||||||
 | 
					                        <enum>QComboBox::InsertAlphabetically</enum>
 | 
				
			||||||
 | 
					                       </property>
 | 
				
			||||||
 | 
					                       <property name="frame">
 | 
				
			||||||
 | 
					                        <bool>true</bool>
 | 
				
			||||||
 | 
					                       </property>
 | 
				
			||||||
                      </widget>
 | 
					                      </widget>
 | 
				
			||||||
                     </item>
 | 
					                     </item>
 | 
				
			||||||
                     <item>
 | 
					                     <item>
 | 
				
			||||||
| 
						 | 
					@ -554,6 +569,12 @@
 | 
				
			||||||
                         <verstretch>0</verstretch>
 | 
					                         <verstretch>0</verstretch>
 | 
				
			||||||
                        </sizepolicy>
 | 
					                        </sizepolicy>
 | 
				
			||||||
                       </property>
 | 
					                       </property>
 | 
				
			||||||
 | 
					                       <property name="styleSheet">
 | 
				
			||||||
 | 
					                        <string notr="true">background-color: rgb(113, 119, 255);</string>
 | 
				
			||||||
 | 
					                       </property>
 | 
				
			||||||
 | 
					                       <property name="insertPolicy">
 | 
				
			||||||
 | 
					                        <enum>QComboBox::InsertAlphabetically</enum>
 | 
				
			||||||
 | 
					                       </property>
 | 
				
			||||||
                      </widget>
 | 
					                      </widget>
 | 
				
			||||||
                     </item>
 | 
					                     </item>
 | 
				
			||||||
                     <item alignment="Qt::AlignRight">
 | 
					                     <item alignment="Qt::AlignRight">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,10 +8,14 @@ OpenRecipeDialog::OpenRecipeDialog(QWidget *parent) :
 | 
				
			||||||
	ui->setupUi(this);
 | 
						ui->setupUi(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ui->recipeTableView->setModel(&this->recipeTableModel);
 | 
						ui->recipeTableView->setModel(&this->recipeTableModel);
 | 
				
			||||||
 | 
						ui->ingredientsListView->setModel(&this->ingredientsModel);
 | 
				
			||||||
 | 
						ui->tagsListView->setModel(&this->tagsModel);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
OpenRecipeDialog::OpenRecipeDialog(RecipeDatabase *recipeDB, QWidget *parent) : OpenRecipeDialog(parent){
 | 
					OpenRecipeDialog::OpenRecipeDialog(RecipeDatabase *recipeDB, QWidget *parent) : OpenRecipeDialog(parent){
 | 
				
			||||||
	this->recipeDB = recipeDB;
 | 
						this->recipeDB = recipeDB;
 | 
				
			||||||
 | 
						this->populateIngredientsList();
 | 
				
			||||||
 | 
						this->populateTagsList();
 | 
				
			||||||
	this->populateRecipesTable();
 | 
						this->populateRecipesTable();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +36,14 @@ void OpenRecipeDialog::populateRecipesTable(){
 | 
				
			||||||
	ui->recipeTableView->show();
 | 
						ui->recipeTableView->show();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void OpenRecipeDialog::populateIngredientsList(){
 | 
				
			||||||
 | 
						this->ingredientsModel.setIngredients(this->recipeDB->retrieveAllIngredients());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void OpenRecipeDialog::populateTagsList(){
 | 
				
			||||||
 | 
						this->tagsModel.setTags(this->recipeDB->retrieveAllTags());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void OpenRecipeDialog::on_deleteRecipeButton_clicked(){
 | 
					void OpenRecipeDialog::on_deleteRecipeButton_clicked(){
 | 
				
			||||||
	QItemSelectionModel *selectModel = ui->recipeTableView->selectionModel();
 | 
						QItemSelectionModel *selectModel = ui->recipeTableView->selectionModel();
 | 
				
			||||||
	if (!selectModel->hasSelection()){
 | 
						if (!selectModel->hasSelection()){
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "model/database/recipedatabase.h"
 | 
					#include "model/database/recipedatabase.h"
 | 
				
			||||||
#include "model/recipe/recipetablemodel.h"
 | 
					#include "model/recipe/recipetablemodel.h"
 | 
				
			||||||
 | 
					#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
				
			||||||
 | 
					#include "model/recipe/tags/taglistmodel.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Ui {
 | 
					namespace Ui {
 | 
				
			||||||
class OpenRecipeDialog;
 | 
					class OpenRecipeDialog;
 | 
				
			||||||
| 
						 | 
					@ -33,7 +35,12 @@ class OpenRecipeDialog : public QDialog
 | 
				
			||||||
		RecipeTableModel recipeTableModel;
 | 
							RecipeTableModel recipeTableModel;
 | 
				
			||||||
		Recipe selectedRecipe;
 | 
							Recipe selectedRecipe;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							IngredientListModel ingredientsModel;
 | 
				
			||||||
 | 
							TagListModel tagsModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void populateRecipesTable();
 | 
							void populateRecipesTable();
 | 
				
			||||||
 | 
							void populateIngredientsList();
 | 
				
			||||||
 | 
							void populateTagsList();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // OPENRECIPEDIALOG_H
 | 
					#endif // OPENRECIPEDIALOG_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
   <rect>
 | 
					   <rect>
 | 
				
			||||||
    <x>0</x>
 | 
					    <x>0</x>
 | 
				
			||||||
    <y>0</y>
 | 
					    <y>0</y>
 | 
				
			||||||
    <width>640</width>
 | 
					    <width>1000</width>
 | 
				
			||||||
    <height>480</height>
 | 
					    <height>480</height>
 | 
				
			||||||
   </rect>
 | 
					   </rect>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
| 
						 | 
					@ -20,10 +20,80 @@
 | 
				
			||||||
  <property name="modal">
 | 
					  <property name="modal">
 | 
				
			||||||
   <bool>true</bool>
 | 
					   <bool>true</bool>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
					  <layout class="QHBoxLayout" name="horizontalLayout_6">
 | 
				
			||||||
   <item alignment="Qt::AlignTop">
 | 
					   <item alignment="Qt::AlignLeft|Qt::AlignTop">
 | 
				
			||||||
    <widget class="QWidget" name="searchPanel" native="true">
 | 
					    <widget class="QWidget" name="searchPanel" native="true">
 | 
				
			||||||
     <layout class="QHBoxLayout" name="horizontalLayout">
 | 
					     <layout class="QVBoxLayout" name="verticalLayout">
 | 
				
			||||||
 | 
					      <item alignment="Qt::AlignLeft">
 | 
				
			||||||
 | 
					       <widget class="QWidget" name="tagsSearchpanel" native="true">
 | 
				
			||||||
 | 
					        <layout class="QVBoxLayout" name="verticalLayout_3">
 | 
				
			||||||
 | 
					         <item>
 | 
				
			||||||
 | 
					          <widget class="QLabel" name="tagLabel">
 | 
				
			||||||
 | 
					           <property name="text">
 | 
				
			||||||
 | 
					            <string>Tag</string>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					          </widget>
 | 
				
			||||||
 | 
					         </item>
 | 
				
			||||||
 | 
					         <item>
 | 
				
			||||||
 | 
					          <widget class="QListView" name="tagsListView">
 | 
				
			||||||
 | 
					           <property name="sizePolicy">
 | 
				
			||||||
 | 
					            <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
 | 
				
			||||||
 | 
					             <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					             <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					            </sizepolicy>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="frameShape">
 | 
				
			||||||
 | 
					            <enum>QFrame::NoFrame</enum>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="selectionMode">
 | 
				
			||||||
 | 
					            <enum>QAbstractItemView::ExtendedSelection</enum>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="isWrapping" stdset="0">
 | 
				
			||||||
 | 
					            <bool>false</bool>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="wordWrap">
 | 
				
			||||||
 | 
					            <bool>false</bool>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					          </widget>
 | 
				
			||||||
 | 
					         </item>
 | 
				
			||||||
 | 
					        </layout>
 | 
				
			||||||
 | 
					       </widget>
 | 
				
			||||||
 | 
					      </item>
 | 
				
			||||||
 | 
					      <item alignment="Qt::AlignLeft">
 | 
				
			||||||
 | 
					       <widget class="QWidget" name="ingredientSearchPanel" native="true">
 | 
				
			||||||
 | 
					        <layout class="QVBoxLayout" name="verticalLayout_4">
 | 
				
			||||||
 | 
					         <item>
 | 
				
			||||||
 | 
					          <widget class="QLabel" name="ingredientLabel">
 | 
				
			||||||
 | 
					           <property name="text">
 | 
				
			||||||
 | 
					            <string>Ingredient</string>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					          </widget>
 | 
				
			||||||
 | 
					         </item>
 | 
				
			||||||
 | 
					         <item>
 | 
				
			||||||
 | 
					          <widget class="QListView" name="ingredientsListView">
 | 
				
			||||||
 | 
					           <property name="sizePolicy">
 | 
				
			||||||
 | 
					            <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
 | 
				
			||||||
 | 
					             <horstretch>0</horstretch>
 | 
				
			||||||
 | 
					             <verstretch>0</verstretch>
 | 
				
			||||||
 | 
					            </sizepolicy>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="frameShape">
 | 
				
			||||||
 | 
					            <enum>QFrame::NoFrame</enum>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="selectionMode">
 | 
				
			||||||
 | 
					            <enum>QAbstractItemView::ExtendedSelection</enum>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="isWrapping" stdset="0">
 | 
				
			||||||
 | 
					            <bool>false</bool>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="wordWrap">
 | 
				
			||||||
 | 
					            <bool>true</bool>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					          </widget>
 | 
				
			||||||
 | 
					         </item>
 | 
				
			||||||
 | 
					        </layout>
 | 
				
			||||||
 | 
					       </widget>
 | 
				
			||||||
 | 
					      </item>
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QWidget" name="nameSearchPanel" native="true">
 | 
					       <widget class="QWidget" name="nameSearchPanel" native="true">
 | 
				
			||||||
        <layout class="QHBoxLayout" name="horizontalLayout_2">
 | 
					        <layout class="QHBoxLayout" name="horizontalLayout_2">
 | 
				
			||||||
| 
						 | 
					@ -40,38 +110,6 @@
 | 
				
			||||||
        </layout>
 | 
					        </layout>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item>
 | 
					 | 
				
			||||||
       <widget class="QWidget" name="tagsSearchpanel" native="true">
 | 
					 | 
				
			||||||
        <layout class="QHBoxLayout" name="horizontalLayout_3">
 | 
					 | 
				
			||||||
         <item>
 | 
					 | 
				
			||||||
          <widget class="QLabel" name="tagLabel">
 | 
					 | 
				
			||||||
           <property name="text">
 | 
					 | 
				
			||||||
            <string>Tag</string>
 | 
					 | 
				
			||||||
           </property>
 | 
					 | 
				
			||||||
          </widget>
 | 
					 | 
				
			||||||
         </item>
 | 
					 | 
				
			||||||
         <item>
 | 
					 | 
				
			||||||
          <widget class="QLineEdit" name="tagEdit"/>
 | 
					 | 
				
			||||||
         </item>
 | 
					 | 
				
			||||||
        </layout>
 | 
					 | 
				
			||||||
       </widget>
 | 
					 | 
				
			||||||
      </item>
 | 
					 | 
				
			||||||
      <item>
 | 
					 | 
				
			||||||
       <widget class="QWidget" name="ingredientSearchPanel" native="true">
 | 
					 | 
				
			||||||
        <layout class="QHBoxLayout" name="horizontalLayout_4">
 | 
					 | 
				
			||||||
         <item>
 | 
					 | 
				
			||||||
          <widget class="QLabel" name="ingredientLabel">
 | 
					 | 
				
			||||||
           <property name="text">
 | 
					 | 
				
			||||||
            <string>Ingredient</string>
 | 
					 | 
				
			||||||
           </property>
 | 
					 | 
				
			||||||
          </widget>
 | 
					 | 
				
			||||||
         </item>
 | 
					 | 
				
			||||||
         <item>
 | 
					 | 
				
			||||||
          <widget class="QLineEdit" name="ingredientEdit"/>
 | 
					 | 
				
			||||||
         </item>
 | 
					 | 
				
			||||||
        </layout>
 | 
					 | 
				
			||||||
       </widget>
 | 
					 | 
				
			||||||
      </item>
 | 
					 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QPushButton" name="searchButton">
 | 
					       <widget class="QPushButton" name="searchButton">
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
| 
						 | 
					@ -86,26 +124,26 @@
 | 
				
			||||||
     </layout>
 | 
					     </layout>
 | 
				
			||||||
    </widget>
 | 
					    </widget>
 | 
				
			||||||
   </item>
 | 
					   </item>
 | 
				
			||||||
   <item alignment="Qt::AlignLeft|Qt::AlignTop">
 | 
					 | 
				
			||||||
    <widget class="QWidget" name="interactionPanel" native="true">
 | 
					 | 
				
			||||||
     <layout class="QHBoxLayout" name="horizontalLayout_5">
 | 
					 | 
				
			||||||
      <item>
 | 
					 | 
				
			||||||
       <widget class="QPushButton" name="deleteRecipeButton">
 | 
					 | 
				
			||||||
        <property name="text">
 | 
					 | 
				
			||||||
         <string/>
 | 
					 | 
				
			||||||
        </property>
 | 
					 | 
				
			||||||
        <property name="icon">
 | 
					 | 
				
			||||||
         <iconset resource="../images.qrc">
 | 
					 | 
				
			||||||
          <normaloff>:/images/images/trash.png</normaloff>:/images/images/trash.png</iconset>
 | 
					 | 
				
			||||||
        </property>
 | 
					 | 
				
			||||||
       </widget>
 | 
					 | 
				
			||||||
      </item>
 | 
					 | 
				
			||||||
     </layout>
 | 
					 | 
				
			||||||
    </widget>
 | 
					 | 
				
			||||||
   </item>
 | 
					 | 
				
			||||||
   <item>
 | 
					   <item>
 | 
				
			||||||
    <widget class="QWidget" name="contentPanel" native="true">
 | 
					    <widget class="QWidget" name="contentPanel" native="true">
 | 
				
			||||||
     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
					     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
				
			||||||
 | 
					      <item alignment="Qt::AlignLeft">
 | 
				
			||||||
 | 
					       <widget class="QWidget" name="interactionPanel" native="true">
 | 
				
			||||||
 | 
					        <layout class="QHBoxLayout" name="horizontalLayout_5">
 | 
				
			||||||
 | 
					         <item>
 | 
				
			||||||
 | 
					          <widget class="QPushButton" name="deleteRecipeButton">
 | 
				
			||||||
 | 
					           <property name="text">
 | 
				
			||||||
 | 
					            <string/>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					           <property name="icon">
 | 
				
			||||||
 | 
					            <iconset resource="../images.qrc">
 | 
				
			||||||
 | 
					             <normaloff>:/images/images/trash.png</normaloff>:/images/images/trash.png</iconset>
 | 
				
			||||||
 | 
					           </property>
 | 
				
			||||||
 | 
					          </widget>
 | 
				
			||||||
 | 
					         </item>
 | 
				
			||||||
 | 
					        </layout>
 | 
				
			||||||
 | 
					       </widget>
 | 
				
			||||||
 | 
					      </item>
 | 
				
			||||||
      <item>
 | 
					      <item>
 | 
				
			||||||
       <widget class="QTableView" name="recipeTableView">
 | 
					       <widget class="QTableView" name="recipeTableView">
 | 
				
			||||||
        <property name="frameShape">
 | 
					        <property name="frameShape">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								main.cpp
								
								
								
								
							
							
						
						
									
										2
									
								
								main.cpp
								
								
								
								
							| 
						 | 
					@ -24,6 +24,8 @@ int main(int argc, char *argv[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	a.exec();
 | 
						a.exec();
 | 
				
			||||||
	recipeDB.closeConnection();
 | 
						recipeDB.closeConnection();
 | 
				
			||||||
 | 
						printf("Total queries: %lu\n", recipeDB.getQueryCount());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Database::Database(string filename){
 | 
					Database::Database(string filename){
 | 
				
			||||||
    this->filename = filename;
 | 
					    this->filename = filename;
 | 
				
			||||||
 | 
						this->queryCount = 0;
 | 
				
			||||||
    openConnection();
 | 
					    openConnection();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +23,7 @@ ResultTable Database::executeSQL(string statement){
 | 
				
			||||||
	t.extractData(stmt);
 | 
						t.extractData(stmt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->returnCode = sqlite3_finalize(stmt);
 | 
						this->returnCode = sqlite3_finalize(stmt);
 | 
				
			||||||
 | 
						this->queryCount++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return t;
 | 
						return t;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -99,6 +101,10 @@ bool Database::tableExists(string tableName){
 | 
				
			||||||
	return !t.isEmpty();
 | 
						return !t.isEmpty();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Database::getLastInsertedRowId(){
 | 
					int Database::getLastInsertedRowId() const{
 | 
				
			||||||
	return sqlite3_last_insert_rowid(this->db);
 | 
						return sqlite3_last_insert_rowid(this->db);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned long Database::getQueryCount() const{
 | 
				
			||||||
 | 
						return this->queryCount;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,9 @@ public:
 | 
				
			||||||
	bool deleteFrom(string tableName, string conditions);
 | 
						bool deleteFrom(string tableName, string conditions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool tableExists(string tableName);
 | 
						bool tableExists(string tableName);
 | 
				
			||||||
	int getLastInsertedRowId();
 | 
						int getLastInsertedRowId() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned long getQueryCount() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void closeConnection();
 | 
						void closeConnection();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,6 +47,9 @@ private:
 | 
				
			||||||
    string sql;
 | 
					    string sql;
 | 
				
			||||||
    char* errorMsg;
 | 
					    char* errorMsg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//Data tracking.
 | 
				
			||||||
 | 
						unsigned long queryCount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void openConnection();
 | 
					    void openConnection();
 | 
				
			||||||
	std::string combineVector(std::vector<std::string> strings, std::string mid);
 | 
						std::string combineVector(std::vector<std::string> strings, std::string mid);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,7 +234,7 @@ vector<RecipeTag> RecipeDatabase::retrieveTags(int recipeId){
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vector<RecipeTag> RecipeDatabase::retrieveAllTags(){
 | 
					vector<RecipeTag> RecipeDatabase::retrieveAllTags(){
 | 
				
			||||||
	ResultTable t = this->selectFrom("recipeTag", "tagName", "ORDER BY tagName");
 | 
						ResultTable t = this->executeSQL("SELECT DISTINCT tagName FROM recipeTag ORDER BY tagName;");
 | 
				
			||||||
	vector<RecipeTag> tags;
 | 
						vector<RecipeTag> tags;
 | 
				
			||||||
	if (!t.isEmpty()){
 | 
						if (!t.isEmpty()){
 | 
				
			||||||
		for (TableRow row : t.rows()){
 | 
							for (TableRow row : t.rows()){
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
#ifndef RECIPEDATABASE_H
 | 
					#ifndef RECIPEDATABASE_H
 | 
				
			||||||
#define RECIPEDATABASE_H
 | 
					#define RECIPEDATABASE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "database.h"
 | 
					#include "database.h"
 | 
				
			||||||
#include "model/recipe/recipe.h"
 | 
					#include "model/recipe/recipe.h"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,5 +23,9 @@ void Ingredient::setName(string newName){
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Ingredient::setFoodGroup(string newFoodGroup){
 | 
					void Ingredient::setFoodGroup(string newFoodGroup){
 | 
				
			||||||
    this->foodGroup = newFoodGroup;
 | 
						this->foodGroup = newFoodGroup;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					string Ingredient::toString(){
 | 
				
			||||||
 | 
						return this->getName();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,8 @@ public:
 | 
				
			||||||
    //Setters
 | 
					    //Setters
 | 
				
			||||||
    void setName(string newName);
 | 
					    void setName(string newName);
 | 
				
			||||||
    void setFoodGroup(string newFoodGroup);
 | 
					    void setFoodGroup(string newFoodGroup);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						string toString();
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
    string name;
 | 
					    string name;
 | 
				
			||||||
    string foodGroup;
 | 
					    string foodGroup;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
					#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IngredientListModel::IngredientListModel(){
 | 
					IngredientListModel::IngredientListModel(){
 | 
				
			||||||
    this->ingredients = vector<RecipeIngredient>();
 | 
						this->ingredients = vector<Ingredient>();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int IngredientListModel::rowCount(const QModelIndex &parent) const{
 | 
					int IngredientListModel::rowCount(const QModelIndex &parent) const{
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,7 @@ int IngredientListModel::rowCount(const QModelIndex &parent) const{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
 | 
					QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
 | 
				
			||||||
    int row = index.row();
 | 
					    int row = index.row();
 | 
				
			||||||
	RecipeIngredient i = this->ingredients[row];
 | 
						Ingredient i = this->ingredients[row];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	string displayStr = i.toString();
 | 
						string displayStr = i.toString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,14 +22,14 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
 | 
				
			||||||
    return QVariant();
 | 
					    return QVariant();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void IngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
 | 
					void IngredientListModel::setIngredients(vector<Ingredient> ingredients){
 | 
				
			||||||
    this->ingredients = ingredients;
 | 
					    this->ingredients = ingredients;
 | 
				
			||||||
    QModelIndex index = createIndex(0, 0);
 | 
					    QModelIndex index = createIndex(0, 0);
 | 
				
			||||||
    QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
 | 
					    QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
 | 
				
			||||||
	emit dataChanged(index, bottomIndex);
 | 
						emit dataChanged(index, bottomIndex);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool IngredientListModel::addIngredient(RecipeIngredient ri){
 | 
					bool IngredientListModel::addIngredient(Ingredient ri){
 | 
				
			||||||
	//Add only if it doesn't exist already.
 | 
						//Add only if it doesn't exist already.
 | 
				
			||||||
	for (unsigned int i = 0; i < this->ingredients.size(); i++){
 | 
						for (unsigned int i = 0; i < this->ingredients.size(); i++){
 | 
				
			||||||
		if (!this->ingredients[i].getName().compare(ri.getName())){
 | 
							if (!this->ingredients[i].getName().compare(ri.getName())){
 | 
				
			||||||
| 
						 | 
					@ -48,6 +48,6 @@ void IngredientListModel::deleteIngredient(int index){
 | 
				
			||||||
	emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0));
 | 
						emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vector<RecipeIngredient> IngredientListModel::getIngredients(){
 | 
					vector<Ingredient> IngredientListModel::getIngredients(){
 | 
				
			||||||
	return this->ingredients;
 | 
						return this->ingredients;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,13 +16,13 @@ public:
 | 
				
			||||||
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
 | 
					    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Custom methods to handle ingredient data.
 | 
					    //Custom methods to handle ingredient data.
 | 
				
			||||||
    void setIngredients(vector<RecipeIngredient> ingredients);
 | 
						void setIngredients(vector<Ingredient> ingredients);
 | 
				
			||||||
	bool addIngredient(RecipeIngredient ri);
 | 
						bool addIngredient(Ingredient ri);
 | 
				
			||||||
	void deleteIngredient(int index);
 | 
						void deleteIngredient(int index);
 | 
				
			||||||
	vector<RecipeIngredient> getIngredients();
 | 
						vector<Ingredient> getIngredients();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    vector<RecipeIngredient> ingredients;
 | 
						vector<Ingredient> ingredients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Helper for printing.
 | 
						//Helper for printing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,10 @@ RecipeIngredient::RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure u
 | 
				
			||||||
	setComment(comment);
 | 
						setComment(comment);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RecipeIngredient::RecipeIngredient(Ingredient &i) : RecipeIngredient(i, 0.0f, UnitOfMeasure("bleh"), "Fuck"){
 | 
				
			||||||
 | 
						//Constructs recipe ingredient from ingredient which is a hidden recipe ingredient.
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RecipeIngredient::RecipeIngredient(){
 | 
					RecipeIngredient::RecipeIngredient(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,7 @@ public:
 | 
				
			||||||
	RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit, string comment);
 | 
						RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit, string comment);
 | 
				
			||||||
    //Constructor using data from a child ingredient.
 | 
					    //Constructor using data from a child ingredient.
 | 
				
			||||||
	RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit, string comment);
 | 
						RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit, string comment);
 | 
				
			||||||
 | 
						RecipeIngredient(Ingredient &i);
 | 
				
			||||||
	RecipeIngredient();
 | 
						RecipeIngredient();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Getters
 | 
					    //Getters
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,53 @@
 | 
				
			||||||
 | 
					#include "recipeingredientlistmodel.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RecipeIngredientListModel::RecipeIngredientListModel(){
 | 
				
			||||||
 | 
						this->ingredients = vector<RecipeIngredient>();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int RecipeIngredientListModel::rowCount(const QModelIndex &parent) const{
 | 
				
			||||||
 | 
						return this->ingredients.size();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QVariant RecipeIngredientListModel::data(const QModelIndex &index, int role) const{
 | 
				
			||||||
 | 
						int row = index.row();
 | 
				
			||||||
 | 
						RecipeIngredient i = this->ingredients[row];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						string displayStr = i.toString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch(role){
 | 
				
			||||||
 | 
						case Qt::DisplayRole:
 | 
				
			||||||
 | 
							return QString::fromStdString(displayStr);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return QVariant();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void RecipeIngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
 | 
				
			||||||
 | 
						this->ingredients = ingredients;
 | 
				
			||||||
 | 
						QModelIndex index = createIndex(0, 0);
 | 
				
			||||||
 | 
						QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
 | 
				
			||||||
 | 
						emit dataChanged(index, bottomIndex);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool RecipeIngredientListModel::addIngredient(RecipeIngredient ri){
 | 
				
			||||||
 | 
						//Add only if it doesn't exist already.
 | 
				
			||||||
 | 
						for (unsigned int i = 0; i < this->ingredients.size(); i++){
 | 
				
			||||||
 | 
							if (!this->ingredients[i].getName().compare(ri.getName())){
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						this->ingredients.push_back(ri);
 | 
				
			||||||
 | 
						QModelIndex index = createIndex(this->ingredients.size()-1, 0);
 | 
				
			||||||
 | 
						QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0);
 | 
				
			||||||
 | 
						emit dataChanged(index, bottomIndex);
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void RecipeIngredientListModel::deleteIngredient(int index){
 | 
				
			||||||
 | 
						this->ingredients.erase(this->ingredients.begin() + index);
 | 
				
			||||||
 | 
						emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vector<RecipeIngredient> RecipeIngredientListModel::getIngredients(){
 | 
				
			||||||
 | 
						return this->ingredients;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,28 @@
 | 
				
			||||||
 | 
					#ifndef RECIPEINGREDIENTLISTMODEL_H
 | 
				
			||||||
 | 
					#define RECIPEINGREDIENTLISTMODEL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QAbstractListModel>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "model/recipe/ingredients/recipeingredient.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RecipeIngredientListModel : public QAbstractListModel
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						public:
 | 
				
			||||||
 | 
							RecipeIngredientListModel();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Overridden methods.
 | 
				
			||||||
 | 
							int rowCount(const QModelIndex &parent = QModelIndex()) const override;
 | 
				
			||||||
 | 
							QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Custom methods to handle ingredient data.
 | 
				
			||||||
 | 
							void setIngredients(vector<RecipeIngredient> ingredients);
 | 
				
			||||||
 | 
							bool addIngredient(RecipeIngredient ri);
 | 
				
			||||||
 | 
							void deleteIngredient(int index);
 | 
				
			||||||
 | 
							vector<RecipeIngredient> getIngredients();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private:
 | 
				
			||||||
 | 
							vector<RecipeIngredient> ingredients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // RECIPEINGREDIENTLISTMODEL_H
 | 
				
			||||||
		Loading…
	
		Reference in New Issue