Refactoring.

Code style.
This commit is contained in:
Roman Telezhynskyi 2023-06-08 13:20:20 +03:00
parent 3a7803b78f
commit b5779ca3e8
13 changed files with 268 additions and 263 deletions

View File

@ -26,26 +26,27 @@
** **
*************************************************************************/ *************************************************************************/
#include "puzzlepreferencespathpage.h" #include "puzzlepreferencespathpage.h"
#include "ui_puzzlepreferencespathpage.h"
#include "../../vpapplication.h" #include "../../vpapplication.h"
#include "ui_puzzlepreferencespathpage.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PuzzlePreferencesPathPage::PuzzlePreferencesPathPage(QWidget *parent) : PuzzlePreferencesPathPage::PuzzlePreferencesPathPage(QWidget *parent)
QWidget(parent), : QWidget(parent),
ui(new Ui::PuzzlePreferencesPathPage) ui(new Ui::PuzzlePreferencesPathPage)
{ {
ui->setupUi(this); ui->setupUi(this);
InitTable(); InitTable();
connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]() connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this,
{ [this]()
ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); {
ui->defaultButton->setDefault(false); ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty());
ui->defaultButton->setDefault(false);
ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty());
ui->editButton->setDefault(true); ui->editButton->setDefault(true);
}); });
connect(ui->defaultButton, &QPushButton::clicked, this, &PuzzlePreferencesPathPage::DefaultPath); connect(ui->defaultButton, &QPushButton::clicked, this, &PuzzlePreferencesPathPage::DefaultPath);
connect(ui->editButton, &QPushButton::clicked, this, &PuzzlePreferencesPathPage::EditPath); connect(ui->editButton, &QPushButton::clicked, this, &PuzzlePreferencesPathPage::EditPath);

View File

@ -30,11 +30,9 @@
#include <QWidget> #include <QWidget>
#include "../vmisc/defglobal.h"
namespace Ui namespace Ui
{ {
class PuzzlePreferencesPathPage; class PuzzlePreferencesPathPage;
} }
class PuzzlePreferencesPathPage : public QWidget class PuzzlePreferencesPathPage : public QWidget
@ -48,7 +46,7 @@ public:
void Apply(); void Apply();
protected: protected:
void changeEvent(QEvent* event) override; void changeEvent(QEvent *event) override;
private slots: private slots:
void DefaultPath(); void DefaultPath();

View File

