Browse Source

using models for events

logicp 5 years ago
parent
commit
b49a8f2645
2 changed files with 27 additions and 10 deletions
  1. 5 1
      include/mainwindow.h
  2. 22 9
      src/mainwindow.cpp

+ 5 - 1
include/mainwindow.h

@@ -13,6 +13,7 @@
 #include <include/argdialog.h>
 #include <include/consoledialog.h>
 #include <QTableView>
+#include <QTimer>
 
 namespace ProcessState {
     static constexpr int READY = 1;
@@ -36,6 +37,8 @@ struct Process {
     }
 };
 
+struct Event {};
+
 namespace Ui {
 class MainWindow;
 }
@@ -64,8 +67,9 @@ private:
     Client* q_client;
     /** Models */
     std::vector<Process> m_processes;
-    QStandardItemModel* m_process_model;
     QList<QString> m_events;
+    QStandardItemModel* m_process_model;
+    QStandardItemModel* m_event_model;
 
 private slots:
     /** Receivers */

+ 22 - 9
src/mainwindow.cpp

@@ -36,13 +36,17 @@ MainWindow::MainWindow(int argc, char** argv, QWidget *parent) :
     arg_ui(new ArgDialog),
     q_client(nullptr) {
     m_process_model = new QStandardItemModel(this);
+    m_event_model = new QStandardItemModel(this);
     q_client = new Client(this, cli_argc, cli_argv);
     ui->setupUi(this);
     this->setWindowTitle("KYGUI");
 
     QPushButton *button = this->findChild<QPushButton*>("connect");
+    button->setMaximumSize(700, 900);
+    button->setMinimumSize(700, 900);
     connect(button, &QPushButton::clicked, this, &MainWindow::connectClient);
-    ui->processList->setModel(m_process_model);   
+    ui->processList->setModel(m_process_model);
+    ui->eventList->setModel(m_event_model);
 }
 
 /**
@@ -117,12 +121,12 @@ void MainWindow::connectClient() {
                 auto datetime = task.args.at(0);
                 auto current_datetime = QDateTime::currentDateTime().toTime_t();
                 auto seconds_diff = std::stoi(datetime) - current_datetime;
-                qDebug() << "Time difference: " << seconds_diff;
-                if (seconds_diff > 3600) {
+//                qDebug() << "Time difference: " << seconds_diff;
+//                if (seconds_diff > 3600) {
                     qDebug() << "Scheduling a task";
                     task.args.push_back(std::to_string(mask));
                     q_client->scheduleTask(task.args, file_pending);
-                }
+//                }
             }
         }
     });
@@ -150,6 +154,15 @@ void MainWindow::connectClient() {
         }
         infoMessageBox(process_info_text, "Process");
     });
+
+    QObject::connect(ui->eventList, &QListView::clicked, this, [this](const QModelIndex &index) {
+        auto event = m_events.at(index.row());
+        infoMessageBox(event, "Event");
+    });
+
+    QTimer *timer = new QTimer(this);
+    connect(timer, &QTimer::timeout, q_client, &Client::ping);
+    timer->start(30000);
 }
 
 void MainWindow::handleKey() {
@@ -174,6 +187,10 @@ QStandardItem* createProcessListItem(Process process) {
     return new QStandardItem(QString("%0 requested for execution. ID: %1\nStatus: %2\nTime: %3   Done: %4").arg(process.name).arg(process.id).arg(ProcessNames[process.state - 1]).arg(process.start).arg(process.end));
 }
 
+QStandardItem* createEventListItem(QString event) {
+    return new QStandardItem(event);
+}
+
 /**
  * @brief MainWindow::updateMessages
  * @param s
@@ -237,11 +254,7 @@ void MainWindow::updateMessages(int t, const QString& message, StringVec v) {
             event_message += message;
         }
         m_events.push_front(event_message);
-        ui->eventList->clear();
-
-        for (const auto& i : Kontainer::ReverseIterator(m_events)) {
-            ui->eventList->addItem(i);
-        }
+        m_event_model->setItem(m_event_model->rowCount(), createEventListItem(event_message));
     } else {
         qDebug() << "Unknown update type. Cannot update UI";
     }