2
* RecipeComboBox.cpp is part of Brewtarget, and is Copyright Philip G. Lee
3
* (rocketman768@gmail.com), 2009.
5
* Brewtarget is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Brewtarget is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include "RecipeComboBox.h"
29
RecipeComboBox::RecipeComboBox(QWidget* parent)
34
void RecipeComboBox::startObservingDB()
36
if( Database::isInitialized() )
38
dbObs = Database::getDatabase();
41
std::list<Recipe*>::iterator it, end;
43
end = dbObs->getRecipeEnd();
45
for( it = dbObs->getRecipeBegin(); it != end; ++it )
51
void RecipeComboBox::addRecipe(Recipe* recipe)
53
recipeObs.push_back(recipe);
56
addItem( tr(recipe->getName().c_str()) );
59
void RecipeComboBox::removeAllRecipes()
62
for( i = 0; i < recipeObs.size(); ++i )
63
removeObserved(recipeObs[i]);
64
recipeObs.clear(); // Clear internal list.
65
clear(); // Clear the combo box's visible list.
68
void RecipeComboBox::notify(Observable *notifier, QVariant info)
72
// Notifier could be the database. Only pay attention if the number of
73
// recipes has changed.
74
if( notifier == dbObs && (info.toInt() == DBRECIPE || info.toInt() == DBALL) )
77
std::list<Recipe*>::iterator it, end;
79
end = dbObs->getRecipeEnd();
81
for( it = dbObs->getRecipeBegin(); it != end; ++it )
85
else // Otherwise, we know that one of the recipes changed.
87
size = recipeObs.size();
88
for( i = 0; i < size; ++i )
89
if( notifier == recipeObs[i] )
91
// Notice we assume 'i' is an index into both 'recipeObs' and also
92
// to the text list in this combo box...
93
setItemText(i, tr(recipeObs[i]->getName().c_str()));
98
void RecipeComboBox::setIndexByRecipeName(std::string name)
102
ndx = findText( tr(name.c_str()), Qt::MatchExactly );
104
setCurrentIndex(ndx);
107
void RecipeComboBox::setIndex(int ndx)
109
setCurrentIndex(ndx);
112
void RecipeComboBox::repopulateList()
114
unsigned int i, size;
117
size = recipeObs.size();
118
for( i = 0; i < size; ++i )
119
addItem( tr(recipeObs[i]->getName().c_str()) );
122
Recipe* RecipeComboBox::getSelectedRecipe()
124
if( currentIndex() >= 0 )
125
return recipeObs[currentIndex()];