changeset 196:416868143486

Add some comments.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Nov 2017 14:14:02 +0200
parents 930191210416
children f7da0c030262
files src/main.cpp
diffstat 1 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.cpp	Thu Nov 09 13:52:51 2017 +0200
+++ b/src/main.cpp	Thu Nov 09 14:14:02 2017 +0200
@@ -836,6 +836,7 @@
         return;
     }
 
+    // Internal sanity check
     SLPersonInfo info;
     if (!slGetPersonInfo(currPerson.id, info))
     {
@@ -843,6 +844,7 @@
         return;
     }
 
+    // Ask for confirmation
     QMessageBox dlg;
     slSetCommonStyleSheet(&dlg);
     dlg.setText(tr("Varmistus"));
@@ -978,15 +980,19 @@
     {
         case 1:
         case 2:
-            queryOrderBy = QStringLiteral(" ORDER BY last_name ") + queryOrderDir + QStringLiteral(",first_name ") + queryOrderDir;
+            queryOrderBy =
+                QStringLiteral(" ORDER BY last_name ") + queryOrderDir +
+                QStringLiteral(",first_name ") + queryOrderDir;
             break;
 
         case 3:
-            queryOrderBy = QStringLiteral(" ORDER BY balance ") + queryOrderDir;
+            queryOrderBy =
+                QStringLiteral(" ORDER BY balance ") + queryOrderDir;
             break;
 
         case 4:
-            queryOrderBy = QStringLiteral(" ORDER BY updated ") + queryOrderDir;
+            queryOrderBy =
+                QStringLiteral(" ORDER BY updated ") + queryOrderDir;
             break;
 
         default:
@@ -1140,6 +1146,7 @@
         QString str;
         if (debt)
         {
+            // Debt was added
             str = tr("Lisättiin velkaa %1 EUR henkilölle '%2 %3' (#%4).").
                 arg(slMoneyValueToStr(value)).
                 arg(info.firstName).
@@ -1148,6 +1155,7 @@
         }
         else
         {
+            // Debt was reduced
             str = tr("Vähennettiin velkaa %1 EUR henkilöltä '%2 %3' (#%4).").
                 arg(slMoneyValueToStr(value)).
                 arg(info.firstName).
@@ -1182,14 +1190,17 @@
 
 void SyntilistaMainWindow::on_button_PayFullDebt_clicked()
 {
+    // Sanity check that there is a selected person
     if (currPerson.id <= 0)
     {
         statusMsg(tr("Ei valittua henkilöä!"));
         return;
     }
 
+    // Check the balance ..
     if (currPerson.balance < 0)
     {
+        // And ask confirmation that user really wants to clear the full debt
         QMessageBox dlg;
         slSetCommonStyleSheet(&dlg);
         dlg.setText(tr("Varmistus"));
@@ -1269,6 +1280,7 @@
 
 void EditPerson::statusMsg(const QString &msg)
 {
+    // Pass the status message to main window
     dynamic_cast<SyntilistaMainWindow *>(parent())->statusMsg(msg);
 }
 
@@ -1296,6 +1308,9 @@
 
 void EditPerson::on_button_OK_clicked()
 {
+    //
+    // Check form validation
+    //
     if (!validateForm())
     {
         slErrorMsg(
@@ -1307,6 +1322,11 @@
 
     if (selPerson.id >= 0)
     {
+        //
+        // We are in update/edit person mode, thus we check if the
+        // first/last name have changed and if there is someone with
+        // different ID and same names.
+        //
         QSqlQuery person;
         person.prepare("SELECT * FROM people WHERE id <> ? AND first_name=? AND last_name=?");
         person.addBindValue(selPerson.id);
@@ -1318,6 +1338,7 @@
 
         if (person.next())
         {
+            // There exists another person with that name
             slErrorMsg(
                 tr("Virhe!"),
                 tr("Ei pysty! Samalla nimellä '%1 %2' on olemassa jo henkilö!").
@@ -1325,6 +1346,7 @@
             return;
         }
 
+        // Allest klar, update the person data
         dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->updatePerson(selPerson);
         dynamic_cast<SyntilistaMainWindow *>(parent())->setActivePerson(selPerson.id);
 
@@ -1333,6 +1355,10 @@
     }
     else
     {
+        //
+        // We are in "add new person" mode, check if there exists
+        // someone with same first+last name.
+        //
         QSqlQuery person;
         person.prepare("SELECT * FROM people WHERE first_name=? AND last_name=?");
         person.addBindValue(selPerson.firstName);
@@ -1343,6 +1369,7 @@
 
         if (person.next())
         {
+            // There exists a record with same name
             slErrorMsg(
                 tr("Virhe!"),
                 tr("Ei pysty! Samalla nimellä '%1 %2' on olemassa jo henkilö!").
@@ -1351,6 +1378,7 @@
             return;
         }
 
+        // Attempt to add a person
         qint64 nid = dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->addPerson(selPerson);
         if (nid < 0)
         {
@@ -1403,6 +1431,9 @@
 }
 
 
+//
+// Set the person to be edited
+//
 void EditPerson::setPerson(qint64 id)
 {
     selPerson.id = id;
@@ -1461,6 +1492,7 @@
 
     if (value.isValid() && role == Qt::DisplayRole)
     {
+        // Format some of the displayed values
         switch (index.column())
         {
             case 3:
@@ -1473,6 +1505,7 @@
 
     if (index.column() == 3 && role == Qt::ForegroundRole)
     {
+        // Use fancy coloring for debt
         double val = QSqlQueryModel::data(index, Qt::DisplayRole).toDouble();
         if (val < 0)
             return QVariant::fromValue(QColor(Qt::red));
@@ -1580,6 +1613,7 @@
 
     if (value.isValid() && role == Qt::DisplayRole)
     {
+        // Format some of the displayed values
         switch (index.column())
         {
             case 1:
@@ -1592,6 +1626,7 @@
 
     if (index.column() == 1 && role == Qt::ForegroundRole)
     {
+        // Use fancy coloring for debt
         double val = QSqlQueryModel::data(index, Qt::DisplayRole).toDouble();
         if (val < 0)
             return QVariant::fromValue(QColor(Qt::red));