1 /************************************************************************
2  **
3  **  @file   def.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   11 4, 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 DEF_H
30 #define DEF_H
31 
32 #include <QtGlobal>
33 #ifdef Q_OS_WIN
34 #  include <qt_windows.h>
35 #endif /*Q_OS_WIN*/
36 
37 #include <qcompilerdetection.h>
38 #include <QPrinter>
39 #include <QString>
40 #include <QStringList>
41 #include <Qt>
42 #include <csignal>
43 #include <QMargins>
44 #include <QLineF>
45 
46 #include "literals.h"
47 #include "debugbreak.h"
48 #include "defglobal.h"
49 
50 template <class T> class QSharedPointer;
51 
52 #include <ciso646>
53 
54 // Backport of relaxed constexpr
55 #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
56 #if defined Q_COMPILER_CONSTEXPR
57 # if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304
58 #  define Q_DECL_RELAXED_CONSTEXPR constexpr
59 #  define Q_RELAXED_CONSTEXPR constexpr
60 # else
61 #  define Q_DECL_RELAXED_CONSTEXPR
62 #  define Q_RELAXED_CONSTEXPR const
63 # endif
64 #else
65 # define Q_DECL_RELAXED_CONSTEXPR
66 # define Q_RELAXED_CONSTEXPR const
67 #endif
68 #endif
69 
70 class QComboBox;
71 class QMarginsF;
72 class VTranslateMeasurements;
73 class QGraphicsItem;
74 
75 #define SceneSize 50000
76 extern const qreal   defCurveApproximationScale;
77 extern const qreal   minCurveApproximationScale;
78 extern const qreal   maxCurveApproximationScale;
79 
80 extern const int minLabelFontSize;
81 extern const int maxLabelFontSize;
82 
83 enum class NodeDetail : qint8 { Contour, Modeling };
84 enum class SceneObject : qint8 { Point, Line, Spline, Arc, ElArc, SplinePath, Detail, Unknown };
85 enum class MeasurementsType : qint8 { Multisize, Individual, Unknown};
86 enum class Unit : qint8 { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE};
87 enum class Source : qint8 { FromGui, FromFile, FromTool };
88 enum class NodeUsage : bool {NotInUse = false, InUse = true};
89 enum class SelectionType : bool {ByMousePress, ByMouseRelease};
90 enum class PageOrientation : bool {Portrait = true, Landscape = false};
91 enum class Draw : qint8 { Calculation, Modeling, Layout };
92 
93 enum class PieceNodeAngle : quint8
94 {
95     ByLength = 0,
96     ByPointsIntersection = 1,
97     ByFirstEdgeSymmetry = 2,
98     BySecondEdgeSymmetry = 3,
99     ByFirstEdgeRightAngle = 4,
100     BySecondEdgeRightAngle = 5,
101     ByLengthCurve = 6, // used only in runtime
102     LAST_ONE_DO_NOT_USE
103 };
104 
105 enum class PassmarkLineType : quint8
106 {
107     OneLine = 0, // Default
108     TwoLines,
109     ThreeLines,
110     TMark,
111     VMark,
112     VMark2,
113     UMark,
114     BoxMark,
115     LAST_ONE_DO_NOT_USE
116 };
117 
118 QString          PassmarkLineTypeToString(PassmarkLineType type);
119 PassmarkLineType StringToPassmarkLineType(const QString &value);
120 
121 enum class PassmarkAngleType : quint8
122 {
123     Straightforward = 0, // Default
124     Bisector,
125     Intersection,
126     IntersectionOnlyLeft,
127     IntersectionOnlyRight,
128     Intersection2,
129     Intersection2OnlyLeft,
130     Intersection2OnlyRight,
131     LAST_ONE_DO_NOT_USE
132 };
133 
134 QString           PassmarkAngleTypeToString(PassmarkAngleType type);
135 PassmarkAngleType StringToPassmarkAngleType(const QString &value);
136 
137 
138 Unit    StrToUnits(const QString &unit);
139 QString UnitsToStr(const Unit &unit, const bool translate = false);
140 
141 
142 enum class PiecePathIncludeType : quint8
143 {
144     AsMainPath = 0,
145     AsCustomSA = 1
146 };
147 
148 enum class PiecePathType :  quint8 {PiecePath = 0, CustomSeamAllowance = 1, InternalPath = 2, Unknown = 3};
149 
150 typedef int ToolVisHolderType;
151 enum class Tool : ToolVisHolderType
152 {
153     Arrow,
154     SinglePoint,
155     DoublePoint,
156     LinePoint,
157     AbstractSpline,
158     Cut,
159     BasePoint,
160     EndLine,
161     Line,
162     AlongLine,
163     ShoulderPoint,
164     Normal,
165     Bisector,
166     LineIntersect,
167     Spline,
168     CubicBezier,
169     CutSpline,
170     CutArc,
171     Arc,
172     ArcWithLength,
173     SplinePath,
174     CubicBezierPath,
175     CutSplinePath,
176     PointOfContact,
177     Piece,
178     PiecePath,
179     NodePoint,
180     NodeArc,
181     NodeElArc,
182     NodeSpline,
183     NodeSplinePath,
184     Height,
185     Triangle,
186     LineIntersectAxis,
187     PointOfIntersectionArcs,
188     PointOfIntersectionCircles,
189     PointOfIntersectionCurves,
190     CurveIntersectAxis,
191     ArcIntersectAxis,
192     PointOfIntersection,
193     PointFromCircleAndTangent,
194     PointFromArcAndTangent,
195     TrueDarts,
196     UnionDetails,
197     Group,
198     Rotation,
199     FlippingByLine,
200     FlippingByAxis,
201     Move,
202     Midpoint,
203     EllipticalArc,
204     Pin,
205     InsertNode,
206     PlaceLabel,
207     DuplicateDetail,
208     LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
209 };
210 
211 enum class Vis : ToolVisHolderType
212 {
213     ControlPointSpline = static_cast<ToolVisHolderType>(Tool::LAST_ONE_DO_NOT_USE),
214     GraphicsSimpleTextItem,
215     SimplePoint,
216     SimpleCurve,
217     ScaledLine,
218     ScaledEllipse,
219     Line,
220     Path,
221     Operation,
222     ToolAlongLine,
223     ToolArc,
224     ToolArcWithLength,
225     ToolBisector,
226     ToolCutArc,
227     ToolEndLine,
228     ToolHeight,
229     ToolLine,
230     ToolLineIntersect,
231     ToolNormal,
232     ToolPointOfContact,
233     ToolPointOfIntersection,
234     ToolPointOfIntersectionArcs,
235     ToolPointOfIntersectionCircles,
236     ToolPointOfIntersectionCurves,
237     ToolPointFromCircleAndTangent,
238     ToolPointFromArcAndTangent,
239     ToolShoulderPoint,
240     ToolSpline,
241     ToolCubicBezier,
242     ToolCubicBezierPath,
243     ToolTriangle,
244     ToolCutSpline,
245     ToolSplinePath,
246     ToolCutSplinePath,
247     ToolLineIntersectAxis,
248     ToolCurveIntersectAxis,
249     ToolTrueDarts,
250     ToolRotation,
251     ToolFlippingByLine,
252     ToolFlippingByAxis,
253     ToolMove,
254     ToolEllipticalArc,
255     ToolPiece,
256     ToolPiecePath,
257     ToolSpecialPoint,
258     ToolPlaceLabel,
259     ToolDuplicateDetail,
260     PieceSpecialPoints,
261     NoBrush,
262     CurvePathItem,
263     GrainlineItem,
264     PieceItem,
265     TextGraphicsItem,
266     ScenePoint,
267     LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
268 };
269 
270 enum class VarType : qint8 { Measurement, Increment, IncrementSeparator, LineLength, CurveLength, CurveCLength,
271                              LineAngle, CurveAngle, ArcRadius, Unknown };
272 
273 enum class IncrementType : qint8 { Increment, Separator };
274 
275 QString       IncrementTypeToString(IncrementType type);
276 IncrementType StringToIncrementType(const QString &value);
277 
278 enum class IMD: qint8 // Individual measurement dimension
279 {
280     N, // None
281     X, // height
282     Y, // size (chest half circumference)
283     W, // waist half circumference
284     Z  // hip half circumference
285 };
286 
287 /* QImage supports a maximum of 32768x32768 px images (signed short).
288  * This follows from the condition: width * height * colordepth < INT_MAX (4 billion) -> 32768 * 32768 * 4 = 4 billion.
289  * The second condition is of course that malloc is able to allocate the requested memory.
290  *
291  * If you really need bigger images you will have to use another wrapper or split into multiple QImage's.
292  */
293 #define QIMAGE_MAX 32768
294 
295 /*
296  * This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow
297  * you to continue afterwards should you choose to.
298  * idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148
299  * Usefull links:
300  * 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? -
301  *    https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func
302  *
303  * 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx
304  *
305  * 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx
306  *
307  * 4. Continue to debug after failed assertion on Linux? [C/C++] -
308  * https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c
309  */
310 #ifndef V_NO_ASSERT
311 
312 #define SCASSERT(cond)                                      \
313 {                                                           \
314     if (!(cond))                                            \
315     {                                                       \
316         qCritical("ASSERT: %s in %s (%s:%u)",               \
317                   #cond, Q_FUNC_INFO , __FILE__, __LINE__); \
318         debug_break();                                      \
319         abort();                                            \
320     }                                                       \
321 }                                                           \
322 
323 #else // define but disable this function if debugging is not set
324 #define SCASSERT(cond) qt_noop();
325 #endif /* V_NO_ASSERT */
326 
327 #ifndef __has_cpp_attribute
328 # define __has_cpp_attribute(x) 0
329 #endif
330 
331 #if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
332 
333 #ifndef QT_HAS_CPP_ATTRIBUTE
334 #ifdef __has_cpp_attribute
335 #  define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
336 #else
337 #  define QT_HAS_CPP_ATTRIBUTE(x) 0
338 #endif
339 #endif // QT_HAS_CPP_ATTRIBUTE
340 
341 #if defined(__cplusplus)
342 #if QT_HAS_CPP_ATTRIBUTE(clang::fallthrough)
343 #    define Q_FALLTHROUGH() [[clang::fallthrough]]
344 #elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
345 #    define Q_FALLTHROUGH() [[gnu::fallthrough]]
346 #elif QT_HAS_CPP_ATTRIBUTE(fallthrough)
347 #  define Q_FALLTHROUGH() [[fallthrough]]
348 #endif
349 #endif
350 #ifndef Q_FALLTHROUGH
351 #  if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL)
352 #    define Q_FALLTHROUGH() __attribute__((fallthrough))
353 #  else
354 #    define Q_FALLTHROUGH() (void)0
355 #endif
356 #endif // defined(__cplusplus)
357 #endif // QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
358 
359 bool IsOptionSet(int argc, char *argv[], const char *option);
360 void InitHighDpiScaling(int argc, char *argv[]);
361 
362 // functions
363 extern const QString degTorad_F;
364 extern const QString radTodeg_F;
365 extern const QString sin_F;
366 extern const QString cos_F;
367 extern const QString tan_F;
368 extern const QString asin_F;
369 extern const QString acos_F;
370 extern const QString atan_F;
371 extern const QString sinh_F;
372 extern const QString cosh_F;
373 extern const QString tanh_F;
374 extern const QString asinh_F;
375 extern const QString acosh_F;
376 extern const QString atanh_F;
377 extern const QString sinD_F;
378 extern const QString cosD_F;
379 extern const QString tanD_F;
380 extern const QString asinD_F;
381 extern const QString acosD_F;
382 extern const QString atanD_F;
383 extern const QString log2_F;
384 extern const QString log10_F;
385 extern const QString log_F;
386 extern const QString ln_F;
387 extern const QString exp_F;
388 extern const QString sqrt_F;
389 extern const QString sign_F;
390 extern const QString rint_F;
391 extern const QString r2cm_F;
392 extern const QString csrCm_F;
393 extern const QString csrInch_F;
394 extern const QString abs_F;
395 extern const QString min_F;
396 extern const QString max_F;
397 extern const QString sum_F;
398 extern const QString avg_F;
399 extern const QString fmod_F;
400 extern const QString warning_F;
401 
402 extern const QStringList builInFunctions;
403 
404 // Placeholders
405 extern const QString pl_size;
406 extern const QString pl_height;
407 extern const QString pl_hip;
408 extern const QString pl_waist;
409 extern const QString pl_sizeLabel;
410 extern const QString pl_heightLabel;
411 extern const QString pl_hipLabel;
412 extern const QString pl_waistLabel;
413 extern const QString pl_date;
414 extern const QString pl_time;
415 extern const QString pl_birthDate;
416 extern const QString pl_patternName;
417 extern const QString pl_patternNumber;
418 extern const QString pl_author;
419 extern const QString pl_customer;
420 extern const QString pl_email;
421 extern const QString pl_userMaterial;
422 extern const QString pl_pExt;
423 extern const QString pl_pUnits;
424 extern const QString pl_pFileName;
425 extern const QString pl_mFileName;
426 extern const QString pl_mExt;
427 extern const QString pl_mUnits;
428 extern const QString pl_mSizeUnits;
429 extern const QString pl_pLetter;
430 extern const QString pl_pAnnotation;
431 extern const QString pl_pOrientation;
432 extern const QString pl_pRotation;
433 extern const QString pl_pTilt;
434 extern const QString pl_pFoldPosition;
435 extern const QString pl_pName;
436 extern const QString pl_pQuantity;
437 extern const QString pl_mFabric;
438 extern const QString pl_mLining;
439 extern const QString pl_mInterfacing;
440 extern const QString pl_mInterlining;
441 extern const QString pl_wCut;
442 extern const QString pl_wOnFold;
443 extern const QString pl_measurement;
444 extern const QString pl_finalMeasurement;
445 
446 // Don't forget to syncronize with XSD schema.
447 const int userMaterialPlaceholdersQuantity = 20;
448 
449 extern const QString cursorArrowOpenHand;
450 extern const QString cursorArrowCloseHand;
451 
452 extern const QString strOne;
453 extern const QString strTwo;
454 extern const QString strThree;
455 
456 extern const QString strStraightforward;
457 extern const QString strBisector;
458 extern const QString strIntersection;
459 extern const QString strIntersectionOnlyLeft;
460 extern const QString strIntersectionOnlyRight;
461 extern const QString strIntersection2;
462 extern const QString strIntersection2OnlyLeft;
463 extern const QString strIntersection2OnlyRight;
464 extern const QString strTypeIncrement;
465 extern const QString strTypeSeparator;
466 
467 extern const QString unitMM;
468 extern const QString unitCM;
469 extern const QString unitINCH;
470 extern const QString unitPX;
471 
472 extern const QString valentinaNamespace;
473 
474 QPixmap QPixmapFromCache(const QString &pixmapPath);
475 void SetItemOverrideCursor(QGraphicsItem *item, const QString & pixmapPath, int hotX = -1, int hotY = -1);
476 
477 //---------------------------------------------------------------------------------------------------------------------
ToPixel(double val,const Unit & unit)478 Q_DECL_RELAXED_CONSTEXPR inline double ToPixel(double val, const Unit &unit)
479 {
480     switch (unit)
481     {
482         case Unit::Mm:
483             return (val / 25.4) * PrintDPI;
484         case Unit::Cm:
485             return ((val * 10.0) / 25.4) * PrintDPI;
486         case Unit::Inch:
487             return val * PrintDPI;
488         case Unit::Px:
489             return val;
490         default:
491             break;
492     }
493     return 0;
494 }
495 
496 //---------------------------------------------------------------------------------------------------------------------
FromPixel(double pix,const Unit & unit)497 Q_DECL_RELAXED_CONSTEXPR inline double FromPixel(double pix, const Unit &unit)
498 {
499     switch (unit)
500     {
501         case Unit::Mm:
502             return (pix / PrintDPI) * 25.4;
503         case Unit::Cm:
504             return ((pix / PrintDPI) * 25.4) / 10.0;
505         case Unit::Inch:
506             return pix / PrintDPI;
507         case Unit::Px:
508             return pix;
509         default:
510             break;
511     }
512     return 0;
513 }
514 
515 //---------------------------------------------------------------------------------------------------------------------
UnitConvertor(qreal value,const Unit & from,const Unit & to)516 Q_DECL_RELAXED_CONSTEXPR inline qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
517 {
518     switch (from)
519     {
520         case Unit::Mm:
521             switch (to)
522             {
523                 case Unit::Mm:
524                     return value;
525                 case Unit::Cm:
526                     return value / 10.0;
527                 case Unit::Inch:
528                     return value / 25.4;
529                 case Unit::Px:
530                     return (value / 25.4) * PrintDPI;
531                 default:
532                     break;
533             }
534             break;
535         case Unit::Cm:
536             switch (to)
537             {
538                 case Unit::Mm:
539                     return value * 10.0;
540                 case Unit::Cm:
541                     return value;
542                 case Unit::Inch:
543                     return value / 2.54;
544                 case Unit::Px:
545                     return ((value * 10.0) / 25.4) * PrintDPI;
546                 default:
547                     break;
548             }
549             break;
550         case Unit::Inch:
551             switch (to)
552             {
553                 case Unit::Mm:
554                     return value * 25.4;
555                 case Unit::Cm:
556                     return value * 2.54;
557                 case Unit::Inch:
558                     return value;
559                 case Unit::Px:
560                     return value * PrintDPI;
561                 default:
562                     break;
563             }
564             break;
565         case Unit::Px:
566             switch (to)
567             {
568                 case Unit::Mm:
569                     return (value / PrintDPI) * 25.4;
570                 case Unit::Cm:
571                     return ((value / PrintDPI) * 25.4) / 10.0;
572                 case Unit::Inch:
573                     return value / PrintDPI;
574                 case Unit::Px:
575                     return value;
576                 default:
577                     break;
578             }
579             break;
580         default:
581             break;
582     }
583     return 0;
584 }
585 
586 //---------------------------------------------------------------------------------------------------------------------
587 /**
588  * @brief UnitConvertor Converts the values of the given margin from given unit to the new unit.
589  * returns a new instand of QMarginsF.
590  */
UnitConvertor(const QMarginsF & margins,const Unit & from,const Unit & to)591 Q_DECL_RELAXED_CONSTEXPR inline QMarginsF UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to)
592 {
593     const qreal left = UnitConvertor(margins.left(), from, to);
594     const qreal top = UnitConvertor(margins.top(), from, to);
595     const qreal right = UnitConvertor(margins.right(), from, to);
596     const qreal bottom = UnitConvertor(margins.bottom(), from, to);
597 
598     return QMarginsF(left, top, right, bottom);
599 }
600 
601 void InitLanguages(QComboBox *combobox);
602 Q_REQUIRED_RESULT QStringList SupportedLocales();
603 
604 Q_REQUIRED_RESULT QString StrippedName(const QString &fullFileName);
605 Q_REQUIRED_RESULT QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath);
606 Q_REQUIRED_RESULT QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath);
607 
608 QStringList SplitFilePaths(const QString &path);
609 
610 QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer);
611 QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
612 
613 Q_REQUIRED_RESULT QPixmap darkenPixmap(const QPixmap &pixmap);
614 
615 void ShowInGraphicalShell(const QString &filePath);
616 
617 Q_REQUIRED_RESULT Q_DECL_RELAXED_CONSTEXPR static inline bool VFuzzyComparePossibleNulls(double p1, double p2);
VFuzzyComparePossibleNulls(double p1,double p2)618 Q_DECL_RELAXED_CONSTEXPR static inline bool VFuzzyComparePossibleNulls(double p1, double p2)
619 {
620     if(qFuzzyIsNull(p1))
621     {
622         return qFuzzyIsNull(p2);
623     }
624     else if(qFuzzyIsNull(p2))
625     {
626         return false;
627     }
628     else
629     {
630         return qFuzzyCompare(p1, p2);
631     }
632 }
633 
634 /**
635  * @brief The CustomSA struct contains record about custom seam allowanse (SA).
636  */
637 struct CustomSARecord
638 {
CustomSARecordCustomSARecord639     CustomSARecord()
640         : startPoint(0),
641           path(0),
642           endPoint(0),
643           reverse(false),
644           includeType(PiecePathIncludeType::AsCustomSA)
645     {}
646 
647     friend QDataStream& operator<<(QDataStream& out, const CustomSARecord& record);
648     friend QDataStream& operator>>(QDataStream& in, CustomSARecord& record);
649 
650     quint32 startPoint{0};
651     quint32 path{0};
652     quint32 endPoint{0};
653     bool reverse{false};
654     PiecePathIncludeType includeType{PiecePathIncludeType::AsCustomSA};
655 
656 private:
657     static const quint32 streamHeader;
658     static const quint16 classVersion;
659 };
660 
661 Q_DECLARE_METATYPE(CustomSARecord)
662 Q_DECLARE_TYPEINFO(CustomSARecord, Q_MOVABLE_TYPE);
663 /****************************************************************************
664 ** This file is derived from code bearing the following notice:
665 ** The sole author of this file, Adam Higerd, has explicitly disclaimed all
666 ** copyright interest and protection for the content within. This file has
667 ** been placed in the public domain according to United States copyright
668 ** statute and case law. In jurisdictions where this public domain dedication
669 ** is not legally recognized, anyone who receives a copy of this file is
670 ** permitted to use, modify, duplicate, and redistribute this file, in whole
671 ** or in part, with no restrictions or conditions. In these jurisdictions,
672 ** this file shall be copyright (C) 2006-2008 by Adam Higerd.
673 ****************************************************************************/
674 
675 #define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface<PUB, PUB##Private> qxt_d;
676 #define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
677 #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
678 #define QXT_D(PUB) PUB##Private& d = qxt_d()
679 #define QXT_P(PUB) PUB& p = qxt_p()
680 
681 template <typename PUB>
682 class QxtPrivate
683 {
684 public:
QxtPrivate()685     QxtPrivate(): qxt_p_ptr(nullptr)
686     {}
~QxtPrivate()687     virtual ~QxtPrivate()
688     {}
QXT_setPublic(PUB * pub)689     inline void QXT_setPublic(PUB* pub)
690     {
691         qxt_p_ptr = pub;
692     }
693 
694 protected:
qxt_p()695     inline PUB& qxt_p()
696     {
697         return *qxt_p_ptr;
698     }
qxt_p()699     inline const PUB& qxt_p() const
700     {
701         return *qxt_p_ptr;
702     }
qxt_ptr()703     inline PUB* qxt_ptr()
704     {
705         return qxt_p_ptr;
706     }
qxt_ptr()707     inline const PUB* qxt_ptr() const
708     {
709         return qxt_p_ptr;
710     }
711 
712 private:
713     Q_DISABLE_COPY(QxtPrivate)
714     PUB* qxt_p_ptr;
715 };
716 
717 template <typename PUB, typename PVT>
718 class QxtPrivateInterface
719 {
720     friend class QxtPrivate<PUB>;
721 public:
722     QxtPrivateInterface() : pvt(new PVT)
723     {}
724     ~QxtPrivateInterface()
725     {
726         delete pvt;
727     }
728 
729     inline void setPublic(PUB* pub)
730     {
731         pvt->QXT_setPublic(pub);
732     }
733     inline PVT& operator()()
734     {
735         return *static_cast<PVT*>(pvt);
736     }
737     inline const PVT& operator()() const
738     {
739         return *static_cast<PVT*>(pvt);
740     }
741     inline PVT * operator->()
742     {
743     return static_cast<PVT*>(pvt);
744     }
745     inline const PVT * operator->() const
746     {
747     return static_cast<PVT*>(pvt);
748     }
749 private:
750     Q_DISABLE_COPY(QxtPrivateInterface)
751     QxtPrivate<PUB>* pvt;
752 };
753 
754 #endif // DEF_H
755