Explorar o código

added pilots Class, Widget and Dialog

fiffty-50 %!s(int64=4) %!d(string=hai) anos
pai
achega
70a1177007

BIN=BIN
assets/database/logbook.db


+ 3 - 1
mainwindow.cpp

@@ -125,7 +125,9 @@ void MainWindow::on_actionNewAircraft_triggered()
 
 void MainWindow::on_actionPilots_triggered()
 {
-    nope();
+    auto pw = new pilotsWidget(this);
+    ui->stackedWidget->addWidget(pw);
+    ui->stackedWidget->setCurrentWidget(pw);
 }
 
 void MainWindow::on_actionNewPilot_triggered()

+ 1 - 0
mainwindow.h

@@ -31,6 +31,7 @@
 #include "src/gui/widgets/settingswidget.h"
 #include "src/gui/widgets/logbookwidget.h"
 #include "src/gui/widgets/aircraftwidget.h"
+#include "src/gui/widgets/pilotswidget.h"
 #include "src/gui/dialogues/newtail.h"
 #include "src/gui/dialogues/newpilot.h"
 

+ 3 - 0
openPilotLog.pro

@@ -33,6 +33,7 @@ SOURCES += \
     src/gui/widgets/aircraftwidget.cpp \
     src/gui/widgets/homewidget.cpp \
     src/gui/widgets/logbookwidget.cpp \
+    src/gui/widgets/pilotswidget.cpp \
     src/gui/widgets/settingswidget.cpp
 
 HEADERS += \
@@ -52,6 +53,7 @@ HEADERS += \
     src/gui/widgets/aircraftwidget.h \
     src/gui/widgets/homewidget.h \
     src/gui/widgets/logbookwidget.h \
+    src/gui/widgets/pilotswidget.h \
     src/gui/widgets/settingswidget.h
 
 FORMS += \
@@ -61,6 +63,7 @@ FORMS += \
     src/gui/widgets/aircraftwidget.ui \
     src/gui/widgets/homewidget.ui \
     src/gui/widgets/logbookwidget.ui \
+    src/gui/widgets/pilotswidget.ui \
     src/gui/widgets/settingswidget.ui
 
 # Default rules for deployment.

+ 1 - 1
openPilotLog.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.11.0, 2020-11-01T21:06:17. -->
+<!-- Written by QtCreator 4.11.0, 2020-11-02T13:20:58. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 1 - 1
src/gui/dialogues/newpilot.cpp

@@ -29,7 +29,7 @@ NewPilot::NewPilot(db::editRole edRole, QWidget *parent) :
     ui->setupUi(this);
 }
 
