More security and less unexpected behaviour. #8
			
				
			
		
		
		
	
							
								
								
									
										11
									
								
								RecipeDB.pro
								
								
								
								
							
							
						
						
									
										11
									
								
								RecipeDB.pro
								
								
								
								
							| 
						 | 
				
			
			@ -34,7 +34,9 @@ SOURCES += model/recipe/instruction.cpp \
 | 
			
		|||
    utils/stringutils.cpp \
 | 
			
		||||
    gui/openrecipedialog.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 \
 | 
			
		||||
    model/recipe/recipe.h \
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +60,9 @@ HEADERS  += model/recipe/instruction.h \
 | 
			
		|||
    utils/stringutils.h \
 | 
			
		||||
    gui/openrecipedialog.h \
 | 
			
		||||
    model/recipe/recipetablemodel.h \
 | 
			
		||||
    gui/mainwindow.h
 | 
			
		||||
    gui/mainwindow.h \
 | 
			
		||||
    gui/newDialogs/newfoodgroupdialog.h \
 | 
			
		||||
    model/recipe/ingredients/recipeingredientlistmodel.h
 | 
			
		||||
 | 
			
		||||
LIBS += -ldl \
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -68,7 +72,8 @@ FORMS    += gui/mainwindow.ui \
 | 
			
		|||
    gui/newDialogs/newtagdialog.ui \
 | 
			
		||||
    gui/newDialogs/newunitdialog.ui \
 | 
			
		||||
    gui/openrecipedialog.ui \
 | 
			
		||||
    gui/mainwindow.ui
 | 
			
		||||
    gui/mainwindow.ui \
 | 
			
		||||
    gui/newDialogs/newfoodgroupdialog.ui
 | 
			
		||||
 | 
			
		||||
DISTFILES += \
 | 
			
		||||
    .gitignore
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
#include <QAbstractListModel>
 | 
			
		||||
 | 
			
		||||
#include "model/recipe/recipe.h"
 | 
			
		||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
			
		||||
#include "model/recipe/ingredients/recipeingredientlistmodel.h"
 | 
			
		||||
#include "gui/newrecipedialog.h"
 | 
			
		||||
#include "gui/openrecipedialog.h"
 | 
			
		||||
