Seamly2D
Code documentation
vabstractapplication.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vabstractapplication.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 18 6, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VABSTRACTAPPLICATION_H
53 #define VABSTRACTAPPLICATION_H
54 
55 #include <qcompilerdetection.h>
56 #include <QApplication>
57 #include <QCoreApplication>
58 #include <QGraphicsScene>
59 #include <QLocale>
60 #include <QMetaObject>
61 #include <QObject>
62 #include <QPointer>
63 #include <QString>
64 #include <QtGlobal>
65 
66 #include "../vmisc/def.h"
67 #include "../vpatterndb/vcontainer.h"
68 #include "../vpatterndb/vtranslatevars.h"
69 #include "def.h"
70 #include "vcommonsettings.h"
71 #include "vlockguard.h"
72 #include "vsettings.h"
73 
74 class QUndoStack;
75 class VAbstractApplication;// use in define
76 class VAbstractPattern;
77 class VContainer;
78 class VMainGraphicsView;
79 
80 #if defined(qApp)
81 #undef qApp
82 #endif
83 #define qApp (static_cast<VAbstractApplication*>(QCoreApplication::instance()))
84 
85 class VAbstractApplication : public QApplication
86 {
87  Q_OBJECT
88 public:
89  VAbstractApplication(int &argc, char ** argv);
90  virtual ~VAbstractApplication() Q_DECL_OVERRIDE;
91 
92  virtual const VTranslateVars *TrVars()=0;
93 
94  QString translationsPath(const QString &locale = QString()) const;
95 
96  void loadTranslations(const QString &locale);
97 
98  Unit patternUnit() const;
99  const Unit *patternUnitP() const;
100  void setPatternUnit(const Unit &patternUnit);
101 
104 
105  virtual void OpenSettings()=0;
107 
108  template <typename T>
109  QString LocaleToString(const T &value);
110 
111  QGraphicsScene *getCurrentScene() const;
112  void setCurrentScene(QGraphicsScene **value);
113 
115  void setSceneView(VMainGraphicsView *value);
116 
117  double toPixel(double val) const;
118  double fromPixel(double pix) const;
119 
122 
124  VContainer *getCurrentData()const;
125 
126  bool getOpeningPattern() const;
127  void setOpeningPattern();
128 
129  QWidget *getMainWindow() const;
130  void setMainWindow(QWidget *value);
131 
132  QUndoStack *getUndoStack() const;
133 
134  virtual bool IsAppInGUIMode()const =0;
135 
136  QString getFilePath() const;
137  void setFilePath(const QString &value);
138 
139 protected:
140  QUndoStack *undoStack;
141 
142  /**
143  * @brief mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main window
144  * modality doesn't work.
145  */
146  QWidget *mainWindow;
147 
148  /**
149  * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable.
150  */
152 
153  QPointer<QTranslator> qtTranslator;
154  QPointer<QTranslator> qtxmlTranslator;
155  QPointer<QTranslator> qtBaseTranslator;
156  QPointer<QTranslator> appTranslator;
157  QPointer<QTranslator> pmsTranslator;
158 
159  virtual void InitTrVars()=0;
160 
161 private:
162  Q_DISABLE_COPY(VAbstractApplication)
166 
167  QGraphicsScene **currentScene;
169 
172 
173  /**
174  * @brief openingPattern true when we opening pattern. If something will be wrong in formula this help understand if
175  * we can allow user use Undo option.
176  */
178 
179  void ClearTranslation();
180 };
181 
182 //---------------------------------------------------------------------------------------------------------------------
183 inline QString VAbstractApplication::getFilePath() const
184 {
185  return patternFilePath;
186 }
187 
188 //---------------------------------------------------------------------------------------------------------------------
189 inline void VAbstractApplication::setFilePath(const QString &value)
190 {
191  patternFilePath = value;
192 }
193 
194 //---------------------------------------------------------------------------------------------------------------------
195 template <typename T>
196 inline QString VAbstractApplication::LocaleToString(const T &value)
197 {
198  QLocale loc;
199  qApp->Settings()->GetOsSeparator() ? loc = QLocale() : loc = QLocale::c();
200  return loc.toString(value);
201 }
202 
203 #endif // VABSTRACTAPPLICATION_H
QWidget * mainWindow
mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main windo...
bool openingPattern
openingPattern true when we opening pattern. If something will be wrong in formula this help understa...
void setCurrentDocument(VAbstractPattern *doc)
QPointer< QTranslator > qtBaseTranslator
void setMainWindow(QWidget *value)
const Unit * patternUnitP() const
VMainGraphicsView * sceneView
void setPatternUnit(const Unit &patternUnit)
MeasurementsType _patternType
void setCurrentScene(QGraphicsScene **value)
virtual ~VAbstractApplication() Q_DECL_OVERRIDE
QWidget * getMainWindow() const
virtual bool IsAppInGUIMode() const =0
double fromPixel(double pix) const
VCommonSettings * settings
settings pointer to settings. Help hide constructor creation settings. Make make code more readable.
QGraphicsScene ** currentScene
QPointer< QTranslator > pmsTranslator
QUndoStack * getUndoStack() const
QString LocaleToString(const T &value)
VContainer * getCurrentData() const
QPointer< QTranslator > appTranslator
virtual void InitTrVars()=0
QPointer< QTranslator > qtTranslator
QString translationsPath(const QString &locale=QString()) const
translationsPath return path to the root directory that contains QM files.
QPointer< QTranslator > qtxmlTranslator
double toPixel(double val) const
VAbstractPattern * doc
void loadTranslations(const QString &locale)
VCommonSettings * Settings()
getSettings hide settings constructor.
MeasurementsType patternType() const
void setPatternType(const MeasurementsType &patternType)
virtual const VTranslateVars * TrVars()=0
void setFilePath(const QString &value)
VMainGraphicsView * getSceneView() const
VAbstractPattern * getCurrentDocument() const
void setSceneView(VMainGraphicsView *value)
void setCurrentData(VContainer *data)
QGraphicsScene * getCurrentScene() const
virtual void OpenSettings()=0
VAbstractApplication(int &argc, char **argv)
The VContainer class container of all variables.
Definition: vcontainer.h:141
The VMainGraphicsView class main scene view.
MeasurementsType
Definition: def.h:104
Unit
Definition: def.h:105
#define qApp