Show error message box only through message handler.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-01 17:59:01 +03:00
parent 00e38fc119
commit 0b57b8821a
15 changed files with 194 additions and 170 deletions

View file

@ -83,7 +83,7 @@ void DialogAboutTape::WebButtonClicked()
{ {
if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false) if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false)
{ {
QMessageBox::warning(this, tr("Warning"), tr("Cannot open your default browser")); qWarning() << tr("Cannot open your default browser");
} }
} }

View file

@ -47,6 +47,8 @@
#include <QLocalServer> #include <QLocalServer>
#include <QMessageBox> #include <QMessageBox>
#include <iostream> #include <iostream>
#include <QGridLayout>
#include <QSpacerItem>
Q_LOGGING_CATEGORY(mApp, "m.application") Q_LOGGING_CATEGORY(mApp, "m.application")
@ -93,13 +95,22 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
switch (type) switch (type)
{ {
case QtDebugMsg: case QtDebugMsg:
vStdOut() << msg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << msg << "\n";
return; return;
case QtWarningMsg: case QtWarningMsg:
case QtCriticalMsg: vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << msg << "\n";
case QtFatalMsg:
vStdErr() << msg << "\n";
break; break;
case QtCriticalMsg:
vStdErr() << QApplication::translate("mNoisyHandler", "CRITICAL:") << msg << "\n";
break;
case QtFatalMsg:
vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << msg << "\n";
break;
#if QT_VERSION > QT_VERSION_CHECK(5, 4, 2)
case QtInfoMsg:
vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << msg << "\n";
break;
#endif
default: default:
break; break;
} }
@ -114,14 +125,23 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
switch (type) switch (type)
{ {
case QtWarningMsg: case QtWarningMsg:
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Warning."));
messageBox.setIcon(QMessageBox::Warning); messageBox.setIcon(QMessageBox::Warning);
break; break;
case QtCriticalMsg: case QtCriticalMsg:
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Critical error."));
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
break; break;
case QtFatalMsg: case QtFatalMsg:
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error."));
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
break; break;
#if QT_VERSION > QT_VERSION_CHECK(5, 4, 2)
case QtInfoMsg:
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Information."));
messageBox.setIcon(QMessageBox::Information);
break;
#endif
case QtDebugMsg: case QtDebugMsg:
default: default:
break; break;
@ -133,11 +153,17 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
if (topWinAllowsPop) if (topWinAllowsPop)
{ {
messageBox.setInformativeText(msg); messageBox.setText(msg);
messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.setWindowModality(Qt::ApplicationModal); messageBox.setWindowModality(Qt::ApplicationModal);
messageBox.setModal(true); messageBox.setModal(true);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::ArrowCursor);
#endif
messageBox.exec(); messageBox.exec();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
} }
} }
} }
@ -230,45 +256,51 @@ bool MApplication::notify(QObject *receiver, QEvent *event)
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
e.CriticalMessageBox(tr("Error parsing file. Program will be terminated."), mainWindow); qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
{ {
e.CriticalMessageBox(tr("Error bad id. Program will be terminated."), mainWindow); qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error bad id. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionConversionError &e) catch (const VExceptionConversionError &e)
{ {
e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated."), mainWindow); qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated."), mainWindow); qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
e.CriticalMessageBox(tr("Error wrong id. Program will be terminated."), mainWindow); qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VException &e) catch (const VException &e)
{ {
e.CriticalMessageBox(tr("Something's wrong!!"), mainWindow); qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return true; return true;
} }
// These last two cases special. I found that we can't show here modal dialog with error message. // These last two cases special. I found that we can't show here modal dialog with error message.
// Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang. // Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang.
catch (const qmu::QmuParserError &e) catch (const qmu::QmuParserError &e)
{ {
qCDebug(mApp, "Parser error: %s", e.GetMsg().toUtf8().constData()); qCCritical(mApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg())));
abort(); std::exit(V_EX_DATAERR);
} }
catch (std::exception &e) catch (std::exception &e)
{ {
qCDebug(mApp, "Critical error! Exception thrown: %s", e.what()); qCCritical(mApp, "%s", qUtf8Printable(tr("Exception thrown: %1. Program will be terminated.").arg(e.what())));
abort(); std::exit(V_EX_SOFTWARE);
} }
return false; return false;
} }

View file

