First ability to create recipe in gui #5
			
				
			
		
		
		
	| 
						 | 
					@ -29,12 +29,13 @@ Recipe NewRecipeDialog::getRecipe(){
 | 
				
			||||||
	Recipe r(ui->recipeNameEdit->text().toStdString(),
 | 
						Recipe r(ui->recipeNameEdit->text().toStdString(),
 | 
				
			||||||
			 this->ingredientListModel.getIngredients(),
 | 
								 this->ingredientListModel.getIngredients(),
 | 
				
			||||||
			 ui->instructionsTextEdit->toHtml().toStdString(),
 | 
								 ui->instructionsTextEdit->toHtml().toStdString(),
 | 
				
			||||||
			 QImage(),//Image
 | 
								 this->img,//Image
 | 
				
			||||||
			 this->tagsListModel.getTags(),//Tags
 | 
								 this->tagsListModel.getTags(),//Tags
 | 
				
			||||||
			 QDate::currentDate(),
 | 
								 QDate::currentDate(),
 | 
				
			||||||
			 ui->prepTimeEdit->time(),
 | 
								 ui->prepTimeEdit->time(),
 | 
				
			||||||
			 ui->cookTimeEdit->time(),
 | 
								 ui->cookTimeEdit->time(),
 | 
				
			||||||
			 (float)ui->servingsSpinBox->value());
 | 
								 (float)ui->servingsSpinBox->value());
 | 
				
			||||||
 | 
						return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool NewRecipeDialog::isAccepted() const{
 | 
					bool NewRecipeDialog::isAccepted() const{
 | 
				
			||||||
| 
						 | 
					@ -103,9 +104,17 @@ void NewRecipeDialog::on_addTagButton_clicked(){
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NewRecipeDialog::on_deleteTagButton_clicked(){
 | 
					void NewRecipeDialog::on_deleteTagButton_clicked(){
 | 
				
			||||||
	QModelIndexList indexList = ui->tagsListView->selectedIndexes();
 | 
						QModelIndexList indexList = ui->tagsListView->selectionModel()->selectedIndexes();
 | 
				
			||||||
	for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){
 | 
						for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){
 | 
				
			||||||
		QModelIndex i = *it;
 | 
							QModelIndex i = *it;
 | 
				
			||||||
		this->tagsListModel.deleteTag(i.row());
 | 
							this->tagsListModel.deleteTag(i.row());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void NewRecipeDialog::on_selectImageButton_clicked(){
 | 
				
			||||||
 | 
						QString filename = QFileDialog::getOpenFileName(this, "Open Image", QString(), "Image Files (*.png *.jpg *.bmp)");
 | 
				
			||||||
 | 
						if (!filename.isEmpty()){
 | 
				
			||||||
 | 
							this->img = QImage(filename);
 | 
				
			||||||
 | 
							ui->imageDisplayLabel->setPixmap(QPixmap(filename));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDialog>
 | 
					#include <QDialog>
 | 
				
			||||||
#include <QTextCharFormat>
 | 
					#include <QTextCharFormat>
 | 
				
			||||||
 | 
					#include <QFileDialog>
 | 
				
			||||||
 | 
					#include <QPixmap>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "model/database/recipedatabase.h"
 | 
					#include "model/database/recipedatabase.h"
 | 
				
			||||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
					#include "model/recipe/ingredients/ingredientlistmodel.h"
 | 
				
			||||||
| 
						 | 
					@ -36,6 +38,10 @@ class NewRecipeDialog : public QDialog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void on_addTagButton_clicked();
 | 
							void on_addTagButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_deleteTagButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_selectImageButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		Ui::NewRecipeDialog *ui;
 | 
							Ui::NewRecipeDialog *ui;
 | 
				
			||||||
		RecipeDatabase *recipeDB;
 | 
							RecipeDatabase *recipeDB;
 | 
				
			||||||
| 
						 | 
					@ -44,6 +50,7 @@ class NewRecipeDialog : public QDialog
 | 
				
			||||||
		vector<RecipeTag> tags;
 | 
							vector<RecipeTag> tags;
 | 
				
			||||||
		IngredientListModel ingredientListModel;
 | 
							IngredientListModel ingredientListModel;
 | 
				
			||||||
		TagListModel tagsListModel;
 | 
							TagListModel tagsListModel;
 | 
				
			||||||
 | 
							QImage img;
 | 
				
			||||||
		bool accepted = false;
 | 
							bool accepted = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Helper functions to fill fields.
 | 
							//Helper functions to fill fields.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -630,9 +630,18 @@
 | 
				
			||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
            <item>
 | 
					            <item>
 | 
				
			||||||
             <widget class="QLabel" name="imageDisplayLabel">
 | 
					             <widget class="QLabel" name="imageDisplayLabel">
 | 
				
			||||||
 | 
					              <property name="maximumSize">
 | 
				
			||||||
 | 
					               <size>
 | 
				
			||||||
 | 
					                <width>500</width>
 | 
				
			||||||
 | 
					                <height>500</height>
 | 
				
			||||||
 | 
					               </size>
 | 
				
			||||||
 | 
					              </property>
 | 
				
			||||||
              <property name="text">
 | 
					              <property name="text">
 | 
				
			||||||
               <string/>
 | 
					               <string/>
 | 
				
			||||||
              </property>
 | 
					              </property>
 | 
				
			||||||
 | 
					              <property name="pixmap">
 | 
				
			||||||
 | 
					               <pixmap resource="../images.qrc">:/images/images/no_image.png</pixmap>
 | 
				
			||||||
 | 
					              </property>
 | 
				
			||||||
              <property name="scaledContents">
 | 
					              <property name="scaledContents">
 | 
				
			||||||
               <bool>true</bool>
 | 
					               <bool>true</bool>
 | 
				
			||||||
              </property>
 | 
					              </property>
 | 
				
			||||||
| 
						 | 
					@ -641,6 +650,13 @@
 | 
				
			||||||
              </property>
 | 
					              </property>
 | 
				
			||||||
             </widget>
 | 
					             </widget>
 | 
				
			||||||
            </item>
 | 
					            </item>
 | 
				
			||||||
 | 
					            <item>
 | 
				
			||||||
 | 
					             <widget class="QPushButton" name="selectImageButton">
 | 
				
			||||||
 | 
					              <property name="text">
 | 
				
			||||||
 | 
					               <string>Select Image...</string>
 | 
				
			||||||
 | 
					              </property>
 | 
				
			||||||
 | 
					             </widget>
 | 
				
			||||||
 | 
					            </item>
 | 
				
			||||||
           </layout>
 | 
					           </layout>
 | 
				
			||||||
          </widget>
 | 
					          </widget>
 | 
				
			||||||
         </item>
 | 
					         </item>
 | 
				
			||||||
| 
						 | 
					@ -735,6 +751,8 @@
 | 
				
			||||||
   </item>
 | 
					   </item>
 | 
				
			||||||
  </layout>
 | 
					  </layout>
 | 
				
			||||||
 </widget>
 | 
					 </widget>
 | 
				
			||||||
 <resources/>
 | 
					 <resources>
 | 
				
			||||||
 | 
					  <include location="../images.qrc"/>
 | 
				
			||||||
 | 
					 </resources>
 | 
				
			||||||
 <connections/>
 | 
					 <connections/>
 | 
				
			||||||
</ui>
 | 
					</ui>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@ public:
 | 
				
			||||||
    //Custom methods to handle ingredient data.
 | 
					    //Custom methods to handle ingredient data.
 | 
				
			||||||
    void setIngredients(vector<RecipeIngredient> ingredients);
 | 
					    void setIngredients(vector<RecipeIngredient> ingredients);
 | 
				
			||||||
	bool addIngredient(RecipeIngredient ri);
 | 
						bool addIngredient(RecipeIngredient ri);
 | 
				
			||||||
 | 
						void deleteIngredient(int index);
 | 
				
			||||||
	vector<RecipeIngredient> getIngredients();
 | 
						vector<RecipeIngredient> getIngredients();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,7 @@ class TagListModel : public QAbstractListModel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void setTags(vector<RecipeTag> tags);
 | 
							void setTags(vector<RecipeTag> tags);
 | 
				
			||||||
		bool addTag(RecipeTag tag);
 | 
							bool addTag(RecipeTag tag);
 | 
				
			||||||
 | 
							void deleteTag(int index);
 | 
				
			||||||
		vector<RecipeTag> getTags();
 | 
							vector<RecipeTag> getTags();
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		vector<RecipeTag> tags;
 | 
							vector<RecipeTag> tags;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue