QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RDocumentInterface.h
Go to the documentation of this file.
1 
20 #ifndef RDOCUMENTINTERFACE_H
21 #define RDOCUMENTINTERFACE_H
22 
23 #include "core_global.h"
24 
25 #include <QKeyEvent>
26 #include <QList>
27 #include <QMap>
28 #include <QMutex>
29 #include <QSharedPointer>
30 #include <QStack>
31 #include <QQueue>
32 #include <QSwipeGesture>
33 #include <QPanGesture>
34 #include <QPinchGesture>
35 
36 #include "RAction.h"
37 #include "RCoordinateEvent.h"
38 #include "RCommandEvent.h"
39 #include "RCoordinateListener.h"
40 #include "RDocument.h"
41 #include "RExporter.h"
42 #include "RStorage.h"
43 #include "RTerminateEvent.h"
44 #include "RTextLabel.h"
45 #include "RUcs.h"
46 
47 #define RDEFAULT_QLIST_QREAL QList<qreal>()
48 #ifndef RDEFAULT_MIN1
49 #define RDEFAULT_MIN1 -1
50 #endif
51 
52 class RGraphicsScene;
53 class RGraphicsView;
54 class RMouseEvent;
55 class ROperation;
56 class RPropertyEvent;
57 class RSnap;
58 class RSnapRestriction;
59 class RScriptHandler;
60 class RTransaction;
61 class RWheelEvent;
62 
63 
64 
83 public:
84  enum IoErrorCode {
112  IoErrorGeneralImportUrlError
113  };
114 
115 public:
116  RDocumentInterface(RDocument& document);
118 
119  void clearCaches();
120 
122  RStorage& getStorage();
123  QList<RGraphicsScene*> getGraphicsScenes();
124  RGraphicsView* getGraphicsViewWithFocus();
125 
126  void addCoordinateListener(RCoordinateListener* l);
127  void notifyCoordinateListeners();
128 
129  void clear();
130 
134  RScriptHandler* getScriptHandler(const QString& extension);
135  bool isScriptRunning();
136 
137  void setDefaultAction(RAction* action);
138  void setCurrentAction(RAction* action);
139  void queueAction(RAction* action);
140  void killAllActions();
141 
142  RAction* getCurrentAction();
143  bool hasCurrentAction();
144 
145  void suspend();
146  void resume();
147 
148  void setClickMode(RAction::ClickMode m);
149  RAction::ClickMode getClickMode();
150 
151  void terminateEvent(RTerminateEvent& event);
152 
153  void keyPressEvent(QKeyEvent& event);
154  void keyReleaseEvent(QKeyEvent& event);
155  void mouseMoveEvent(RMouseEvent& event);
156  void mousePressEvent(RMouseEvent& event);
157  void mouseReleaseEvent(RMouseEvent& event);
158  void mouseDoubleClickEvent(RMouseEvent& event);
159  void coordinateEvent(RCoordinateEvent& event);
160  void coordinateEventPreview(RCoordinateEvent& event);
161  void commandEvent(RCommandEvent& event);
162  void commandEventPreview(RCommandEvent& event);
163  void wheelEvent(RWheelEvent& event);
164  void tabletEvent(RTabletEvent& event);
165  void swipeGestureEvent(QSwipeGesture& gesture);
166  void panGestureEvent(QPanGesture& gesture);
167  void pinchGestureEvent(QPinchGesture& gesture);
168 
169  void propertyChangeEvent(RPropertyEvent& event);
170  void ucsSetEvent(const QString& ucsName);
171 
172  void enableUpdates();
173  void disableUpdates();
174 
175  void enableRegeneration();
176  void disableRegeneration();
177 
178  void enableMouseTracking();
179  void disableMouseTracking();
180 
181  void updateAllEntities();
182 
183  void regenerateScenes(bool undone = false);
184  void regenerateScenes(QSet<REntity::Id>& entityIds, bool updateViews);
185  void regenerateScenes(REntity::Id entityId, bool updateViews);
186 
187  void updateSelectionStatus(QSet<REntity::Id>& entityIds, bool updateViews);
188  void updateSelectionStatus(REntity::Id entityId, bool updateViews);
189 
190  void regenerateViews(bool force=false);
191  void repaintViews();
192 
193  void registerScene(RGraphicsScene& scene);
194  void unregisterScene(RGraphicsScene& scene);
195 
196  void setCursor(const QCursor& cursor, bool global = true);
197 
199  const QUrl& url, const QString& nameFilter = "", bool notify = true);
201  const QString& fileName, const QString& nameFilter = "", bool notify = true);
202 
203  QString getCorrectedFileName(const QString& fileName, const QString& fileVersion);
204  bool exportFile(const QString& fileName, const QString& fileVersion = "", bool resetModified = true);
205 
206  void undo();
207  void redo();
208  void flushTransactions();
209 
210  void setSnap(RSnap* snap);
211  RSnap* getSnap();
212 
213  void setSnapRestriction(RSnapRestriction* snapRestriction);
214  RSnapRestriction* getSnapRestriction();
215 
216  RVector snap(RMouseEvent& event);
217 
218  REntity::Id getClosestEntity(RMouseEvent& event);
219  REntity::Id getClosestEntity(const RVector& position,
220  double range, double strictRange = RMAXDOUBLE,
221  bool includeLockedLayers = true);
222  void highlightEntity(REntity::Id entityId);
223  void highlightReferencePoint(const RVector& position);
224  void selectEntities(const QSet<REntity::Id>& entityIds, bool add = false);
225  void selectEntity(REntity::Id entityId, bool add = false);
226  void deselectEntities(const QSet<REntity::Id>& entityIds);
227  void deselectEntity(REntity::Id entityId);
228  void selectBoxXY(const RBox& box, bool add = false);
229  void selectAll();
230  void deselectAll();
231  void clearSelection();
232  bool hasSelection();
233 
234  void addZoomBoxToPreview(const RBox& box);
235  void addShapeToPreview(RShape& shape, const RColor& color,
236  const QBrush& brush, RLineweight::Lineweight lineweight,
237  Qt::PenStyle style, const QList<qreal>& dashValues = RDEFAULT_QLIST_QREAL);
238  void addAuxShapeToPreview(RShape& shape);
239  void addEntityToPreview(REntity& entity);
240  void beginPreview();
241  void endPreview();
242  void clearPreview();
243  bool isPreviewEmpty();
244  void keepPreview();
245 
246  void showPropertiesOf(REntity& entity);
247  void clearProperties();
248 
249  void zoomIn();
250  void zoomOut();
251  void autoZoom(int margin = RDEFAULT_MIN1);
252  bool zoomToSelection();
253  void zoomTo(const RBox& region, int margin = 0);
254  void zoomPrevious();
255 
256  void previewOperation(const ROperation* operation);
257  RTransaction applyOperation(const ROperation* operation);
258 
259  void objectChangeEvent(QList<RObject::Id>& objectIds);
260 
261  RVector getRelativeZero() const;
262  RVector getLastPosition() const;
263  void setRelativeZero(const RVector& p);
264 
265  void lockRelativeZero();
266  void unlockRelativeZero();
267  bool isRelativeZeroLocked() const;
268 
269  RVector getCursorPosition() const;
270  void setCursorPosition(const RVector& p);
271  void setCursorOverride(bool on);
272  bool getCursorOverride() const;
273 
274  void deleteTerminatedActions();
275 
276  void setCurrentColor(const RColor& color);
277  RColor getCurrentColor();
278 
279  void setCurrentLineweight(RLineweight::Lineweight lw);
280  RLineweight::Lineweight getCurrentLineweight();
281 
282  void setCurrentLinetype(RLinetype::Id ltId);
283  void setCurrentLinetypePattern(const RLinetypePattern& p);
284  RLinetype::Id getCurrentLinetypeId();
285  RLinetypePattern getCurrentLinetypePattern();
286 
287  void setCurrentLayer(const RLayer& layer);
288  void setCurrentLayer(const QString& layerName);
289 
290  void setCurrentBlock(const RBlock& block);
291  void setCurrentBlock(const QString& blockName);
292 
293  void setCurrentView(const QString& viewName);
294 
295  void setCurrentUcs(const RUcs& ucs);
296  void setCurrentUcs(const QString& ucsName);
297  RUcs getCurrentUcs();
298  QString getCurrentUcsName();
299 
300  RGraphicsView* getLastKnownViewWithFocus();
301  void setLastKnownViewWithFocus(RGraphicsView* view);
302 
304  static void deleteClipboard();
305  bool isClipboard() {
306  return this==clipboard;
307  }
308  bool isSuspended() {
309  return suspended;
310  }
311  void setNotifyListeners(bool on) {
312  notifyListeners = on;
313  }
314 
315  QVariant eval(const QString& ext, const QString& script);
316 
317 private:
318  void handleClickEvent(RAction& action, RMouseEvent& event);
319  void previewClickEvent(RAction& action, RMouseEvent& event);
320 
321 private:
323  QList<RGraphicsScene*> scenes;
325  QMap<QString, RScriptHandler*> scriptHandlers;
326 
328  QStack<RAction*> currentActions;
329  QQueue<RAction*> queuedActions;
330 
331  QList<RCoordinateListener*> coordinateListeners;
332 
335 
341  QString currentUcsName;
342  bool suspended;
343 
346 
348 
350  bool deleting;
352 
355 };
356 
359 
360 #endif