@ -166,7 +166,7 @@ void TMainWindow::LoadFile(const QString &path)
{ {
if (not QFileInfo(path).exists()) if (not QFileInfo(path).exists())
{ {
qCritical()<<tr("File '%1' doesn't exist!").arg(path); qCCritical(tMainWindow, "%s", qUtf8Printable(tr("File '%1' doesn't exist!").arg(path)));
if (qApp->IsTestMode()) if (qApp->IsTestMode())
{ {
std::exit(V_EX_NOINPUT); std::exit(V_EX_NOINPUT);
@ -190,8 +190,12 @@ void TMainWindow::LoadFile(const QString &path)
if (lock->GetLockError() == QLockFile::LockFailedError) if (lock->GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(tMainWindow, "%s", tr("This file already opened in another window.").toUtf8().constData()); qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
lock.reset(); lock.reset();
if (qApp->IsTestMode())
{
std::exit(V_EX_NOINPUT);
}
return; return;
} }
@ -257,7 +261,8 @@ void TMainWindow::LoadFile(const QString &path)
} }
catch (VException &e) catch (VException &e)
{ {
e.CriticalMessageBox(tr("File error."), this); qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
ui->labelToolTip->setVisible(true); ui->labelToolTip->setVisible(true);
ui->tabWidget->setVisible(false); ui->tabWidget->setVisible(false);
delete m; delete m;
@ -497,8 +502,8 @@ void TMainWindow::FileSaveAs()
{ {
if (lock->GetLockError() == QLockFile::LockFailedError) if (lock->GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(tMainWindow, "%s", tr("Failed to lock. This file already opened in another window.") qCCritical(tMainWindow, "%s",
.toUtf8().constData()); qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
return; return;
} }
} }
@ -525,8 +530,8 @@ void TMainWindow::FileSaveAs()
if (lock->GetLockError() == QLockFile::LockFailedError) if (lock->GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(tMainWindow, "%s", tr("Failed to lock. This file already opened in another window. " qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. "
"Expect collissions when run 2 copies of the program.").toUtf8().constData()); "Expect collissions when run 2 copies of the program.")));
lock.reset(); lock.reset();
return; return;
} }
@ -780,7 +785,9 @@ void TMainWindow::Fx()
} }
catch(const VExceptionBadId & e) catch(const VExceptionBadId & e)
{ {
e.CriticalMessageBox(tr("Can't find measurement."), this); qCCritical(tMainWindow, "%s\n\n%s\n\n%s",
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return; return;
} }
@ -931,7 +938,7 @@ void TMainWindow::ImportFromPattern()
if (tmp.GetLockError() == QLockFile::LockFailedError) if (tmp.GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(tMainWindow, "%s", tr("This file already opened in another window.").toUtf8().constData()); qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
return; return;
} }
@ -953,7 +960,8 @@ void TMainWindow::ImportFromPattern()
} }
catch (VException &e) catch (VException &e)
{ {
e.CriticalMessageBox(tr("File error."), this); qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return; return;
} }
@ -1153,7 +1161,9 @@ void TMainWindow::SaveMName()
} }
catch(const VExceptionBadId &e) catch(const VExceptionBadId &e)
{ {
e.CriticalMessageBox(tr("Can't find measurement."), this); qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return; return;
} }
@ -1180,7 +1190,7 @@ void TMainWindow::SaveMName()
} }
else else
{ {
qWarning() << tr("The name of known measurement forbidden to change."); qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The name of known measurement forbidden to change.")));
} }
} }
@ -1224,7 +1234,9 @@ void TMainWindow::SaveMValue()
} }
catch(const VExceptionBadId & e) catch(const VExceptionBadId & e)
{ {
e.CriticalMessageBox(tr("Can't find measurement."), this); qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return; return;
} }

View file

