QCAD
Open Source 2D CAD
RTextBasedData.h
Go to the documentation of this file.
1 
20 #ifndef RTEXTBASEDDATA_H
21 #define RTEXTBASEDDATA_H
22 
23 #include "core_global.h"
24 
25 #include "RDocument.h"
26 #include "REntityData.h"
27 #include "RPainterPath.h"
28 #include "RPainterPathSource.h"
29 #include "RVector.h"
30 #include "RTextLayout.h"
31 #include "RTextProxy.h"
32 
33 class QTextDocument;
34 
45  friend class RTextBasedEntity;
46 
47 protected:
49 
50 public:
52  RTextBasedData(const RVector& position,
53  const RVector& alignmentPoint,
54  double textHeight,
55  double textWidth,
56  RS::VAlign verticalAlignment,
57  RS::HAlign horizontalAlignment,
58  RS::TextDrawingDirection drawingDirection,
59  RS::TextLineSpacingStyle lineSpacingStyle,
60  double lineSpacingFactor,
61  const QString& text,
62  const QString& fontName,
63  bool bold,
64  bool italic,
65  double angle,
66  bool simple);
67  virtual ~RTextBasedData() {}
68 
69  virtual RS::EntityType getType() const {
70  return RS::EntityTextBased;
71  }
72 
73  virtual bool isValid() const {
74  return !text.isNull();
75  }
76  virtual bool isSane() const;
77 
78  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
79  double getWidth() const;
80  double getHeight() const;
81 
82  void sync(const RTextBasedData& other);
83 
84  virtual RVector getPointOnEntity() const;
85 
86  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
87  Q_UNUSED(queryBox);
88  return QList<RVector>();
89  }
90  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
91  Q_UNUSED(queryBox);
92  return QList<RVector>();
93  }
94  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
95  Q_UNUSED(queryBox);
96  return QList<RVector>();
97  }
98  virtual QList<RVector> getPointsWithDistanceToEnd(
99  double distance, int from = RS::FromAny, const RBox& queryBox = RDEFAULT_RBOX) const {
100  Q_UNUSED(distance);
101  Q_UNUSED(from);
102  Q_UNUSED(queryBox);
103 
104  return QList<RVector>();
105  }
106 
107  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
108  virtual bool intersectsWith(const RShape& shape) const;
109 
114  return position;
115  }
116 
117  void setPosition(const RVector& position) {
118  this->position = position;
119  }
120 
126  return alignmentPoint;
127  }
128 
129  void setAlignmentPoint(const RVector& alignmentPoint) {
130  this->alignmentPoint = alignmentPoint;
131  }
132 
133  void setText(const QString& text);
134 
135  QString getFontName() const {
136  return fontName;
137  }
138 
139  void setFontName(const QString& fontName) {
140  this->fontName = fontName;
141  update();
142  }
143 
144  QString getFontFile() const {
145  return fontFile;
146  }
147 
148  void setFontFile(const QString& fontFile) {
149  this->fontFile = fontFile;
150  }
151 
152  bool isBold() const {
153  return bold;
154  }
155 
156  void setBold(bool on) {
157  bold = on;
158  update();
159  }
160 
161  bool isItalic() const {
162  return italic;
163  }
164 
165  void setItalic(bool on) {
166  italic = on;
167  update();
168  }
169 
170  double getTextHeight() const {
171  return textHeight;
172  }
173 
174  void setTextHeight(double h) {
175  this->textHeight = h;
176  update();
177  }
178 
182  double getTextWidth() const {
183  return textWidth;
184  }
185 
186  void setTextWidth(double w) {
187  this->textWidth = w;
188  update();
189  }
190 
191  void setVAlign(RS::VAlign valign) {
192  this->verticalAlignment = valign;
193  update();
194  }
195 
197  return this->verticalAlignment;
198  }
199 
200  void setHAlign(RS::HAlign halign) {
201  this->horizontalAlignment = halign;
202  update();
203  }
204 
206  return this->horizontalAlignment;
207  }
208 
210  this->drawingDirection = drawingDirection;
211  update();
212  }
213 
215  return drawingDirection;
216  }
217 
219  this->lineSpacingStyle = lineSpacingStyle;
220  update();
221  }
222 
224  return lineSpacingStyle;
225  }
226 
227  void setLineSpacingFactor(double lineSpacingFactor) {
228  if (lineSpacingFactor<0) {
229  return;
230  }
231  this->lineSpacingFactor = lineSpacingFactor;
232  update();
233  }
234 
235  double getLineSpacingFactor() const {
236  return lineSpacingFactor;
237  }
238 
239  void setAngle(double angle) {
240  this->angle = angle;
241  update();
242  }
243 
244  double getAngle() const {
245  return angle;
246  }
247 
248  void setXScale(double xScale) {
249  this->xScale = xScale;
250  update();
251  }
252 
253  double getXScale() const {
254  return xScale;
255  }
256 
257  void setSimple(bool on) {
258  simple = on;
259  update();
260  }
261 
262  bool isSimple() const {
263  return simple;
264  }
265 
266  void setDimensionLabel(bool on) {
267  dimensionLabel = on;
268  update();
269  }
270 
271  bool isDimensionLabel() const {
272  return dimensionLabel;
273  }
274 
275  void setSelected(bool on) {
277  update();
278  }
279 
280  void setHighlighted(bool on) {
281  highlighted = on;
282  }
283 
284  bool isHighlighted() const {
285  return highlighted;
286  }
287 
288  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
289 
290  virtual bool moveReferencePoint(const RVector& referencePoint,
291  const RVector& targetPoint);
292 
293  virtual bool move(const RVector& offset);
294  virtual bool rotate(double rotation, const RVector& center);
295  virtual bool scale(const RVector& scaleFactors, const RVector& center);
296  virtual bool mirror(const RLine& axis);
297  virtual bool flipHorizontal();
298  virtual bool flipVertical();
299 
300  virtual QString getText() const {
301  return text;
302  }
303  virtual QString getRenderedText(bool escapeUnicode = false) const;
304  virtual QString getPlainText() const;
305  virtual QString getEscapedText(bool escapeUnicode = false) const;
306  static QString escapeUnicode(const QString& str);
307  virtual QFont getMainFont() const;
308 
309  virtual void update(bool layout) const;
310  virtual void update() const {
311  update(true);
312  }
313  virtual bool isDirty() const;
314 
315  virtual QList<RPainterPath> getPainterPaths(bool draft = false, double pixelSizeHint = RDEFAULT_MIN1) const;
316  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const;
317  virtual QList<QSharedPointer<RShape> > getExploded() const;
318 
319  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const {
320  Q_UNUSED(pos);
321  Q_UNUSED(range);
322  Q_UNUSED(ignoreComplex)
323  return QSharedPointer<RShape>();
324  }
325 
326  virtual RVector getClosestPointOnEntity(const RVector& point, double range, bool limited) const;
327 
328  QList<RTextLayout> getTextLayouts() const;
329 
330  QList<RTextBasedData> getSimpleTextBlocks() const;
331 
332 // virtual RTextBasedData getRenderedTextData() const {
333 // return *this;
334 // }
335 
336  static bool hasProxy() {
337  return textProxy!=NULL;
338  }
339 
343  static void setTextProxy(RTextProxy* p) {
344  if (textProxy!=NULL) {
345  delete textProxy;
346  }
347  textProxy = p;
348  }
349 
354  return textProxy;
355  }
356 
357  static QString toEscapedText(const QTextDocument& textDocument, const RColor& initialColor, double fontHeightFactor=1.0);
358  static QString toRichText(const QString& escapedText, const QFont& mainFont, double fontHeightFactor=1.0);
359 
360 protected:
361  QString text;
364  double textHeight;
365  double textWidth;
371  QString fontName;
372  QString fontFile;
373  bool bold;
374  bool italic;
375  double angle;
376  double xScale;
377  bool simple;
380 
381  mutable double height;
382  mutable double width;
383  mutable RBox boundingBox;
384  mutable QList<RPainterPath> painterPaths;
385  mutable bool dirty;
386  mutable bool gotDraft;
387  mutable QList<RTextLayout> textLayouts;
388 
389 private:
391 };
392 
393 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RTextBasedData& t);
394 
398 Q_DECLARE_METATYPE(QSharedPointer<RTextBasedData>)
399 Q_DECLARE_METATYPE(QSharedPointer<RTextBasedData>*)
400 
401 #endif
Represents a box e.g.
Definition: RBox.h:43
Base class for all entity data classes.
Definition: REntityData.h:65
virtual bool flipVertical()
Definition: REntityData.cpp:565
virtual RVector getPointOnEntity() const
Definition: REntityData.cpp:309
void setVAlign(RS::VAlign valign)
Definition: RTextBasedData.h:191
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: RTextBasedData.h:310
bool isBold() const
Definition: RTextBasedData.h:152
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
void setPosition(const RVector &position)
Definition: RTextBasedData.h:117
#define RDEFAULT_RBOX
Definition: RBox.h:32
virtual bool mirror(const RLine &axis)
Definition: REntityData.cpp:547
virtual RVector getClosestPointOnEntity(const RVector &point, double range=RNANDOUBLE, bool limited=true) const
Definition: REntityData.cpp:378
static void setTextProxy(RTextProxy *p)
Definition: RTextBasedData.h:343
TextLineSpacingStyle
Line spacing style for texts.
Definition: RS.h:192
virtual bool isSane() const
Definition: REntityData.h:93
void setAngle(double angle)
Definition: RTextBasedData.h:239
double width
Definition: RTextBasedData.h:382
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:76
virtual bool flipHorizontal()
Definition: REntityData.cpp:561
VAlign
Vertical alignments.
Definition: RS.h:161
void setFontName(const QString &fontName)
Definition: RTextBasedData.h:139
virtual QList< QSharedPointer< RShape > > getExploded() const
Definition: RTextBasedEntity.h:101
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntityData.h:104
QString getFontName() const
Definition: RTextBasedData.h:135
bool isItalic() const
Definition: RTextBasedData.h:161
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntityData.cpp:507
QString getEscapedText(bool escapeUnicode=false) const
Definition: RTextBasedEntity.h:236
virtual QList< RVector > getEndPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: RTextBasedData.h:86
Any text based entity (text, attribute def, attribute)
Definition: RS.h:104
#define QCADCORE_EXPORT
Definition: core_global.h:10
QString fontName
Definition: RTextBasedData.h:371
double height
Definition: RTextBasedData.h:381
void setSimple(bool on)
Definition: RTextBasedData.h:257
static RTextProxy * textProxy
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RTextBasedData.h:390
bool dirty
Definition: RTextBasedData.h:385
virtual void setSelected(bool on)
Selects or deselects this entity.
Definition: REntityData.h:178
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntityData.cpp:261
static bool hasProxy()
Definition: RTextBasedData.h:336
bool dimensionLabel
Definition: RTextBasedData.h:378
double getXScale() const
Definition: RTextBasedData.h:253
RS::HAlign horizontalAlignment
Definition: RTextBasedData.h:367
RS::TextDrawingDirection drawingDirection
Definition: RTextBasedData.h:368
virtual bool intersectsWith(const RShape &shape) const
Definition: REntityData.cpp:439
#define RNANDOUBLE
Definition: RMath.h:71
Start or end.
Definition: RS.h:203
void setSelected(bool on)
Selects or deselects this entity.
Definition: RTextBasedData.h:275
void setLineSpacingFactor(double lineSpacingFactor)
Definition: RTextBasedData.h:227
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:131
RS::VAlign verticalAlignment
Definition: RTextBasedData.h:366
double getWidth() const
Definition: RTextBasedEntity.h:153
Stores and manages all data that defines the geometry and appearance of a text based entity (text...
Definition: RTextBasedData.h:44
Color.
Definition: RColor.h:42
double xScale
Definition: RTextBasedData.h:376
void setHAlign(RS::HAlign halign)
Definition: RTextBasedData.h:200
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:527
double getAngle() const
Definition: RTextBasedData.h:244
RS::TextDrawingDirection getDrawingDirection() const
Definition: RTextBasedData.h:214
bool bold
Definition: RTextBasedData.h:373
bool highlighted
Definition: RTextBasedData.h:379
Text entity.
Definition: RTextBasedEntity.h:38
double angle
Definition: RTextBasedData.h:375
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntityData.cpp:275
RVector position
Definition: RTextBasedData.h:362
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
virtual bool moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint)=0
Moves the given reference point to the given target point or does nothing if this entity has no refer...
bool isHighlighted() const
Definition: RTextBasedData.h:284
RVector alignmentPoint
Definition: RTextBasedData.h:363
Q_DECLARE_METATYPE(RMath *)
void setHighlighted(bool on)
Definition: RTextBasedData.h:280
void setTextWidth(double w)
Definition: RTextBasedData.h:186
void setAlignmentPoint(const RVector &alignmentPoint)
Definition: RTextBasedData.h:129
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny, const RBox &queryBox=RDEFAULT_RBOX) const
Definition: RTextBasedData.h:98
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:517
void setTextHeight(double h)
Definition: RTextBasedData.h:174
virtual QString getText() const
Definition: RTextBasedData.h:300
Interface for entity data classes that can deliver painter paths.
Definition: RPainterPathSource.h:40
#define RMAXDOUBLE
Definition: RMath.h:63
void setDrawingDirection(RS::TextDrawingDirection drawingDirection)
Definition: RTextBasedData.h:209
QString getFontFile() const
Definition: RTextBasedData.h:144
static RTextProxy * getTextProxy()
Definition: RTextBasedData.h:353
virtual ~RTextBasedData()
Definition: RTextBasedData.h:67
bool simple
Definition: RTextBasedData.h:377
void sync(const RTextBasedEntity &other)
Definition: RTextBasedEntity.h:252
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
RS::VAlign getVAlign() const
Definition: RTextBasedData.h:196
bool isSimple() const
Definition: RTextBasedData.h:262
Low-level mathematical representation of a line.
Definition: RLine.h:41
QList< RTextBasedData > getSimpleTextBlocks() const
Definition: RTextBasedEntity.h:256
void setLineSpacingStyle(RS::TextLineSpacingStyle lineSpacingStyle)
Definition: RTextBasedData.h:218
RS::HAlign getHAlign() const
Definition: RTextBasedData.h:205
QString getPlainText() const
Definition: RTextBasedEntity.h:244
bool italic
Definition: RTextBasedData.h:374
RVector getAlignmentPoint() const
Definition: RTextBasedData.h:125
virtual bool isValid() const
Definition: RTextBasedData.h:73
Definition: RS.h:132
void setText(const QString &text)
Definition: RTextBasedEntity.h:248
#define RDEFAULT_MIN1
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RExplodable.h:30
bool gotDraft
Definition: RTextBasedData.h:386
double getHeight() const
Definition: RTextBasedEntity.h:156
double getTextHeight() const
Definition: RTextBasedData.h:170
void setFontFile(const QString &fontFile)
Definition: RTextBasedData.h:148
void setItalic(bool on)
Definition: RTextBasedData.h:165
RVector getPosition() const
Definition: RTextBasedData.h:113
QList< RPainterPath > painterPaths
Definition: RTextBasedData.h:384
RS::TextLineSpacingStyle getLineSpacingStyle() const
Definition: RTextBasedData.h:223
virtual QList< RVector > getCenterPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: RTextBasedData.h:94
RBox boundingBox
Definition: RTextBasedData.h:383
void setBold(bool on)
Definition: RTextBasedData.h:156
double getTextWidth() const
Width of the text box used for line wrapping (not supported).
Definition: RTextBasedData.h:182
double getLineSpacingFactor() const
Definition: RTextBasedData.h:235
double textWidth
Definition: RTextBasedData.h:365
QString text
Definition: RTextBasedData.h:361
virtual RS::EntityType getType() const
Definition: RTextBasedData.h:69
HAlign
Horizontal alignments.
Definition: RS.h:171
TextDrawingDirection
Text drawing direction.
Definition: RS.h:183
Interface for geometrical shape classes.
Definition: RShape.h:52
void setDimensionLabel(bool on)
Definition: RTextBasedData.h:266
QList< RPainterPath > getPainterPaths(bool draft=false) const
Definition: RTextBasedEntity.h:93
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntityData.h:371
QList< RTextLayout > textLayouts
Definition: RTextBasedData.h:387
virtual QSharedPointer< RShape > getClosestShape(const RVector &pos, double range=RNANDOUBLE, bool ignoreComplex=false) const
Definition: RTextBasedData.h:319
virtual QList< RVector > getMiddlePoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: RTextBasedData.h:90
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RTextBasedData &t)
Definition: RTextBasedData.cpp:971
RS::TextLineSpacingStyle lineSpacingStyle
Definition: RTextBasedData.h:369
double lineSpacingFactor
Definition: RTextBasedData.h:370
double textHeight
Definition: RTextBasedData.h:364
Proxy for advanced text functionality.
Definition: RTextProxy.h:36
bool isDimensionLabel() const
Definition: RTextBasedData.h:271
QString fontFile
Definition: RTextBasedData.h:372
RDocument * document
Definition: RObject.h:271
void setXScale(double xScale)
Definition: RTextBasedData.h:248