|
1 /** |
|
2 * ProfileWaters.cpp is part of bmsapp. |
|
3 * |
|
4 * bmsapp is free software: you can redistribute it and/or modify |
|
5 * it under the terms of the GNU General Public License as published by |
|
6 * the Free Software Foundation, either version 3 of the License, or |
|
7 * (at your option) any later version. |
|
8 * |
|
9 * bmsapp is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #include "ProfileWaters.h" |
|
18 #include "EditProfileWater.h" |
|
19 #include "../ui/ui_ProfileWaters.h" |
|
20 #include "config.h" |
|
21 #include "bmsapp.h" |
|
22 |
|
23 |
|
24 ProfileWaters::ProfileWaters(QWidget *parent) : QDialog(parent), ui(new Ui::ProfileWaters) |
|
25 { |
|
26 qDebug() << "ProfileWaters start"; |
|
27 |
|
28 ui->setupUi(this); |
|
29 emit refreshTable(); |
|
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Profile Waters").arg(VERSIONSTRING) ); |
|
32 } |
|
33 |
|
34 |
|
35 void ProfileWaters::refreshTable() |
|
36 { |
|
37 QString w; |
|
38 QWidget* pWidget; |
|
39 QLabel *label; |
|
40 QHBoxLayout* pLayout; |
|
41 |
|
42 qDebug() << "ProfileWaters reload"; |
|
43 |
|
44 QSqlQuery query("SELECT * FROM profile_water ORDER BY name"); |
|
45 const QStringList labels({tr("Name"), tr("Notes"), tr("Ca"), tr("Mg"), tr("Na"), tr("CaCO3"), tr("Cl"), tr("SO4"), tr("pH"), tr("Edit")}); |
|
46 |
|
47 ui->tableWaters->setColumnCount(10); |
|
48 ui->tableWaters->setColumnWidth(0, 150); /* Name */ |
|
49 ui->tableWaters->setColumnWidth(1, 375); /* Notes */ |
|
50 ui->tableWaters->setColumnWidth(2, 75); /* Ca */ |
|
51 ui->tableWaters->setColumnWidth(3, 75); /* Mg */ |
|
52 ui->tableWaters->setColumnWidth(4, 75); /* Na */ |
|
53 ui->tableWaters->setColumnWidth(5, 75); /* CaCO3 */ |
|
54 ui->tableWaters->setColumnWidth(6, 75); /* Cl */ |
|
55 ui->tableWaters->setColumnWidth(7, 75); /* SO4 */ |
|
56 ui->tableWaters->setColumnWidth(8, 75); /* pH */ |
|
57 ui->tableWaters->setColumnWidth(9, 80); /* Edit button */ |
|
58 ui->tableWaters->setRowCount(query.size()); |
|
59 ui->tableWaters->setHorizontalHeaderLabels(labels); |
|
60 ui->tableWaters->verticalHeader()->hide(); |
|
61 ui->tableWaters->setFixedSize(1130 + 24, 640); /* Even if this is too large, it works */ |
|
62 |
|
63 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
|
64 rightitem->setTextAlignment(Qt::AlignRight); |
|
65 |
|
66 query.first(); |
|
67 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
|
68 ui->tableWaters->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
|
69 ui->tableWaters->setItem(ridx, 1, new QTableWidgetItem(query.value(9).toString())); /* Notes */ |
|
70 |
|
71 w = QString("%1").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Ca */ |
|
72 QTableWidgetItem *item = new QTableWidgetItem(w); |
|
73 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
74 ui->tableWaters->setItem(ridx, 2, item); |
|
75 |
|
76 w = QString("%1").arg(query.value(7).toDouble(), 2, 'f', 1, '0' ); /* Mg */ |
|
77 item = new QTableWidgetItem(w); |
|
78 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
79 ui->tableWaters->setItem(ridx, 3, item); |
|
80 |
|
81 w = QString("%1").arg(query.value(6).toDouble(), 2, 'f', 1, '0' ); /* Na */ |
|
82 item = new QTableWidgetItem(w); |
|
83 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
84 ui->tableWaters->setItem(ridx, 4, item); |
|
85 |
|
86 w = QString("%1").arg(query.value(10).toDouble(), 2, 'f', 1, '0' ); /* CaCO3 */ |
|
87 item = new QTableWidgetItem(w); |
|
88 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
89 ui->tableWaters->setItem(ridx, 5, item); |
|
90 |
|
91 w = QString("%1").arg(query.value(5).toDouble(), 2, 'f', 1, '0' ); /* Cl */ |
|
92 item = new QTableWidgetItem(w); |
|
93 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
94 ui->tableWaters->setItem(ridx, 6, item); |
|
95 |
|
96 w = QString("%1").arg(query.value(4).toDouble(), 2, 'f', 1, '0' ); /* SO4 */ |
|
97 item = new QTableWidgetItem(w); |
|
98 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
99 ui->tableWaters->setItem(ridx, 7, item); |
|
100 |
|
101 w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' ); /* pH */ |
|
102 item = new QTableWidgetItem(w); |
|
103 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
104 ui->tableWaters->setItem(ridx, 8, item); |
|
105 |
|
106 /* Add the Edit button */ |
|
107 pWidget = new QWidget(); |
|
108 QPushButton* btn_edit = new QPushButton(); |
|
109 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
|
110 btn_edit->setText(tr("Edit")); |
|
111 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
|
112 pLayout = new QHBoxLayout(pWidget); |
|
113 pLayout->addWidget(btn_edit); |
|
114 pLayout->setContentsMargins(5, 0, 5, 0); |
|
115 pWidget->setLayout(pLayout); |
|
116 ui->tableWaters->setCellWidget(ridx, 9, pWidget); |
|
117 query.next(); |
|
118 } |
|
119 |
|
120 setWindowTitle( QString("BMSapp - %1 - Profile Waters").arg(VERSIONSTRING) ); |
|
121 } |
|
122 |
|
123 |
|
124 ProfileWaters::~ProfileWaters() |
|
125 { |
|
126 qDebug() << "ProfileWaters done"; |
|
127 delete ui; |
|
128 } |
|
129 |
|
130 |
|
131 void ProfileWaters::edit(int recno) |
|
132 { |
|
133 qDebug() << "ProfileWaters edit:" << recno; |
|
134 |
|
135 EditProfileWater dialog(recno, this); |
|
136 /* Signal from editor if a refresh is needed */ |
|
137 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
|
138 dialog.setModal(true); |
|
139 dialog.exec(); |
|
140 } |
|
141 |
|
142 |
|
143 void ProfileWaters::on_editButton_clicked() |
|
144 { |
|
145 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
146 int recno = pb->objectName().toInt(); |
|
147 qDebug() << Q_FUNC_INFO << recno; |
|
148 edit(recno); |
|
149 } |
|
150 |
|
151 |
|
152 void ProfileWaters::on_insertButton_clicked() |
|
153 { |
|
154 qDebug() << Q_FUNC_INFO; |
|
155 edit(-1); |
|
156 } |
|
157 |
|
158 |
|
159 void ProfileWaters::on_quitButton_clicked() |
|
160 { |
|
161 emit firstWindow(); |
|
162 } |
|
163 |