Browse Source

added customContextMenu for tableview in logbookwidget and edited actions

fiffty-50 4 years ago
parent
commit
b3ffbd877e
5 changed files with 132 additions and 132 deletions
  1. 4 3
      mainwindow.cpp
  2. 3 2
      mainwindow.ui
  3. 3 3
      src/gui/dialogues/newflight.ui
  4. 119 121
      src/gui/widgets/logbookwidget.cpp
  5. 3 3
      src/gui/widgets/logbookwidget.h

+ 4 - 3
mainwindow.cpp

@@ -33,12 +33,13 @@ MainWindow::MainWindow(QWidget *parent)
         button->setMinimumWidth(128);
     }
 
-    ui->actionLogbook->setIcon(QIcon(":/icons/ionicon-icons/book-outline.png"));
     ui->actionHome->setIcon(QIcon(":/icons/ionicon-icons/home-outline.png"));
-    ui->actionSettings->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
-    ui->actionQuit->setIcon(QIcon(":/icons/ionicon-icons/power-outline.png"));
+    ui->actionNewFlight->setIcon(QIcon(":/icons/ionicon-icons/airplane-outline.png"));
+    ui->actionLogbook->setIcon(QIcon(":/icons/ionicon-icons/book-outline.png"));
     ui->actionAircraft->setIcon(QIcon(":/icons/ionicon-icons/airplane-outline.png"));
     ui->actionPilots->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
+    ui->actionSettings->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
+    ui->actionQuit->setIcon(QIcon(":/icons/ionicon-icons/power-outline.png"));
 
     // Adds space between toolbar items
     auto *spacer = new QWidget();

+ 3 - 2
mainwindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1280</width>
-    <height>720</height>
+    <width>1920</width>
+    <height>1080</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -35,6 +35,7 @@
     <bool>false</bool>
    </attribute>
    <addaction name="actionHome"/>
+   <addaction name="actionNewFlight"/>
    <addaction name="actionLogbook"/>
    <addaction name="actionAircraft"/>
    <addaction name="actionPilots"/>

+ 3 - 3
src/gui/dialogues/newflight.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>727</width>
-    <height>726</height>
+    <width>1280</width>
+    <height>720</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -201,7 +201,7 @@
            <second>0</second>
            <year>2019</year>
            <month>12</month>
-           <day>3</day>
+           <day>2</day>
           </datetime>
          </property>
          <property name="displayFormat">

+ 119 - 121
src/gui/widgets/logbookwidget.cpp

@@ -31,7 +31,7 @@ LogbookWidget::LogbookWidget(QWidget *parent) :
     ui->filterDateEdit_2->setDate(QDate::currentDate());
     ui->newFlightButton->setFocus();
 
-
+    //customContextMenu for tablewidget
     menu->addAction(ui->actionEdit_Flight);
     menu->addAction(ui->actionDelete_Flight);
 
@@ -43,21 +43,108 @@ LogbookWidget::~LogbookWidget()
     delete ui;
 }
 
