1 /************************************************************************ 2 ** 3 ** @file vabstractapplication.h 4 ** @author Roman Telezhynskyi <dismine(at)gmail.com> 5 ** @date 18 6, 2015 6 ** 7 ** @brief 8 ** @copyright 9 ** This source code is part of the Valentina project, a pattern making 10 ** program, whose allow create and modeling patterns of clothing. 11 ** Copyright (C) 2015 Valentina project 12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved. 13 ** 14 ** Valentina is free software: you can redistribute it and/or modify 15 ** it under the terms of the GNU General Public License as published by 16 ** the Free Software Foundation, either version 3 of the License, or 17 ** (at your option) any later version. 18 ** 19 ** Valentina is distributed in the hope that it will be useful, 20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 ** GNU General Public License for more details. 23 ** 24 ** You should have received a copy of the GNU General Public License 25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>. 26 ** 27 *************************************************************************/ 28 29 #ifndef VABSTRACTAPPLICATION_H 30 #define VABSTRACTAPPLICATION_H 31 32 #include <qcompilerdetection.h> 33 #include <QApplication> 34 #include <QCoreApplication> 35 #include <QLocale> 36 #include <QMetaObject> 37 #include <QObject> 38 #include <QPointer> 39 #include <QString> 40 #include <QtGlobal> 41 #include <QTranslator> 42 #include <QFileDialog> 43 44 #include "../vmisc/def.h" 45 #include "../vpatterndb/vtranslatevars.h" 46 #include "vcommonsettings.h" 47 48 class QUndoStack; 49 class VAbstractApplication;// use in define 50 class VCommonSettings; 51 52 class VAbstractApplication : public QApplication 53 { 54 Q_OBJECT 55 public: 56 VAbstractApplication(int &argc, char ** argv); 57 virtual ~VAbstractApplication() =default; 58 59 virtual const VTranslateVars *TrVars()=0; 60 61 QString translationsPath(const QString &locale = QString()) const; 62 63 void LoadTranslation(const QString &locale); 64 65 virtual void OpenSettings()=0; 66 VCommonSettings *Settings(); 67 68 template <typename T> 69 QString LocaleToString(const T &value); 70 71 QUndoStack *getUndoStack() const; 72 73 virtual bool IsAppInGUIMode()const =0; 74 virtual bool IsPedantic() const; 75 76 static QString ClearMessage(QString msg); 77 78 static const QString warningMessageSignature; 79 bool IsWarningMessage(const QString &message) const; 80 81 QFileDialog::Options NativeFileDialog(QFileDialog::Options options = QFileDialog::Options()) const; 82 83 #if defined(Q_OS_WIN) 84 static void WinAttachConsole(); 85 #endif 86 87 static VAbstractApplication *VApp(); 88 89 protected: 90 QUndoStack *undoStack; 91 92 /** 93 * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. 94 */ 95 VCommonSettings *settings{nullptr}; 96 97 QPointer<QTranslator> qtTranslator{nullptr}; 98 QPointer<QTranslator> qtxmlTranslator{nullptr}; 99 QPointer<QTranslator> qtBaseTranslator{nullptr}; 100 QPointer<QTranslator> appTranslator{nullptr}; 101 QPointer<QTranslator> pmsTranslator{nullptr}; 102 103 virtual void InitTrVars()=0; 104 105 protected slots: 106 virtual void AboutToQuit()=0; 107 108 private: 109 Q_DISABLE_COPY(VAbstractApplication) 110 111 void ClearTranslation(); 112 }; 113 114 //--------------------------------------------------------------------------------------------------------------------- 115 template <typename T> LocaleToString(const T & value)116inline QString VAbstractApplication::LocaleToString(const T &value) 117 { 118 QLocale loc; 119 VAbstractApplication::VApp()->Settings()->GetOsSeparator() ? loc = QLocale() : loc = QLocale::c(); 120 return loc.toString(value); 121 } 122 123 //--------------------------------------------------------------------------------------------------------------------- 124 inline auto VAbstractApplication::VApp() -> VAbstractApplication * 125 { 126 return qobject_cast<VAbstractApplication*>(QCoreApplication::instance()); 127 } 128 129 //--------------------------------------------------------------------------------------------------------------------- 130 /** 131 * @brief getSettings hide settings constructor. 132 * @return pointer to class for acssesing to settings in ini file. 133 */ Settings()134inline VCommonSettings *VAbstractApplication::Settings() 135 { 136 SCASSERT(settings != nullptr) 137 return settings; 138 } 139 140 #endif // VABSTRACTAPPLICATION_H 141