@ -95,19 +95,30 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
case QtDebugMsg: case QtDebugMsg:
debugdate += QString(":DEBUG:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) debugdate += QString(":DEBUG:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
.arg(context.function).arg(context.category).arg(msg); .arg(context.function).arg(context.category).arg(msg);
vStdOut() << QApplication::translate("vNoisyHandler", "DEBUG:") << msg << "\n";
break; break;
case QtWarningMsg: case QtWarningMsg:
debugdate += QString(":WARNING:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) debugdate += QString(":WARNING:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
.arg(context.function).arg(context.category).arg(msg); .arg(context.function).arg(context.category).arg(msg);
vStdErr() << QApplication::translate("vNoisyHandler", "WARNING:") << msg << "\n";
break; break;
case QtCriticalMsg: case QtCriticalMsg:
debugdate += QString(":CRITICAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) debugdate += QString(":CRITICAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
.arg(context.function).arg(context.category).arg(msg); .arg(context.function).arg(context.category).arg(msg);
vStdErr() << QApplication::translate("vNoisyHandler", "CRITICAL:") << msg << "\n";
break; break;
case QtFatalMsg: case QtFatalMsg:
debugdate += QString(":FATAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) debugdate += QString(":FATAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
.arg(context.function).arg(context.category).arg(msg); .arg(context.function).arg(context.category).arg(msg);
vStdErr() << QApplication::translate("vNoisyHandler", "FATAL:") << msg << "\n";
break; break;
#if QT_VERSION > QT_VERSION_CHECK(5, 4, 2)
case QtInfoMsg:
debugdate += QString(":INFO:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
.arg(context.function).arg(context.category).arg(msg);
vStdOut() << QApplication::translate("vNoisyHandler", "INFO:") << msg << "\n";
break;
#endif
default: default:
break; break;
} }
@ -115,11 +126,6 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
(*qApp->LogFile()) << debugdate << endl; (*qApp->LogFile()) << debugdate << endl;
} }
if (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg)
{
vStdErr() << msg << "\n";
}
if (isGuiThread) if (isGuiThread)
{ {
//fixme: trying to make sure there are no save/load dialogs are opened, because error message during them will //fixme: trying to make sure there are no save/load dialogs are opened, because error message during them will
@ -131,14 +137,23 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
switch (type) switch (type)
{ {
case QtWarningMsg: case QtWarningMsg:
messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Warning."));
messageBox.setIcon(QMessageBox::Warning); messageBox.setIcon(QMessageBox::Warning);
break; break;
case QtCriticalMsg: case QtCriticalMsg:
messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Critical error."));
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
break; break;
case QtFatalMsg: case QtFatalMsg:
messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Fatal error."));
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
break; break;
#if QT_VERSION > QT_VERSION_CHECK(5, 4, 2)
case QtInfoMsg:
messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Information."));
messageBox.setIcon(QMessageBox::Information);
break;
#endif
case QtDebugMsg: case QtDebugMsg:
default: default:
break; break;
@ -150,11 +165,17 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
if (topWinAllowsPop) if (topWinAllowsPop)
{ {
messageBox.setInformativeText(msg); messageBox.setText(msg);
messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.setWindowModality(Qt::ApplicationModal); messageBox.setWindowModality(Qt::ApplicationModal);
messageBox.setModal(true); messageBox.setModal(true);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::ArrowCursor);
#endif
messageBox.exec(); messageBox.exec();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
} }
} }
} }
@ -271,45 +292,51 @@ bool VApplication::notify(QObject *receiver, QEvent *event)
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
e.CriticalMessageBox(tr("Error parsing file. Program will be terminated."), mainWindow); qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
{ {
e.CriticalMessageBox(tr("Error bad id. Program will be terminated."), mainWindow); qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error bad id. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionConversionError &e) catch (const VExceptionConversionError &e)
{ {
e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated."), mainWindow); qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated."), mainWindow); qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
e.CriticalMessageBox(tr("Error wrong id. Program will be terminated."), mainWindow); qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id. Program will be terminated.")),
abort(); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
std::exit(V_EX_DATAERR);
} }
catch (const VException &e) catch (const VException &e)
{ {
e.CriticalMessageBox(tr("Something's wrong!!"), mainWindow); qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return true; return true;
} }
// These last two cases special. I found that we can't show here modal dialog with error message. // These last two cases special. I found that we can't show here modal dialog with error message.
// Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang. // Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang.
catch (const qmu::QmuParserError &e) catch (const qmu::QmuParserError &e)
{ {
qCDebug(vApp, "Parser error: %s", e.GetMsg().toUtf8().constData()); qCCritical(vApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg())));
abort(); std::exit(V_EX_DATAERR);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
qCDebug(vApp, "Critical error! Exception thrown: %s", e.what()); qCCritical(vApp, "%s", qUtf8Printable(tr("Exception thrown: %1. Program will be terminated.").arg(e.what())));
abort(); std::exit(V_EX_SOFTWARE);
} }
return false; return false;
} }

View file

@ -94,7 +94,7 @@ void DialogAboutApp::webButtonClicked()
{ {
if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false) if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false)
{ {
QMessageBox::warning(this, tr("Warning"), tr("Cannot open your default browser")); qWarning() << tr("Cannot open your default browser");
} }
} }

