First ability to create recipe in gui #5

Merged
andrewlalis merged 6 commits from development into master 2018-03-10 15:03:09 +00:00
15 changed files with 381 additions and 5 deletions
Showing only changes of commit 4f78b37460 - Show all commits

View File

@ -27,7 +27,9 @@ SOURCES += model/recipe/instruction.cpp \
model/database/recipedatabase.cpp \ model/database/recipedatabase.cpp \
utils/fileutils.cpp \ utils/fileutils.cpp \
gui/newrecipedialog.cpp \ gui/newrecipedialog.cpp \
model/recipe/tags/taglistmodel.cpp model/recipe/tags/taglistmodel.cpp \
gui/newDialogs/newingredientdialog.cpp \
gui/newDialogs/newtagdialog.cpp
HEADERS += model/recipe/instruction.h \ HEADERS += model/recipe/instruction.h \
model/recipe/recipe.h \ model/recipe/recipe.h \
@ -44,12 +46,16 @@ HEADERS += model/recipe/instruction.h \
model/database/recipedatabase.h \ model/database/recipedatabase.h \
utils/fileutils.h \ utils/fileutils.h \
gui/newrecipedialog.h \ gui/newrecipedialog.h \
model/recipe/tags/taglistmodel.h model/recipe/tags/taglistmodel.h \
gui/newDialogs/newingredientdialog.h \
gui/newDialogs/newtagdialog.h
LIBS += -ldl \ LIBS += -ldl \
FORMS += gui/mainwindow.ui \ FORMS += gui/mainwindow.ui \
gui/newrecipedialog.ui gui/newrecipedialog.ui \
gui/newDialogs/newingredientdialog.ui \
gui/newDialogs/newtagdialog.ui
DISTFILES += \ DISTFILES += \
.gitignore .gitignore

View File

@ -25,6 +25,10 @@
<property name="windowTitle"> <property name="windowTitle">
<string>RecipeDB</string> <string>RecipeDB</string>
</property> </property>
<property name="windowIcon">
<iconset resource="../images.qrc">
<normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
</property>
<property name="windowOpacity"> <property name="windowOpacity">
<double>1.000000000000000</double> <double>1.000000000000000</double>
</property> </property>
@ -556,6 +560,8 @@ p, li { white-space: pre-wrap; }
</widget> </widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources>
<include location="../images.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -0,0 +1,18 @@
#include "newingredientdialog.h"
#include "ui_newingredientdialog.h"
NewIngredientDialog::NewIngredientDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewIngredientDialog)
{
ui->setupUi(this);
}
NewIngredientDialog::~NewIngredientDialog()
{
delete ui;
}
Ingredient NewIngredientDialog::getIngredient(){
return Ingredient(ui->nameEdit->text().toLower().toStdString(), ui->foodGroupEdit->text().toLower().toStdString());
}

View File

@ -0,0 +1,26 @@
#ifndef NEWINGREDIENTDIALOG_H
#define NEWINGREDIENTDIALOG_H
#include <QDialog>
#include "model/recipe/ingredients/ingredient.h"
namespace Ui {
class NewIngredientDialog;
}
class NewIngredientDialog : public QDialog
{
Q_OBJECT
public:
explicit NewIngredientDialog(QWidget *parent = 0);
~NewIngredientDialog();
//Access values.
Ingredient getIngredient();
private:
Ui::NewIngredientDialog *ui;
};
#endif // NEWINGREDIENTDIALOG_H

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewIngredientDialog</class>
<widget class="QDialog" name="NewIngredientDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>240</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>New Ingredient</string>
</property>
<property name="windowIcon">
<iconset resource="../../images.qrc">
<normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="mainContentPanel" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item alignment="Qt::AlignTop">
<widget class="QWidget" name="namePanel" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="nameEdit"/>
</item>
</layout>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QWidget" name="foodGroupPanel" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="foodGroupLabel">
<property name="text">
<string>Food Group</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="foodGroupEdit"/>
</item>
</layout>
</widget>
</item>
</layout>
</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>NewIngredientDialog</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>NewIngredientDialog</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>

View File

@ -0,0 +1,18 @@
#include "newtagdialog.h"
#include "ui_newtagdialog.h"
NewTagDialog::NewTagDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::newTagDialog)
{
ui->setupUi(this);
}
NewTagDialog::~NewTagDialog()
{
delete ui;
}
RecipeTag NewTagDialog::getTag(){
return RecipeTag(ui->tagEdit->text().toLower().toStdString());
}

View File

@ -0,0 +1,26 @@
#ifndef NEWTAGDIALOG_H
#define NEWTAGDIALOG_H
#include <QDialog>
#include "model/recipe/tags/recipetag.h"
namespace Ui {
class newTagDialog;
}
class NewTagDialog : public QDialog
{
Q_OBJECT
public:
explicit NewTagDialog(QWidget *parent = 0);
~NewTagDialog();
//Access values
RecipeTag getTag();
private:
Ui::newTagDialog *ui;
};
#endif // NEWTAGDIALOG_H

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>newTagDialog</class>
<widget class="QDialog" name="newTagDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>240</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset resource="../../images.qrc">
<normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item alignment="Qt::AlignTop">
<widget class="QWidget" name="tagEditWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="tagLabel">
<property name="text">
<string>New Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="tagEdit"/>
</item>
</layout>
</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>newTagDialog</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>newTagDialog</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>

