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