View file

@ -86,20 +86,17 @@ void DialogLayoutProgress::Arranged(int count)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutProgress::Error(const LayoutErrors &state) void DialogLayoutProgress::Error(const LayoutErrors &state)
{ {
QString text;
switch (state) switch (state)
{ {
case LayoutErrors::NoError: case LayoutErrors::NoError:
return; return;
case LayoutErrors::PrepareLayoutError: case LayoutErrors::PrepareLayoutError:
text = tr("Couldn't prepare data for creation layout"); qCritical() << tr("Couldn't prepare data for creation layout");
QMessageBox::critical(this, tr("Critical error"), text, QMessageBox::Ok, QMessageBox::Ok);
break; break;
case LayoutErrors::ProcessStoped: case LayoutErrors::ProcessStoped:
break; break;
case LayoutErrors::EmptyPaperError: case LayoutErrors::EmptyPaperError:
text = tr("Several workpieces left not arranged, but none of them match for paper"); qCritical() << tr("Several workpieces left not arranged, but none of them match for paper");
QMessageBox::critical(this, tr("Critical error"), text, QMessageBox::Ok, QMessageBox::Ok);
break; break;
default: default:
break; break;

View file

@ -68,8 +68,6 @@
Q_LOGGING_CATEGORY(vMainWindow, "v.mainwindow") Q_LOGGING_CATEGORY(vMainWindow, "v.mainwindow")
#define OUT_FILE_ERROR vStdErr() << tr("File error: ") << e.ErrorMessage() << e.DetailedInformation() << "\n"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief MainWindow constructor. * @brief MainWindow constructor.
@ -289,9 +287,8 @@ bool MainWindow::LoadMeasurements(const QString &path)
{ {
if (m->MUnit() == Unit::Inch) if (m->MUnit() == Unit::Inch)
{ {
QMessageBox::critical(this, tr("Wrong units."), qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")),
tr("Application doesn't support standard table with inches.")); qUtf8Printable(tr("Application doesn't support standard table with inches.")));
qCDebug(vMainWindow, "Application doesn't support standard table with inches.");
return false; return false;
} }
m->SetDataSize(); m->SetDataSize();
@ -306,14 +303,8 @@ bool MainWindow::LoadMeasurements(const QString &path)
} }
catch (VException &e) catch (VException &e)
{ {
if (qApp->CheckGUI()) qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
{ qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
e.CriticalMessageBox(tr("File error."), this);
}
else
{
OUT_FILE_ERROR;
}
delete m; delete m;
return false; return false;
} }
@ -1878,8 +1869,8 @@ bool MainWindow::SaveAs()
{ {
if (lock->GetLockError() == QLockFile::LockFailedError) if (lock->GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(vMainWindow, "%s", tr("Failed to lock. This file already opened in another window.") qCCritical(vMainWindow, "%s",
.toUtf8().constData()); qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
return false; return false;
} }
} }
@ -1916,9 +1907,9 @@ bool MainWindow::SaveAs()
qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); qCDebug(vMainWindow, "Error type: %d", lock->GetLockError());
if (lock->GetLockError() == QLockFile::LockFailedError) if (lock->GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(vMainWindow, "%s", tr("Failed to lock. This file already opened in another window. " qCCritical(vMainWindow, "%s",
"Expect collissions when run 2 copies of the program.") qUtf8Printable(tr("Failed to lock. This file already opened in another window. Expect "
.toUtf8().constData()); "collissions when run 2 copies of the program.")));
lock.reset(); lock.reset();
} }
} }
@ -2132,44 +2123,42 @@ void MainWindow::FullParseFile()
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
e.CriticalMessageBox(tr("Error parsing file."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionConversionError &e) catch (const VExceptionConversionError &e)
{ {
e.CriticalMessageBox(tr("Error can't convert value."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
e.CriticalMessageBox(tr("Error empty parameter."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
e.CriticalMessageBox(tr("Error wrong id."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
catch (VException &e) catch (VException &e)
{ {
e.CriticalMessageBox(tr("Error parsing file."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
catch (const std::bad_alloc &) catch (const std::bad_alloc &)
{ {
#ifndef QT_NO_CURSOR qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc).")));
QApplication::restoreOverrideCursor();
#endif
QMessageBox::critical(this, tr("Critical error!"), tr("Error parsing file (std::bad_alloc)."), QMessageBox::Ok,
QMessageBox::Ok);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
@ -2208,13 +2197,15 @@ void MainWindow::GlobalChangePP(const QString &patternPiece)
} }
catch (VExceptionBadId &e) catch (VExceptionBadId &e)
{ {
e.CriticalMessageBox(tr("Bad id."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Bad id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
e.CriticalMessageBox(tr("Error empty parameter."), this); qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; return;
} }
@ -3140,7 +3131,7 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); qCDebug(vMainWindow, "Error type: %d", lock->GetLockError());
if (lock->GetLockError() == QLockFile::LockFailedError) if (lock->GetLockError() == QLockFile::LockFailedError)
{ {
qCCritical(vMainWindow, "%s", tr("This file already opened in another window.").toUtf8().constData()); qCCritical(vMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
Clear(); Clear();
return false; return false;
} }
@ -3195,14 +3186,8 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
} }
catch (VException &e) catch (VException &e)
{ {
if (qApp->CheckGUI()) qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
{ qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
e.CriticalMessageBox(tr("File error."), this);
}
else
{
OUT_FILE_ERROR;
}
Clear(); Clear();
return false; return false;
} }
@ -3560,7 +3545,7 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams)
{ {
if (details->count() == 0) if (details->count() == 0)
{ {
qCCritical(vMainWindow, "%s", tr("You can't export empty scene.").toUtf8().constData()); qCCritical(vMainWindow, "%s", qUtf8Printable(tr("You can't export empty scene.")));
std::exit(V_EX_DATAERR); std::exit(V_EX_DATAERR);
} }
} }

View file

@ -147,24 +147,22 @@ void MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
{ {
QString text;
switch (state) switch (state)
{ {
case LayoutErrors::NoError: case LayoutErrors::NoError:
return; return;
case LayoutErrors::PrepareLayoutError: case LayoutErrors::PrepareLayoutError:
text = tr("Couldn't prepare data for creation layout"); qCritical() << tr("Couldn't prepare data for creation layout");
break; break;
case LayoutErrors::ProcessStoped: case LayoutErrors::ProcessStoped:
break; break;
case LayoutErrors::EmptyPaperError: case LayoutErrors::EmptyPaperError:
text = tr("Several workpieces left not arranged, but none of them match for paper"); qCritical() << tr("Several workpieces left not arranged, but none of them match for paper");
break; break;
default: default:
break; break;
} }
qCritical() << text;
std::exit(V_EX_DATAERR); std::exit(V_EX_DATAERR);
} }
@ -591,7 +589,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const
QPainter painter; QPainter painter;
if (painter.begin( &printer ) == false) if (painter.begin( &printer ) == false)
{ // failed to open file { // failed to open file
qCritical("Can't open printer %s", qPrintable(name)); qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name)));
return; return;
} }
painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
@ -789,9 +787,8 @@ void MainWindowsNoGUI::PrintPreview()
{ {
if(QPrinterInfo::availablePrinters().isEmpty()) if(QPrinterInfo::availablePrinters().isEmpty())
{ {
QMessageBox::critical(this, tr("Print error"), qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")),
tr("Cannot proceed because there are no available printers in your system."), qUtf8Printable(tr("Cannot proceed because there are no available printers in your system.")));
QMessageBox::Ok);
return; return;
} }
else else

View file

@ -307,7 +307,8 @@ bool VPattern::SaveDocument(const QString &fileName, QString &error) const
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
e.CriticalMessageBox(tr("Error no unique id."), qApp->getMainWindow()); qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error no unique id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return false; return false;
} }
@ -351,44 +352,42 @@ void VPattern::LiteParseTree(const Document &parse)
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
e.CriticalMessageBox(tr("Error parsing file."), qApp->getMainWindow()); qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
emit SetEnabledGUI(false); emit SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionConversionError &e) catch (const VExceptionConversionError &e)
{ {
e.CriticalMessageBox(tr("Error can't convert value."), qApp->getMainWindow()); qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
emit SetEnabledGUI(false); emit SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
e.CriticalMessageBox(tr("Error empty parameter."), qApp->getMainWindow()); qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
emit SetEnabledGUI(false); emit SetEnabledGUI(false);
return; return;
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
e.CriticalMessageBox(tr("Error wrong id."), qApp->getMainWindow()); qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
emit SetEnabledGUI(false); emit SetEnabledGUI(false);
return; return;
} }
catch (VException &e) catch (VException &e)
{ {
e.CriticalMessageBox(tr("Error parsing file."), qApp->getMainWindow()); qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
emit SetEnabledGUI(false); emit SetEnabledGUI(false);
return; return;
} }
catch (const std::bad_alloc &) catch (const std::bad_alloc &)
{ {
#ifndef QT_NO_CURSOR qCCritical(vXML, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc).")));
QApplication::restoreOverrideCursor();
#endif
QMessageBox::critical(qApp->getMainWindow(), tr("Critical error!"), tr("Error parsing file (std::bad_alloc)."),
QMessageBox::Ok, QMessageBox::Ok);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
emit SetEnabledGUI(false); emit SetEnabledGUI(false);
return; return;
} }

View file

@ -78,37 +78,6 @@ QString VException::ErrorMessage() const
return error; return error;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief CriticalMessageBox show Critical Message Box.
* @param situation main text message box.
*/
void VException::CriticalMessageBox(const QString &situation, QWidget * parent) const
{
QMessageBox msgBox(parent);
msgBox.setWindowTitle(tr("Critical error!"));
msgBox.setText(situation);
msgBox.setInformativeText(ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
if (moreInfo.isEmpty() == false)
{
msgBox.setDetailedText(DetailedInformation());
}
msgBox.setIcon(QMessageBox::Critical);
QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout* layout = static_cast<QGridLayout*>(msgBox.layout());
SCASSERT(layout != nullptr);
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
//Disable Qt::WaitCursor for error message.
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
qCDebug(vExcep, "Critical error! %s %s %s", situation.toUtf8().constData(), ErrorMessage().toUtf8().constData(),
DetailedInformation().toUtf8().constData());
msgBox.exec();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief AddMoreInformation add more information for error * @brief AddMoreInformation add more information for error

View file

@ -54,7 +54,6 @@ public:
virtual QString ErrorMessage() const; virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const; virtual QString DetailedInformation() const;
QString What() const; QString What() const;
virtual void CriticalMessageBox(const QString &situation, QWidget *parent = nullptr) const;
void AddMoreInformation(const QString &info); void AddMoreInformation(const QString &info);
QString MoreInformation() const; QString MoreInformation() const;
protected: protected:

View file

@ -300,7 +300,7 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2,
{ {
if (QPointF(px.at(i-1), py.at(i-1)) == QPointF(px.at(i), py.at(i))) if (QPointF(px.at(i-1), py.at(i-1)) == QPointF(px.at(i), py.at(i)))
{ {
qCritical("All neighbors points in path must be unique."); qDebug("All neighbors points in path must be unique.");
} }
} }
} }

View file

@ -418,6 +418,10 @@ void SetOverrideCursor(const QString &pixmapPath, int hotX, int hotY)
{ {
QApplication::setOverrideCursor(QCursor(newPixmap, hotX, hotY)); QApplication::setOverrideCursor(QCursor(newPixmap, hotX, hotY));
} }
#else
Q_UNUSED(pixmapPath);
Q_UNUSED(hotX);
Q_UNUSED(hotY);
#endif #endif
} }
@ -439,6 +443,8 @@ void RestoreOverrideCursor(const QString &pixmapPath)
{ {
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
#else
Q_UNUSED(pixmapPath);
#endif #endif
} }

View file

@ -163,18 +163,12 @@ enum class GSizes : unsigned char { ALL,
*/ */
#ifndef V_NO_ASSERT #ifndef V_NO_ASSERT
#ifdef Q_CC_MSVC
#define V_PRETTY_FUNCTION __FUNCSIG__
#else // GCC/Clang
#define V_PRETTY_FUNCTION __PRETTY_FUNCTION__
#endif /*Q_CC_MSVC*/
#define SCASSERT(cond) \ #define SCASSERT(cond) \
{ \ { \
if (!(cond)) \ if (!(cond)) \
{ \ { \
qDebug("ASSERT: %s in %s (%s:%u)", \ qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, V_PRETTY_FUNCTION, __FILE__, __LINE__); \ #cond, Q_FUNC_INFO , __FILE__, __LINE__); \
debug_break(); \ debug_break(); \
} \ } \
} \ } \

View file

@ -17,6 +17,13 @@
#include <QtGlobal> #include <QtGlobal>
// Backport useful macros
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
# ifndef qUtf8Printable
# define qUtf8Printable(string) QString(string).toUtf8().constData()
# endif
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
// //