View File

@ -118,3 +118,27 @@ void NewRecipeDialog::on_selectImageButton_clicked(){
ui->imageDisplayLabel->setPixmap(QPixmap(filename)); ui->imageDisplayLabel->setPixmap(QPixmap(filename));
} }
} }
void NewRecipeDialog::on_deleteIngredientButton_clicked(){
QModelIndexList indexList = ui->ingredientsListView->selectionModel()->selectedIndexes();
for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){
QModelIndex i = *it;
this->ingredientListModel.deleteIngredient(i.row());
}
}
void NewRecipeDialog::on_newIngredientButton_clicked(){
NewIngredientDialog d(this);
d.show();
if (d.exec() == QDialog::Accepted){
Ingredient i = d.getIngredient();
this->recipeDB->storeIngredient(i);
this->populateIngredientsBox();
}
}
void NewRecipeDialog::on_newTagButton_clicked(){
newTagDialog
d.show();
}

View File

@ -10,6 +10,9 @@
#include "model/recipe/ingredients/ingredientlistmodel.h" #include "model/recipe/ingredients/ingredientlistmodel.h"
#include "model/recipe/tags/taglistmodel.h" #include "model/recipe/tags/taglistmodel.h"
#include "gui/newDialogs/newingredientdialog.h"
#include "gui/newDialogs/newtagdialog.h"
namespace Ui { namespace Ui {
class NewRecipeDialog; class NewRecipeDialog;
} }
@ -42,6 +45,12 @@ class NewRecipeDialog : public QDialog
void on_selectImageButton_clicked(); void on_selectImageButton_clicked();
void on_deleteIngredientButton_clicked();
void on_newIngredientButton_clicked();
void on_newTagButton_clicked();
private: private:
Ui::NewRecipeDialog *ui; Ui::NewRecipeDialog *ui;
RecipeDatabase *recipeDB; RecipeDatabase *recipeDB;

View File

@ -22,6 +22,13 @@
<property name="windowTitle"> <property name="windowTitle">
<string>New Recipe</string> <string>New Recipe</string>
</property> </property>
<property name="windowIcon">
<iconset resource="../images.qrc">
<normaloff>:/images/images/icon.png</normaloff>:/images/images/icon.png</iconset>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
@ -327,6 +334,9 @@
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -599,6 +609,9 @@
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="batchSize"> <property name="batchSize">
<number>100</number> <number>100</number>
</property> </property>
@ -610,7 +623,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item alignment="Qt::AlignTop"> <item>
<widget class="QWidget" name="imagePanel" native="true"> <widget class="QWidget" name="imagePanel" native="true">
<layout class="QVBoxLayout" name="verticalLayout_13"> <layout class="QVBoxLayout" name="verticalLayout_13">
<property name="spacing"> <property name="spacing">
@ -665,6 +678,9 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="instructionsPanel" native="true"> <widget class="QWidget" name="instructionsPanel" native="true">
<property name="styleSheet">
<string notr="true">background-color: rgb(250, 250, 255);</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8"> <layout class="QVBoxLayout" name="verticalLayout_8">
<item> <item>
<widget class="QLabel" name="instructionsLabel"> <widget class="QLabel" name="instructionsLabel">
@ -728,6 +744,12 @@
</item> </item>
<item> <item>
<widget class="QTextEdit" name="instructionsTextEdit"> <widget class="QTextEdit" name="instructionsTextEdit">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="placeholderText"> <property name="placeholderText">
<string>Enter instructions here.</string> <string>Enter instructions here.</string>
</property> </property>
@ -741,9 +763,15 @@
<property name="layoutDirection"> <property name="layoutDirection">
<enum>Qt::LeftToRight</enum> <enum>Qt::LeftToRight</enum>
</property> </property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="/images"> <qresource prefix="/images">
<file>images/no_image.png</file> <file>images/no_image.png</file>
<file>images/icon.png</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
images/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

View File

@ -55,6 +55,7 @@ bool IngredientListModel::addIngredient(RecipeIngredient ri){
void IngredientListModel::deleteIngredient(int index){ void IngredientListModel::deleteIngredient(int index){
this->ingredients.erase(this->ingredients.begin() + index); this->ingredients.erase(this->ingredients.begin() + index);
emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0));
} }
vector<RecipeIngredient> IngredientListModel::getIngredients(){ vector<RecipeIngredient> IngredientListModel::getIngredients(){

View File

@ -41,6 +41,7 @@ bool TagListModel::addTag(RecipeTag tag){
void TagListModel::deleteTag(int index){ void TagListModel::deleteTag(int index){
this->tags.erase(this->tags.begin() + index); this->tags.erase(this->tags.begin() + index);
emit dataChanged(createIndex(0, 0), createIndex(this->tags.size()-1, 0));
} }
vector<RecipeTag> TagListModel::getTags(){ vector<RecipeTag> TagListModel::getTags(){