@ -27,24 +27,24 @@
*************************************************************************/ *************************************************************************/
#include "vpapplication.h" #include "vpapplication.h"
#include "version.h"
#include "vpmainwindow.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/exception/vexceptionbadid.h" #include "../ifc/exception/vexceptionbadid.h"
#include "../ifc/exception/vexceptionconversionerror.h" #include "../ifc/exception/vexceptionconversionerror.h"
#include "../ifc/exception/vexceptionemptyparameter.h" #include "../ifc/exception/vexceptionemptyparameter.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/exception/vexceptionwrongid.h" #include "../ifc/exception/vexceptionwrongid.h"
#include "../vmisc/vsysexits.h" #include "../vmisc/vsysexits.h"
#include "version.h"
#include "vpmainwindow.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/qt_dispatch/qt_dispatch.h"
#include "../fervor/fvupdater.h" #include "../fervor/fvupdater.h"
#include "../vmisc/qt_dispatch/qt_dispatch.h"
#include <QMessageBox>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QMessageBox>
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
@ -55,9 +55,9 @@ Q_LOGGING_CATEGORY(pApp, "p.application") // NOLINT
QT_WARNING_POP QT_WARNING_POP
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QLocalSocket>
#include <QLocalServer>
#include <QFileOpenEvent> #include <QFileOpenEvent>
#include <QLocalServer>
#include <QLocalSocket>
#include <QPixmapCache> #include <QPixmapCache>
#if !defined(BUILD_REVISION) && defined(QBS_BUILD) #if !defined(BUILD_REVISION) && defined(QBS_BUILD)
@ -66,7 +66,8 @@ QT_WARNING_POP
#endif #endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) // NOLINT(readability-function-cognitive-complexity) inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context,
const QString &msg) // NOLINT(readability-function-cognitive-complexity)
{ {
// only the GUI thread should display message boxes. If you are // only the GUI thread should display message boxes. If you are
// writing a multithreaded application and the error happens on // writing a multithreaded application and the error happens on
@ -77,9 +78,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
if (not isGuiThread) if (not isGuiThread)
{ {
auto Handler = [](QtMsgType type, const QMessageLogContext &context, const QString &msg) auto Handler = [](QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ { noisyFailureMsgHandler(type, context, msg); };
noisyFailureMsgHandler(type, context, msg);
};
q_dispatch_async_main(Handler, type, context, msg); q_dispatch_async_main(Handler, type, context, msg);
return; return;
@ -102,20 +101,20 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
#endif //defined(V_NO_ASSERT) #endif // defined(V_NO_ASSERT)
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
# if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
// Try hide very annoying, Qt related, warnings in Mac OS X // Try hide very annoying, Qt related, warnings in Mac OS X
// QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton) // QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)
// https://bugreports.qt.io/browse/QTBUG-42846 // https://bugreports.qt.io/browse/QTBUG-42846
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QNSView"))) if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QNSView")))
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
# endif #endif
# if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
// Hide Qt bug 'Assertion when reading an icns file' // Hide Qt bug 'Assertion when reading an icns file'
// https://bugreports.qt.io/browse/QTBUG-45537 // https://bugreports.qt.io/browse/QTBUG-45537
// Remove after Qt fix will be released // Remove after Qt fix will be released
@ -123,7 +122,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
# endif #endif
// Hide anything that starts with QMacCGContext // Hide anything that starts with QMacCGContext
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QMacCGContext::"))) if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QMacCGContext::")))
@ -141,8 +140,8 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
// this is another one that doesn't make sense as just a debug message. pretty serious // this is another one that doesn't make sense as just a debug message. pretty serious
// sign of a problem // sign of a problem
// http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue) // http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue)
if ((type == QtDebugMsg) && msg.contains(QStringLiteral("QPainter::begin")) if ((type == QtDebugMsg) && msg.contains(QStringLiteral("QPainter::begin")) &&
&& msg.contains(QStringLiteral("Paint device returned engine"))) msg.contains(QStringLiteral("Paint device returned engine")))
{ {
type = QtWarningMsg; type = QtWarningMsg;
} }
@ -150,8 +149,8 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
// This qWarning about "Cowardly refusing to send clipboard message to hung application..." // This qWarning about "Cowardly refusing to send clipboard message to hung application..."
// is something that can easily happen if you are debugging and the application is paused. // is something that can easily happen if you are debugging and the application is paused.
// As it is so common, not worth popping up a dialog. // As it is so common, not worth popping up a dialog.
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QClipboard::event")) if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QClipboard::event")) &&
&& msg.contains(QStringLiteral("Cowardly refusing"))) msg.contains(QStringLiteral("Cowardly refusing")))
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
@ -170,11 +169,11 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
case QtFatalMsg: case QtFatalMsg:
vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << msg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << msg << "\n";
break; break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
case QtInfoMsg: case QtInfoMsg:
vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << msg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << msg << "\n";
break; break;
#endif #endif
default: default:
break; break;
} }
@ -184,10 +183,10 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
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
//lead to crash // lead to crash
const bool topWinAllowsPop = (QApplication::activeModalWidget() == nullptr) || const bool topWinAllowsPop = (QApplication::activeModalWidget() == nullptr) ||
!QApplication::activeModalWidget()->inherits("QFileDialog"); !QApplication::activeModalWidget()->inherits("QFileDialog");
QMessageBox messageBox; QMessageBox messageBox;
switch (type) switch (type)
{ {
@ -203,12 +202,12 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error")); messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error"));
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
break; break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
case QtInfoMsg: case QtInfoMsg:
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Information")); messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Information"));
messageBox.setIcon(QMessageBox::Information); messageBox.setIcon(QMessageBox::Information);
break; break;
#endif #endif
case QtDebugMsg: case QtDebugMsg:
Q_UNREACHABLE(); //-V501 Q_UNREACHABLE(); //-V501
break; break;
@ -226,13 +225,13 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
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 #ifndef QT_NO_CURSOR
QGuiApplication::setOverrideCursor(Qt::ArrowCursor); QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
#endif #endif
messageBox.exec(); messageBox.exec();
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
QGuiApplication::restoreOverrideCursor(); QGuiApplication::restoreOverrideCursor();
#endif #endif
} }
} }
} }
@ -253,7 +252,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPApplication::VPApplication(int &argc, char **argv) VPApplication::VPApplication(int &argc, char **argv)
:VAbstractApplication(argc, argv) : VAbstractApplication(argc, argv)
{ {
setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR)); setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR));
setApplicationName(QStringLiteral(VER_INTERNALNAME_STR)); setApplicationName(QStringLiteral(VER_INTERNALNAME_STR));
@ -289,7 +288,8 @@ auto VPApplication::notify(QObject *receiver, QEvent *event) -> bool
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
qCCritical(pApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file. Program will be terminated.")), //-V807 qCCritical(pApp, "%s\n\n%s\n\n%s",
qUtf8Printable(tr("Error parsing file. Program will be terminated.")), //-V807
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
exit(V_EX_DATAERR); exit(V_EX_DATAERR);
} }
@ -326,8 +326,8 @@ auto VPApplication::notify(QObject *receiver, QEvent *event) -> bool
} }
catch (const VException &e) catch (const VException &e)
{ {
qCCritical(pApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), qCCritical(pApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), qUtf8Printable(e.ErrorMessage()),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.DetailedInformation()));
return true; return true;
} }
catch (std::exception &e) catch (std::exception &e)
@ -348,7 +348,7 @@ auto VPApplication::IsAppInGUIMode() const -> bool
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPApplication::MainWindow()-> VPMainWindow * auto VPApplication::MainWindow() -> VPMainWindow *
{ {
Clean(); Clean();
if (m_mainWindows.isEmpty()) if (m_mainWindows.isEmpty())
@ -362,7 +362,7 @@ auto VPApplication::MainWindow()-> VPMainWindow *
auto VPApplication::MainWindows() -> QList<VPMainWindow *> auto VPApplication::MainWindows() -> QList<VPMainWindow *>
{ {
Clean(); Clean();
QList<VPMainWindow*> list; QList<VPMainWindow *> list;
list.reserve(m_mainWindows.size()); list.reserve(m_mainWindows.size());
for (auto &w : m_mainWindows) for (auto &w : m_mainWindows)
{ {
@ -406,19 +406,19 @@ void VPApplication::InitOptions()
QPixmapCache::setCacheLimit(50 * 1024 /* 50 MB */); QPixmapCache::setCacheLimit(50 * 1024 /* 50 MB */);
LoadTranslation(QString());// By default the console version uses system locale LoadTranslation(QString()); // By default the console version uses system locale
VPCommandLine::Instance(); VPCommandLine::Instance();
CheckSystemLocale(); CheckSystemLocale();
static const char * GENERIC_ICON_TO_CHECK = "document-open"; static const char *GENERIC_ICON_TO_CHECK = "document-open";
if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK)) if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK))
{ {
//If there is no default working icon theme then we should // If there is no default working icon theme then we should
//use an icon theme that we provide via a .qrc file // use an icon theme that we provide via a .qrc file
//This case happens under Windows and Mac OS X // This case happens under Windows and Mac OS X
//This does not happen under GNOME or KDE // This does not happen under GNOME or KDE
QIcon::setThemeName(QStringLiteral("win.icon.theme")); QIcon::setThemeName(QStringLiteral("win.icon.theme"));
} }
ActivateDarkMode(); ActivateDarkMode();
@ -450,17 +450,17 @@ void VPApplication::ActivateDarkMode()
VPSettings *settings = PuzzleSettings(); VPSettings *settings = PuzzleSettings();
if (settings->GetDarkMode()) if (settings->GetDarkMode())
{ {
QFile f(QStringLiteral(":qdarkstyle/style.qss")); QFile f(QStringLiteral(":qdarkstyle/style.qss"));
if (!f.exists()) if (!f.exists())
{ {
qDebug()<<"Unable to set stylesheet, file not found\n"; qDebug() << "Unable to set stylesheet, file not found\n";
} }
else else
{ {
f.open(QFile::ReadOnly | QFile::Text); f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f); QTextStream ts(&f);
VPApplication::VApp()->setStyleSheet(ts.readAll()); VPApplication::VApp()->setStyleSheet(ts.readAll());
} }
} }
} }
@ -530,20 +530,21 @@ void VPApplication::ProcessCMD()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPApplication::event(QEvent *e) -> bool auto VPApplication::event(QEvent *e) -> bool
{ {
switch(e->type()) switch (e->type())
{ {
// In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is // In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is
// Mac specific). // Mac specific).
case QEvent::FileOpen: case QEvent::FileOpen:
{ {
auto *fileOpenEvent = static_cast<QFileOpenEvent *>(e); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) auto *fileOpenEvent =
static_cast<QFileOpenEvent *>(e); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
const QString macFileOpen = fileOpenEvent->file(); const QString macFileOpen = fileOpenEvent->file();
if(not macFileOpen.isEmpty()) if (not macFileOpen.isEmpty())
{ {
VPMainWindow *mw = MainWindow(); VPMainWindow *mw = MainWindow();
if (mw != nullptr) if (mw != nullptr)
{ {
mw->LoadFile(macFileOpen); // open file in existing window mw->LoadFile(macFileOpen); // open file in existing window
} }
return true; return true;
} }
@ -560,7 +561,7 @@ auto VPApplication::event(QEvent *e) -> bool
} }
return true; return true;
} }
#endif //defined(Q_OS_MAC) #endif // defined(Q_OS_MAC)
default: default:
return VAbstractApplication::event(e); return VAbstractApplication::event(e);
} }
@ -585,7 +586,7 @@ void VPApplication::AboutToQuit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPApplication::NewLocalSocketConnection() void VPApplication::NewLocalSocketConnection()
{ {
QScopedPointer<QLocalSocket>socket(m_localServer->nextPendingConnection()); QScopedPointer<QLocalSocket> socket(m_localServer->nextPendingConnection());
if (socket.isNull()) if (socket.isNull())
{ {
return; return;
@ -633,16 +634,15 @@ void VPApplication::StartLocalServer(const QString &serverName)
connect(m_localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection); connect(m_localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection);
if (not m_localServer->listen(serverName)) if (not m_localServer->listen(serverName))
{ {
qCDebug(pApp, "Can't begin to listen for incoming connections on name '%s'", qCDebug(pApp, "Can't begin to listen for incoming connections on name '%s'", qUtf8Printable(serverName));
qUtf8Printable(serverName));
if (m_localServer->serverError() == QAbstractSocket::AddressInUseError) if (m_localServer->serverError() == QAbstractSocket::AddressInUseError)
{ {
QLocalServer::removeServer(serverName); QLocalServer::removeServer(serverName);
if (not m_localServer->listen(serverName)) if (not m_localServer->listen(serverName))
{ {
qCWarning(pApp, "%s", qCWarning(
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'") pApp, "%s",
.arg(serverName))); qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'").arg(serverName)));
} }
} }
} }
@ -715,5 +715,5 @@ auto VPApplication::CommandLine() -> VPCommandLinePtr
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPApplication::VApp() -> VPApplication * auto VPApplication::VApp() -> VPApplication *
{ {
return qobject_cast<VPApplication*>(QCoreApplication::instance()); return qobject_cast<VPApplication *>(QCoreApplication::instance());
} }

View File

@ -35,9 +35,10 @@
class VPSettings : public VCommonSettings class VPSettings : public VCommonSettings
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
VPSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), VPSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(),
QObject *parent = nullptr); QObject *parent = nullptr);
VPSettings(const QString &fileName, Format format, QObject *parent = nullptr); VPSettings(const QString &fileName, Format format, QObject *parent = nullptr);
~VPSettings() override = default; ~VPSettings() override = default;

View File

@ -32,7 +32,6 @@
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include "../ifc/xml/vabstractconverter.h" #include "../ifc/xml/vabstractconverter.h"
#include "../layout/layoutdef.h" #include "../layout/layoutdef.h"
#include "../vmisc/defglobal.h"
#include <QLoggingCategory> #include <QLoggingCategory>

View File

@ -27,30 +27,31 @@
*************************************************************************/ *************************************************************************/
#include "tapepreferencespathpage.h" #include "tapepreferencespathpage.h"
#include "ui_tapepreferencespathpage.h"
#include "../../mapplication.h" #include "../../mapplication.h"
#include "../../vtapesettings.h" #include "../../vtapesettings.h"
#include "ui_tapepreferencespathpage.h"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
TapePreferencesPathPage::TapePreferencesPathPage(QWidget *parent) TapePreferencesPathPage::TapePreferencesPathPage(QWidget *parent)
: QWidget(parent), : QWidget(parent),
ui(new Ui::TapePreferencesPathPage) ui(new Ui::TapePreferencesPathPage)
{ {
ui->setupUi(this); ui->setupUi(this);
InitTable(); InitTable();
connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]() connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this,
{ [this]()
ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); {
ui->defaultButton->setDefault(false); ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty());
ui->defaultButton->setDefault(false);
ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty());
ui->editButton->setDefault(true); ui->editButton->setDefault(true);
}); });
connect(ui->defaultButton, &QPushButton::clicked, this, &TapePreferencesPathPage::DefaultPath); connect(ui->defaultButton, &QPushButton::clicked, this, &TapePreferencesPathPage::DefaultPath);
connect(ui->editButton, &QPushButton::clicked, this, &TapePreferencesPathPage::EditPath); connect(ui->editButton, &QPushButton::clicked, this, &TapePreferencesPathPage::EditPath);

