changeset 145:9f3c0a99bcb1

Add display for total number of people on the database.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 Aug 2017 01:21:27 +0300
parents 75a4faa219a9
children 4adf047e090a
files src/main.cpp src/main.h src/mainwindow.ui
diffstat 3 files changed, 34 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.cpp	Thu Aug 24 18:06:11 2017 +0300
+++ b/src/main.cpp	Fri Aug 25 01:21:27 2017 +0300
@@ -226,6 +226,7 @@
         "#label_BalanceValue { font-size: %4pt; font-weight: bold; }"
         "#label_EUR { font-size: %4pt; font-weight: bold; }"
         "#edit_Amount { font-size: %4pt; margin: 0.5em; padding: 0.5em; }"
+        "#label_NumPeopleValue { color: green; }"
         ).
         arg(12 * settings.uiScale).
         arg(14 * settings.uiScale).
@@ -1157,42 +1158,35 @@
     model_People->setHeaderData(3, Qt::Horizontal, tr("Tase"));
     model_People->setHeaderData(4, Qt::Horizontal, tr("Muutettu"));
 
-    updateTotalBalance();
+    updateMiscValues();
 }
 
 
 //
-// Update total balance value in the UI
+// Update some values in the UI
 //
-void SyntilistaMainWindow::updateTotalBalance()
+void SyntilistaMainWindow::updateMiscValues()
 {
     // Update total balance value
     QSqlQuery query;
     query.prepare(QStringLiteral("SELECT TOTAL(value) FROM transactions AS balance"));
     query.exec();
-    if (!slCheckAndReportSQLError("updatePersonList() get total balance query", query.lastError()))
-    {
-        slErrorMsg(
-            tr("SQL-tietokantavirhe"),
-            tr("Tietokantaa kyseltäessä tapahtui virhe."));
-    }
-    else
+    if (slCheckAndReportSQLError("updateMiscValues() get total balance query", query.lastError()) &&
+        query.next())
     {
-        double balance;
-        QString tmp ;
-        if (query.next())
-        {
-            balance = query.value(0).toDouble();;
-            tmp = slMoneyValueToStr(balance);
-        }
-        else
-        {
-            balance = -1;
-            tmp = "?";
-        }
+        double balance = query.value(0).toDouble();;
+        ui->label_TotalBalanceValue->setText(slMoneyValueToStr(balance));
+        ui->label_TotalBalanceValue->setStyleSheet(balance < 0 ? "color: red;" : "color: green;");
+    }
 
-        ui->label_TotalBalanceValue->setText(tmp);
-        ui->label_TotalBalanceValue->setStyleSheet(balance < 0 ? "color: red;" : "color: green;");
+    // Update number of people
+    query.finish();
+    query.prepare(QStringLiteral("SELECT COUNT(*) FROM people"));
+    query.exec();
+    if (slCheckAndReportSQLError("updateMiscValues() get people count", query.lastError()) &&
+        query.next())
+    {
+        ui->label_NumPeopleValue->setText(query.value(0).toString());
     }
 }
 
@@ -1241,7 +1235,7 @@
 
     QSqlDatabase::database().commit();
 
-    updateTotalBalance();
+    updateMiscValues();
 
     return 0;
 }
--- a/src/main.h	Thu Aug 24 18:06:11 2017 +0300
+++ b/src/main.h	Fri Aug 25 01:21:27 2017 +0300
@@ -136,7 +136,7 @@
     int  addTransaction(qint64 id, double value, PersonInfo &info);
     int  addTransactionGUI(qint64 id, bool debt, double value);
     void updatePersonList();
-    void updateTotalBalance();
+    void updateMiscValues();
     void backupDatabase();
 
     bool printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int page, QPainter *pt, QPrinter *printer);
--- a/src/mainwindow.ui	Thu Aug 24 18:06:11 2017 +0300
+++ b/src/mainwindow.ui	Fri Aug 25 01:21:27 2017 +0300
@@ -52,6 +52,20 @@
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_7">
          <item>
+          <widget class="QLabel" name="label_NumPeopleText">
+           <property name="text">
+            <string>Henkilöitä</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QLabel" name="label_NumPeopleValue">
+           <property name="text">
+            <string>0</string>
+           </property>
+          </widget>
+         </item>
+         <item>
           <widget class="QLabel" name="label_TotalBalanceText">
            <property name="text">
             <string>Kokonaistase:</string>