From 28c91d06566570670d458b1d20685a5b5db2dfc9 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 28 Jan 2021 12:10:16 -0800 Subject: [PATCH] Workaround for a Qt bug recreating QApplication. Fixes #610. --- common/lc_application.cpp | 43 +++++++++++++++++++++------------------ common/lc_application.h | 4 +++- qt/qtmain.cpp | 9 ++++++-- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index f406f68c..80685f0a 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -157,10 +157,6 @@ lcApplication::lcApplication(int& Argc, char** Argv) : QApplication(Argc, Argv) { setApplicationDisplayName(QLatin1String("LeoCAD")); - setOrganizationDomain(QLatin1String("leocad.org")); - setOrganizationName(QLatin1String("LeoCAD Software")); - setApplicationName(QLatin1String("LeoCAD")); - setApplicationVersion(QLatin1String(LC_VERSION_TEXT)); gApplication = this; mDefaultStyle = style()->objectName(); @@ -333,6 +329,9 @@ bool lcApplication::LoadPartsLibrary(const QList>& LibraryP lcCommandLineOptions lcApplication::ParseCommandLineOptions() { + lcPreferences Preferences; + Preferences.LoadDefaults(); + lcCommandLineOptions Options; Options.ParseOK = true; @@ -349,10 +348,12 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions() Options.SetZPlanes = false; Options.SetFadeStepsColor = false; Options.SetHighlightColor = false; - Options.FadeSteps = mPreferences.mFadeSteps; - Options.ImageHighlight = mPreferences.mHighlightNewParts; + Options.FadeSteps = Preferences.mFadeSteps; + Options.ImageHighlight = Preferences.mHighlightNewParts; Options.ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); Options.ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); + Options.ShadingMode = Preferences.mShadingMode; + Options.LineWidth = Preferences.mLineWidth; Options.AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); Options.StudStyle = static_cast(lcGetProfileInt(LC_PROFILE_STUD_STYLE)); Options.ImageStart = 0; @@ -364,15 +365,15 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions() Options.FoV = 0.0f; Options.ZPlanes = lcVector2(0.0f, 0.0f); Options.Viewpoint = lcViewpoint::Count; - Options.FadeStepsColor = mPreferences.mFadeStepsColor; - Options.HighlightColor = mPreferences.mHighlightNewPartsColor; - Options.StudCylinderColor = mPreferences.mStudCylinderColor; - Options.PartEdgeColor = mPreferences.mPartEdgeColor; - Options.BlackEdgeColor = mPreferences.mBlackEdgeColor; - Options.DarkEdgeColor = mPreferences.mDarkEdgeColor; - Options.PartEdgeContrast = mPreferences.mPartEdgeContrast; - Options.PartColorValueLDIndex = mPreferences.mPartColorValueLDIndex; - Options.AutomateEdgeColor = mPreferences.mAutomateEdgeColor; + Options.FadeStepsColor = Preferences.mFadeStepsColor; + Options.HighlightColor = Preferences.mHighlightNewPartsColor; + Options.StudCylinderColor = Preferences.mStudCylinderColor; + Options.PartEdgeColor = Preferences.mPartEdgeColor; + Options.BlackEdgeColor = Preferences.mBlackEdgeColor; + Options.DarkEdgeColor = Preferences.mDarkEdgeColor; + Options.PartEdgeContrast = Preferences.mPartEdgeContrast; + Options.PartColorValueLDIndex = Preferences.mPartColorValueLDIndex; + Options.AutomateEdgeColor = Preferences.mAutomateEdgeColor; QStringList Arguments = arguments(); @@ -721,13 +722,13 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions() if (ParseString(ShadingString, true)) { if (ShadingString == QLatin1String("wireframe")) - mPreferences.mShadingMode = lcShadingMode::Wireframe; + Options.ShadingMode = lcShadingMode::Wireframe; else if (ShadingString == QLatin1String("flat")) - mPreferences.mShadingMode = lcShadingMode::Flat; + Options.ShadingMode = lcShadingMode::Flat; else if (ShadingString == QLatin1String("default")) - mPreferences.mShadingMode = lcShadingMode::DefaultLights; + Options.ShadingMode = lcShadingMode::DefaultLights; else if (ShadingString == QLatin1String("full")) - mPreferences.mShadingMode = lcShadingMode::Full; + Options.ShadingMode = lcShadingMode::Full; else { Options.StdErr += tr("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, ShadingString); @@ -736,7 +737,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions() } } else if (Option == QLatin1String("--line-width")) - ParseFloat(mPreferences.mLineWidth, 0.0f, 10.0f); + ParseFloat(Options.LineWidth, 0.0f, 10.0f); else if (Option == QLatin1String("--aa-samples")) { if (ParseInteger(Options.AASamples, 1, 8) && Options.AASamples != 1 && Options.AASamples != 2 && Options.AASamples != 4 && Options.AASamples != 8) @@ -939,6 +940,8 @@ lcStartupMode lcApplication::Initialize(const QList>& Libra } } + mPreferences.mShadingMode = Options.ShadingMode; + mPreferences.mLineWidth = Options.LineWidth; mPreferences.mStudCylinderColor = Options.StudCylinderColor; mPreferences.mPartEdgeColor = Options.PartEdgeColor; mPreferences.mBlackEdgeColor = Options.BlackEdgeColor; diff --git a/common/lc_application.h b/common/lc_application.h index 1bdbff22..d179f8fe 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -104,6 +104,8 @@ struct lcCommandLineOptions int ImageWidth; int ImageHeight; int AASamples; + lcShadingMode ShadingMode; + float LineWidth; lcStudStyle StudStyle; lcStep ImageStart; lcStep ImageEnd; @@ -149,7 +151,7 @@ public: ~lcApplication(); void SetProject(Project* Project); - lcCommandLineOptions ParseCommandLineOptions(); + static lcCommandLineOptions ParseCommandLineOptions(); lcStartupMode Initialize(const QList>& LibraryPaths); void Shutdown(); void ShowPreferencesDialog(); diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 2e980383..a38dd010 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -123,8 +123,8 @@ static void lcRegisterShellFileTypes() static void lcInitializeSurfaceFormat(int argc, char* argv[]) { - lcApplication Application(argc, argv); - const lcCommandLineOptions Options = Application.ParseCommandLineOptions(); + QCoreApplication Application(argc, argv); + const lcCommandLineOptions Options = lcApplication::ParseCommandLineOptions(); if (Options.ParseOK && Options.AASamples > 1) { @@ -136,6 +136,11 @@ static void lcInitializeSurfaceFormat(int argc, char* argv[]) int main(int argc, char *argv[]) { + QCoreApplication::setOrganizationDomain(QLatin1String("leocad.org")); + QCoreApplication::setOrganizationName(QLatin1String("LeoCAD Software")); + QCoreApplication::setApplicationName(QLatin1String("LeoCAD")); + QCoreApplication::setApplicationVersion(QLatin1String(LC_VERSION_TEXT)); + lcInitializeSurfaceFormat(argc, argv); QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);