浏览代码

edited ui of pilotsWidget

fiffty-50 4 年之前
父节点
当前提交
756a416a7b

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

@@ -163,6 +163,7 @@ void AircraftWidget::tableView_selectionChanged()
 void AircraftWidget::tableView_headerClicked(int column)
 {
     sortColumn = column;
+    Settings::write("userdata/acSortColumn", column);
 }
 
 void AircraftWidget::acft_editing_finished()

+ 68 - 60
src/gui/widgets/pilotswidget.cpp

@@ -27,7 +27,8 @@ PilotsWidget::PilotsWidget(QWidget *parent) :
     ui(new Ui::PilotsWidget)
 {
     ui->setupUi(this);
-    refreshView();
+    sortColumn = Settings::read("userdata/pilSortColumn").toInt();
+    refreshModelAndView();         
 }
 
 PilotsWidget::~PilotsWidget()
@@ -35,24 +36,30 @@ 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(selectedPilot), Db::editExisting, this);
-    connect(np, SIGNAL(accepted()), this, SLOT(widget_accepted()));
-    connect(np, SIGNAL(rejected()), this, SLOT(widget_accepted()));
+void PilotsWidget::tableView_selectionChanged()//const QItemSelection &index, const QItemSelection &
+{   
+    auto *selection = ui->tableView->selectionModel();
+    selectedPilots.clear();
 
-    np->setWindowFlag(Qt::Widget);
-    ui->stackedWidget->addWidget(np);
-    ui->stackedWidget->setCurrentWidget(np);
+    for (const auto& row : selection->selectedRows()) {
+        selectedPilots << row.data().toInt();
+        DEB("Selected Tails(s) with ID: " << selectedPilots);
+    }
+    if(selectedPilots.length() == 1) {
+        auto nt = new NewPilot(Pilot(selectedPilots.first()), Db::editExisting, this);
+        connect(nt, SIGNAL(accepted()), this, SLOT(pilot_editing_finished()));
+        connect(nt, SIGNAL(rejected()), this, SLOT(pilot_editing_finished()));
+        nt->setWindowFlag(Qt::Widget);
+        ui->stackedWidget->addWidget(nt);
+        ui->stackedWidget->setCurrentWidget(nt);
+    }
 
 }
 
-void PilotsWidget::setSelectedPilot(const qint32 &value)
+void PilotsWidget::tableView_headerClicked(int column)
 {
-    selectedPilot = value;
+    sortColumn = column;
+    Settings::write("userdata/pilSortColumn", column);
 }
 
 void PilotsWidget::on_newButton_clicked()