-void LogbookWidget::tableView_selectionChanged(const QItemSelection &,
-                                               const QItemSelection &)// TO DO
+/*
+ * Functions
+ */
+
+void LogbookWidget::refreshView(int view_id)
 {
-    auto *selection = ui->tableView->selectionModel();
-    if(selection->hasSelection()){
-        selectedFlights.clear();
-        for(const auto& row : selection->selectedRows()){
-            selectedFlights << row.data().toInt();
-            DEB("Selected Flight(s) with ID: " << selectedFlights);
-        }
-    }else {
-        selectedFlights = {0};
-        DEB("No Flights selected.");
+    switch (view_id) {
+    case 0:
+        defaultView();
+        break;
+    case 1:
+        easaView();
+        break;
+    default:
+        defaultView();
     }
+    QTableView *view = ui->tableView;
+    view->setSelectionBehavior(QAbstractItemView::SelectRows);
+    view->setSelectionMode(QAbstractItemView::ExtendedSelection);
+    view->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    view->setContextMenuPolicy(Qt::CustomContextMenu);
+    view->horizontalHeader()->setStretchLastSection(QHeaderView::Stretch);
+    view->verticalHeader()->hide();
+    view->setAlternatingRowColors(true);
+    view->hideColumn(0);
+    connect(ui->tableView->selectionModel(),
+            SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+            SLOT(tableView_selectionChanged()));
+}
+
+void LogbookWidget::defaultView()
+{
+    DEB("Loading Default View...");
+    QSqlTableModel *model = new QSqlTableModel;
+    model->setTable("Logbook");
+    model->select();
+
+    QTableView *view = ui->tableView;
+    view->setModel(model);
+
+    view->setColumnWidth(1, 120);
+    view->setColumnWidth(2, 60);
+    view->setColumnWidth(3, 60);
+    view->setColumnWidth(4, 60);
+    view->setColumnWidth(5, 60);
+    view->setColumnWidth(6, 60);
+    view->setColumnWidth(7, 180);
+    view->setColumnWidth(8, 180);
+    view->setColumnWidth(9, 120);
+    view->setColumnWidth(10, 90);
 
+    view->show();
+}
+
+void LogbookWidget::easaView()
+{
+    DEB("Loading EASA View...");
+    QSqlTableModel *model = new QSqlTableModel;
+    model->setTable("viewEASA");
+    model->select();
+
+    QTableView *view = ui->tableView;
+    view->setModel(model);
+
+    view->setColumnWidth(1,120);
+    view->setColumnWidth(2,60);
+    view->setColumnWidth(3,60);
+    view->setColumnWidth(4,60);
+    view->setColumnWidth(5,60);
+    view->setColumnWidth(6,180);
+    view->setColumnWidth(7,120);
+    view->setColumnWidth(8,30);
+    view->setColumnWidth(9,30);
+    view->setColumnWidth(10,30);
+    view->setColumnWidth(11,30);
+    view->setColumnWidth(12,120);
+    view->setColumnWidth(13,15);
+    view->setColumnWidth(14,15);
+    view->setColumnWidth(15,60);
+    view->setColumnWidth(16,60);
+    view->setColumnWidth(17,60);
+    view->setColumnWidth(18,60);
+    view->setColumnWidth(19,60);
+    view->setColumnWidth(20,60);
+    view->setColumnWidth(21,120);
+
+    view->show();
+}
+
+/*
+ * Slots
+ */
+
+void LogbookWidget::tableView_selectionChanged()//
+{
+    auto *selection = ui->tableView->selectionModel();
+
+    selectedFlights.clear();
+    for (const auto& row : selection->selectedRows()) {
+        selectedFlights << row.data().toInt();
+        DEB("Selected Flight(s) with ID: " << selectedFlights);
+    }
 }
 
 void LogbookWidget::on_newFlightButton_clicked()
@@ -82,26 +169,32 @@ void LogbookWidget::on_editFlightButton_clicked()
 
 void LogbookWidget::on_deleteFlightPushButton_clicked()
 {
+    DEB("Flights selected: " << selectedFlights.length());
     if (selectedFlights.length() > 0 && selectedFlights.length() < 11) {
         QVector<QString> columns = {
             "doft", "dept", "dest"
         };
         QVector<QString> details;
-        QString detailsstring = "The following flight(s) will be deleted:\n\n";
+        QString warningMsg = "The following flight(s) will be deleted:<br><br><b><tt>";
         for(const auto& selectedFlight : selectedFlights){
             details = Db::multiSelect(columns, "flights", "id",
                                        QString::number(selectedFlight), Db::exactMatch);
             for (const auto &item : details) {
-                detailsstring.append(item);
-                detailsstring.append(QLatin1Char(' '));
+                warningMsg.append(item);
+                warningMsg.append(' ');
             }
-            detailsstring.append("\n");
+            warningMsg.append("<br>");
         }
-        detailsstring.append("\n\nAre you sure?");
+        warningMsg.append("</b></tt><br>Deleting Flights is irreversible."
+                          "<br>Do you want to proceed?");
 
-        QMessageBox::StandardButton reply;
-        reply = QMessageBox::question(this, "Delete Flight", detailsstring,
-                                      QMessageBox::Yes | QMessageBox::No);
+        QMessageBox confirm;
+        confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+        confirm.setDefaultButton(QMessageBox::No);
+        confirm.setIcon(QMessageBox::Question);
+        confirm.setWindowTitle("Delete Flight");
+        confirm.setText(warningMsg);
+        int reply = confirm.exec();
         if (reply == QMessageBox::Yes) {
             for (const auto& selectedFlight : selectedFlights) {
                 DEB("Deleting flight with ID# " << selectedFlight);
@@ -112,11 +205,13 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
         }
     } else if (selectedFlights.length() == 0) {
         QMessageBox nope(this);
+        nope.setIcon(QMessageBox::Information);
         nope.setText("No Flight Selected.");
         nope.exec();
     } else if (selectedFlights.length() > 10) {
-        auto& warningMsg = "You have selected " + QString::number(selectedFlights.length()) + " flights.\n\n"
-                                                                                              "Deleting these flights is irreversible.\n\nAre you sure you want to proceed?";
+        auto& warningMsg = "You have selected " + QString::number(selectedFlights.length())
+                         + " flights.\n\n Deleting these flights is irreversible.\n\n"
+                           "Are you sure you want to proceed?";
         QMessageBox confirm;
         confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
         confirm.setDefaultButton(QMessageBox::No);
@@ -156,103 +251,6 @@ void LogbookWidget::on_showAllButton_clicked()
     refreshView(Settings::read("logbook/view").toInt());
 }
 
-void LogbookWidget::refreshView(int view_id)
-{
-    switch (view_id) {
-    case 0:
-        defaultView();
-        break;
-    case 1:
-        easaView();
-        break;
-    default:
-        defaultView();
-    }
-
-}
-
-void LogbookWidget::defaultView()
-{
-    DEB("Loading Default View...");
-    QSqlTableModel *model = new QSqlTableModel;
-    model->setTable("Logbook");
-    model->select();
-
-    QTableView *view = ui->tableView;
-    view->setModel(model);
-    view->setSelectionBehavior(QAbstractItemView::SelectRows);
-    //view->setSelectionMode(QAbstractItemView::SingleSelection);
-    view->setSelectionMode(QAbstractItemView::ExtendedSelection);
-    view->setEditTriggers(QAbstractItemView::NoEditTriggers);
-    view->setColumnWidth(1, 120);
-    view->setColumnWidth(2, 60);
-    view->setColumnWidth(3, 60);
-    view->setColumnWidth(4, 60);
-    view->setColumnWidth(5, 60);
-    view->setColumnWidth(6, 60);
-    view->setColumnWidth(7, 180);
-    view->setColumnWidth(8, 180);
-    view->setColumnWidth(9, 120);
-    view->setColumnWidth(10, 90);
-    view->horizontalHeader()->setStretchLastSection(QHeaderView::Stretch);
-    view->verticalHeader()->hide();
-    view->setAlternatingRowColors(true);
-    view->hideColumn(0);
-    view->show();
-
-    ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
-    connect(ui->tableView->selectionModel(),
-            SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
-            SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
-}
-
-void LogbookWidget::easaView()
-{
-    DEB("Loading EASA View...");
-    QSqlTableModel *model = new QSqlTableModel;
-    model->setTable("viewEASA");
-    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->verticalHeader()->hide();
-    view->setAlternatingRowColors(true);
-    view->hideColumn(0);
-
-    view->setColumnWidth(1,120);
-    view->setColumnWidth(2,60);
-    view->setColumnWidth(3,60);
-    view->setColumnWidth(4,60);
-    view->setColumnWidth(5,60);
-    view->setColumnWidth(6,180);
-    view->setColumnWidth(7,120);
-    view->setColumnWidth(8,30);
-    view->setColumnWidth(9,30);
-    view->setColumnWidth(10,30);
-    view->setColumnWidth(11,30);
-    view->setColumnWidth(12,120);
-    view->setColumnWidth(13,15);
-    view->setColumnWidth(14,15);
-    view->setColumnWidth(15,60);
-    view->setColumnWidth(16,60);
-    view->setColumnWidth(17,60);
-    view->setColumnWidth(18,60);
-    view->setColumnWidth(19,60);
-    view->setColumnWidth(20,60);
-    view->setColumnWidth(21,120);
-
-    view->show();
-    ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
-    connect(ui->tableView->selectionModel(),
-            SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
-            SLOT(tableView_selectionChanged(const QItemSelection &, const QItemSelection &)));
-}
-
-
 void LogbookWidget::on_tableView_customContextMenuRequested(const QPoint &pos)
 {
     menu->popup(ui->tableView->viewport()->mapToGlobal(pos));
@@ -268,7 +266,7 @@ void LogbookWidget::on_actionEdit_Flight_triggered()
     emit ui->editFlightButton->clicked();
 }
 
-void LogbookWidget::on_tableView_doubleClicked(const QModelIndex &index)
+void LogbookWidget::on_tableView_doubleClicked()
 {
     emit ui->editFlightButton->clicked();
 }

+ 3 - 3
src/gui/widgets/logbookwidget.h

@@ -46,7 +46,7 @@ public:
     explicit LogbookWidget(QWidget *parent = nullptr);
     ~LogbookWidget();
 
-    QVector<qint32> selectedFlights = {0};
+    QVector<qint32> selectedFlights;
 
 private slots:
     void on_newFlightButton_clicked();
@@ -59,7 +59,7 @@ private slots:
 
     void on_showAllButton_clicked();
 
-    void tableView_selectionChanged(const QItemSelection &index, const QItemSelection &);
+    void tableView_selectionChanged();
 
     void on_tableView_customContextMenuRequested(const QPoint &pos);
 
@@ -67,7 +67,7 @@ private slots:
 
     void on_actionEdit_Flight_triggered();
 
-    void on_tableView_doubleClicked(const QModelIndex &index);
+    void on_tableView_doubleClicked();
 
 private:
     Ui::LogbookWidget *ui;