src/ldtypes.cc

changeset 562
c4ff45e98551
parent 560
39085791128f
child 564
79b23e02dcf1
equal deleted inserted replaced
561:1d90296ad3fc 562:c4ff45e98551
28 cfg (String, ld_defaultname, ""); 28 cfg (String, ld_defaultname, "");
29 cfg (String, ld_defaultuser, ""); 29 cfg (String, ld_defaultuser, "");
30 cfg (Int, ld_defaultlicense, 0); 30 cfg (Int, ld_defaultlicense, 0);
31 31
32 // List of all LDObjects 32 // List of all LDObjects
33 QList<LDObject*> g_LDObjects; 33 static QList<LDObject*> g_LDObjects;
34 34
35 // ============================================================================= 35 // =============================================================================
36 // LDObject constructors 36 // LDObject constructors
37 // ----------------------------------------------------------------------------- 37 // -----------------------------------------------------------------------------
38 LDObject::LDObject() : 38 LDObject::LDObject() :
48 } 48 }
49 49
50 // ============================================================================= 50 // =============================================================================
51 // ----------------------------------------------------------------------------- 51 // -----------------------------------------------------------------------------
52 void LDObject::chooseID() 52 void LDObject::chooseID()
53 { int32 id = 1; // 0 is invalid 53 { int32 id = 1; // 0 shalt be null
54 54
55 for (LDObject* obj : g_LDObjects) 55 for (LDObject* obj : g_LDObjects)
56 { assert (obj != this);
57
56 if (obj->getID() >= id) 58 if (obj->getID() >= id)
57 id = obj->getID() + 1; 59 id = obj->getID() + 1;
60 }
58 61
59 setID (id); 62 setID (id);
60 } 63 }
61 64
62 // ============================================================================= 65 // =============================================================================
226 229
227 // Replace the instance of the old object with the new object 230 // Replace the instance of the old object with the new object
228 getFile()->setObject (idx, other); 231 getFile()->setObject (idx, other);
229 232
230 // Remove the old object 233 // Remove the old object
231 delete this; 234 deleteSelf();
232 } 235 }
233 236
234 // ============================================================================= 237 // =============================================================================
235 // ----------------------------------------------------------------------------- 238 // -----------------------------------------------------------------------------
236 void LDObject::swap (LDObject* other) 239 void LDObject::swap (LDObject* other)
269 LDObject::~LDObject() {} 272 LDObject::~LDObject() {}
270 273
271 // ============================================================================= 274 // =============================================================================
272 // ----------------------------------------------------------------------------- 275 // -----------------------------------------------------------------------------
273 void LDObject::deleteSelf() 276 void LDObject::deleteSelf()
274 { dlog( "#%1: type: %2\n", getID(), getType()); 277 { // If this object was selected, unselect it now
275
276 // If this object was selected, unselect it now
277 if (isSelected()) 278 if (isSelected())
278 unselect(); 279 unselect();
279 280
280 // If this object was associated to a file, remove it off it now 281 // If this object was associated to a file, remove it off it now
281 if (getFile()) 282 if (getFile())
397 // ============================================================================= 398 // =============================================================================
398 // ----------------------------------------------------------------------------- 399 // -----------------------------------------------------------------------------
399 str LDObject::typeName (LDObject::Type type) 400 str LDObject::typeName (LDObject::Type type)
400 { LDObject* obj = LDObject::getDefault (type); 401 { LDObject* obj = LDObject::getDefault (type);
401 str name = obj->getTypeName(); 402 str name = obj->getTypeName();
402 delete obj; 403 obj->deleteSelf();
403 return name; 404 return name;
404 } 405 }
405 406
406 // ============================================================================= 407 // =============================================================================
407 // ----------------------------------------------------------------------------- 408 // -----------------------------------------------------------------------------
427 text += ", "; 428 text += ", ";
428 429
429 str noun = fmt ("%1%2", typeName (objType), plural (count)); 430 str noun = fmt ("%1%2", typeName (objType), plural (count));
430 431
431 // Plural of "vertex" is "vertices", correct that 432 // Plural of "vertex" is "vertices", correct that
432
433 if (objType == LDObject::Vertex && count != 1) 433 if (objType == LDObject::Vertex && count != 1)
434 noun = "vertices"; 434 noun = "vertices";
435 435
436 text += fmt ("%1 %2", count, noun); 436 text += fmt ("%1 %2", count, noun);
437 firstDetails = false; 437 firstDetails = false;
609 } 609 }
610 610
611 // ============================================================================= 611 // =============================================================================
612 // ----------------------------------------------------------------------------- 612 // -----------------------------------------------------------------------------
613 LDObject* LDObject::fromID (int id) 613 LDObject* LDObject::fromID (int id)
614 { for (LDObject * obj : g_LDObjects) 614 { for (LDObject* obj : g_LDObjects)
615 if (obj->getID() == id) 615 if (obj->getID() == id)
616 return obj; 616 return obj;
617 617
618 return null; 618 return null;
619 } 619 }

mercurial