Added icons to add and delete buttons, fixed out of bounds error on deletion.
This commit is contained in:
parent
4f78b37460
commit
b4ce47aad5
|
@ -138,7 +138,31 @@ void NewRecipeDialog::on_newIngredientButton_clicked(){
|
|||
}
|
||||
|
||||
void NewRecipeDialog::on_newTagButton_clicked(){
|
||||
newTagDialog
|
||||
NewTagDialog d(this);
|
||||
d.show();
|
||||
if (d.exec() == QDialog::Accepted){
|
||||
RecipeTag tag = d.getTag();
|
||||
//Temporarily add this to the tags list, and it will be saved if the recipe is saved.
|
||||
this->tags.push_back(tag);
|
||||
ui->tagsComboBox->clear();
|
||||
for (unsigned int i = 0; i < this->tags.size(); i++){
|
||||
QString s = QString::fromStdString(this->tags[i].getValue());
|
||||
ui->tagsComboBox->insertItem(i, s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NewRecipeDialog::on_removeTagButton_clicked(){
|
||||
int index = ui->tagsComboBox->currentIndex();
|
||||
if (index < 0 || index >= this->tags.size()){
|
||||
return;
|
||||
}
|
||||
RecipeTag tag = this->tags[ui->tagsComboBox->currentIndex()];
|
||||
string content = "Are you sure you wish to delete the following tag:\n"+tag.getValue();
|
||||
QMessageBox::StandardButton reply = QMessageBox::question(this, QString("Delete Tag"), QString(content.c_str()));
|
||||
if (reply == QMessageBox::Yes){
|
||||
this->recipeDB->deleteTag(tag);
|
||||
this->populateTagsBox();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QTextCharFormat>
|
||||
#include <QFileDialog>
|
||||
#include <QPixmap>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "model/database/recipedatabase.h"
|
||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||
|
@ -51,6 +52,8 @@ class NewRecipeDialog : public QDialog
|
|||
|
||||
void on_newTagButton_clicked();
|
||||
|
||||
void on_removeTagButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::NewRecipeDialog *ui;
|
||||
RecipeDatabase *recipeDB;
|
||||
|
|
|
@ -279,12 +279,34 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="tagsComboBox"/>
|
||||
<widget class="QComboBox" name="tagsComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="newTagButton">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
<property name="toolTip">
|
||||
<string>Create a new tag</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/images/plus_icon.png</normaloff>:/images/images/plus_icon.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="removeTagButton">
|
||||
<property name="toolTip">
|
||||
<string>Permanently delete this tag</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/images/minus_icon.png</normaloff>:/images/images/minus_icon.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -460,6 +482,9 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="currentText">
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -467,8 +492,12 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newIngredientButton">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
<property name="toolTip">
|
||||
<string>Create a new ingredient</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/images/plus_icon.png</normaloff>:/images/images/plus_icon.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -532,12 +561,20 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="unitComboBox"/>
|
||||
<widget class="QComboBox" name="unitComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="newUnitButton">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/images/plus_icon.png</normaloff>:/images/images/plus_icon.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
<qresource prefix="/images">
|
||||
<file>images/no_image.png</file>
|
||||
<file>images/icon.png</file>
|
||||
<file>images/plus_icon.png</file>
|
||||
<file>images/minus_icon.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 480 B |
Binary file not shown.
After Width: | Height: | Size: 912 B |
|
@ -223,6 +223,10 @@ vector<RecipeTag> RecipeDatabase::retrieveAllTags(){
|
|||
return tags;
|
||||
}
|
||||
|
||||
void RecipeDatabase::deleteTag(RecipeTag tag){
|
||||
ResultTable t = this->executeSQL("DELETE FROM recipeTag WHERE tagName="+surroundString(tag.getValue(), "'"));
|
||||
}
|
||||
|
||||
void RecipeDatabase::ensureTablesExist(){
|
||||
//Make sure that foreign keys are enabled.
|
||||
this->executeSQL("PRAGMA foreign_keys = ON;");
|
||||
|
|
|
@ -37,6 +37,9 @@ class RecipeDatabase : public Database
|
|||
vector<UnitOfMeasure> retrieveAllUnitsOfMeasure();
|
||||
vector<RecipeTag> retrieveTags(int recipeId);
|
||||
vector<RecipeTag> retrieveAllTags();
|
||||
|
||||
//Deletion.
|
||||
void deleteTag(RecipeTag tag);
|
||||
private:
|
||||
|
||||
//Utility methods.
|
||||
|
|
Loading…
Reference in New Issue