diff --git a/src/app/tape/dialogs/dialogabouttape.cpp b/src/app/tape/dialogs/dialogabouttape.cpp index b1f216cc3..23a95bad7 100644 --- a/src/app/tape/dialogs/dialogabouttape.cpp +++ b/src/app/tape/dialogs/dialogabouttape.cpp @@ -83,7 +83,7 @@ void DialogAboutTape::WebButtonClicked() { 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"); } } diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index eaf00bdff..f4b5f9201 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -47,6 +47,8 @@ #include #include #include +#include +#include Q_LOGGING_CATEGORY(mApp, "m.application") @@ -93,13 +95,22 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con switch (type) { case QtDebugMsg: - vStdOut() << msg << "\n"; + vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << msg << "\n"; return; case QtWarningMsg: - case QtCriticalMsg: - case QtFatalMsg: - vStdErr() << msg << "\n"; + vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << msg << "\n"; 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: break; } @@ -114,14 +125,23 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con switch (type) { case QtWarningMsg: + messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Warning.")); messageBox.setIcon(QMessageBox::Warning); break; case QtCriticalMsg: + messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Critical error.")); messageBox.setIcon(QMessageBox::Critical); break; case QtFatalMsg: + messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error.")); messageBox.setIcon(QMessageBox::Critical); 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: default: break; @@ -133,11 +153,17 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con { if (topWinAllowsPop) { - messageBox.setInformativeText(msg); + messageBox.setText(msg); messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setWindowModality(Qt::ApplicationModal); messageBox.setModal(true); + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::ArrowCursor); + #endif messageBox.exec(); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif } } } @@ -230,45 +256,51 @@ bool MApplication::notify(QObject *receiver, QEvent *event) } catch (const VExceptionObjectError &e) { - e.CriticalMessageBox(tr("Error parsing file. Program will be terminated."), mainWindow); - abort(); + qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionBadId &e) { - e.CriticalMessageBox(tr("Error bad id. Program will be terminated."), mainWindow); - abort(); + qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error bad id. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionConversionError &e) { - e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated."), mainWindow); - abort(); + qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionEmptyParameter &e) { - e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated."), mainWindow); - abort(); + qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionWrongId &e) { - e.CriticalMessageBox(tr("Error wrong id. Program will be terminated."), mainWindow); - abort(); + qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } 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; } // 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. catch (const qmu::QmuParserError &e) { - qCDebug(mApp, "Parser error: %s", e.GetMsg().toUtf8().constData()); - abort(); + qCCritical(mApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg()))); + std::exit(V_EX_DATAERR); } - catch (std::exception& e) + catch (std::exception &e) { - qCDebug(mApp, "Critical error! Exception thrown: %s", e.what()); - abort(); + qCCritical(mApp, "%s", qUtf8Printable(tr("Exception thrown: %1. Program will be terminated.").arg(e.what()))); + std::exit(V_EX_SOFTWARE); } return false; } diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 9a95d5520..da203ec47 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -166,7 +166,7 @@ void TMainWindow::LoadFile(const QString &path) { if (not QFileInfo(path).exists()) { - qCritical()<IsTestMode()) { std::exit(V_EX_NOINPUT); @@ -190,8 +190,12 @@ void TMainWindow::LoadFile(const QString &path) 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(); + if (qApp->IsTestMode()) + { + std::exit(V_EX_NOINPUT); + } return; } @@ -257,7 +261,8 @@ void TMainWindow::LoadFile(const QString &path) } 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->tabWidget->setVisible(false); delete m; @@ -497,8 +502,8 @@ void TMainWindow::FileSaveAs() { if (lock->GetLockError() == QLockFile::LockFailedError) { - qCCritical(tMainWindow, "%s", tr("Failed to lock. This file already opened in another window.") - .toUtf8().constData()); + qCCritical(tMainWindow, "%s", + qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); return; } } @@ -525,8 +530,8 @@ void TMainWindow::FileSaveAs() if (lock->GetLockError() == QLockFile::LockFailedError) { - qCCritical(tMainWindow, "%s", tr("Failed to lock. This file already opened in another window. " - "Expect collissions when run 2 copies of the program.").toUtf8().constData()); + qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. " + "Expect collissions when run 2 copies of the program."))); lock.reset(); return; } @@ -780,7 +785,9 @@ void TMainWindow::Fx() } 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; } @@ -931,7 +938,7 @@ void TMainWindow::ImportFromPattern() 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; } @@ -953,7 +960,8 @@ void TMainWindow::ImportFromPattern() } 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; } @@ -1151,9 +1159,11 @@ void TMainWindow::SaveMName() // Translate to internal look. meash = data->GetVariable(nameField->data(Qt::UserRole).toString()); } - 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; } @@ -1180,7 +1190,7 @@ void TMainWindow::SaveMName() } 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) { - 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; } @@ -1720,7 +1732,7 @@ bool TMainWindow::MaybeSave() QMessageBox::StandardButton ret; ret = QMessageBox::warning(this, tr("Unsaved changes"), tr("Measurements have been modified.\n" - "Do you want to save your changes?"), + "Do you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); if (ret == QMessageBox::Save) { diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index cfee6a918..ed54c79f1 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -95,19 +95,30 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con case QtDebugMsg: debugdate += QString(":DEBUG:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) .arg(context.function).arg(context.category).arg(msg); + vStdOut() << QApplication::translate("vNoisyHandler", "DEBUG:") << msg << "\n"; break; case QtWarningMsg: debugdate += QString(":WARNING:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) .arg(context.function).arg(context.category).arg(msg); + vStdErr() << QApplication::translate("vNoisyHandler", "WARNING:") << msg << "\n"; break; case QtCriticalMsg: debugdate += QString(":CRITICAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) .arg(context.function).arg(context.category).arg(msg); + vStdErr() << QApplication::translate("vNoisyHandler", "CRITICAL:") << msg << "\n"; break; case QtFatalMsg: debugdate += QString(":FATAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line) .arg(context.function).arg(context.category).arg(msg); + vStdErr() << QApplication::translate("vNoisyHandler", "FATAL:") << msg << "\n"; 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: break; } @@ -115,11 +126,6 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con (*qApp->LogFile()) << debugdate << endl; } - if (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg) - { - vStdErr() << msg << "\n"; - } - if (isGuiThread) { //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) { case QtWarningMsg: + messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Warning.")); messageBox.setIcon(QMessageBox::Warning); break; case QtCriticalMsg: + messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Critical error.")); messageBox.setIcon(QMessageBox::Critical); break; case QtFatalMsg: + messageBox.setWindowTitle(QApplication::translate("vNoisyHandler", "Fatal error.")); messageBox.setIcon(QMessageBox::Critical); 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: default: break; @@ -150,11 +165,17 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con { if (topWinAllowsPop) { - messageBox.setInformativeText(msg); + messageBox.setText(msg); messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setWindowModality(Qt::ApplicationModal); messageBox.setModal(true); + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::ArrowCursor); + #endif messageBox.exec(); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif } } } @@ -271,45 +292,51 @@ bool VApplication::notify(QObject *receiver, QEvent *event) } catch (const VExceptionObjectError &e) { - e.CriticalMessageBox(tr("Error parsing file. Program will be terminated."), mainWindow); - abort(); + qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionBadId &e) { - e.CriticalMessageBox(tr("Error bad id. Program will be terminated."), mainWindow); - abort(); + qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error bad id. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionConversionError &e) { - e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated."), mainWindow); - abort(); + qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionEmptyParameter &e) { - e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated."), mainWindow); - abort(); + qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } catch (const VExceptionWrongId &e) { - e.CriticalMessageBox(tr("Error wrong id. Program will be terminated."), mainWindow); - abort(); + qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id. Program will be terminated.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + std::exit(V_EX_DATAERR); } 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; } // 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. catch (const qmu::QmuParserError &e) { - qCDebug(vApp, "Parser error: %s", e.GetMsg().toUtf8().constData()); - abort(); + qCCritical(vApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg()))); + std::exit(V_EX_DATAERR); } catch (std::exception& e) { - qCDebug(vApp, "Critical error! Exception thrown: %s", e.what()); - abort(); + qCCritical(vApp, "%s", qUtf8Printable(tr("Exception thrown: %1. Program will be terminated.").arg(e.what()))); + std::exit(V_EX_SOFTWARE); } return false; } diff --git a/src/app/valentina/dialogs/dialogaboutapp.cpp b/src/app/valentina/dialogs/dialogaboutapp.cpp index cfad9e947..ed677aec3 100644 --- a/src/app/valentina/dialogs/dialogaboutapp.cpp +++ b/src/app/valentina/dialogs/dialogaboutapp.cpp @@ -94,7 +94,7 @@ void DialogAboutApp::webButtonClicked() { 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"); } } diff --git a/src/app/valentina/dialogs/dialoglayoutprogress.cpp b/src/app/valentina/dialogs/dialoglayoutprogress.cpp index edb45a9b4..79b2403cf 100644 --- a/src/app/valentina/dialogs/dialoglayoutprogress.cpp +++ b/src/app/valentina/dialogs/dialoglayoutprogress.cpp @@ -86,20 +86,17 @@ void DialogLayoutProgress::Arranged(int count) //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutProgress::Error(const LayoutErrors &state) { - QString text; switch (state) { case LayoutErrors::NoError: return; case LayoutErrors::PrepareLayoutError: - text = tr("Couldn't prepare data for creation layout"); - QMessageBox::critical(this, tr("Critical error"), text, QMessageBox::Ok, QMessageBox::Ok); + qCritical() << tr("Couldn't prepare data for creation layout"); break; case LayoutErrors::ProcessStoped: break; case LayoutErrors::EmptyPaperError: - text = tr("Several workpieces left not arranged, but none of them match for paper"); - QMessageBox::critical(this, tr("Critical error"), text, QMessageBox::Ok, QMessageBox::Ok); + qCritical() << tr("Several workpieces left not arranged, but none of them match for paper"); break; default: break; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 00a1a72eb..f25dc6a7d 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -68,8 +68,6 @@ Q_LOGGING_CATEGORY(vMainWindow, "v.mainwindow") -#define OUT_FILE_ERROR vStdErr() << tr("File error: ") << e.ErrorMessage() << e.DetailedInformation() << "\n" - //--------------------------------------------------------------------------------------------------------------------- /** * @brief MainWindow constructor. @@ -289,9 +287,8 @@ bool MainWindow::LoadMeasurements(const QString &path) { if (m->MUnit() == Unit::Inch) { - QMessageBox::critical(this, tr("Wrong units."), - tr("Application doesn't support standard table with inches.")); - qCDebug(vMainWindow, "Application doesn't support standard table with inches."); + qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")), + qUtf8Printable(tr("Application doesn't support standard table with inches."))); return false; } m->SetDataSize(); @@ -306,14 +303,8 @@ bool MainWindow::LoadMeasurements(const QString &path) } catch (VException &e) { - if (qApp->CheckGUI()) - { - e.CriticalMessageBox(tr("File error."), this); - } - else - { - OUT_FILE_ERROR; - } + qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); delete m; return false; } @@ -1878,8 +1869,8 @@ bool MainWindow::SaveAs() { if (lock->GetLockError() == QLockFile::LockFailedError) { - qCCritical(vMainWindow, "%s", tr("Failed to lock. This file already opened in another window.") - .toUtf8().constData()); + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); return false; } } @@ -1916,9 +1907,9 @@ bool MainWindow::SaveAs() qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); if (lock->GetLockError() == QLockFile::LockFailedError) { - qCCritical(vMainWindow, "%s", tr("Failed to lock. This file already opened in another window. " - "Expect collissions when run 2 copies of the program.") - .toUtf8().constData()); + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("Failed to lock. This file already opened in another window. Expect " + "collissions when run 2 copies of the program."))); lock.reset(); } } @@ -2132,44 +2123,42 @@ void MainWindow::FullParseFile() } 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); return; } 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); return; } 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); return; } 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); return; } 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); return; } catch (const std::bad_alloc &) { -#ifndef QT_NO_CURSOR - 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 + qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc)."))); SetEnabledGUI(false); return; } @@ -2208,13 +2197,15 @@ void MainWindow::GlobalChangePP(const QString &patternPiece) } 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); return; } 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); return; } @@ -2749,7 +2740,7 @@ bool MainWindow::MaybeSave() { QMessageBox::StandardButton ret; ret = QMessageBox::warning(this, tr("Unsaved changes"), tr("The pattern has been modified.\n" - "Do you want to save your changes?"), + "Do you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); if (ret == QMessageBox::Save) { @@ -3140,7 +3131,7 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); 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(); return false; } @@ -3195,14 +3186,8 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu } catch (VException &e) { - if (qApp->CheckGUI()) - { - e.CriticalMessageBox(tr("File error."), this); - } - else - { - OUT_FILE_ERROR; - } + qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); Clear(); return false; } @@ -3560,7 +3545,7 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) { 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); } } diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 4d74eb013..e2566209f 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -147,24 +147,22 @@ void MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator) //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) { - QString text; switch (state) { case LayoutErrors::NoError: return; case LayoutErrors::PrepareLayoutError: - text = tr("Couldn't prepare data for creation layout"); + qCritical() << tr("Couldn't prepare data for creation layout"); break; case LayoutErrors::ProcessStoped: break; 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; default: break; } - qCritical() << text; std::exit(V_EX_DATAERR); } @@ -591,7 +589,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const QPainter painter; if (painter.begin( &printer ) == false) { // failed to open file - qCritical("Can't open printer %s", qPrintable(name)); + qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name))); return; } painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); @@ -789,9 +787,8 @@ void MainWindowsNoGUI::PrintPreview() { if(QPrinterInfo::availablePrinters().isEmpty()) { - QMessageBox::critical(this, tr("Print error"), - tr("Cannot proceed because there are no available printers in your system."), - QMessageBox::Ok); + qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), + qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); return; } else diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 6c59a41f5..5bb77ab59 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -307,7 +307,8 @@ bool VPattern::SaveDocument(const QString &fileName, QString &error) const } 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; } @@ -351,44 +352,42 @@ void VPattern::LiteParseTree(const Document &parse) } 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); return; } 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); return; } 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); return; } 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); return; } 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); return; } catch (const std::bad_alloc &) { -#ifndef QT_NO_CURSOR - 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 + qCCritical(vXML, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc)."))); emit SetEnabledGUI(false); return; } diff --git a/src/libs/ifc/exception/vexception.cpp b/src/libs/ifc/exception/vexception.cpp index 1c621b2c5..64c019c44 100644 --- a/src/libs/ifc/exception/vexception.cpp +++ b/src/libs/ifc/exception/vexception.cpp @@ -78,37 +78,6 @@ QString VException::ErrorMessage() const 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(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 diff --git a/src/libs/ifc/exception/vexception.h b/src/libs/ifc/exception/vexception.h index 66dcb63ed..78db09df8 100644 --- a/src/libs/ifc/exception/vexception.h +++ b/src/libs/ifc/exception/vexception.h @@ -54,7 +54,6 @@ public: virtual QString ErrorMessage() const; virtual QString DetailedInformation() const; QString What() const; - virtual void CriticalMessageBox(const QString &situation, QWidget *parent = nullptr) const; void AddMoreInformation(const QString &info); QString MoreInformation() const; protected: diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 139839473..ab51f05ce 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -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))) { - qCritical("All neighbors points in path must be unique."); + qDebug("All neighbors points in path must be unique."); } } } diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 8bc3d4969..c79655754 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -418,6 +418,10 @@ void SetOverrideCursor(const QString &pixmapPath, int hotX, int hotY) { QApplication::setOverrideCursor(QCursor(newPixmap, hotX, hotY)); } +#else + Q_UNUSED(pixmapPath); + Q_UNUSED(hotX); + Q_UNUSED(hotY); #endif } @@ -439,6 +443,8 @@ void RestoreOverrideCursor(const QString &pixmapPath) { QApplication::restoreOverrideCursor(); } +#else + Q_UNUSED(pixmapPath); #endif } diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 00dc252b3..196f0de76 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -163,18 +163,12 @@ enum class GSizes : unsigned char { ALL, */ #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) \ { \ if (!(cond)) \ { \ qDebug("ASSERT: %s in %s (%s:%u)", \ - #cond, V_PRETTY_FUNCTION, __FILE__, __LINE__); \ + #cond, Q_FUNC_INFO , __FILE__, __LINE__); \ debug_break(); \ } \ } \ diff --git a/src/libs/vmisc/logging.h b/src/libs/vmisc/logging.h index 214e256d5..6ca293f0c 100644 --- a/src/libs/vmisc/logging.h +++ b/src/libs/vmisc/logging.h @@ -17,6 +17,13 @@ #include +// 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) //