@@ -60,40 +67,42 @@ void PilotsWidget::on_newButton_clicked()
     auto np = new NewPilot(Db::createNew, this);
     connect(np,
             SIGNAL(accepted()), this,
-            SLOT(widget_accepted()));
+            SLOT(pilot_editing_finished()));
     np->show();
 }
 
 void PilotsWidget::on_deletePushButton_clicked()
 {
-    if (selectedPilot > 0) {
-
-        auto pil = new Pilot(selectedPilot);
-        if(!pil->remove()) {
-            QVector<QString> columns = {"doft","dept","dest"};
-            QVector<QString> details = Db::multiSelect(columns, "flights", "pic",
-                                                       QString::number(selectedPilot), Db::exactMatch);
-            auto mb = new QMessageBox(this);
-            QString message = "\nUnable to delete. The following error has ocurred:\n\n";
-            if(!details.isEmpty()){
-                message += pil->error + QLatin1String("\n\n");
-                message += "This is most likely the case because a flight exists with the Pilot "
-                           "you are trying to delete. You have to change or remove this flight "
-                           "before being able to remove this pilot from the database.\n\n"
-                           "The following flight(s) with this pilot have been found:\n\n";
-                auto space = QLatin1Char(' ');
-                for(int i = 0; i <= 30 && i <=details.length()-3; i+=3){
-                    message += details[i] + space
-                             + details[i+1] + space
-                             + details[i+2] + QLatin1String("\n");
+    if(selectedPilots.length() == 1){
+        for(const auto& selectedPilot : selectedPilots){
+            if (selectedPilot > 0) {
+                auto pil = new Pilot(selectedPilot);
+                if(!pil->remove()) {
+                    QVector<QString> columns = {"doft","dept","dest"};
+                    QVector<QString> details = Db::multiSelect(columns, "flights", "pic",
+                                                               QString::number(selectedPilot), Db::exactMatch);
+                    auto mb = new QMessageBox(this);
+                    QString message = "\nUnable to delete. The following error has ocurred:\n\n";
+                    if(!details.isEmpty()){
+                        message += pil->error + QLatin1String("\n\n");
+                        message += "This is most likely the case because a flight exists with the Pilot "
+                                   "you are trying to delete. You have to change or remove this flight "
+                                   "before being able to remove this pilot from the database.\n\n"
+                                   "The following flight(s) with this pilot have been found:\n\n";
+                        auto space = QLatin1Char(' ');
+                        for(int i = 0; i <= 30 && i <=details.length()-3; i+=3){
+                            message += details[i] + space
+                                    + details[i+1] + space
+                                    + details[i+2] + QLatin1String("\n");
+                        }
+                    }
+                    mb->setText(message);
+                    mb->setIcon(QMessageBox::Critical);
+                    mb->show();
                 }
             }
-            mb->setText(message);
-            mb->setIcon(QMessageBox::Critical);
-            mb->show();
         }
-        refreshView();
-
+        refreshModelAndView();
     } else {
         auto mb = new QMessageBox(this);
         mb->setText("No Pilot selected.");
@@ -101,26 +110,15 @@ void PilotsWidget::on_deletePushButton_clicked()
     }
 }
 
-void PilotsWidget::widget_accepted()
+void PilotsWidget::pilot_editing_finished()
 {
-    DEB("Refreshing View...");
-    refreshView();
+    refreshModelAndView();
 }
 
-void PilotsWidget::refreshView()
+void PilotsWidget::refreshModelAndView()
 {
-    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;
+    ui->stackedWidget->setCurrentWidget(parent()->findChild<QWidget*>("welcomePage"));
+
     model->setTable("viewPilots");
     model->setFilter("ID > 1");//to not allow editing of self, shall be done via settings
     model->select();
@@ -131,18 +129,28 @@ void PilotsWidget::refreshView()
     view->setSelectionMode(QAbstractItemView::SingleSelection);
     view->setEditTriggers(QAbstractItemView::NoEditTriggers);
     view->horizontalHeader()->setStretchLastSection(QHeaderView::Stretch);
-    view->setColumnWidth(0, 60);
+    view->hideColumn(0);
     view->setColumnWidth(1, 180);
-    view->setColumnWidth(2, 120);
+    view->setColumnWidth(2, 180);
     view->verticalHeader()->hide();
     view->setAlternatingRowColors(true);
     view->setSortingEnabled(true);
 
-    view->sortByColumn(Settings::read("userdata/pilSortColumn").toInt(), Qt::AscendingOrder);
+    view->sortByColumn(sortColumn, Qt::AscendingOrder);
 
     view->show();
 
     connect(ui->tableView->selectionModel(),
             SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
-            SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
+            this,
+            SLOT(tableView_selectionChanged()));
+    connect(ui->tableView->horizontalHeader(),
+            SIGNAL(sectionClicked(int)),
+            this,
+            SLOT(tableView_headerClicked(int)));
+}
+
+void PilotsWidget::on_searchLineEdit_textChanged(const QString &arg1)
+{
+    model->setFilter("\"" + ui->searchComboBox->currentText() + "\" LIKE \"%" + arg1 + "%\" AND ID > 1");
 }

+ 12 - 6
src/gui/widgets/pilotswidget.h

@@ -39,23 +39,29 @@ public:
     explicit PilotsWidget(QWidget *parent = nullptr);
     ~PilotsWidget();
 
-    void setSelectedPilot(const qint32 &value);
-
 private slots:
-    void tableView_selectionChanged(const QItemSelection &index, const QItemSelection &);
+    void tableView_selectionChanged();
+
+    void tableView_headerClicked(int);
 
     void on_newButton_clicked();
 
     void on_deletePushButton_clicked();
 
-    void widget_accepted();
+    void pilot_editing_finished();
+
+    void on_searchLineEdit_textChanged(const QString &arg1);
 
 private:
     Ui::PilotsWidget *ui;
 
-    qint32 selectedPilot = 0;
+    QSqlTableModel *model = new QSqlTableModel;
+
+    qint32 sortColumn;
+
+    QVector<qint32> selectedPilots;
 
-    void refreshView();
+    void refreshModelAndView();
 };
 
 #endif // PILOTSWIDGET_H

+ 86 - 4
src/gui/widgets/pilotswidget.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>640</width>
-    <height>480</height>
+    <width>1920</width>
+    <height>1080</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -34,8 +34,90 @@
      </item>
      <item>
       <widget class="QStackedWidget" name="stackedWidget">
-       <widget class="QWidget" name="page"/>
-       <widget class="QWidget" name="page_2"/>
+       <widget class="QWidget" name="welcomePage">
+        <layout class="QGridLayout" name="gridLayout_3">
+         <item row="0" column="0">
+          <spacer name="verticalSpacer">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>424</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item row="1" column="0">
+          <layout class="QGridLayout" name="gridLayout_2">
+           <item row="0" column="0">
+            <widget class="QLabel" name="searchLabel">
+             <property name="text">
+              <string>Search:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="1">
+            <widget class="QLineEdit" name="searchLineEdit"/>
+           </item>
+           <item row="1" column="0">
+            <widget class="QLabel" name="searchInLabel">
+             <property name="text">
+              <string>Search in:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="1" column="1">
+            <widget class="QComboBox" name="searchComboBox">
+             <item>
+              <property name="text">
+               <string>Last Name</string>
+              </property>
+             </item>
+             <item>
+              <property name="text">
+               <string>First Name</string>
+              </property>
+             </item>
+             <item>
+              <property name="text">
+               <string>Company</string>
+              </property>
+             </item>
+            </widget>
+           </item>
+           <item row="2" column="0" colspan="2">
+            <widget class="QLabel" name="spacerLabel">
+             <property name="text">
+              <string/>
+             </property>
+            </widget>
+           </item>
+           <item row="3" column="0" colspan="2">
+            <widget class="QLabel" name="welcomeLabel">
+             <property name="text">
+              <string>Select a Pilot from the List to show or edit details.</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </item>
+         <item row="2" column="0">
+          <spacer name="verticalSpacer_2">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>423</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </widget>
       </widget>
      </item>
      <item>

+ 1 - 11
src/gui/widgets/settingswidget.ui

@@ -17,7 +17,7 @@
    <item row="0" column="1">
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>1</number>
+      <number>2</number>
      </property>
      <widget class="QWidget" name="personalTab">
       <attribute name="title">
@@ -582,11 +582,6 @@
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
-         <item>
-          <property name="text">
-           <string>ID</string>
-          </property>
-         </item>
          <item>
           <property name="text">
            <string>Last Name</string>
@@ -622,11 +617,6 @@
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
-         <item>
-          <property name="text">
-           <string>ID</string>
-          </property>
-         </item>
          <item>
           <property name="text">
            <string>Registration</string>