# HG changeset patch # User Matti Hamalainen # Date 1503613287 -10800 # Node ID 9f3c0a99bcb15d08d280b0fe0690f2981cfb864a # Parent 75a4faa219a965c5ce6d18881e12ea6873047811 Add display for total number of people on the database. diff -r 75a4faa219a9 -r 9f3c0a99bcb1 src/main.cpp --- 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; } diff -r 75a4faa219a9 -r 9f3c0a99bcb1 src/main.h --- 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); diff -r 75a4faa219a9 -r 9f3c0a99bcb1 src/mainwindow.ui --- 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 @@ + + + Henkilöitä + + + + + + + 0 + + + + Kokonaistase: