16 * You should have received a copy of the GNU General Public License |
16 * You should have received a copy of the GNU General Public License |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 */ |
18 */ |
19 |
19 |
20 |
20 |
21 void EditRecipe::refreshMiscs() |
21 bool EditRecipe::misc_sort_test(const Miscs &D1, const Miscs &D2) |
22 { |
22 { |
|
23 if (D1.m_use_use > D2.m_use_use) |
|
24 return false; |
|
25 if (D1.m_use_use < D2.m_use_use) |
|
26 return true; |
|
27 if (D1.m_type > D2.m_type) |
|
28 return false; |
|
29 if (D1.m_type < D2.m_type) |
|
30 return true; |
|
31 return (D1.m_amount > D2.m_amount); |
23 } |
32 } |
24 |
33 |
25 |
34 |
|
35 void EditRecipe::refreshMiscs() |
|
36 { |
|
37 QString w; |
|
38 QWidget* pWidget; |
|
39 QHBoxLayout* pLayout; |
|
40 QTableWidgetItem *item; |
|
41 |
|
42 qDebug() << "refreshMiscs" << recipe->miscs.size(); |
|
43 std::sort(recipe->miscs.begin(), recipe->miscs.end(), misc_sort_test); |
|
44 |
|
45 /* |
|
46 * During filling the table turn off the cellChanged signal because every cell that is filled |
|
47 * triggers the cellChanged signal. The QTableWidget has no better signal to use. |
|
48 */ |
|
49 this->ignoreChanges = true; |
|
50 |
|
51 const QStringList labels({tr("Ingredient"), tr("Type"), tr("Use at"), tr("Time"), tr("Amount"), tr("Delete"), tr("Edit") }); |
|
52 |
|
53 ui->miscsTable->setColumnCount(7); |
|
54 ui->miscsTable->setColumnWidth(0, 300); /* Ingredient */ |
|
55 ui->miscsTable->setColumnWidth(1, 100); /* Type */ |
|
56 ui->miscsTable->setColumnWidth(2, 100); /* Added */ |
|
57 ui->miscsTable->setColumnWidth(3, 75); /* Time */ |
|
58 ui->miscsTable->setColumnWidth(4, 90); /* Amount */ |
|
59 ui->miscsTable->setColumnWidth(5, 80); /* Delete */ |
|
60 ui->miscsTable->setColumnWidth(6, 80); /* Edit */ |
|
61 ui->miscsTable->setHorizontalHeaderLabels(labels); |
|
62 ui->miscsTable->verticalHeader()->hide(); |
|
63 ui->miscsTable->setRowCount(recipe->miscs.size()); |
|
64 |
|
65 ui->mw_acidPick->setCurrentIndex(-1); |
|
66 |
|
67 for (int i = 0; i < recipe->miscs.size(); i++) { |
|
68 |
|
69 ui->miscsTable->setItem(i, 0, new QTableWidgetItem(recipe->miscs.at(i).m_name)); |
|
70 |
|
71 item = new QTableWidgetItem(m_types[recipe->miscs.at(i).m_type]); |
|
72 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
73 ui->miscsTable->setItem(i, 1, item); |
|
74 |
|
75 item = new QTableWidgetItem(m_uses[recipe->miscs.at(i).m_use_use]); |
|
76 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
77 ui->miscsTable->setItem(i, 2, item); |
|
78 |
|
79 if (recipe->miscs.at(i).m_use_use == 2) { // Boil |
|
80 item = new QTableWidgetItem(QString("%1 min.").arg(recipe->miscs.at(i).m_time, 1, 'f', 0, '0')); |
|
81 } else if (recipe->miscs.at(i).m_use_use == 3 || recipe->miscs.at(i).m_use_use == 4) { // Primary or secondary |
|
82 item = new QTableWidgetItem(QString("%1 days.").arg(recipe->miscs.at(i).m_time / 1440, 1, 'f', 0, '0')); |
|
83 } else { |
|
84 item = new QTableWidgetItem(QString("")); |
|
85 } |
|
86 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
87 ui->miscsTable->setItem(i, 3, item); |
|
88 |
|
89 if (recipe->miscs.at(i).m_amount_is_weight) |
|
90 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->miscs.at(i).m_amount * 1000.0, 2, 'f', 1, '0')); |
|
91 else |
|
92 item = new QTableWidgetItem(QString("%1 ml").arg(recipe->miscs.at(i).m_amount * 1000.0, 2, 'f', 1, '0')); |
|
93 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
94 ui->miscsTable->setItem(i, 4, item); |
|
95 |
|
96 /* |
|
97 * Add the Delete and Edit row buttons. |
|
98 * Not for water agents, these are set on the water tab. |
|
99 */ |
|
100 if (recipe->miscs.at(i).m_type == 4) { |
|
101 ui->miscsTable->removeCellWidget(i, 5); |
|
102 ui->miscsTable->removeCellWidget(i, 6); |
|
103 } else { |
|
104 pWidget = new QWidget(); |
|
105 QPushButton* btn_dele = new QPushButton(); |
|
106 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
|
107 btn_dele->setText(tr("Delete")); |
|
108 connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteFermentRow_clicked())); |
|
109 pLayout = new QHBoxLayout(pWidget); |
|
110 pLayout->addWidget(btn_dele); |
|
111 pLayout->setContentsMargins(5, 0, 5, 0); |
|
112 pWidget->setLayout(pLayout); |
|
113 ui->miscsTable->setCellWidget(i, 5, pWidget); |
|
114 |
|
115 pWidget = new QWidget(); |
|
116 QPushButton* btn_edit = new QPushButton(); |
|
117 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
|
118 btn_edit->setText(tr("Edit")); |
|
119 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editFermentRow_clicked())); |
|
120 pLayout = new QHBoxLayout(pWidget); |
|
121 pLayout->addWidget(btn_edit); |
|
122 pLayout->setContentsMargins(5, 0, 5, 0); |
|
123 pWidget->setLayout(pLayout); |
|
124 ui->miscsTable->setCellWidget(i, 6, pWidget); |
|
125 } |
|
126 |
|
127 /* |
|
128 * Update the water agents. |
|
129 */ |
|
130 if (recipe->miscs.at(i).m_type == 4) { |
|
131 if (recipe->miscs.at(i).m_name == "CaCl2") { |
|
132 ui->bs_cacl2Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
133 } else if (recipe->miscs.at(i).m_name == "CaSO4") { |
|
134 ui->bs_caso4Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
135 } else if (recipe->miscs.at(i).m_name == "MgSO4") { |
|
136 ui->bs_mgso4Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
137 } else if (recipe->miscs.at(i).m_name == "NaCl") { |
|
138 ui->bs_naclEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
139 } else if (recipe->miscs.at(i).m_name == "MgCl2") { |
|
140 ui->bs_mgcl2Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
141 } else if (recipe->miscs.at(i).m_name == "NaHCO3") { |
|
142 ui->bs_nahco3Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
143 } else if (recipe->miscs.at(i).m_name == "CaCO3") { |
|
144 ui->bs_caco3Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
145 } else if (recipe->miscs.at(i).m_name == "Melkzuur" || recipe->miscs.at(i).m_name == "Lactic") { |
|
146 recipe->wa_acid_name = 0; |
|
147 recipe->wa_acid_perc = my_acids.at(0).AcidPrc; |
|
148 ui->mw_acidPick->setCurrentIndex(0); |
|
149 ui->mw_acidpercEdit->setValue(my_acids.at(0).AcidPrc); |
|
150 ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
151 } else if (recipe->miscs.at(i).m_name == "Zoutzuur" || recipe->miscs.at(i).m_name == "Hydrochloric") { |
|
152 recipe->wa_acid_name = 1; |
|
153 recipe->wa_acid_perc = my_acids.at(1).AcidPrc; |
|
154 ui->mw_acidPick->setCurrentIndex(1); |
|
155 ui->mw_acidpercEdit->setValue(my_acids.at(1).AcidPrc); |
|
156 ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
157 } else if (recipe->miscs.at(i).m_name == "Fosforzuur" || recipe->miscs.at(i).m_name == "Phosphoric") { |
|
158 recipe->wa_acid_name = 2; |
|
159 recipe->wa_acid_perc = my_acids.at(2).AcidPrc; |
|
160 ui->mw_acidPick->setCurrentIndex(2); |
|
161 ui->mw_acidpercEdit->setValue(my_acids.at(2).AcidPrc); |
|
162 ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
163 } else if (recipe->miscs.at(i).m_name == "Zwavelzuur" || recipe->miscs.at(i).m_name == "Sulfuric") { |
|
164 recipe->wa_acid_name = 3; |
|
165 recipe->wa_acid_perc = my_acids.at(3).AcidPrc; |
|
166 ui->mw_acidPick->setCurrentIndex(3); |
|
167 ui->mw_acidpercEdit->setValue(my_acids.at(3).AcidPrc); |
|
168 ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
|
169 } |
|
170 } |
|
171 } |
|
172 } |
|
173 |
|
174 |