2
* YeastDialog.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/>.
21
#include <QInputDialog>
25
#include "YeastDialog.h"
26
#include "observable.h"
29
#include "MainWindow.h"
31
#include "YeastEditor.h"
33
YeastDialog::YeastDialog(MainWindow* parent)
38
yeastEditor = new YeastEditor(this);
42
connect( pushButton_addToRecipe, SIGNAL( clicked() ), this, SLOT( addYeast() ) );
43
connect( pushButton_edit, SIGNAL( clicked() ), this, SLOT( editSelected() ) );
44
connect( pushButton_new, SIGNAL( clicked() ), this, SLOT( newYeast() ) );
45
connect( pushButton_remove, SIGNAL(clicked()), this, SLOT( removeYeast() ) );
48
void YeastDialog::removeYeast()
50
QModelIndexList selected = yeastTableWidget->selectedIndexes();
53
size = selected.size();
57
// Make sure only one row is selected.
58
row = selected[0].row();
59
for( i = 1; i < size; ++i )
61
if( selected[i].row() != row )
65
Yeast *yeast = yeastTableWidget->getModel()->getYeast(row);
66
dbObs->removeYeast(yeast);
69
void YeastDialog::notify(Observable *notifier, QVariant info)
71
if( notifier != dbObs || (info.toInt() != DBYEAST && info.toInt() != DBALL) )
74
yeastTableWidget->getModel()->removeAll();
79
void YeastDialog::startObservingDB()
81
dbObs = Database::getDatabase();
86
void YeastDialog::populateTable()
88
std::list<Yeast*>::iterator it, end;
90
if( ! Database::isInitialized() )
93
numYeasts = dbObs->getNumYeasts();
94
end = dbObs->getYeastEnd();
95
for( it = dbObs->getYeastBegin(); it != end; ++it )
96
yeastTableWidget->getModel()->addYeast(*it);
99
void YeastDialog::addYeast()
101
QModelIndexList selected = yeastTableWidget->selectedIndexes();
104
size = selected.size();
108
// Make sure only one row is selected.
109
row = selected[0].row();
110
for( i = 1; i < size; ++i )
112
if( selected[i].row() != row )
116
Yeast *yeast = yeastTableWidget->getModel()->getYeast(row);
117
mainWindow->addYeastToRecipe(new Yeast(*yeast) ); // Need to add a copy so we don't change the database.
120
void YeastDialog::editSelected()
122
QModelIndexList selected = yeastTableWidget->selectedIndexes();
125
size = selected.size();
129
// Make sure only one row is selected.
130
row = selected[0].row();
131
for( i = 1; i < size; ++i )
133
if( selected[i].row() != row )
137
Yeast *yeast = yeastTableWidget->getModel()->getYeast(row);
138
yeastEditor->setYeast(yeast);
142
void YeastDialog::newYeast()
144
QString name = QInputDialog::getText(this, tr("Yeast name"),
149
Yeast* y = new Yeast();
150
std::string stdname = name.toStdString();
154
yeastEditor->setYeast(y);