-NewPilot::NewPilot(db::editRole edRole, pilot existingEntry, QWidget *parent) :
+NewPilot::NewPilot(pilot existingEntry, db::editRole edRole, QWidget *parent) :
     QDialog(parent),
     ui(new Ui::NewPilot)
 {

+ 1 - 1
src/gui/dialogues/newpilot.h

@@ -32,7 +32,7 @@ class NewPilot : public QDialog
 
 public:
     explicit NewPilot(db::editRole, QWidget *parent = nullptr);
-    explicit NewPilot(db::editRole, pilot, QWidget *parent = nullptr);
+    explicit NewPilot(pilot, db::editRole, QWidget *parent = nullptr);
     ~NewPilot();
 
 private slots:

+ 5 - 0
src/gui/widgets/aircraftwidget.cpp

@@ -30,6 +30,7 @@ aircraftWidget::aircraftWidget(QWidget *parent) :
 
     QString welcomeMessage = "Select an Aircraft to show or edit details.";
     QWidget *start = new QWidget();
+    start->setObjectName("welcomeAC");
     QLabel *label = new QLabel(welcomeMessage);
     label->setAlignment(Qt::AlignCenter);
     QHBoxLayout *layout = new QHBoxLayout();
@@ -101,7 +102,11 @@ void aircraftWidget::on_deleteButton_clicked()
         model->setTable("viewTails");
         model->select();
         ui->tableView->setModel(model);
+        connect(ui->tableView->selectionModel(),
+        SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+        SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
 
+        ui->stackedWidget->setCurrentWidget(parent()->findChild<QWidget*>("welcomeAC"));
 
     }else{
         auto mb = new QMessageBox(this);

+ 1 - 1
src/gui/widgets/homewidget.cpp

@@ -53,7 +53,7 @@ homeWidget::~homeWidget()
 void homeWidget::on_pushButton_clicked()
 {
     auto pl = new pilot("pilots",498);
-    auto np = new NewPilot(db::editExisting,*pl,this);
+    auto np = new NewPilot(*pl,db::editExisting,this);
     np->show();
 
     //auto ob = db(db::pilots,34);

+ 1 - 0
src/gui/widgets/homewidget.h

@@ -27,6 +27,7 @@
 #include "src/classes/aircraft.h"
 #include "src/gui/dialogues/newpilot.h"
 
+
 namespace Ui {
 class homeWidget;
 }

+ 3 - 0
src/gui/widgets/logbookwidget.cpp

@@ -131,6 +131,9 @@ void logbookWidget::on_deleteFlightPushButton_clicked()
             ShowAllModel->setTable("Logbook");
             ShowAllModel->select();
             ui->tableView->setModel(ShowAllModel);
+            connect(ui->tableView->selectionModel(),
+            SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+            SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
         }
     }else
     {

+ 121 - 0
src/gui/widgets/pilotswidget.cpp

@@ -0,0 +1,121 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "pilotswidget.h"
+#include "ui_pilotswidget.h"
+
+// Debug Makro
+#define DEB(expr) \
+    qDebug() << __PRETTY_FUNCTION__ << "\t" << expr
+
+pilotsWidget::pilotsWidget(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::pilotsWidget)
+{
+    ui->setupUi(this);
+
+    QString welcomeMessage = "Select a Pilot to show or edit details.";
+    QWidget *start = new QWidget();
+    start->setObjectName("welcomePL");
+    QLabel *label = new QLabel(welcomeMessage);
+    label->setAlignment(Qt::AlignCenter);
+    QHBoxLayout *layout = new QHBoxLayout();
+    layout->addWidget(label);
+    start->setLayout(layout);
+    ui->stackedWidget->addWidget(start);
+    ui->stackedWidget->setCurrentWidget(start);
+
+
+    QSqlTableModel *model = new QSqlTableModel;
+    model->setTable("viewPilots");
+    model->select();
+
+    QTableView *view = ui->tableView;
+    view->setModel(model);
+    view->setSelectionBehavior(QAbstractItemView::SelectRows);
+    view->setSelectionMode(QAbstractItemView::SingleSelection);
+    view->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    view->horizontalHeader()->setStretchLastSection(QHeaderView::Stretch);
+    view->setColumnWidth(0,60);
+    view->setColumnWidth(1,240);
+    view->setColumnWidth(2,180);
+    view->verticalHeader()->hide();
+    view->setAlternatingRowColors(true);
+    view->setSortingEnabled(true);
+    QSettings settings;
+
+    view->sortByColumn(settings.value("userdata/pilSortColumn").toInt(),Qt::AscendingOrder);
+
+    view->show();
+
+    connect(ui->tableView->selectionModel(),
+    SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+    SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
+}
+
+pilotsWidget::~pilotsWidget()
+{
+    delete ui;
+}
+
+void pilotsWidget::tableView_selectionChanged(const QItemSelection &index, const QItemSelection &)
+{
+    setSelectedPilot(index.indexes()[0].data().toInt());
+    DEB("Selected Pilot with ID#: " << selectedPilot);
+
+    auto np = new NewPilot(pilot("pilots",selectedPilot), db::editExisting, this);
+
+    np->setWindowFlag(Qt::Widget);
+    ui->stackedWidget->addWidget(np);
+    ui->stackedWidget->setCurrentWidget(np);
+}
+
+void pilotsWidget::setSelectedPilot(const qint32 &value)
+{
+    selectedPilot = value;
+}
+
+void pilotsWidget::on_newButton_clicked()
+{
+    auto np = new NewPilot(db::createNew,this);
+    np->show();
+}
+
+void pilotsWidget::on_deletePushButton_clicked()
+{
+    if(selectedPilot > 0){
+
+        auto pil = new pilot("pilots",selectedPilot);
+        pil->remove();
+
+
+        QSqlTableModel *model = new QSqlTableModel;
+        model->setTable("viewPilots");
+        model->select();
+        ui->tableView->setModel(model);
+        connect(ui->tableView->selectionModel(),
+        SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+        SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
+
+        ui->stackedWidget->setCurrentWidget(parent()->findChild<QWidget*>("welcomePL"));
+
+    }else{
+        auto mb = new QMessageBox(this);
+        mb->setText("No Pilot selected.");
+        mb->show();
+    }
+}

+ 57 - 0
src/gui/widgets/pilotswidget.h

@@ -0,0 +1,57 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#ifndef PILOTSWIDGET_H
+#define PILOTSWIDGET_H
+
+#include <QWidget>
+#include <QItemSelection>
+#include <QSqlTableModel>
+#include <QDebug>
+#include <QLabel>
+#include <QSettings>
+#include "src/classes/pilot.h"
+#include "src/gui/dialogues/newpilot.h"
+
+namespace Ui {
+class pilotsWidget;
+}
+
+class pilotsWidget : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit pilotsWidget(QWidget *parent = nullptr);
+    ~pilotsWidget();
+
+    void setSelectedPilot(const qint32 &value);
+
+private slots:
+    void tableView_selectionChanged(const QItemSelection &index, const QItemSelection &);
+
+    void on_newButton_clicked();
+
+    void on_deletePushButton_clicked();
+
+private:
+    Ui::pilotsWidget *ui;
+
+    qint32 selectedPilot = 0;
+};
+
+#endif // PILOTSWIDGET_H

+ 74 - 0
src/gui/widgets/pilotswidget.ui

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>pilotsWidget</class>
+ <widget class="QWidget" name="pilotsWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>640</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QTableView" name="tableView"/>
+   </item>
+   <item row="0" column="1">
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QStackedWidget" name="stackedWidget">
+       <widget class="QWidget" name="page"/>
+       <widget class="QWidget" name="page_2"/>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="1" column="0">
+    <widget class="QPushButton" name="newButton">
+     <property name="text">
+      <string>New Pilot</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <widget class="QPushButton" name="deletePushButton">
+     <property name="text">
+      <string>Delet Pilot</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>