QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RLinetypePattern.h
Go to the documentation of this file.
1 
20 #ifndef RLINETYPEPATTERN_H
21 #define RLINETYPEPATTERN_H
22 
23 #include "core_global.h"
24 
25 #include <stdarg.h>
26 #include <math.h>
27 
28 #include <QCoreApplication>
29 #include <QMetaType>
30 #include <QString>
31 #include <QPair>
32 #include <QList>
33 #include <QVector>
34 #include <QMap>
35 
36 #include "RPainterPath.h"
37 
46  Q_DECLARE_TR_FUNCTIONS(RLinetypePattern);
47 
48  friend class RLinetype;
49 
50 public:
54  RLinetypePattern(bool metric, const QString& name, const QString& description, int num...);
55 
56  RLinetypePattern(bool metric, const QString& name, const QString& description, const QList<double>& dashes);
57 
58  void set(const QList<double>& dashes);
59 
60  static QList<QPair<QString, RLinetypePattern*> > loadAllFrom(bool metric, const QString& fileName);
61 
63  RLinetypePattern(bool metric, const QString& name, const QString& description);
64  RLinetypePattern(const RLinetypePattern& other);
66 
67  bool isValid() const;
68  int getNumDashes() const;
69  QString getName() const;
70  void setName(const QString& n);
71  QString getDescription() const;
72  void setDescription(const QString& d);
73 
74  QString getLabel() const;
75  bool isMetric() const {
76  return metric;
77  }
78  void setMetric(bool on) {
79  metric = on;
80  }
81 
82  bool setPatternString(const QString& patternString);
83  QString getPatternString() const;
84  QList<double> getPattern() const;
85  double getPatternLength() const;
86  double getDashLengthAt(int i) const;
87  double getDashOffsetAt(const QList<double>& dashes, int i) const;
88 
89  bool hasShapeNumberAt(int i) const;
90  int getShapeNumberAt(int i) const;
91  void setShapeNumberAt(int i, int num);
92 
93  bool hasShapeScaleAt(int i) const;
94  double getShapeScaleAt(int i) const;
95  void setShapeScaleAt(int i, double s);
96 
97  bool hasShapeRotationAt(int i) const;
98  double getShapeRotationAt(int i) const;
99  void setShapeRotationAt(int i, double r);
100 
101  bool hasShapeOffsetAt(int i) const;
102  RVector getShapeOffsetAt(int i) const;
103  void setShapeOffsetAt(int i, const RVector& offset);
104 
105  bool hasShapeTextAt(int i) const;
106  QString getShapeTextAt(int i) const;
107  void setShapeTextAt(int i, const QString& s);
108 
109  bool hasShapeTextStyleAt(int i) const;
110  QString getShapeTextStyleAt(int i) const;
111  void setShapeTextStyleAt(int i, const QString& s);
112 
113  QList<int> getShapeIndices() const;
114  bool hasShapes() const;
115  bool hasShapeAt(int i) const;
116  QList<RPainterPath> getShapeAt(int i) const;
117  void updateShapes();
118  double getLargestGap() const;
119  bool hasDashAt(double pos) const;
120  double getDelta(double pos) const;
121  double getPatternOffset(double length);
122  QList<double> getSymmetries() const {
123  return symmetries;
124  }
125 
129  double getPatternOffsetAt(double length, double symmetryPos, double* gap = NULL, bool end = false);
130  void scale(double factor);
131 
132  QVector<qreal> getScreenBasedLinetype();
133 
134  RLinetypePattern& operator=(const RLinetypePattern& other);
135  bool operator==(const RLinetypePattern& other) const;
136 
137  bool isLoaded() { return true; }
138  void load() {}
139 
140  static void initNameMap();
141 
142 private:
143  bool metric;
144  QString name;
145  QString description;
146  mutable QString patternString;
147 
148  QList<double> pattern;
149 
150  QMap<int, QList<RPainterPath> > shapes;
151  QMap<int, QString> shapeTexts;
152  QMap<int, QString> shapeTextStyles;
153  QMap<int, int> shapeNumbers;
154  QMap<int, double> shapeScales;
155  QMap<int, double> shapeRotations;
156  QMap<int, RVector> shapeOffsets;
157 
158  // internal info about segments at which the pattern is symmetrical:
159  QList<double> symmetries;
160 
161  static QMap<QString, QString> nameMap;
162 };
163 
164 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLinetypePattern& p);
165 
170 Q_DECLARE_METATYPE(_RMapQStringRLinetypePattern*)
171 Q_DECLARE_METATYPE(_RMapQStringRLinetypePattern)
172 
173 #endif