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 
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 
198  RDocumentInterface::IoErrorCode importUrl(const QUrl& url, bool notify = true);
200  const QString& fileName, const QString& nameFilter = "", bool notify = true);
201 
202  QString getCorrectedFileName(const QString& fileName, const QString& fileVersion);
203  bool exportFile(const QString& fileName, const QString& fileVersion = "", bool resetModified = true);
204 
205  void undo();
206  void redo();
207  void flushTransactions();
208 
209  void setSnap(RSnap* snap);
210  RSnap* getSnap();
211 
212  void setSnapRestriction(RSnapRestriction* snapRestriction);
213  RSnapRestriction* getSnapRestriction();
214 
215  RVector snap(RMouseEvent& event);
216 
217  REntity::Id getClosestEntity(RMouseEvent& event);
218  REntity::Id getClosestEntity(const RVector& position, double range, double strictRange = RMAXDOUBLE, bool includeLockedLayers = true);
219  void highlightEntity(REntity::Id entityId);
220  void highlightReferencePoint(const RVector& position);
221  void selectEntities(const QSet<REntity::Id>& entityIds, bool add = false);
222  void selectEntity(REntity::Id entityId, bool add = false);
223  void deselectEntities(const QSet<REntity::Id>& entityIds);
224  void deselectEntity(REntity::Id entityId);
225  void selectBoxXY(const RBox& box, bool add = false);
226  void selectAll();
227  void deselectAll();
228  void clearSelection();
229  bool hasSelection();
230 
231  void addZoomBoxToPreview(const RBox& box);
232  void addShapeToPreview(RShape& shape, const RColor& color,
233  const QBrush& brush, RLineweight::Lineweight lineweight,
234  Qt::PenStyle style, const QList<qreal>& dashValues = RDEFAULT_QLIST_QREAL);
235  void addAuxShapeToPreview(RShape& shape);
236  void addEntityToPreview(REntity& entity);
237  void beginPreview();
238  void endPreview();
239  void clearPreview();
240  bool isPreviewEmpty();
241  void keepPreview();
242 
243  void showPropertiesOf(REntity& entity);
244  void clearProperties();
245 
246  void zoomIn();
247  void zoomOut();
248  void autoZoom(int margin = RDEFAULT_MIN1);
249  bool zoomToSelection();
250  void zoomTo(const RBox& region, int margin = 0);
251  void zoomPrevious();
252 
253  void previewOperation(const ROperation* operation);
254  RTransaction applyOperation(const ROperation* operation);
255 
256  void objectChangeEvent(QList<RObject::Id>& objectIds);
257 
258  RVector getRelativeZero() const;
259  RVector getLastPosition() const;
260  void setRelativeZero(const RVector& p);
261 
262  void lockRelativeZero();
263  void unlockRelativeZero();
264  bool isRelativeZeroLocked() const;
265 
266  RVector getCursorPosition() const;
267  void setCursorPosition(const RVector& p);
268  void setCursorOverride(bool on);
269  bool getCursorOverride() const;
270 
271  void deleteTerminatedActions();
272 
273  void setCurrentColor(const RColor& color);
274  RColor getCurrentColor();
275 
276  void setCurrentLineweight(RLineweight::Lineweight lw);
277  RLineweight::Lineweight getCurrentLineweight();
278 
279  void setCurrentLinetype(RLinetype::Id ltId);
280  void setCurrentLinetypePattern(const RLinetypePattern& p);
281  RLinetype::Id getCurrentLinetypeId();
282  RLinetypePattern getCurrentLinetypePattern();
283 
284  void setCurrentLayer(const RLayer& layer);
285  void setCurrentLayer(const QString& layerName);
286 
287  void setCurrentBlock(const RBlock& block);
288  void setCurrentBlock(const QString& blockName);
289 
290  void setCurrentView(const QString& viewName);
291 
292  void setCurrentUcs(const RUcs& ucs);
293  void setCurrentUcs(const QString& ucsName);
294  RUcs getCurrentUcs();
295  QString getCurrentUcsName();
296 
297  RGraphicsView* getLastKnownViewWithFocus();
298  void setLastKnownViewWithFocus(RGraphicsView* view);
299 
301  bool isClipboard() {
302  return this==clipboard;
303  }
304  bool isSuspended() {
305  return suspended;
306  }
307  void setNotifyListeners(bool on) {
308  notifyListeners = on;
309  }
310 
311 private:
312  void handleClickEvent(RAction& action, RMouseEvent& event);
313  void previewClickEvent(RAction& action, RMouseEvent& event);
314 
315 private:
317  QList<RGraphicsScene*> scenes;
319  QMap<QString, RScriptHandler*> scriptHandlers;
320 
322  QStack<RAction*> currentActions;
323  QQueue<RAction*> queuedActions;
324 
325  QList<RCoordinateListener*> coordinateListeners;
326 
329 
335  QString currentUcsName;
336  bool suspended;
337 
340 
342 
344  bool deleting;
346 
349 };
350 
353 
354 #endif