diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.cpp b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.cpp index 6b01954b23..ff0154f5e9 100644 --- a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.cpp +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.cpp @@ -16,32 +16,10 @@ namespace AzQtComponents { - class AzQtApplication::Impl - : private AZ::Debug::TraceMessageBus::Handler - { - friend class AzQtApplication; - - public: - Impl(AzQtApplication* app) : m_app(app) - { - - } - AzQtApplication* m_app; - - ////////////////////////////////////////////////////////////////////////// - // AZ::Debug::TraceMessageBus::Handler overrides... - bool OnOutput(const char* window, const char* message) override; - ////////////////////////////////////////////////////////////////////////// - - protected: - AZStd::vector m_startupLogSink; - AZStd::unique_ptr m_logFile; - - }; AzQtApplication::AzQtApplication(int& argc, char** argv) : QApplication(argc, argv) - , m_impl(new Impl(this)) + , m_impl(new AzQtTraceLogger) { // Use a common Qt settings path for applications that don't register their own application name if (QApplication::applicationName().isEmpty()) @@ -56,43 +34,13 @@ namespace AzQtComponents QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); // Must be set before QApplication is initialized, so that we support HighDpi monitors, like the Retina displays - // on Windows 10 + // on Windows 10 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware); - - - m_impl->AZ::Debug::TraceMessageBus::Handler::BusConnect(); - } - - AzQtApplication::~AzQtApplication() - { - m_impl->AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); - } - - - bool AzQtApplication::Impl::OnOutput(const char* window, const char* message) - { - // Suppress spam from the Source Control system - constexpr char sourceControlWindow[] = "Source Control"; - - if (0 == strncmp(window, sourceControlWindow, AZ_ARRAY_SIZE(sourceControlWindow))) - { - return true; - } - - if (m_logFile) - { - m_logFile->AppendLog(AzFramework::LogFile::SEV_NORMAL, window, message); - } - else - { - m_startupLogSink.push_back({ window, message }); - } - return false; } } // namespace AzQtComponents diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h index 426f4cd78c..cf180ff1cc 100644 --- a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h @@ -10,7 +10,6 @@ * */ - #pragma once #include @@ -20,6 +19,7 @@ #include #include #include +#include namespace AzQtComponents @@ -28,23 +28,14 @@ namespace AzQtComponents : public QApplication { public: - AzQtApplication(int& argc, char** argv); - ~AzQtApplication(); - - + AzQtApplication(int& argc, char** argv); private: AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - class Impl; - AZStd::unique_ptr m_impl; + AZStd::unique_ptr m_impl; AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING }; - class LogMessage - { - public: - AZStd::string window; - AZStd::string message; - }; + } // namespace AzQtComponents diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtTraceLogger.cpp b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtTraceLogger.cpp new file mode 100644 index 0000000000..2e943083b3 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtTraceLogger.cpp @@ -0,0 +1,38 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +namespace AzQtComponents +{ + bool AzQtTraceLogger::OnOutput(const char* window, const char* message) + { + // Suppress spam from the Source Control system + constexpr char sourceControlWindow[] = "Source Control"; + + if (0 == strncmp(window, sourceControlWindow, AZ_ARRAY_SIZE(sourceControlWindow))) + { + return true; + } + + if (m_logFile) + { + m_logFile->AppendLog(AzFramework::LogFile::SEV_NORMAL, window, message); + } + else + { + m_startupLogSink.push_back({ window, message }); + } + return false; + } +} // namespace AzQtComponents + diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtTraceLogger.h b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtTraceLogger.h new file mode 100644 index 0000000000..f94ce5c809 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtTraceLogger.h @@ -0,0 +1,49 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#include +#include + +namespace AzQtComponents +{ + class AzQtTraceLogger : private AZ::Debug::TraceMessageBus::Handler + { + public: + AzQtTraceLogger() + { + AZ::Debug::TraceMessageBus::Handler::BusConnect(); + } + ~AzQtTraceLogger() + { + AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + } + + protected: + ////////////////////////////////////////////////////////////////////////// + // AZ::Debug::TraceMessageBus::Handler overrides... + bool OnOutput(const char* window, const char* message) override; + ////////////////////////////////////////////////////////////////////////// + + struct LogMessage + { + public: + AZStd::string window; + AZStd::string message; + }; + AZStd::vector m_startupLogSink; + AZStd::unique_ptr m_logFile; + }; + +} +