View File

@ -31,11 +31,9 @@
#include <QWidget> #include <QWidget>
#include "../vmisc/defglobal.h"
namespace Ui namespace Ui
{ {
class TapePreferencesPathPage; class TapePreferencesPathPage;
} }
class TapePreferencesPathPage : public QWidget class TapePreferencesPathPage : public QWidget
@ -47,11 +45,13 @@ public:
~TapePreferencesPathPage() override; ~TapePreferencesPathPage() override;
void Apply(); void Apply();
protected: protected:
void changeEvent(QEvent* event) override; void changeEvent(QEvent *event) override;
private slots: private slots:
void DefaultPath(); void DefaultPath();
void EditPath(); void EditPath();
private: private:
// cppcheck-suppress unknownMacro // cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(TapePreferencesPathPage) // NOLINT Q_DISABLE_COPY_MOVE(TapePreferencesPathPage) // NOLINT

View File

@ -27,37 +27,37 @@
*************************************************************************/ *************************************************************************/
#include "mapplication.h" #include "mapplication.h"
#include "version.h"
#include "tmainwindow.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/exception/vexceptionbadid.h" #include "../ifc/exception/vexceptionbadid.h"
#include "../ifc/exception/vexceptionconversionerror.h" #include "../ifc/exception/vexceptionconversionerror.h"
#include "../ifc/exception/vexceptionemptyparameter.h" #include "../ifc/exception/vexceptionemptyparameter.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/exception/vexceptionwrongid.h" #include "../ifc/exception/vexceptionwrongid.h"
#include "../vmisc/vsysexits.h"
#include "../vmisc/projectversion.h" #include "../vmisc/projectversion.h"
#include "../vmisc/vsysexits.h"
#include "tmainwindow.h"
#include "version.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/qt_dispatch/qt_dispatch.h"
#include "../qmuparser/qmuparsererror.h"
#include "../fervor/fvupdater.h" #include "../fervor/fvupdater.h"
#include "../qmuparser/qmuparsererror.h"
#include "../vmisc/qt_dispatch/qt_dispatch.h"
#include <QDir> #include <QDir>
#include <QFileOpenEvent> #include <QFileOpenEvent>
#include <QLocalSocket> #include <QGlobalStatic>
#include <QResource>
#include <QTranslator>
#include <QPointer>
#include <QLocalServer>
#include <QMessageBox>
#include <iostream>
#include <QGridLayout> #include <QGridLayout>
#include <QLocalServer>
#include <QLocalSocket>
#include <QMessageBox>
#include <QPointer>
#include <QResource>
#include <QSpacerItem> #include <QSpacerItem>
#include <QThread> #include <QThread>
#include <QGlobalStatic> #include <QTranslator>
#include <iostream>
#if !defined(BUILD_REVISION) && defined(QBS_BUILD) #if !defined(BUILD_REVISION) && defined(QBS_BUILD)
#include <vcsRepoState.h> #include <vcsRepoState.h>
@ -65,7 +65,7 @@
#endif #endif
#if defined(APPIMAGE) && defined(Q_OS_LINUX) #if defined(APPIMAGE) && defined(Q_OS_LINUX)
# include "../vmisc/appimage.h" #include "../vmisc/appimage.h"
#endif // defined(APPIMAGE) && defined(Q_OS_LINUX) #endif // defined(APPIMAGE) && defined(Q_OS_LINUX)
QT_WARNING_PUSH QT_WARNING_PUSH
@ -81,19 +81,19 @@ QT_WARNING_POP
namespace namespace
{ {
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_A, (QLatin1String("dimensionA"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_A, (QLatin1String("dimensionA"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_A, (QChar('a'))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_A, (QChar('a'))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_B, (QLatin1String("dimensionB"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_B, (QLatin1String("dimensionB"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_B, (QChar('b'))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_B, (QChar('b'))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_C, (QLatin1String("dimensionC"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_C, (QLatin1String("dimensionC"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_C, (QChar('c'))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_C, (QChar('c'))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_UNITS, (QLatin1String("units"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_UNITS, (QLatin1String("units"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_UNITS, (QChar('u'))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_UNITS, (QChar('u'))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_TEST, (QLatin1String("test"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_TEST, (QLatin1String("test"))) // NOLINT
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
@ -107,9 +107,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
if (not isGuiThread) if (not isGuiThread)
{ {
auto Handler = [](QtMsgType type, const QMessageLogContext &context, const QString &msg) auto Handler = [](QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ { noisyFailureMsgHandler(type, context, msg); };
noisyFailureMsgHandler(type, context, msg);
};
q_dispatch_async_main(Handler, type, context, msg); q_dispatch_async_main(Handler, type, context, msg);
return; return;
@ -132,20 +130,20 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
#endif //defined(V_NO_ASSERT) #endif // defined(V_NO_ASSERT)
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
# if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
// Try hide very annoying, Qt related, warnings in Mac OS X // Try hide very annoying, Qt related, warnings in Mac OS X
// QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton) // QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)
// https://bugreports.qt.io/browse/QTBUG-42846 // https://bugreports.qt.io/browse/QTBUG-42846
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QNSView"))) if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QNSView")))
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
# endif #endif
# if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
// Hide Qt bug 'Assertion when reading an icns file' // Hide Qt bug 'Assertion when reading an icns file'
// https://bugreports.qt.io/browse/QTBUG-45537 // https://bugreports.qt.io/browse/QTBUG-45537
// Remove after Qt fix will be released // Remove after Qt fix will be released
@ -153,7 +151,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
# endif #endif
// Hide anything that starts with QMacCGContext // Hide anything that starts with QMacCGContext
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QMacCGContext::"))) if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QMacCGContext::")))
@ -171,8 +169,8 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
// this is another one that doesn't make sense as just a debug message. pretty serious // this is another one that doesn't make sense as just a debug message. pretty serious
// sign of a problem // sign of a problem
// http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue) // http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue)
if ((type == QtDebugMsg) && msg.contains(QStringLiteral("QPainter::begin")) if ((type == QtDebugMsg) && msg.contains(QStringLiteral("QPainter::begin")) &&
&& msg.contains(QStringLiteral("Paint device returned engine"))) msg.contains(QStringLiteral("Paint device returned engine")))
{ {
type = QtWarningMsg; type = QtWarningMsg;
} }
@ -180,8 +178,8 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
// This qWarning about "Cowardly refusing to send clipboard message to hung application..." // This qWarning about "Cowardly refusing to send clipboard message to hung application..."
// is something that can easily happen if you are debugging and the application is paused. // is something that can easily happen if you are debugging and the application is paused.
// As it is so common, not worth popping up a dialog. // As it is so common, not worth popping up a dialog.
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QClipboard::event")) if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QClipboard::event")) &&
&& msg.contains(QStringLiteral("Cowardly refusing"))) msg.contains(QStringLiteral("Cowardly refusing")))
{ {
type = QtDebugMsg; type = QtDebugMsg;
} }
@ -207,11 +205,11 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
case QtFatalMsg: case QtFatalMsg:
vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << logMsg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << logMsg << "\n";
break; break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
case QtInfoMsg: case QtInfoMsg:
vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << logMsg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << logMsg << "\n";
break; break;
#endif #endif
default: default:
break; break;
} }
@ -221,10 +219,10 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
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
//lead to crash // lead to crash
const bool topWinAllowsPop = (QApplication::activeModalWidget() == nullptr) || const bool topWinAllowsPop = (QApplication::activeModalWidget() == nullptr) ||
!QApplication::activeModalWidget()->inherits("QFileDialog"); !QApplication::activeModalWidget()->inherits("QFileDialog");
QMessageBox messageBox; QMessageBox messageBox;
switch (type) switch (type)
{ {
@ -240,12 +238,12 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error")); messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error"));
messageBox.setIcon(QMessageBox::Critical); messageBox.setIcon(QMessageBox::Critical);
break; break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
case QtInfoMsg: case QtInfoMsg:
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Information")); messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Information"));
messageBox.setIcon(QMessageBox::Information); messageBox.setIcon(QMessageBox::Information);
break; break;
#endif #endif
case QtDebugMsg: case QtDebugMsg:
Q_UNREACHABLE(); //-V501 Q_UNREACHABLE(); //-V501
break; break;
@ -263,13 +261,13 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
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 #ifndef QT_NO_CURSOR
QGuiApplication::setOverrideCursor(Qt::ArrowCursor); QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
#endif #endif
messageBox.exec(); messageBox.exec();
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
QGuiApplication::restoreOverrideCursor(); QGuiApplication::restoreOverrideCursor();
#endif #endif
} }
} }
} }
@ -290,7 +288,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MApplication::MApplication(int &argc, char **argv) MApplication::MApplication(int &argc, char **argv)
:VAbstractApplication(argc, argv) : VAbstractApplication(argc, argv)
{ {
setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR)); setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR));
setApplicationName(QStringLiteral(VER_INTERNALNAME_STR)); setApplicationName(QStringLiteral(VER_INTERNALNAME_STR));
@ -332,7 +330,8 @@ auto MApplication::notify(QObject *receiver, QEvent *event) -> bool
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file. Program will be terminated.")), //-V807 qCCritical(mApp, "%s\n\n%s\n\n%s",
qUtf8Printable(tr("Error parsing file. Program will be terminated.")), //-V807
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
exit(V_EX_DATAERR); exit(V_EX_DATAERR);
} }
@ -369,8 +368,8 @@ auto MApplication::notify(QObject *receiver, QEvent *event) -> bool
} }
catch (const VException &e) catch (const VException &e)
{ {
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), qUtf8Printable(e.ErrorMessage()),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.DetailedInformation()));
return true; return true;
} }
catch (const qmu::QmuParserWarning &e) catch (const qmu::QmuParserWarning &e)
@ -423,7 +422,7 @@ auto MApplication::MainWindow() -> TMainWindow *
auto MApplication::MainWindows() -> QList<TMainWindow *> auto MApplication::MainWindows() -> QList<TMainWindow *>
{ {
Clean(); Clean();
QList<TMainWindow*> list; QList<TMainWindow *> list;
list.reserve(m_mainWindows.size()); list.reserve(m_mainWindows.size());
for (auto &w : m_mainWindows) for (auto &w : m_mainWindows)
{ {
@ -446,18 +445,18 @@ void MApplication::InitOptions()
qCDebug(mApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(QStringLiteral(", ")))); qCDebug(mApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(QStringLiteral(", "))));
qCDebug(mApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid()))); qCDebug(mApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid())));
LoadTranslation(QString());// By default the console version uses system locale LoadTranslation(QString()); // By default the console version uses system locale
CheckSystemLocale(); CheckSystemLocale();
static const char * GENERIC_ICON_TO_CHECK = "document-open"; static const char *GENERIC_ICON_TO_CHECK = "document-open";
if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK)) if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK))
{ {
//If there is no default working icon theme then we should // If there is no default working icon theme then we should
//use an icon theme that we provide via a .qrc file // use an icon theme that we provide via a .qrc file
//This case happens under Windows and Mac OS X // This case happens under Windows and Mac OS X
//This does not happen under GNOME or KDE // This does not happen under GNOME or KDE
QIcon::setThemeName(QStringLiteral("win.icon.theme")); QIcon::setThemeName(QStringLiteral("win.icon.theme"));
} }
ActivateDarkMode(); ActivateDarkMode();
QResource::registerResource(diagramsPath()); QResource::registerResource(diagramsPath());
@ -468,21 +467,20 @@ void MApplication::InitOptions()
void MApplication::ActivateDarkMode() void MApplication::ActivateDarkMode()
{ {
VTapeSettings *settings = TapeSettings(); VTapeSettings *settings = TapeSettings();
if (settings->GetDarkMode()) if (settings->GetDarkMode())
{ {
QFile f(QStringLiteral(":qdarkstyle/style.qss")); QFile f(QStringLiteral(":qdarkstyle/style.qss"));
if (!f.exists()) if (!f.exists())
{ {
qDebug()<<"Unable to set stylesheet, file not found\n"; qDebug() << "Unable to set stylesheet, file not found\n";
} }
else else
{ {
f.open(QFile::ReadOnly | QFile::Text); f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f); QTextStream ts(&f);
qApp->setStyleSheet(ts.readAll()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) qApp->setStyleSheet(ts.readAll()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
} }
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -501,20 +499,21 @@ void MApplication::InitTrVars()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto MApplication::event(QEvent *e) -> bool auto MApplication::event(QEvent *e) -> bool
{ {
switch(e->type()) switch (e->type())
{ {
// In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is // In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is
// Mac specific). // Mac specific).
case QEvent::FileOpen: case QEvent::FileOpen:
{ {
auto *fileOpenEvent = static_cast<QFileOpenEvent *>(e); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) auto *fileOpenEvent =
static_cast<QFileOpenEvent *>(e); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
const QString macFileOpen = fileOpenEvent->file(); const QString macFileOpen = fileOpenEvent->file();
if(not macFileOpen.isEmpty()) if (not macFileOpen.isEmpty())
{ {
TMainWindow *mw = MainWindow(); TMainWindow *mw = MainWindow();
if (mw) if (mw)
{ {
mw->LoadFile(macFileOpen); // open file in existing window mw->LoadFile(macFileOpen); // open file in existing window
} }
return true; return true;
} }
@ -531,7 +530,7 @@ auto MApplication::event(QEvent *e) -> bool
} }
return true; return true;
} }
#endif //defined(Q_OS_MAC) #endif // defined(Q_OS_MAC)
default: default:
return VAbstractApplication::event(e); return VAbstractApplication::event(e);
} }
@ -629,7 +628,7 @@ void MApplication::RetranslateGroups()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MApplication::RetranslateTables() void MApplication::RetranslateTables()
{ {
const QList<TMainWindow*> list = MainWindows(); const QList<TMainWindow *> list = MainWindows();
for (auto *w : list) for (auto *w : list)
{ {
w->RetranslateTable(); w->RetranslateTable();
@ -688,7 +687,7 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto MApplication::VApp() -> MApplication * auto MApplication::VApp() -> MApplication *
{ {
return qobject_cast<MApplication*>(QCoreApplication::instance()); return qobject_cast<MApplication *>(QCoreApplication::instance());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -757,27 +756,31 @@ void MApplication::InitParserOptions(QCommandLineParser &parser)
{ {
parser.addPositionalArgument(QStringLiteral("filename"), tr("The measurement file.")); parser.addPositionalArgument(QStringLiteral("filename"), tr("The measurement file."));
parser.addOptions( parser.addOptions({
{ {{*SINGLE_OPTION_DIMENSION_A, *LONG_OPTION_DIMENSION_A},
{{*SINGLE_OPTION_DIMENSION_A, *LONG_OPTION_DIMENSION_A}, tr("Set base for dimension A in the table units."), tr("Set base for dimension A in the table units."),
tr("The dimension A base")}, tr("The dimension A base")},
{{*SINGLE_OPTION_DIMENSION_B, *LONG_OPTION_DIMENSION_B}, tr("Set base for dimension B in the table units."), {{*SINGLE_OPTION_DIMENSION_B, *LONG_OPTION_DIMENSION_B},
tr("The dimension B base")}, tr("Set base for dimension B in the table units."),
tr("The dimension B base")},
{{*SINGLE_OPTION_DIMENSION_C, *LONG_OPTION_DIMENSION_C}, tr("Set base for dimension C in the table units."), {{*SINGLE_OPTION_DIMENSION_C, *LONG_OPTION_DIMENSION_C},
tr("The dimension C base")}, tr("Set base for dimension C in the table units."),
tr("The dimension C base")},
{{*SINGLE_OPTION_UNITS, *LONG_OPTION_UNITS}, tr("Set pattern file units: cm, mm, inch."), {{*SINGLE_OPTION_UNITS, *LONG_OPTION_UNITS},
tr("The pattern units")}, tr("Set pattern file units: cm, mm, inch."),
tr("The pattern units")},
{*LONG_OPTION_TEST, {*LONG_OPTION_TEST,
tr("Use for unit testing. Run the program and open a file without showing the main window.")}, tr("Use for unit testing. Run the program and open a file without showing the main window.")},
{LONG_OPTION_NO_HDPI_SCALING, {LONG_OPTION_NO_HDPI_SCALING,
tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). " tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). "
"Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")}, "Alternatively you can use the %1 environment variable.")
}); .arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")},
});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -787,16 +790,15 @@ void MApplication::StartLocalServer(const QString &serverName)
connect(m_localServer, &QLocalServer::newConnection, this, &MApplication::NewLocalSocketConnection); connect(m_localServer, &QLocalServer::newConnection, this, &MApplication::NewLocalSocketConnection);
if (not m_localServer->listen(serverName)) if (not m_localServer->listen(serverName))
{ {
qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'", qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'", qUtf8Printable(serverName));
qUtf8Printable(serverName));
if (m_localServer->serverError() == QAbstractSocket::AddressInUseError) if (m_localServer->serverError() == QAbstractSocket::AddressInUseError)
{ {
QLocalServer::removeServer(serverName); QLocalServer::removeServer(serverName);
if (not m_localServer->listen(serverName)) if (not m_localServer->listen(serverName))
{ {
qCWarning(mApp, "%s", qCWarning(
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'") mApp, "%s",
.arg(serverName))); qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'").arg(serverName)));
} }
} }
} }
@ -896,7 +898,7 @@ void MApplication::ParseDimensionAOption(QCommandLineParser &parser, int &dimens
bool ok = false; bool ok = false;
dimensionAValue = value.toInt(&ok); dimensionAValue = value.toInt(&ok);
if(ok && dimensionAValue > 0) if (ok && dimensionAValue > 0)
{ {
flagDimensionA = true; flagDimensionA = true;
} }
@ -917,7 +919,7 @@ void MApplication::ParseDimensionBOption(QCommandLineParser &parser, int &dimens
bool ok = false; bool ok = false;
dimensionBValue = value.toInt(&ok); dimensionBValue = value.toInt(&ok);
if(ok && dimensionBValue > 0) if (ok && dimensionBValue > 0)
{ {
flagDimensionB = true; flagDimensionB = true;
} }
@ -938,7 +940,7 @@ void MApplication::ParseDimensionCOption(QCommandLineParser &parser, int &dimens
bool ok = false; bool ok = false;
dimensionCValue = value.toInt(&ok); dimensionCValue = value.toInt(&ok);
if(ok && dimensionCValue > 0) if (ok && dimensionCValue > 0)
{ {
flagDimensionC = true; flagDimensionC = true;
} }

View File

@ -27,30 +27,31 @@
*************************************************************************/ *************************************************************************/
#include "preferencespathpage.h" #include "preferencespathpage.h"
#include "ui_preferencespathpage.h"
#include "../vmisc/vvalentinasettings.h"
#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vabstractvalapplication.h"
#include "../vmisc/vvalentinasettings.h"
#include "ui_preferencespathpage.h"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PreferencesPathPage::PreferencesPathPage(QWidget *parent) PreferencesPathPage::PreferencesPathPage(QWidget *parent)
: QWidget(parent), : QWidget(parent),
ui(new Ui::PreferencesPathPage) ui(new Ui::PreferencesPathPage)
{ {
ui->setupUi(this); ui->setupUi(this);
InitTable(); InitTable();
connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]() connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this,
{ [this]()
ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); {
ui->defaultButton->setDefault(false); ui->defaultButton->setEnabled(not ui->pathTable->selectedItems().isEmpty());
ui->defaultButton->setDefault(false);
ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty()); ui->editButton->setEnabled(not ui->pathTable->selectedItems().isEmpty());
ui->editButton->setDefault(true); ui->editButton->setDefault(true);
}); });
connect(ui->defaultButton, &QPushButton::clicked, this, &PreferencesPathPage::DefaultPath); connect(ui->defaultButton, &QPushButton::clicked, this, &PreferencesPathPage::DefaultPath);
connect(ui->editButton, &QPushButton::clicked, this, &PreferencesPathPage::EditPath); connect(ui->editButton, &QPushButton::clicked, this, &PreferencesPathPage::EditPath);

View File

@ -31,11 +31,9 @@
#include <QWidget> #include <QWidget>
#include "../vmisc/defglobal.h"
namespace Ui namespace Ui
{ {
class PreferencesPathPage; class PreferencesPathPage;
} }
class PreferencesPathPage : public QWidget class PreferencesPathPage : public QWidget
@ -49,7 +47,7 @@ public:
auto Apply() -> QStringList; auto Apply() -> QStringList;
protected: protected:
void changeEvent(QEvent* event) override; void changeEvent(QEvent *event) override;
private slots: private slots:
void DefaultPath(); void DefaultPath();

View File

@ -29,18 +29,19 @@
#ifndef TESTVAPPLICATION_H #ifndef TESTVAPPLICATION_H
#define TESTVAPPLICATION_H #define TESTVAPPLICATION_H
#include "vabstractvalapplication.h"
#include "projectversion.h"
#include "../vmisc/vcommonsettings.h"
#include "../vmisc/compatibility.h" #include "../vmisc/compatibility.h"
#include "../vmisc/vcommonsettings.h"
#include "projectversion.h"
#include "vabstractvalapplication.h"
class VTestSettings : public VCommonSettings class VTestSettings : public VCommonSettings
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
VTestSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), VTestSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(),
QObject *parent = nullptr) QObject *parent = nullptr)
: VCommonSettings(format, scope, organization, application, parent) : VCommonSettings(format, scope, organization, application, parent)
{ {
REGISTER_META_TYPE_STREAM_OPERATORS(QMarginsF); REGISTER_META_TYPE_STREAM_OPERATORS(QMarginsF);
} }
@ -49,10 +50,11 @@ public:
class TestVApplication final : public VAbstractValApplication class TestVApplication final : public VAbstractValApplication
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
TestVApplication(int &argc, char ** argv) TestVApplication(int &argc, char **argv)
: VAbstractValApplication(argc, argv), : VAbstractValApplication(argc, argv),
m_trVars(nullptr) m_trVars(nullptr)
{ {
setApplicationName("ValentinaTest"); setApplicationName("ValentinaTest");
setOrganizationName(VER_COMPANYNAME_STR); setOrganizationName(VER_COMPANYNAME_STR);
@ -72,19 +74,14 @@ public:
virtual auto IsAppInGUIMode() const -> bool override { return false; } virtual auto IsAppInGUIMode() const -> bool override { return false; }
virtual void InitTrVars() override virtual void InitTrVars() override {}
{}
void SetTrVars(VTranslateVars *trVars) void SetTrVars(VTranslateVars *trVars) { m_trVars = trVars; }
{
m_trVars = trVars;
}
static auto VApp() -> TestVApplication * { return static_cast<TestVApplication *>(QCoreApplication::instance()); } static auto VApp() -> TestVApplication * { return static_cast<TestVApplication *>(QCoreApplication::instance()); }
protected slots: protected slots:
virtual void AboutToQuit() override virtual void AboutToQuit() override {}
{}
private: private:
Q_DISABLE_COPY_MOVE(TestVApplication) // NOLINT Q_DISABLE_COPY_MOVE(TestVApplication) // NOLINT

View File

@ -29,17 +29,21 @@
#include "vabstractapplication.h" #include "vabstractapplication.h"
#include <QDir> #include <QDir>
#include <QFileSystemWatcher>
#include <QFuture>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QMessageLogger> #include <QMessageLogger>
#include <QStandardPaths>
#include <QTranslator> #include <QTranslator>
#include <QUndoStack> #include <QUndoStack>
#include <QWidget>
#include <Qt> #include <Qt>
#include <QtDebug> #include <QtDebug>
#include <QWidget>
#include <QStandardPaths>
#include "QtConcurrent/qtconcurrentrun.h"
#include "compatibility.h" #include "compatibility.h"
#include "svgfont/vsvgfontdatabase.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h" #include "../vmisc/vtextcodec.h"
@ -48,11 +52,11 @@
#endif #endif
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
# include <unistd.h> #include <unistd.h>
#endif #endif
#if defined(APPIMAGE) && defined(Q_OS_LINUX) #if defined(APPIMAGE) && defined(Q_OS_LINUX)
# include "appimage.h" #include "appimage.h"
#endif // defined(APPIMAGE) && defined(Q_OS_LINUX) #endif // defined(APPIMAGE) && defined(Q_OS_LINUX)
namespace namespace
@ -97,14 +101,14 @@ auto LoadQM(QTranslator *translator, const QString &filename, const QString &loc
return false; return false;
} }
} // namespace } // namespace
const QString VAbstractApplication::warningMessageSignature = QStringLiteral("[PATTERN MESSAGE]"); const QString VAbstractApplication::warningMessageSignature = QStringLiteral("[PATTERN MESSAGE]");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractApplication::VAbstractApplication(int &argc, char **argv) VAbstractApplication::VAbstractApplication(int &argc, char **argv)
:QApplication(argc, argv), : QApplication(argc, argv),
undoStack(new QUndoStack(this)) undoStack(new QUndoStack(this))
{ {
QString rules; QString rules;
@ -116,7 +120,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
// See issue #568: Certificate checking on Mac OS X. // See issue #568: Certificate checking on Mac OS X.
rules += QLatin1String("qt.network.ssl.critical=false\n" rules += QLatin1String("qt.network.ssl.critical=false\n"
"qt.network.ssl.fatal=false\n"); "qt.network.ssl.fatal=false\n");
#endif //defined(V_NO_ASSERT) #endif // defined(V_NO_ASSERT)
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 4, 1) #endif // QT_VERSION >= QT_VERSION_CHECK(5, 4, 1)
#if defined(V_NO_ASSERT) #if defined(V_NO_ASSERT)
@ -185,8 +189,8 @@ auto VAbstractApplication::translationsPath(const QString &locale) -> QString
} }
else else
{ {
mainPath = QCoreApplication::applicationDirPath() + QLatin1String("/../Resources") + trPath + QLatin1String("/") mainPath = QCoreApplication::applicationDirPath() + QLatin1String("/../Resources") + trPath +
+ locale + QLatin1String(".lproj"); QLatin1String("/") + locale + QLatin1String(".lproj");
} }
QDir dirBundle(mainPath); QDir dirBundle(mainPath);
if (dirBundle.exists()) if (dirBundle.exists())
@ -284,11 +288,11 @@ void VAbstractApplication::LoadTranslation(QString locale)
if (locale.isEmpty()) if (locale.isEmpty())
{ {
qDebug()<<"Default locale"; qDebug() << "Default locale";
} }
else else
{ {
qDebug()<<"Checked locale:"<<locale; qDebug() << "Checked locale:" << locale;
} }
ClearTranslation(); ClearTranslation();
@ -322,7 +326,7 @@ void VAbstractApplication::LoadTranslation(QString locale)
LoadQM(pmsTranslator, QStringLiteral("measurements_") + Settings()->GetPMSystemCode() + '_', locale, appQmDir); LoadQM(pmsTranslator, QStringLiteral("measurements_") + Settings()->GetPMSystemCode() + '_', locale, appQmDir);
installTranslator(pmsTranslator); installTranslator(pmsTranslator);
InitTrVars();//Very important do it after load QM files. InitTrVars(); // Very important do it after load QM files.
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -428,7 +432,7 @@ void VAbstractApplication::CheckSystemLocale()
qFatal("Incompatible locale \"%s\"", qPrintable(defLocale)); qFatal("Incompatible locale \"%s\"", qPrintable(defLocale));
} }
auto CheckLanguage =[](QStandardPaths::StandardLocation type, const QStringList &test) auto CheckLanguage = [](QStandardPaths::StandardLocation type, const QStringList &test)
{ {
const QString path = QStandardPaths::locate(type, QString(), QStandardPaths::LocateDirectory); const QString path = QStandardPaths::locate(type, QString(), QStandardPaths::LocateDirectory);
return std::any_of(test.begin(), test.end(), [path](const QString &t) { return path.contains(t); }); return std::any_of(test.begin(), test.end(), [path](const QString &t) { return path.contains(t); });

View File

@ -29,25 +29,27 @@
#ifndef VABSTRACTAPPLICATION_H #ifndef VABSTRACTAPPLICATION_H
#define VABSTRACTAPPLICATION_H #define VABSTRACTAPPLICATION_H
#include <qcompilerdetection.h>
#include <QApplication> #include <QApplication>
#include <QCoreApplication> #include <QCoreApplication>
#include <QFileDialog>
#include <QLocale> #include <QLocale>
#include <QMetaObject> #include <QMetaObject>
#include <QObject> #include <QObject>
#include <QPointer> #include <QPointer>
#include <QString> #include <QString>
#include <QtGlobal>
#include <QTranslator> #include <QTranslator>
#include <QFileDialog> #include <QtGlobal>
#include <qcompilerdetection.h>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vpatterndb/vtranslatevars.h" #include "../vpatterndb/vtranslatevars.h"
#include "vcommonsettings.h" #include "vcommonsettings.h"
class QUndoStack; class QUndoStack;
class VAbstractApplication;// use in define class VAbstractApplication; // use in define
class VCommonSettings; class VCommonSettings;
class VSvgFontDatabase;
class QFileSystemWatcher;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class VTextCodec; class VTextCodec;
@ -60,9 +62,10 @@ QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
class VAbstractApplication : public QApplication class VAbstractApplication : public QApplication
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
VAbstractApplication(int &argc, char ** argv); VAbstractApplication(int &argc, char **argv);
virtual ~VAbstractApplication(); ~VAbstractApplication() override;
virtual auto TrVars() -> const VTranslateVars * = 0; virtual auto TrVars() -> const VTranslateVars * = 0;
@ -70,7 +73,7 @@ public:
void LoadTranslation(QString locale); void LoadTranslation(QString locale);
virtual void OpenSettings()=0; virtual void OpenSettings() = 0;
auto Settings() -> VCommonSettings *; auto Settings() -> VCommonSettings *;
template <typename T> auto LocaleToString(const T &value) -> QString; template <typename T> auto LocaleToString(const T &value) -> QString;
@ -114,12 +117,12 @@ protected:
QPointer<QTranslator> appTranslator{nullptr}; QPointer<QTranslator> appTranslator{nullptr};
QPointer<QTranslator> pmsTranslator{nullptr}; QPointer<QTranslator> pmsTranslator{nullptr};
virtual void InitTrVars()=0; virtual void InitTrVars() = 0;
static void CheckSystemLocale(); static void CheckSystemLocale();
protected slots: protected slots:
virtual void AboutToQuit()=0; virtual void AboutToQuit() = 0;
private: private:
Q_DISABLE_COPY_MOVE(VAbstractApplication) // NOLINT Q_DISABLE_COPY_MOVE(VAbstractApplication) // NOLINT
@ -144,7 +147,7 @@ template <typename T> inline auto VAbstractApplication::LocaleToString(const T &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline auto VAbstractApplication::VApp() -> VAbstractApplication * inline auto VAbstractApplication::VApp() -> VAbstractApplication *
{ {
return qobject_cast<VAbstractApplication*>(QCoreApplication::instance()); return qobject_cast<VAbstractApplication *>(QCoreApplication::instance());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------