From 339bb73e9f23fcdba7f91ea0d16b82574f1882d0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 14 Jul 2022 14:52:23 +0200 Subject: [PATCH] Base: add convenience classes/functions that are marked as deprecated in Qt 5.15 and removed in Qt 6 --- src/Base/CMakeLists.txt | 4 +++ src/Base/Mutex.cpp | 37 +++++++++++++++++++++++++++ src/Base/Mutex.h | 39 +++++++++++++++++++++++++++++ src/Base/QtTools.cpp | 35 ++++++++++++++++++++++++++ src/Base/QtTools.h | 55 +++++++++++++++++++++++++++++++++++++++++ src/Base/Sequencer.cpp | 10 +------- 6 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 src/Base/Mutex.cpp create mode 100644 src/Base/Mutex.h create mode 100644 src/Base/QtTools.cpp create mode 100644 src/Base/QtTools.h diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index f5a711055d..e6d59bd6e0 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -242,6 +242,7 @@ SET(FreeCADBase_CPP_SRCS Matrix.cpp MatrixPyImp.cpp MemDebug.cpp + Mutex.cpp Parameter.xsd Parameter.cpp ParameterPy.cpp @@ -251,6 +252,7 @@ SET(FreeCADBase_CPP_SRCS PlacementPyImp.cpp PyExport.cpp PyObjectBase.cpp + QtTools.cpp Reader.cpp Rotation.cpp RotationPyImp.cpp @@ -306,12 +308,14 @@ SET(FreeCADBase_HPP_SRCS Interpreter.h Matrix.h MemDebug.h + Mutex.h Observer.h Parameter.h Persistence.h Placement.h PyExport.h PyObjectBase.h + QtTools.h Reader.h Rotation.h Sequencer.h diff --git a/src/Base/Mutex.cpp b/src/Base/Mutex.cpp new file mode 100644 index 0000000000..5913e2e4b5 --- /dev/null +++ b/src/Base/Mutex.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "Mutex.h" + + +#if QT_VERSION < QT_VERSION_CHECK(5,14,0) +QRecursiveMutex::QRecursiveMutex() : QMutex(QMutex::Recursive) +{ +} + +QRecursiveMutex::~QRecursiveMutex() +{ +} +#endif diff --git a/src/Base/Mutex.h b/src/Base/Mutex.h new file mode 100644 index 0000000000..6c8ddee7fe --- /dev/null +++ b/src/Base/Mutex.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef BASE_MUTEX_H +#define BASE_MUTEX_H + +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(5,14,0) +class BaseExport QRecursiveMutex : public QMutex +{ +public: + QRecursiveMutex(); + ~QRecursiveMutex(); +}; +#endif + +#endif // BASE_MUTEX_H diff --git a/src/Base/QtTools.cpp b/src/Base/QtTools.cpp new file mode 100644 index 0000000000..3c6931be5d --- /dev/null +++ b/src/Base/QtTools.cpp @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "QtTools.h" + + +#if QT_VERSION < QT_VERSION_CHECK(5,14,0) +namespace Qt { + BaseExport QTextStream& endl(QTextStream& stream) { + return stream << QLatin1Char('\n') << flush; + } +} +#endif diff --git a/src/Base/QtTools.h b/src/Base/QtTools.h new file mode 100644 index 0000000000..7daf815b91 --- /dev/null +++ b/src/Base/QtTools.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef BASE_QTTOOLS_H +#define BASE_QTTOOLS_H + +#include +#include +#include + +// Suppress warning about 'SkipEmptyParts' not being used +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-variable" +#elif defined (__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) +#include +namespace Qt +{ + BaseExport QTextStream& endl(QTextStream& stream); + static auto SkipEmptyParts = QString::SkipEmptyParts; +} +#endif + +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined (__GNUC__) +# pragma GCC diagnostic pop +#endif + +#endif // BASE_QTTOOLS_H diff --git a/src/Base/Sequencer.cpp b/src/Base/Sequencer.cpp index eb195d2295..13b554cac9 100644 --- a/src/Base/Sequencer.cpp +++ b/src/Base/Sequencer.cpp @@ -24,11 +24,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include #endif #include "Sequencer.h" +#include "Mutex.h" using namespace Base; @@ -38,11 +38,7 @@ namespace Base { // members static std::vector _instances; /**< A vector of all created instances */ static SequencerLauncher* _topLauncher; /**< The outermost launcher */ -#if QT_VERSION >= QT_VERSION_CHECK(5,14,0) static QRecursiveMutex mutex; /**< A mutex-locker for the launcher */ -#else - static QMutex mutex; /**< A mutex-locker for the launcher */ -#endif /** Sets a global sequencer object. * Access to the last registered object is performed by @see Sequencer(). */ @@ -68,11 +64,7 @@ namespace Base { */ std::vector SequencerP::_instances; SequencerLauncher* SequencerP::_topLauncher = nullptr; -#if QT_VERSION >= QT_VERSION_CHECK(5,14,0) QRecursiveMutex SequencerP::mutex; -#else - QMutex SequencerP::mutex(QMutex::Recursive); -#endif } SequencerBase& SequencerBase::Instance ()