From 810e62b8ba9c0fa5152592ef6b01400bfcfe59c0 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Sat, 23 Mar 2019 04:05:04 +0000 Subject: Qt5 / KDE5 refactor create_SalInstance Move most common code into Qt5Instance (static) functions. Not much saved with regard to LOC, but since the code was 95% C'n'P, I hope it'll be less error prone this way. Also handle all QApplication argument pointers via std::unique_ptr from the beginning. Change-Id: I87b2f571d398db7ccce3e740f16205b251be4ced Reviewed-on: https://gerrit.libreoffice.org/69578 Tested-by: Jenkins Reviewed-by: Aleksei Nikiforov --- vcl/inc/qt5/Qt5Instance.hxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'vcl/inc') diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx index 52153846faa1..a9be3581f64b 100644 --- a/vcl/inc/qt5/Qt5Instance.hxx +++ b/vcl/inc/qt5/Qt5Instance.hxx @@ -27,12 +27,21 @@ #include +#include #include +#include +#include class QApplication; class SalYieldMutex; class SalFrame; +struct StdFreeCStr +{ + void operator()(char* arg) const noexcept { std::free(arg); } +}; +using FreeableCStr = std::unique_ptr; + class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject, public SalGenericInstance, public SalUserEventList @@ -44,9 +53,8 @@ class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject, const bool m_bUseCairo; std::unordered_map> m_aClipboards; -public: std::unique_ptr m_pQApplication; - std::unique_ptr m_pFakeArgvFreeable; + std::vector m_pFakeArgvFreeable; std::unique_ptr m_pFakeArgv; std::unique_ptr m_pFakeArgc; @@ -61,9 +69,17 @@ Q_SIGNALS: void deleteObjectLaterSignal(QObject* pObject); public: - explicit Qt5Instance(bool bUseCairo = false); + explicit Qt5Instance(std::unique_ptr& pQApp, bool bUseCairo = false); virtual ~Qt5Instance() override; + // handle common SalInstance setup + static void AllocFakeCmdlineArgs(std::unique_ptr& rFakeArgv, + std::unique_ptr& rFakeArgc, + std::vector& rFakeArgvFreeable); + void MoveFakeCmdlineArgs(std::unique_ptr& rFakeArgv, std::unique_ptr& rFakeArgc, + std::vector& rFakeArgvFreeable); + static std::unique_ptr CreateQApplication(int& nArgc, char** pArgv); + void RunInMainThread(std::function func); virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override; -- cgit