changeset 271:df3f902588af

Add parent window argument to slErrorMsg() and use it. Also use main window as parent for other static/modal dialogs.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 17 Mar 2023 13:09:43 +0200
parents 8c6fb6ee6f9e
children d18f1a8cb4df
files src/editperson.cpp src/main.cpp src/printing.cpp src/util.cpp src/util.h
diffstat 5 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/editperson.cpp	Sun Feb 12 15:20:11 2023 +0200
+++ b/src/editperson.cpp	Fri Mar 17 13:09:43 2023 +0200
@@ -87,7 +87,7 @@
     //
     if (!validateForm())
     {
-        slErrorMsg(
+        slErrorMsg(this,
             tr("Virhe!"),
             tr("Vaaditut kentät (etunimi, sukunimi) eivät ole täytetty tai lisätietojen pituus on liian suuri."));
 
@@ -113,7 +113,7 @@
         if (person.next())
         {
             // There exists another person with that name
-            slErrorMsg(
+            slErrorMsg(this,
                 tr("Virhe!"),
                 tr("Ei pysty! Samalla nimellä '%1 %2' on olemassa jo henkilö!").
                 arg(selPerson.firstName).arg(selPerson.lastName));
@@ -144,7 +144,7 @@
         if (person.next())
         {
             // There exists a record with same name
-            slErrorMsg(
+            slErrorMsg(this,
                 tr("Virhe!"),
                 tr("Ei pysty! Samalla nimellä '%1 %2' on olemassa jo henkilö!").
                 arg(selPerson.firstName).arg(selPerson.lastName));
@@ -156,7 +156,7 @@
         qint64 nid = dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->addPerson(selPerson);
         if (nid < 0)
         {
-            slErrorMsg(
+            slErrorMsg(this,
                 tr("Virhe!"),
                 tr("Tietokannan käsittelyssä tapahtui virhe (#%1).").
                 arg(nid));
--- a/src/main.cpp	Sun Feb 12 15:20:11 2023 +0200
+++ b/src/main.cpp	Fri Mar 17 13:09:43 2023 +0200
@@ -161,7 +161,7 @@
     RunGuard guard(QStringLiteral(APP_VENDOR) + QStringLiteral(APP_ID));
     if (!guard.tryToRun())
     {
-        slErrorMsg(
+        slErrorMsg(0,
             QObject::tr("Virhe!"),
             QObject::tr(
             "Syntilista-sovellus on jo käynnissä. Sulje tämä ikkuna ja "
@@ -215,7 +215,7 @@
 
     if (!db.open())
     {
-        slErrorMsg(
+        slErrorMsg(0,
             QObject::tr("Tietokantaa ei voitu avata"),
             QObject::tr("Yhteyttä SQL-tietokantaan ei saatu.<br><br>Virhe: %1<br><br>").
             arg(db.lastError().text())
@@ -228,7 +228,7 @@
     //
     if (!slConditionallyCreateSQLTables(db, slSQLSchemaData, nslSQLSchemaData))
     {
-        slErrorMsg(
+        slErrorMsg(0,
             QObject::tr("Tietokantataulua ei voitu luoda"),
             QObject::tr("Virhe: %1<br><br>").
             arg(db.lastError().text())
@@ -346,7 +346,7 @@
         QDateTime::fromSecsSinceEpoch(0).msecsTo(settings.dbLastBackup) > 0 &&
         delta > (1000 * 60 * 60 * 24) * threshold)
     {
-        slErrorMsg(
+        slErrorMsg(this,
             tr("<h1>Huomio!</h1>"),
             tr(
             "<p>Edellisestä onnistuneesta tietokannan varmuuskopioinnista on kulunut <b>%1</b> päivää.</p>"
@@ -748,8 +748,9 @@
     }
 
     // Ask for confirmation
-    QMessageBox dlg;
+    QMessageBox dlg(this);
     slSetCommonStyleSheet(&dlg);
+
     dlg.setText(tr("Varmistus"));
     dlg.setInformativeText(tr(
         "<h3>Haluatko varmasti poistaa henkilön:</h3>"
@@ -774,7 +775,8 @@
         setActivePerson(-1);
         if (rv != 0)
         {
-            slErrorMsg(tr("SQL-tietokantavirhe"),
+            slErrorMsg(this,
+                tr("SQL-tietokantavirhe"),
                 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1.").
                 arg(rv));
         }
@@ -1083,7 +1085,7 @@
     }
     else
     {
-        slErrorMsg(
+        slErrorMsg(this,
             tr("SQL-tietokantavirhe"),
             tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1.").
             arg(ret));
@@ -1118,7 +1120,7 @@
     if (currPerson.balance < 0)
     {
         // And ask confirmation that user really wants to clear the full debt
-        QMessageBox dlg;
+        QMessageBox dlg(this);
         slSetCommonStyleSheet(&dlg);
         dlg.setText(tr("Varmistus"));
         dlg.setInformativeText(tr(
--- a/src/printing.cpp	Sun Feb 12 15:20:11 2023 +0200
+++ b/src/printing.cpp	Fri Mar 17 13:09:43 2023 +0200
@@ -132,7 +132,7 @@
 
     if (!slCheckAndReportSQLError(query, "printDocumentPage()"))
     {
-        slErrorMsg(
+        slErrorMsg(this,
             tr("SQL-tietokantavirhe"),
             tr("Tietokantaa selattaessa tapahtui virhe."));
 
--- a/src/util.cpp	Sun Feb 12 15:20:11 2023 +0200
+++ b/src/util.cpp	Fri Mar 17 13:09:43 2023 +0200
@@ -92,9 +92,9 @@
 //
 // Display an error dialog with given title and message
 //
-int slErrorMsg(const QString &title, const QString &msg)
+int slErrorMsg(QWidget *parent, const QString &title, const QString &msg)
 {
-    QMessageBox dlg;
+    QMessageBox dlg(parent);
 
     slLog("ERROR", msg);
 
--- a/src/util.h	Sun Feb 12 15:20:11 2023 +0200
+++ b/src/util.h	Fri Mar 17 13:09:43 2023 +0200
@@ -10,6 +10,9 @@
 #define SL_UTIL_H
 
 
+#include <QWidget>
+
+
 #define SQL_MAX_SCHEMA_INSERTS 16
 
 
@@ -37,7 +40,7 @@
 const QString slDateTimeToStr(const QDateTime &val);
 
 void slLog(const QString &mtype, const QString &msg);
-int slErrorMsg(const QString &title, const QString &msg);
+int slErrorMsg(QWidget *parent, const QString &title, const QString &msg);
 
 bool slCheckAndReportSQLError(const QSqlQuery &query, const QString where, bool report = false);
 bool slConditionallyCreateSQLTables(QSqlDatabase &db, const SLSQLSchemaDef *schema, const int nschema);