From 75f9aff5dc64e759252177377ce5bbb0b909225b Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Tue, 8 Feb 2022 19:54:08 +0100 Subject: [PATCH] Formular zur Erfassung der Amts-Adressen --- amtadressdialog.cpp | 103 ++++++++++++++++++++++ amtadressdialog.h | 50 +++++++++++ amtadressdialog.ui | 206 ++++++++++++++++++++++++++++++++++++++++++++ mainwindow.cpp | 21 ++++- mainwindow.h | 2 + mainwindow.ui | 12 +++ pmv-client.pro | 7 ++ 7 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 amtadressdialog.cpp create mode 100644 amtadressdialog.h create mode 100644 amtadressdialog.ui diff --git a/amtadressdialog.cpp b/amtadressdialog.cpp new file mode 100644 index 0000000..681f053 --- /dev/null +++ b/amtadressdialog.cpp @@ -0,0 +1,103 @@ +/* Diese Datei ist Teil von pmv-client + * + * pmv-client ist Freie Software: Sie können es unter den Bedingungen + * der GNU General Public License, wie von der Free Software Foundation, + * Version 3 der Lizenz weiter verteilen und/oder modifizieren. + * + * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein + * wird, jedoch OHNE JEDE GEWÄHR,; sogar ohne die implizite Gewähr der + * MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. + * Siehe die GNU General Public License für weitere Einzelheiten. + * + * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem + * Programm erhalten haben. Wenn nicht, siehe . + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "amtadressdialog.h" +#include "ui_amtadressdialog.h" + +#include +#include +#include + +AmtAdressDialog::AmtAdressDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::AmtAdressDialog) +{ + ui->setupUi(this); + + // Modell initialisieren + model = new QSqlTableModel(this); + model->setTable("amtadresse"); + model->setEditStrategy(QSqlTableModel::OnManualSubmit); + model->setHeaderData(0, Qt::Horizontal, "ID"); + model->setHeaderData(1, Qt::Horizontal, "Bezeichnung"); + model->setHeaderData(2, Qt::Horizontal, "Abteilung"); + model->setHeaderData(3, Qt::Horizontal, "Zusatz"); + model->setHeaderData(4, Qt::Horizontal, "Straße"); + model->setHeaderData(5, Qt::Horizontal, "PLZ"); + model->setHeaderData(6, Qt::Horizontal, "Ort"); + model->setHeaderData(7, Qt::Horizontal, "Telefon"); + model->setHeaderData(8, Qt::Horizontal, "Email"); + model->setHeaderData(9, Qt::Horizontal, "Bemerkungen"); + model->setSort(0, Qt::AscendingOrder); + + // View initialisieren + ui->tableView->setModel(model); + ui->tableView->setColumnHidden(0, true); + ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->tableView->horizontalHeader()->setStretchLastSection(true); + model->select(); + + // Mapping der Eingabefelder + mapper = new QDataWidgetMapper(this); + mapper->setModel(model); + mapper->addMapping(ui->lineEdit_bezeichnung, model->fieldIndex("bezeichnung")); + mapper->addMapping(ui->lineEdit_abteilung, model->fieldIndex("abteilung")); + mapper->addMapping(ui->lineEdit_zusatz, model->fieldIndex("zusatz")); + mapper->addMapping(ui->lineEdit_strasse, model->fieldIndex("strasse")); + mapper->addMapping(ui->lineEdit_plz, model->fieldIndex("plz")); + mapper->addMapping(ui->lineEdit_ort, model->fieldIndex("ort")); + mapper->addMapping(ui->lineEdit_telefon, model->fieldIndex("telefon")); + mapper->addMapping(ui->lineEdit_email, model->fieldIndex("email")); + mapper->addMapping(ui->plainTextEdit, model->fieldIndex("bemerkungen")); + + connect(ui->tableView->selectionModel(),&QItemSelectionModel::currentRowChanged, + mapper, &QDataWidgetMapper::setCurrentModelIndex); + +} + +AmtAdressDialog::~AmtAdressDialog() +{ + delete ui; +} + +void AmtAdressDialog::on_buttonBox_accepted() +{ +} + +void AmtAdressDialog::on_pushButton_neu_clicked() +{ + QSqlRecord r = model->record(); + r.setGenerated("id", true); + r.setValue("bezeichnung", "Neues Amt"); + if (!model->insertRecord(-1, r)) { + qDebug() << model->lastError().text(); + } + +} + +void AmtAdressDialog::on_pushButton_speichern_clicked() +{ + mapper->submit(); + if (model->submitAll()) { + qDebug() << "Submitted to database"; + } else { + qDebug() << "summitAll() failed!"; + qDebug() << model->lastError().text(); + } + +} diff --git a/amtadressdialog.h b/amtadressdialog.h new file mode 100644 index 0000000..7b8a723 --- /dev/null +++ b/amtadressdialog.h @@ -0,0 +1,50 @@ +/* Diese Datei ist Teil von pmv-client + * + * pmv-client ist Freie Software: Sie können es unter den Bedingungen + * der GNU General Public License, wie von der Free Software Foundation, + * Version 3 der Lizenz weiter verteilen und/oder modifizieren. + * + * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein + * wird, jedoch OHNE JEDE GEWÄHR,; sogar ohne die implizite Gewähr der + * MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. + * Siehe die GNU General Public License für weitere Einzelheiten. + * + * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem + * Programm erhalten haben. Wenn nicht, siehe . + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#ifndef AMTADRESSDIALOG_H +#define AMTADRESSDIALOG_H + +#include +#include +#include + +namespace Ui { +class AmtAdressDialog; +} + +class AmtAdressDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AmtAdressDialog(QWidget *parent = nullptr); + ~AmtAdressDialog(); + +private slots: + void on_buttonBox_accepted(); + + void on_pushButton_neu_clicked(); + + void on_pushButton_speichern_clicked(); + +private: + Ui::AmtAdressDialog *ui; + QSqlTableModel *model; + QDataWidgetMapper *mapper; +}; + +#endif // AMTADRESSDIALOG_H diff --git a/amtadressdialog.ui b/amtadressdialog.ui new file mode 100644 index 0000000..f7729d2 --- /dev/null +++ b/amtadressdialog.ui @@ -0,0 +1,206 @@ + + + AmtAdressDialog + + + + 0 + 0 + 833 + 566 + + + + Amtadressen + + + + + + + + + + + + + + + + + Straße + + + + + + + + + + PLZ + + + + + + + Email + + + + + + + Abteilung + + + + + + + + + + Zusatz + + + + + + + Bezeichnung + + + + + + + + + + Telefon + + + + + + + + + + + + + Ort + + + + + + + + + + Bemerkungen + + + + + + + + + + + + + + Neu + + + + + + + Speichern + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + tableView + lineEdit_bezeichnung + lineEdit_abteilung + lineEdit_zusatz + lineEdit_strasse + lineEdit_plz + lineEdit_ort + lineEdit_telefon + lineEdit_email + plainTextEdit + pushButton_neu + pushButton_speichern + + + + + buttonBox + accepted() + AmtAdressDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AmtAdressDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 3e84bc0..e54d46b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -33,6 +33,7 @@ #include "importdialog.h" #include "wahldialog.h" #include "wahlkreisdialog.h" +#include "amtadressdialog.h" #include "configdialog.h" MainWindow::MainWindow(QWidget *parent) @@ -254,8 +255,17 @@ void MainWindow::on_actionVerbindung_triggered() void MainWindow::on_actionUeber_triggered() { QMessageBox msg; - msg.about(this, "Über PMV", "Piraten Mitglieder Verwaltung.
" - "Schneller Hack um Ausfall des Bundessystems zu kompensieren."); + QString msgstr = "

Piraten Mitglieder Verwaltung.
Schneller Hack um Ausfall des Bundessystems zu kompensieren.

"; + + if (db.isValid() && db.isOpen()) { + msgstr += QString("

Datenbankversion %1\n

").arg(lv.getVersion()); + // TODO Versionsdatum einbauen. Funktionsweise von .arg() mit mehreren Variablen? + } + else { + msgstr += "Datenbank nicht geöffnet."; + } + msg.about(this, "Über PMV", msgstr); + } void MainWindow::on_pushButton_edit_clicked() @@ -315,6 +325,12 @@ void MainWindow::on_actionWahlkreise_triggered() wkd.exec(); } +void MainWindow::on_actionAmtadressen_triggered() +{ + AmtAdressDialog dlg(this); + dlg.exec(); +} + void MainWindow::on_actionEinstellungen_triggered() { ConfigDialog dialog(this, &lv); @@ -381,3 +397,4 @@ void MainWindow::on_checkBox_stateChanged(int arg1) model->setQuery("SELECT nr, vorname, nachname, status FROM mitglied WHERE status<>'ausgetreten' ORDER BY nr"); } } + diff --git a/mainwindow.h b/mainwindow.h index 829c072..7125f4e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -70,6 +70,8 @@ private slots: void on_checkBox_stateChanged(int arg1); + void on_actionAmtadressen_triggered(); + private: Ui::MainWindow *ui; QSqlQueryModel *model; diff --git a/mainwindow.ui b/mainwindow.ui index e56c9d6..0ae74e3 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -149,6 +149,8 @@ + + @@ -231,6 +233,16 @@ Einstellungen + + + Amtadressen + + + + + ---- + + tableView diff --git a/pmv-client.pro b/pmv-client.pro index 46fa745..3e41ada 100644 --- a/pmv-client.pro +++ b/pmv-client.pro @@ -7,11 +7,16 @@ TEMPLATE = app CONFIG += c++11 +OBJECTS_DIR = build +MOC_DIR = build/moc +UI_DIR = build/ui + # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + amtadressdialog.cpp \ configdialog.cpp \ conndialog.cpp \ datedelegate.cpp \ @@ -26,6 +31,7 @@ SOURCES += \ wahlkreisdialog.cpp HEADERS += \ + amtadressdialog.h \ configdialog.h \ conndialog.h \ datedelegate.h \ @@ -39,6 +45,7 @@ HEADERS += \ wahlkreisdialog.h FORMS += \ + amtadressdialog.ui \ configdialog.ui \ conndialog.ui \ editdialog.ui \