src/ldObject.cc

changeset 949
a9ba8ffd9534
parent 946
9cbd658b63f9
equal deleted inserted replaced
948:3a91828475fd 949:a9ba8ffd9534
45 // LDObject constructors 45 // LDObject constructors
46 // 46 //
47 LDObject::LDObject (LDDocument* document) : 47 LDObject::LDObject (LDDocument* document) :
48 m_isHidden (false), 48 m_isHidden (false),
49 m_isSelected (false), 49 m_isSelected (false),
50 m_document (nullptr),
50 qObjListEntry (null) 51 qObjListEntry (null)
51 { 52 {
52 if (document) 53 if (document)
53 document->addObject (this); 54 document->addObject (this);
54 55
78 LDObject::~LDObject() 79 LDObject::~LDObject()
79 { 80 {
80 // Don't bother during program termination 81 // Don't bother during program termination
81 if (IsExiting() == false) 82 if (IsExiting() == false)
82 { 83 {
83 // If this object was selected, unselect it now 84 deselect();
84 if (isSelected() and document() != null)
85 deselect();
86 85
87 // If this object was associated to a file, remove it off it now 86 // If this object was associated to a file, remove it off it now
88 if (document() != null) 87 if (document() != null)
89 document()->forgetObject (this); 88 document()->forgetObject (this);
90 89
425 424
426 // ============================================================================= 425 // =============================================================================
427 // ----------------------------------------------------------------------------- 426 // -----------------------------------------------------------------------------
428 long LDObject::lineNumber() const 427 long LDObject::lineNumber() const
429 { 428 {
430 assert (document() != null); 429 if (document() != null)
431 430 {
432 for (int i = 0; i < document()->getObjectCount(); ++i) 431 for (int i = 0; i < document()->getObjectCount(); ++i)
433 { 432 {
434 if (document()->getObject (i) == this) 433 if (document()->getObject (i) == this)
435 return i; 434 return i;
435 }
436 } 436 }
437 437
438 return -1; 438 return -1;
439 } 439 }
440 440
860 860
861 // ============================================================================= 861 // =============================================================================
862 // 862 //
863 void LDObject::deselect() 863 void LDObject::deselect()
864 { 864 {
865 if (document() != null) 865 if (isSelected() and document() != null)
866 { 866 {
867 document()->removeFromSelection (this); 867 document()->removeFromSelection (this);
868 868
869 // If this object is inverted with INVERTNEXT, deselect the INVERTNEXT as well. 869 // If this object is inverted with INVERTNEXT, deselect the INVERTNEXT as well.
870 LDBFC* invertnext; 870 LDBFC* invertnext;

mercurial