src/toolsets/basictoolset.cpp

changeset 1073
a0a0d581309b
parent 1072
9ce9496427f2
child 1074
a62f810ca26f
equal deleted inserted replaced
1072:9ce9496427f2 1073:a0a0d581309b
35 BasicToolset::BasicToolset (MainWindow *parent) : 35 BasicToolset::BasicToolset (MainWindow *parent) :
36 Toolset (parent) {} 36 Toolset (parent) {}
37 37
38 int BasicToolset::copyToClipboard() 38 int BasicToolset::copyToClipboard()
39 { 39 {
40 LDObjectList objs = selectedObjects(); 40 const QSet<LDObject*>& objects = selectedObjects();
41 int count = 0; 41 int count = 0;
42 qApp->clipboard()->clear(); 42 qApp->clipboard()->clear();
43 QString data; 43 QString data;
44 44
45 for (LDObject* obj : objs) 45 for (LDObject* obj : objects)
46 { 46 {
47 if (not data.isEmpty()) 47 if (not data.isEmpty())
48 data += "\n"; 48 data += "\n";
49 49
50 data += obj->asText(); 50 data += obj->asText();
77 77
78 for (QString line : clipboardText.split ("\n")) 78 for (QString line : clipboardText.split ("\n"))
79 { 79 {
80 LDObject* pasted = ParseLine (line); 80 LDObject* pasted = ParseLine (line);
81 currentDocument()->insertObject (idx++, pasted); 81 currentDocument()->insertObject (idx++, pasted);
82 pasted->select(); 82 currentDocument()->addToSelection(pasted);
83 ++num; 83 ++num;
84 } 84 }
85 85
86 print (tr ("%1 objects pasted"), num); 86 print (tr ("%1 objects pasted"), num);
87 m_window->refresh(); 87 m_window->refresh();
94 print (tr ("%1 objects deleted"), num); 94 print (tr ("%1 objects deleted"), num);
95 } 95 }
96 96
97 void BasicToolset::doInline (bool deep) 97 void BasicToolset::doInline (bool deep)
98 { 98 {
99 for (LDSubfileReference* ref : filterByType<LDSubfileReference> (selectedObjects())) 99 for (LDSubfileReference* reference : filterByType<LDSubfileReference> (selectedObjects()))
100 { 100 {
101 // Get the index of the subfile so we know where to insert the 101 // Get the index of the subfile so we know where to insert the
102 // inlined contents. 102 // inlined contents.
103 int idx = ref->lineNumber(); 103 int idx = reference->lineNumber();
104 104
105 if (idx != -1) 105 if (idx != -1)
106 { 106 {
107 LDObjectList objs = ref->inlineContents (deep, false); 107 Model inlined;
108 108 reference->inlineContents(inlined, deep, false);
109
109 // Merge in the inlined objects 110 // Merge in the inlined objects
110 for (LDObject* inlineobj : objs) 111 print("Inlined %1 objects.\n", countof(inlined.objects()));
112 for (LDObject* inlinedObject : inlined.objects())
111 { 113 {
112 QString line = inlineobj->asText(); 114 currentDocument()->insertObject (idx++, inlinedObject);
113 inlineobj->destroy(); 115 currentDocument()->addToSelection(inlinedObject);
114 LDObject* newobj = ParseLine (line);
115 currentDocument()->insertObject (idx++, newobj);
116 newobj->select();
117 } 116 }
118 117
119 // Delete the subfile now as it's been inlined. 118 // Delete the subfile now as it's been inlined.
120 ref->destroy(); 119 currentDocument()->remove(reference);
121 } 120 }
122 } 121 }
123 122
124 for (LDBezierCurve* curve : filterByType<LDBezierCurve> (selectedObjects())) 123 for (LDBezierCurve* curve : filterByType<LDBezierCurve> (selectedObjects()))
125 curve->replace (curve->rasterize(grid()->bezierCurveSegments())); 124 {
125 Model curveModel;
126 curve->rasterize(curveModel, grid()->bezierCurveSegments());
127 currentDocument()->replace(curve, curveModel);
128 }
126 } 129 }
127 130
128 void BasicToolset::inlineShallow() 131 void BasicToolset::inlineShallow()
129 { 132 {
130 doInline (false); 133 doInline (false);
185 for (QString line : QString (inputbox->toPlainText()).split ("\n")) 188 for (QString line : QString (inputbox->toPlainText()).split ("\n"))
186 { 189 {
187 LDObject* obj = ParseLine (line); 190 LDObject* obj = ParseLine (line);
188 191
189 currentDocument()->insertObject (idx, obj); 192 currentDocument()->insertObject (idx, obj);
190 obj->select(); 193 currentDocument()->addToSelection(obj);
191 idx++; 194 idx++;
192 } 195 }
193 196
194 m_window->refresh(); 197 m_window->refresh();
195 m_window->scrollToSelection(); 198 m_window->scrollToSelection();
198 void BasicToolset::setColor() 201 void BasicToolset::setColor()
199 { 202 {
200 if (selectedObjects().isEmpty()) 203 if (selectedObjects().isEmpty())
201 return; 204 return;
202 205
203 LDObjectList objs = selectedObjects(); 206 QSet<LDObject*> objs = selectedObjects();
204 207
205 // If all selected objects have the same color, said color is our default 208 // If all selected objects have the same color, said color is our default
206 // value to the color selection dialog. 209 // value to the color selection dialog.
207 LDColor color; 210 LDColor color;
208 LDColor defaultcol = m_window->getUniformSelectedColor(); 211 LDColor defaultcol = m_window->getUniformSelectedColor();
261 264
262 void BasicToolset::edit() 265 void BasicToolset::edit()
263 { 266 {
264 if (countof(selectedObjects()) == 1) 267 if (countof(selectedObjects()) == 1)
265 { 268 {
266 LDObject* obj = selectedObjects().first(); 269 LDObject* obj = *selectedObjects().begin();
267 AddObjectDialog::staticDialog (obj->type(), obj); 270 AddObjectDialog::staticDialog (obj->type(), obj);
268 } 271 }
269 } 272 }
270 273
271 void BasicToolset::modeSelect() 274 void BasicToolset::modeSelect()

mercurial