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 
121  RDocument& getDocument();
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  void enableMouseTracking();
175  void disableMouseTracking();
176 
177  void updateAllEntities();
178 
179  void regenerateScenes(bool undone = false);
180  void regenerateScenes(QSet<REntity::Id>& entityIds, bool updateViews);
181  void regenerateScenes(REntity::Id entityId, bool updateViews);
182 
183  void updateSelectionStatus(QSet<REntity::Id>& entityIds, bool updateViews);
184  void updateSelectionStatus(REntity::Id entityId, bool updateViews);
185 
186  void regenerateViews(bool force=false);
187  void repaintViews();
188 
189  void registerScene(RGraphicsScene& scene);
190  void unregisterScene(RGraphicsScene& scene);
191 
192  void setCursor(const QCursor& cursor, bool global = true);
193 
194  RDocumentInterface::IoErrorCode importUrl(const QUrl& url, bool notify = true);
196  const QString& fileName, const QString& nameFilter = "", bool notify = true);
197 
198  QString getCorrectedFileName(const QString& fileName, const QString& fileVersion);
199  bool exportFile(const QString& fileName, const QString& fileVersion = "", bool resetModified = true);
200 
201  void undo();
202  void redo();
203 
204  void setSnap(RSnap* snap);
205  RSnap* getSnap();
206 
207  void setSnapRestriction(RSnapRestriction* snapRestriction);
208  RSnapRestriction* getSnapRestriction();
209 
210  RVector snap(RMouseEvent& event);
211 
212  REntity::Id getClosestEntity(RMouseEvent& event);
213  REntity::Id getClosestEntity(const RVector& position, double range, bool includeLockedLayers = true);
214  void highlightEntity(REntity::Id entityId);
215  void highlightReferencePoint(const RVector& position);
216  void selectEntities(const QSet<REntity::Id>& entityIds, bool add = false);
217  void selectEntity(REntity::Id entityId, bool add = false);
218  void deselectEntities(const QSet<REntity::Id>& entityIds);
219  void deselectEntity(REntity::Id entityId);
220  void selectBoxXY(const RBox& box, bool add = false);
221  void selectAll();
222  void deselectAll();
223  void clearSelection();
224  bool hasSelection();
225 
226  void addZoomBoxToPreview(const RBox& box);
227  void addShapeToPreview(RShape& shape, const RColor& color,
228  const QBrush& brush, RLineweight::Lineweight lineweight,
229  Qt::PenStyle style, const QList<qreal>& dashValues = RDEFAULT_QLIST_QREAL);
230  void addAuxShapeToPreview(RShape& shape);
231  void addEntityToPreview(REntity& entity);
232  void beginPreview();
233  void endPreview();
234  void clearPreview();
235  bool isPreviewEmpty();
236  void keepPreview();
237 
238  void showPropertiesOf(REntity& entity);
239  void clearProperties();
240 
241  void zoomIn();
242  void zoomOut();
243  void autoZoom(int margin = RDEFAULT_MIN1);
244  bool zoomToSelection();
245  void zoomTo(const RBox& region, int margin = 0);
246  void zoomPrevious();
247 
248  void previewOperation(const ROperation* operation);
249  RTransaction applyOperation(const ROperation* operation);
250 
251  void objectChangeEvent(QList<RObject::Id>& objectIds);
252 
253  RVector getRelativeZero() const;
254  RVector getLastPosition() const;
255  void setRelativeZero(const RVector& p);
256 
257  void lockRelativeZero();
258  void unlockRelativeZero();
259  bool isRelativeZeroLocked() const;
260 
261  RVector getCursorPosition() const;
262  void setCursorPosition(const RVector& p);
263  void setCursorOverride(bool on);
264  bool getCursorOverride() const;
265 
266  void deleteTerminatedActions();
267 
268  void setCurrentColor(const RColor& color);
269  RColor getCurrentColor();
270 
271  void setCurrentLineweight(RLineweight::Lineweight lw);
272  RLineweight::Lineweight getCurrentLineweight();
273 
274  void setCurrentLinetype(RLinetype lt);
275  RLinetype getCurrentLinetype();
276 
277  void setCurrentLayer(const RLayer& layer);
278  void setCurrentLayer(const QString& layerName);
279 
280  void setCurrentBlock(const RBlock& block);
281  void setCurrentBlock(const QString& blockName);
282 
283  void setCurrentView(const QString& viewName);
284 
285  void setCurrentUcs(const RUcs& ucs);
286  void setCurrentUcs(const QString& ucsName);
287  RUcs getCurrentUcs();
288  QString getCurrentUcsName();
289 
290  RGraphicsView* getLastKnownViewWithFocus();
291  void setLastKnownViewWithFocus(RGraphicsView* view);
292 
294  bool isClipboard() {
295  return this==clipboard;
296  }
297  bool isSuspended() {
298  return suspended;
299  }
300  void setNotifyListeners(bool on) {
301  notifyListeners = on;
302  }
303 
304 private:
305  void handleClickEvent(RAction& action, RMouseEvent& event);
306  void previewClickEvent(RAction& action, RMouseEvent& event);
307 
308 private:
310  QList<RGraphicsScene*> scenes;
312  QMap<QString, RScriptHandler*> scriptHandlers;
313 
315  QStack<RAction*> currentActions;
316  QQueue<RAction*> queuedActions;
317 
318  QList<RCoordinateListener*> coordinateListeners;
319 
322 
328  QString currentUcsName;
329  bool suspended;
330 
332 
334 
336  bool deleting;
338 
341 };
342 
345 
346 #endif