From 7e354a56d7a804592c45b3780ba4804888abe619 Mon Sep 17 00:00:00 2001 From: NeoTheFox Date: Sat, 21 Mar 2015 16:36:14 +0300 Subject: [PATCH] More error messages --- errorwindow.cpp | 17 ++++++++++++++++- errorwindow.h | 3 ++- mainwindow.cpp | 11 +++++++++-- repraptor.h | 6 ++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/errorwindow.cpp b/errorwindow.cpp index c6787df..cc37e21 100644 --- a/errorwindow.cpp +++ b/errorwindow.cpp @@ -1,11 +1,26 @@ #include "errorwindow.h" #include "ui_errorwindow.h" -ErrorWindow::ErrorWindow(QWidget *parent, QString errorText) : +using namespace RepRaptor; + +ErrorWindow::ErrorWindow(QWidget *parent, QString errorText, int errType): QDialog(parent), ui(new Ui::ErrorWindow) { ui->setupUi(this); + switch(errType) + { + case SerialPortError: + ui->label->setText("Serial port error:"); + break; + case OpenFileError: + ui->label->setText("File open error:"); + break; + default: + ui->label->setText("Unknown error type:"); + break; + } + ui->errorlabel->setText(errorText); } diff --git a/errorwindow.h b/errorwindow.h index 20a8558..2a59b22 100644 --- a/errorwindow.h +++ b/errorwindow.h @@ -4,6 +4,7 @@ #include #include "erroricon.h" +#include "repraptor.h" namespace Ui { class ErrorWindow; @@ -14,7 +15,7 @@ class ErrorWindow : public QDialog Q_OBJECT public: - explicit ErrorWindow(QWidget *parent = 0, QString errorText = "Unknown error"); + explicit ErrorWindow(QWidget *parent = 0, QString errorText = "Unknown error", int errType = 0); ~ErrorWindow(); private: diff --git a/mainwindow.cpp b/mainwindow.cpp index cbeeff6..c67f07f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -222,6 +222,13 @@ void MainWindow::parseFile(QString filename) ui->filename->setText(gfile.fileName().split(QDir::separator()).last()); ui->filelines->setText(QString::number(gcode.size()) + QString("/0 lines")); } + else + { + ErrorWindow window(this, "Can't open file", OpenFileError); + ui->filename->setText(""); + ui->filelines->setText(""); + window.exec(); + } } void MainWindow::serialupdate() @@ -691,7 +698,7 @@ void MainWindow::serialError(QSerialPort::SerialPortError error) } //Spawn the error message - ErrorWindow errorwindow(this, errorMsg); + ErrorWindow errorwindow(this, errorMsg, SerialPortError); errorwindow.exec(); } @@ -871,7 +878,7 @@ void MainWindow::baudrateSetFailed(int b) { ErrorWindow errorwindow(this, QString("Baudrate set failed:\n" + QString::number(b) + - " baud")); + " baud"), SerialPortError); errorwindow.show(); } diff --git a/repraptor.h b/repraptor.h index 344d2ba..f731dfa 100644 --- a/repraptor.h +++ b/repraptor.h @@ -24,6 +24,12 @@ namespace RepRaptor OtherFirmware }; + enum ErrorType + { + SerialPortError, + OpenFileError + }; + typedef struct { int T, P;