]> Shamusworld >> Repos - architektonas/blob - src/base/rs_document.cpp
7379472c1281969c6c9ae290c10dca5bd40aaed4
[architektonas] / src / base / rs_document.cpp
1 // rs_document.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/28/2010  Added this text. :-)
13 //
14
15 #include "rs_document.h"
16
17 /**
18  * Constructor.
19  *
20  * @param parent Parent of the document. Often that's NULL but
21  *        for blocks it's the blocklist.
22  */
23 RS_Document::RS_Document(RS_EntityContainer * parent):
24         RS_EntityContainer(parent), RS_Undo()
25 {
26         RS_DEBUG->print("RS_Document::RS_Document() ");
27
28         filename = "";
29         formatType = RS2::FormatUnknown;
30         setModified(false);
31         RS_Color col(RS2::FlagByLayer);
32         activePen = RS_Pen(col, RS2::WidthByLayer, RS2::LineByLayer);
33 }
34
35 RS_Document::~RS_Document()
36 {
37 }
38
39 /**
40  * @return true for all document entities (e.g. Graphics or Blocks).
41  */
42 bool RS_Document::isDocument() const
43 {
44         return true;
45 }
46
47 /**
48  * Removes an entity from the entiy container. Implementation
49  * from RS_Undo.
50  */
51 void RS_Document::removeUndoable(RS_Undoable * u)
52 {
53         if (u != NULL && u->undoRtti() == RS2::UndoableEntity)
54         {
55                 removeEntity((RS_Entity *)u);
56         }
57 }
58
59 /**
60  * @return Currently active drawing pen.
61  */
62 RS_Pen RS_Document::getActivePen() const
63 {
64         return activePen;
65 }
66
67 /**
68  * Sets the currently active drawing pen to p.
69  */
70 void RS_Document::setActivePen(RS_Pen p)
71 {
72         activePen = p;
73 }
74
75 /**
76  * @return File name of the document currently loaded.
77  * Note, that the default file name is empty.
78  */
79 QString RS_Document::getFilename() const
80 {
81         return filename;
82 }
83
84 /**
85  * Sets file name for the document currently loaded.
86  */
87 void RS_Document::setFilename(const QString & fn)
88 {
89         filename = fn;
90 }
91
92 /**
93  * Sets the documents modified status to 'm'.
94  */
95 void RS_Document::setModified(bool m)
96 {
97         //std::cout << "RS_Document::setModified: %d" << (int)m << std::endl;
98         modified = m;
99 }
100
101 /**
102  * @retval true The document has been modified since it was last saved.
103  * @retval false The document has not been modified since it was last saved.
104  */
105 bool RS_Document::isModified() const
106 {
107         return modified;
108 }
109
110 /**
111  * Overwritten to set modified flag before starting an undo cycle.
112  */
113 void RS_Document::startUndoCycle()
114 {
115         setModified(true);
116         RS_Undo::startUndoCycle();
117 }