changeset 8:466d89a2a629

More cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 30 Mar 2017 15:31:20 +0300
parents b076c4dfc376
children 1f442052d332
files main.cpp
diffstat 1 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/main.cpp	Thu Mar 30 15:12:26 2017 +0300
+++ b/main.cpp	Thu Mar 30 15:31:20 2017 +0300
@@ -17,10 +17,9 @@
 
 
 
-void appError(QString title, QString msg)
+void errorMsg()
 {
     QMessageBox::critical(0, title, msg, QMessageBox::Ok);
-    QApplication::exit();
 }
 
 
@@ -120,14 +119,12 @@
 
     if (!db.open())
     {
-        appError(
-            "Cannot open database",
-            "Unable to establish a database connection.\n"
-            "This example needs SQLite support. Please read "
-            "the Qt SQL driver documentation for information how "
-            "to build it."
+        errorMsg(
+            tr("Tietokantaa ei voitu avata"),
+            tr("Yhteyttä SQL-tietokantaan ei saatu.\n\nVirhe: %1\n\n").
+            arg(db.lastError().text())
             );
-        return false;
+        return 1;
     }
 
     QSqlQuery query;
@@ -367,7 +364,7 @@
     QMessageBox::StandardButton ret =
         QMessageBox::question(this,
         tr("Varmistus"),
-        tr("\nHaluatko varmasti poistaa henkilön:\n\n<b>'%1, %2'</b> (ID #%3)?\n\n"
+        tr("\nHaluatko varmasti poistaa henkilön:\n\n'%1, %2' (ID #%3)?\n\n"
         "Tämä poistaa sekä henkilön ja hänen koko tapahtumahistoriansa PYSYVÄSTI!\n").
         arg(info.lastName).arg(info.firstName).arg(info.id),
         QMessageBox::Yes | QMessageBox::No);
@@ -377,7 +374,7 @@
         int rv = deletePerson(info.id);
         if (rv != 0)
         {
-            appError(tr("SQL-tietokantavirhe"),
+            errorMsg(tr("SQL-tietokantavirhe"),
                 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1.").
                 arg(rv));
         }
@@ -563,9 +560,11 @@
 {
     PersonInfo info;
 
+    // Check if person is selected
     if (id <= 0)
         return -1;
 
+    // Check value
     if (value == 0)
     {
         QString tmp = (debt ? "lisätty" : "vähennetty");
@@ -573,9 +572,11 @@
         return 1;
     }
 
+    // Perform transaction insert
     int ret = addTransaction(id, debt ? -value : value, info);
     if (ret == 0)
     {
+        // All ok, clear amount entry and update person data
         ui->edit_Amount->clear();
         updatePersonData(info.id);
 
@@ -600,8 +601,10 @@
     }
     else
     {
-        appError(tr("SQL-tietokantavirhe"),
-            tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe (koodi=%1).").arg(ret));
+        errorMsg(
+            tr("SQL-tietokantavirhe"),
+            tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1.").
+            arg(ret));
     }
 
     return ret;
@@ -625,7 +628,12 @@
     if (currPerson.balance < 0)
         addTransactionGUI(currPerson.id, false, -currPerson.balance);
     else
-        statusMsg("Valitulla henkilöllä ei ole velkaa.");
+    {
+        statusMsg(
+            tr("Valitulla henkilöllä '%1, %2' ei ole velkaa.").
+            arg(currPerson.lastName).
+            arg(currPerson.firstName));
+    }
 }