2
* MiscDialog.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 "MiscDialog.h"
26
#include "observable.h"
29
#include "MainWindow.h"
31
#include "MiscEditor.h"
33
MiscDialog::MiscDialog(MainWindow* parent)
40
miscEdit = new MiscEditor(this);
42
connect( pushButton_addToRecipe, SIGNAL( clicked() ), this, SLOT( addMisc() ) );
43
connect( pushButton_new, SIGNAL(clicked()), this, SLOT( newMisc() ) );
44
connect( pushButton_edit, SIGNAL(clicked()), this, SLOT(editSelected()) );
45
connect( pushButton_remove, SIGNAL(clicked()), this, SLOT(removeMisc()) );
48
void MiscDialog::removeMisc()
50
QModelIndexList selected = miscTableWidget->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
Misc* m = miscTableWidget->getModel()->getMisc(row);
69
void MiscDialog::notify(Observable *notifier, QVariant info)
71
if( notifier != dbObs || (info.toInt() != DBMISC && info.toInt() != DBALL) )
74
miscTableWidget->getModel()->removeAll();
78
void MiscDialog::startObservingDB()
80
dbObs = Database::getDatabase();
85
void MiscDialog::populateTable()
87
std::list<Misc*>::iterator it, end;
89
if( ! Database::isInitialized() )
92
numMiscs = dbObs->getNumMiscs();
93
end = dbObs->getMiscEnd();
94
for( it = dbObs->getMiscBegin(); it != end; ++it )
95
miscTableWidget->getModel()->addMisc(*it);
98
void MiscDialog::addMisc()
100
QModelIndexList selected = miscTableWidget->selectedIndexes();
103
size = selected.size();
107
// Make sure only one row is selected.
108
row = selected[0].row();
109
for( i = 1; i < size; ++i )
111
if( selected[i].row() != row )
115
Misc *misc = miscTableWidget->getModel()->getMisc(row);
116
mainWindow->addMiscToRecipe(new Misc(*misc) ); // Need to add a copy so we don't change the database.
119
void MiscDialog::editSelected()
121
QModelIndexList selected = miscTableWidget->selectedIndexes();
124
size = selected.size();
128
// Make sure only one row is selected.
129
row = selected[0].row();
130
for( i = 1; i < size; ++i )
132
if( selected[i].row() != row )
136
Misc* m = miscTableWidget->getModel()->getMisc(row);
137
miscEdit->setMisc(m);
141
void MiscDialog::newMisc()
143
QString name = QInputDialog::getText(this, tr("Misc name"),
148
Misc *m = new Misc();
149
std::string stdname = name.toStdString();
153
miscEdit->setMisc(m);