File indexing completed on 2025-06-29 04:09:08
0001 /*************************************************************************** 0002 object.cpp: abstract base class for all Kst objects 0003 ------------------- 0004 begin : May 25, 2003 0005 copyright : (C) 2003 The University of Toronto 0006 email : netterfield@astro.utoronto.ca 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "object.h" 0019 0020 class ScriptInterface; 0021 0022 #include "objectstore.h" 0023 0024 namespace Kst { 0025 0026 const QString Object::staticTypeString = "Object"; 0027 0028 Object::Object() : 0029 Shared(), KstRWLock(), NamedObject(), 0030 _store(0L), _serial(0), _serialOfLastChange(0), _interface(0) 0031 { 0032 } 0033 0034 0035 Object::~Object() { 0036 } 0037 0038 0039 QString Object::type() { 0040 return staticMetaObject.className(); 0041 } 0042 0043 void Object::reset() { 0044 _serial = _serialOfLastChange = Forced; 0045 } 0046 0047 const QString& Object::typeString() const { 0048 return staticTypeString; 0049 } 0050 0051 ScriptInterface* Object::createScriptInterface() { 0052 return NULL; 0053 } 0054 0055 ScriptInterface* Object::scriptInterface() { 0056 if (!_interface) { 0057 _interface = createScriptInterface(); 0058 } 0059 return _interface; 0060 } 0061 0062 0063 // Returns count - 1 to account for "this" and the list pointer, therefore 0064 // you MUST have a reference-counted pointer to call this function 0065 int Object::getUsage() const { 0066 return _KShared_count() - 1; 0067 } 0068 0069 0070 void Object::deleteDependents() { 0071 QList<ObjectPtr> Objects = _store->objectList(); 0072 foreach (ObjectPtr object, Objects) { 0073 if (object->uses(this)) { 0074 _store->removeObject(object); 0075 } 0076 } 0077 } 0078 0079 0080 bool Object::uses(ObjectPtr p) const { 0081 Q_UNUSED(p) 0082 0083 return false; 0084 } 0085 0086 0087 ObjectStore* Object::store() const { 0088 return _store; 0089 } 0090 0091 // decide, based on serial numbers, whether to do an update. 0092 // if all inputs are up to date, update. Otherwise, defer. 0093 Object::UpdateType Object::objectUpdate(qint64 newSerial) { 0094 Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); 0095 0096 if (newSerial == _serial) { 0097 return NoChange; 0098 } 0099 0100 if (newSerial == Forced) { // register the forced update, but don't do it now. 0101 //qDebug()<<"Forced, def"; 0102 _serial = Forced; 0103 return Deferred; 0104 } else if (minInputSerial() < newSerial) { // if an input was forced, this will be true 0105 return Deferred; 0106 } else if ((_serialOfLastChange < maxInputSerialOfLastChange()) || (_serial == Object::Forced)) { 0107 internalUpdate(); 0108 _serialOfLastChange = newSerial; 0109 _serial = newSerial; 0110 return Updated; 0111 } else { 0112 _serial = newSerial; 0113 return NoChange; 0114 } 0115 } 0116 } 0117 0118 // vim: ts=2 sw=2 et