#include "utils/stringutils.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +39,7 @@ public:
 | 
			
		|||
	private:
 | 
			
		||||
    Ui::MainWindow *ui;
 | 
			
		||||
	RecipeDatabase *recipeDB;
 | 
			
		||||
    IngredientListModel ingredientModel;
 | 
			
		||||
	RecipeIngredientListModel ingredientModel;
 | 
			
		||||
	TagListModel tagsListModel;
 | 
			
		||||
 | 
			
		||||
    //Hidden manipulation methods.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -604,6 +604,9 @@ font: "Noto Sans CJK KR";</string>
 | 
			
		|||
                  <property name="horizontalScrollBarPolicy">
 | 
			
		||||
                   <enum>Qt::ScrollBarAlwaysOff</enum>
 | 
			
		||||
                  </property>
 | 
			
		||||
                  <property name="editTriggers">
 | 
			
		||||
                   <set>QAbstractItemView::NoEditTriggers</set>
 | 
			
		||||
                  </property>
 | 
			
		||||
                  <property name="selectionMode">
 | 
			
		||||
                   <enum>QAbstractItemView::ExtendedSelection</enum>
 | 
			
		||||
                  </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(){
 | 
			
		||||
	vector<string> foodGroups = this->recipeDB->retrieveAllFoodGroups();
 | 
			
		||||
	printf("Found %ld food Groups.\n", foodGroups.size());
 | 
			
		||||
	ui->foodGroupBox->clear();
 | 
			
		||||
	for (unsigned int i = 0; i < foodGroups.size(); i++){
 | 
			
		||||
		QString s = QString::fromStdString(foodGroups[i]);
 | 
			
		||||
		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
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
#include "model/recipe/ingredients/ingredient.h"
 | 
			
		||||
#include "model/database/recipedatabase.h"
 | 
			
		||||
#include "gui/newDialogs/newfoodgroupdialog.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class NewIngredientDialog;
 | 
			
		||||
| 
						 | 
				
			
			@ -21,6 +24,11 @@ class NewIngredientDialog : public QDialog
 | 
			
		|||
		//Access values.
 | 
			
		||||
		Ingredient getIngredient();
 | 
			
		||||
 | 
			
		||||
	private slots:
 | 
			
		||||
		void on_addFoodGroupButton_clicked();
 | 
			
		||||
 | 
			
		||||
		void on_deleteFoodGroupButton_clicked();
 | 
			
		||||
 | 
			
		||||
	private:
 | 
			
		||||
		Ui::NewIngredientDialog *ui;
 | 
			
		||||
		RecipeDatabase *recipeDB;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,6 +70,9 @@
 | 
			
		|||
                <verstretch>0</verstretch>
 | 
			
		||||
               </sizepolicy>
 | 
			
		||||
              </property>
 | 
			
		||||
              <property name="insertPolicy">
 | 
			
		||||
               <enum>QComboBox::InsertAlphabetically</enum>
 | 
			
		||||
              </property>
 | 
			
		||||
             </widget>
 | 
			
		||||
            </item>
 | 
			
		||||
            <item alignment="Qt::AlignRight">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,16 +7,19 @@
 | 
			
		|||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>240</width>
 | 
			
		||||
    <height>320</height>
 | 
			
		||||
    <height>121</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Dialog</string>
 | 
			
		||||
   <string>New Tag</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowIcon">
 | 
			
		||||
   <iconset resource="../../images.qrc">
 | 
			
		||||
    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="styleSheet">
 | 
			
		||||
   <string notr="true">font: 25 "Noto Sans CJK KR Light";</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="modal">
 | 
			
		||||
   <bool>true</bool>
 | 
			
		||||
  </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -26,6 +29,14 @@
 | 
			
		|||
     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
			
		||||
      <item>
 | 
			
		||||
       <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">
 | 
			
		||||
         <string>New Tag</string>
 | 
			
		||||
        </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +46,16 @@
 | 
			
		|||
       </widget>
 | 
			
		||||
      </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>
 | 
			
		||||
     </layout>
 | 
			
		||||
    </widget>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,8 +6,8 @@
 | 
			
		|||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>240</width>
 | 
			
		||||
    <height>350</height>
 | 
			
		||||
    <width>195</width>
 | 
			
		||||
    <height>340</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +17,9 @@
 | 
			
		|||
   <iconset resource="../../images.qrc">
 | 
			
		||||
    <normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="styleSheet">
 | 
			
		||||
   <string notr="true">font: 25 "Noto Sans CJK KR Light";</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="modal">
 | 
			
		||||
   <bool>true</bool>
 | 
			
		||||
  </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -26,6 +29,14 @@
 | 
			
		|||
     <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
			
		||||
      <item>
 | 
			
		||||
       <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">
 | 
			
		||||
         <string>Unit Name</string>
 | 
			
		||||
        </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +50,14 @@
 | 
			
		|||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <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">
 | 
			
		||||
         <string>Plural Name</string>
 | 
			
		||||
        </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -52,6 +71,14 @@
 | 
			
		|||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <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">
 | 
			
		||||
         <string>Abbreviation</string>
 | 
			
		||||
        </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -86,6 +113,14 @@
 | 
			
		|||
             <verstretch>0</verstretch>
 | 
			
		||||
            </sizepolicy>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="font">
 | 
			
		||||
            <font>
 | 
			
		||||
             <pointsize>12</pointsize>
 | 
			
		||||
             <weight>3</weight>
 | 
			
		||||
             <italic>false</italic>
 | 
			
		||||
             <bold>false</bold>
 | 
			
		||||
            </font>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Type:</string>
 | 
			
		||||
           </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +144,14 @@
 | 
			
		|||
        <layout class="QVBoxLayout" name="verticalLayout_3">
 | 
			
		||||
         <item>
 | 
			
		||||
          <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">
 | 
			
		||||
            <string>Metric Coefficient</string>
 | 
			
		||||
           </property>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -199,8 +199,8 @@ void NewRecipeDialog::on_newUnitButton_clicked(){
 | 
			
		|||
	d.show();
 | 
			
		||||
	if (d.exec() == QDialog::Accepted){
 | 
			
		||||
		UnitOfMeasure u = d.getUnit();
 | 
			
		||||
		if (!this->recipeDB->storeUnitOfMeasure(u) || u.getName().empty() || u.getNamePlural().empty() || u.getAbbreviation().empty()){
 | 
			
		||||
			QMessageBox::critical(this, "Error", "Unable to store new unit.");
 | 
			
		||||
		if (u.getName().empty() || u.getNamePlural().empty() || u.getAbbreviation().empty() || !this->recipeDB->storeUnitOfMeasure(u)){
 | 
			
		||||
			QMessageBox::critical(this, "Error", "Unable to store new unit. Make sure all the information is filled in!");
 | 
			
		||||
		} else {
 | 
			
		||||
			this->populateUnitsBox();
 | 
			
		||||
			ui->unitComboBox->setCurrentText(QString::fromStdString(u.getName()));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@
 | 
			
		|||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
#include "model/database/recipedatabase.h"
 | 
			
		||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
			
		||||
#include "model/recipe/ingredients/recipeingredientlistmodel.h"
 | 
			
		||||
#include "model/recipe/tags/taglistmodel.h"
 | 
			
		||||
 | 
			
		||||
#include "gui/newDialogs/newingredientdialog.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +67,7 @@ class NewRecipeDialog : public QDialog
 | 
			
		|||
		vector<Ingredient> ingredients;
 | 
			
		||||
		vector<UnitOfMeasure> units;
 | 
			
		||||
		vector<RecipeTag> tags;
 | 
			
		||||
		IngredientListModel ingredientListModel;
 | 
			
		||||
		RecipeIngredientListModel ingredientListModel;
 | 
			
		||||
		TagListModel tagsListModel;
 | 
			
		||||
		QImage img;
 | 
			
		||||
		bool accepted = false;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -273,6 +273,12 @@
 | 
			
		|||
                   <verstretch>0</verstretch>
 | 
			
		||||
                  </sizepolicy>
 | 
			
		||||
                 </property>
 | 
			
		||||
                 <property name="styleSheet">
 | 
			
		||||
                  <string notr="true">background-color: rgb(113, 119, 255);</string>
 | 
			
		||||
                 </property>
 | 
			
		||||
                 <property name="insertPolicy">
 | 
			
		||||
                  <enum>QComboBox::InsertAlphabetically</enum>
 | 
			
		||||
                 </property>
 | 
			
		||||
                </widget>
 | 
			
		||||
               </item>
 | 
			
		||||
               <item alignment="Qt::AlignRight">
 | 
			
		||||
| 
						 | 
				
			
			@ -459,12 +465,21 @@
 | 
			
		|||
                         <verstretch>0</verstretch>
 | 
			
		||||
                        </sizepolicy>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="styleSheet">
 | 
			
		||||
                        <string notr="true">background-color: rgb(113, 119, 255);</string>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="editable">
 | 
			
		||||
                        <bool>false</bool>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="currentText">
 | 
			
		||||
                        <string/>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="insertPolicy">
 | 
			
		||||
                        <enum>QComboBox::InsertAlphabetically</enum>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="frame">
 | 
			
		||||
                        <bool>true</bool>
 | 
			
		||||
                       </property>
 | 
			
		||||
                      </widget>
 | 
			
		||||
                     </item>
 | 
			
		||||
                     <item>
 | 
			
		||||
| 
						 | 
				
			
			@ -554,6 +569,12 @@
 | 
			
		|||
                         <verstretch>0</verstretch>
 | 
			
		||||
                        </sizepolicy>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="styleSheet">
 | 
			
		||||
                        <string notr="true">background-color: rgb(113, 119, 255);</string>
 | 
			
		||||
                       </property>
 | 
			
		||||
                       <property name="insertPolicy">
 | 
			
		||||
                        <enum>QComboBox::InsertAlphabetically</enum>
 | 
			
		||||
                       </property>
 | 
			
		||||
                      </widget>
 | 
			
		||||
                     </item>
 | 
			
		||||
                     <item alignment="Qt::AlignRight">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,10 +8,14 @@ OpenRecipeDialog::OpenRecipeDialog(QWidget *parent) :
 | 
			
		|||
	ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
	ui->recipeTableView->setModel(&this->recipeTableModel);
 | 
			
		||||
	ui->ingredientsListView->setModel(&this->ingredientsModel);
 | 
			
		||||
	ui->tagsListView->setModel(&this->tagsModel);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
OpenRecipeDialog::OpenRecipeDialog(RecipeDatabase *recipeDB, QWidget *parent) : OpenRecipeDialog(parent){
 | 
			
		||||
	this->recipeDB = recipeDB;
 | 
			
		||||
	this->populateIngredientsList();
 | 
			
		||||
	this->populateTagsList();
 | 
			
		||||
	this->populateRecipesTable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +36,14 @@ void OpenRecipeDialog::populateRecipesTable(){
 | 
			
		|||
	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(){
 | 
			
		||||
	QItemSelectionModel *selectModel = ui->recipeTableView->selectionModel();
 | 
			
		||||
	if (!selectModel->hasSelection()){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,8 @@
 | 
			
		|||
 | 
			
		||||
#include "model/database/recipedatabase.h"
 | 
			
		||||
#include "model/recipe/recipetablemodel.h"
 | 
			
		||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
			
		||||
#include "model/recipe/tags/taglistmodel.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class OpenRecipeDialog;
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +35,12 @@ class OpenRecipeDialog : public QDialog
 | 
			
		|||
		RecipeTableModel recipeTableModel;
 | 
			
		||||
		Recipe selectedRecipe;
 | 
			
		||||
 | 
			
		||||
		IngredientListModel ingredientsModel;
 | 
			
		||||
		TagListModel tagsModel;
 | 
			
		||||
 | 
			
		||||
		void populateRecipesTable();
 | 
			
		||||
		void populateIngredientsList();
 | 
			
		||||
		void populateTagsList();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // OPENRECIPEDIALOG_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>640</width>
 | 
			
		||||
    <width>1000</width>
 | 
			
		||||
    <height>480</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
| 
						 | 
				
			
			@ -20,10 +20,80 @@
 | 
			
		|||
  <property name="modal">
 | 
			
		||||
   <bool>true</bool>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
   <item alignment="Qt::AlignTop">
 | 
			
		||||
  <layout class="QHBoxLayout" name="horizontalLayout_6">
 | 
			
		||||
   <item alignment="Qt::AlignLeft|Qt::AlignTop">
 | 
			
		||||
    <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>
 | 
			
		||||
       <widget class="QWidget" name="nameSearchPanel" native="true">
 | 
			
		||||
        <layout class="QHBoxLayout" name="horizontalLayout_2">
 | 
			
		||||
| 
						 | 
				
			
			@ -40,38 +110,6 @@
 | 
			
		|||
        </layout>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </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>
 | 
			
		||||
       <widget class="QPushButton" name="searchButton">
 | 
			
		||||
        <property name="text">
 | 
			
		||||
| 
						 | 
				
			
			@ -86,26 +124,26 @@
 | 
			
		|||
     </layout>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </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>
 | 
			
		||||
    <widget class="QWidget" name="contentPanel" native="true">
 | 
			
		||||
     <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>
 | 
			
		||||
       <widget class="QTableView" name="recipeTableView">
 | 
			
		||||
        <property name="frameShape">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								main.cpp
								
								
								
								
							
							
						
						
									
										2
									
								
								main.cpp
								
								
								
								
							| 
						 | 
				
			
			@ -24,6 +24,8 @@ int main(int argc, char *argv[])
 | 
			
		|||
 | 
			
		||||
	a.exec();
 | 
			
		||||
	recipeDB.closeConnection();
 | 
			
		||||
	printf("Total queries: %lu\n", recipeDB.getQueryCount());
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
 | 
			
		||||
Database::Database(string filename){
 | 
			
		||||
    this->filename = filename;
 | 
			
		||||
	this->queryCount = 0;
 | 
			
		||||
    openConnection();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +23,7 @@ ResultTable Database::executeSQL(string statement){
 | 
			
		|||
	t.extractData(stmt);
 | 
			
		||||
 | 
			
		||||
	this->returnCode = sqlite3_finalize(stmt);
 | 
			
		||||
	this->queryCount++;
 | 
			
		||||
 | 
			
		||||
	return t;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -99,6 +101,10 @@ bool Database::tableExists(string tableName){
 | 
			
		|||
	return !t.isEmpty();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Database::getLastInsertedRowId(){
 | 
			
		||||
int Database::getLastInsertedRowId() const{
 | 
			
		||||
	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 tableExists(string tableName);
 | 
			
		||||
	int getLastInsertedRowId();
 | 
			
		||||
	int getLastInsertedRowId() const;
 | 
			
		||||
 | 
			
		||||
	unsigned long getQueryCount() const;
 | 
			
		||||
 | 
			
		||||
	void closeConnection();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -45,6 +47,9 @@ private:
 | 
			
		|||
    string sql;
 | 
			
		||||
    char* errorMsg;
 | 
			
		||||
 | 
			
		||||
	//Data tracking.
 | 
			
		||||
	unsigned long queryCount;
 | 
			
		||||
 | 
			
		||||
    void openConnection();
 | 
			
		||||
	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(){
 | 
			
		||||
	ResultTable t = this->selectFrom("recipeTag", "tagName", "ORDER BY tagName");
 | 
			
		||||
	ResultTable t = this->executeSQL("SELECT DISTINCT tagName FROM recipeTag ORDER BY tagName;");
 | 
			
		||||
	vector<RecipeTag> tags;
 | 
			
		||||
	if (!t.isEmpty()){
 | 
			
		||||
		for (TableRow row : t.rows()){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
#ifndef RECIPEDATABASE_H
 | 
			
		||||
#define RECIPEDATABASE_H
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <map>
 | 
			
		||||
 | 
			
		||||
#include "database.h"
 | 
			
		||||
#include "model/recipe/recipe.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,5 +23,9 @@ void Ingredient::setName(string newName){
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void Ingredient::setFoodGroup(string newFoodGroup){
 | 
			
		||||
    this->foodGroup = newFoodGroup;
 | 
			
		||||
	this->foodGroup = newFoodGroup;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
string Ingredient::toString(){
 | 
			
		||||
	return this->getName();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,6 +23,8 @@ public:
 | 
			
		|||
    //Setters
 | 
			
		||||
    void setName(string newName);
 | 
			
		||||
    void setFoodGroup(string newFoodGroup);
 | 
			
		||||
 | 
			
		||||
	string toString();
 | 
			
		||||
protected:
 | 
			
		||||
    string name;
 | 
			
		||||
    string foodGroup;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
			
		||||
 | 
			
		||||
IngredientListModel::IngredientListModel(){
 | 
			
		||||
    this->ingredients = vector<RecipeIngredient>();
 | 
			
		||||
	this->ingredients = vector<Ingredient>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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{
 | 
			
		||||
    int row = index.row();
 | 
			
		||||
	RecipeIngredient i = this->ingredients[row];
 | 
			
		||||
	Ingredient i = this->ingredients[row];
 | 
			
		||||
 | 
			
		||||
	string displayStr = i.toString();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -22,14 +22,14 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
 | 
			
		|||
    return QVariant();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
 | 
			
		||||
void IngredientListModel::setIngredients(vector<Ingredient> ingredients){
 | 
			
		||||
    this->ingredients = ingredients;
 | 
			
		||||
    QModelIndex index = createIndex(0, 0);
 | 
			
		||||
    QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
 | 
			
		||||
	emit dataChanged(index, bottomIndex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool IngredientListModel::addIngredient(RecipeIngredient ri){
 | 
			
		||||
bool IngredientListModel::addIngredient(Ingredient 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())){
 | 
			
		||||
| 
						 | 
				
			
			@ -48,6 +48,6 @@ void IngredientListModel::deleteIngredient(int index){
 | 
			
		|||
	emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vector<RecipeIngredient> IngredientListModel::getIngredients(){
 | 
			
		||||
vector<Ingredient> IngredientListModel::getIngredients(){
 | 
			
		||||
	return this->ingredients;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,13 +16,13 @@ public:
 | 
			
		|||
    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 setIngredients(vector<Ingredient> ingredients);
 | 
			
		||||
	bool addIngredient(Ingredient ri);
 | 
			
		||||
	void deleteIngredient(int index);
 | 
			
		||||
	vector<RecipeIngredient> getIngredients();
 | 
			
		||||
	vector<Ingredient> getIngredients();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    vector<RecipeIngredient> ingredients;
 | 
			
		||||
	vector<Ingredient> ingredients;
 | 
			
		||||
 | 
			
		||||
	//Helper for printing.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,10 @@ RecipeIngredient::RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure u
 | 
			
		|||
	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(){
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,7 @@ public:
 | 
			
		|||
	RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit, string comment);
 | 
			
		||||
    //Constructor using data from a child ingredient.
 | 
			
		||||
	RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit, string comment);
 | 
			
		||||
	RecipeIngredient(Ingredient &i);
 | 
			
		||||
	RecipeIngredient();
 | 
			
		||||
 | 
			
		||||
    //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