src/EditMisc.cpp

changeset 292
b6ec2e275736
parent 90
2396457a8167
child 385
09af9f46518f
--- a/src/EditMisc.cpp	Wed Jun 15 10:54:04 2022 +0200
+++ b/src/EditMisc.cpp	Wed Jun 15 14:48:10 2022 +0200
@@ -50,24 +50,24 @@
 	query.exec();
 	query.next();
 
-	ui->nameEdit->setText(query.value(1).toString());
-	ui->typeEdit->setCurrentIndex(query.value(2).toInt());
-	ui->useEdit->setCurrentIndex(query.value(3).toInt());
-	ui->timeEdit->setValue(query.value(4).toInt());
-	ui->isweightEdit->setChecked(query.value(5).toInt() ? true:false);
-	ui->useforEdit->setPlainText(query.value(6).toString());
-	ui->notesEdit->setPlainText(query.value(7).toString());
-	ui->alwaysEdit->setChecked(query.value(8).toInt() ? true:false);
-	ui->inventoryEdit->setValue(query.value(9).toDouble());
-	ui->costEdit->setValue(query.value(10).toDouble());
-	ui->valueEdit->setValue(query.value(9).toDouble() * query.value(10).toDouble());
-	if (query.value(11).toString().length() == 10) {
-            ui->prodEdit->setDate(query.value(11).toDate());
+	ui->nameEdit->setText(query.value("name").toString());
+	ui->typeEdit->setCurrentIndex(query.value("type").toInt());
+	ui->useEdit->setCurrentIndex(query.value("use_use").toInt());
+	ui->timeEdit->setValue(query.value("time").toInt());
+	ui->isweightEdit->setChecked(query.value("amount_is_weight").toInt() ? true:false);
+	ui->useforEdit->setPlainText(query.value("use_for").toString());
+	ui->notesEdit->setPlainText(query.value("notes").toString());
+	ui->alwaysEdit->setChecked(query.value("always_on_stock").toInt() ? true:false);
+	ui->inventoryEdit->setValue(query.value("inventory").toDouble() * 1000.0);
+	ui->costEdit->setValue(query.value("cost").toDouble());
+	ui->valueEdit->setValue(query.value("inventory").toDouble() * query.value("cost").toDouble());
+	if (query.value("production_date").toString().length() == 10) {
+            ui->prodEdit->setDate(query.value("production_date").toDate());
         } else {
             ui->prodEdit->clear();
         }
-	if (query.value(12).toString().length() == 10) {
-	    ui->thtEdit->setDate(query.value(12).toDate());
+	if (query.value("tht_date").toString().length() == 10) {
+	    ui->thtEdit->setDate(query.value("tht_date").toDate());
 	} else {
 	    ui->thtEdit->clear();
 	}
@@ -79,19 +79,24 @@
 	ui->prodEdit->clear();
 	ui->thtEdit->clear();
     }
+    UnitSet();
     TimeSet();
     connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditMisc::is_changed);
     connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed);
     connect(ui->useEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed);
     connect(ui->timeEdit, &QSpinBox::textChanged, this, &EditMisc::time_changed);
-    connect(ui->isweightEdit, &QCheckBox::stateChanged, this, &EditMisc::is_changed);
+    connect(ui->isweightEdit, &QCheckBox::stateChanged, this, &EditMisc::weight_changed);
     connect(ui->useforEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
     connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
     connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditMisc::is_changed);
     connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed);
     connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed);
     connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed);
+    connect(ui->prodButton1, SIGNAL(clicked()), this, SLOT(prod_date_today()));
+    connect(ui->prodButton2, SIGNAL(clicked()), this, SLOT(prod_date_clear()));
     connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed);
+    connect(ui->thtButton1, SIGNAL(clicked()), this, SLOT(tht_date_today()));
+    connect(ui->thtButton2, SIGNAL(clicked()), this, SLOT(tht_date_clear()));
 
     ui->saveButton->setEnabled(false);
     ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false);
@@ -208,6 +213,16 @@
 }
 
 
+void EditMisc::UnitSet()
+{
+    if (ui->isweightEdit->isChecked()) {
+	ui->inventoryEdit->setSuffix(tr(" gr"));
+    } else {
+	ui->inventoryEdit->setSuffix(tr(" ml"));
+    }
+}
+
+
 void EditMisc::TimeSet()
 {
     int	time = ui->timeEdit->value();
@@ -254,7 +269,7 @@
 
 void EditMisc::is_changed()
 {
-    ui->valueEdit->setValue(ui->inventoryEdit->value() * ui->costEdit->value());
+    ui->valueEdit->setValue((ui->inventoryEdit->value() / 1000.0) * ui->costEdit->value());
     ui->saveButton->setEnabled(true);
     ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false);
     this->textIsChanged = true;
@@ -262,6 +277,13 @@
 }
 
 
+void EditMisc::weight_changed()
+{
+    UnitSet();
+    is_changed();
+}
+
+
 void EditMisc::time_changed()
 {
     TimeSet();
@@ -288,3 +310,33 @@
     this->close();
     this->setResult(1);
 }
+
+
+void EditMisc::prod_date_clear()
+{
+    ui->prodEdit->setDate(QDate());
+    is_changed();
+}
+
+
+void EditMisc::prod_date_today()
+{
+    ui->prodEdit->setDate(QDate::currentDate());
+    is_changed();
+}
+
+
+void EditMisc::tht_date_clear()
+{
+    ui->thtEdit->setDate(QDate());
+    is_changed();
+}
+
+
+void EditMisc::tht_date_today()
+{
+    ui->thtEdit->setDate(QDate::currentDate());
+    is_changed();
+}
+
+

mercurial