[rkward-cvs] rkward/rkward/plugin rkcomponentproperties.cpp,1.5,1.6 rkcomponentproperties.h,1.5,1.6

Thomas Friedrichsmeier tfry at users.sourceforge.net
Wed Dec 7 16:55:51 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/plugin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7602

Modified Files:
	rkcomponentproperties.cpp rkcomponentproperties.h 
Log Message:
A few more lines of implementation

Index: rkcomponentproperties.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentproperties.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** rkcomponentproperties.cpp	30 Nov 2005 22:08:39 -0000	1.5
--- rkcomponentproperties.cpp	7 Dec 2005 16:55:48 -0000	1.6
***************
*** 555,563 ****
  ///////////////////////////////////////////////// RObjects ////////////////////////////////////////////////////////
  
! RKComponentPropertyRObjects::RKComponentPropertyRObjects (QObject *parent, bool required) {
  	RK_TRACE (PLUGIN);
  
  // no initial requirements
! 	int dims = min_length = max_length = min_num_objects = min_num_objects_if_any = max_num_objects = -1;
  }
  
--- 555,572 ----
  ///////////////////////////////////////////////// RObjects ////////////////////////////////////////////////////////
  
! #include "../rkglobals.h"
! #include "../core/robjectlist.h"
! #include "../core/rkmodificationtracker.h"
! 
! RKComponentPropertyRObjects::RKComponentPropertyRObjects (QObject *parent, bool required) : RKComponentPropertyBase (parent, required) {
  	RK_TRACE (PLUGIN);
  
  // no initial requirements
! 	dims = min_length = max_length = min_num_objects = min_num_objects_if_any = max_num_objects = -1;
! 	separator = ";";
! 
! // get notifications about changed/removed objects
! 	connect (RKGlobals::tracker (), SIGNAL (objectRemoved (RObject *)), this, SLOT (removeObjectValue (RObject *)));
! 	connect (RKGlobals::tracker (), SIGNAL (objectPropertiesChanged (RObject *)), this, SLOT (objectPropertiesChanged (RObject *)));
  }
  
***************
*** 580,589 ****
  
  	if (isObjectValid (object)) {
! 		if (!object_list->contains (object)) {
! 			object_list->append (object);
  			checkListLengthValid ();
  			emit (valueChanged (this));
  		}
  	}
  }
  
--- 589,600 ----
  
  	if (isObjectValid (object)) {
! 		if (!object_list.contains (object)) {
! 			object_list.append (object);
  			checkListLengthValid ();
  			emit (valueChanged (this));
  		}
+ 		return isValid ();
  	}
+ 	return false;
  }
  
***************
*** 591,597 ****
  	RK_TRACE (PLUGIN);
  
! 	object_list->remove (object);
! 	checkListLengthValid ();
! 	emit (valueChanged (this));
  }
  
--- 602,611 ----
  	RK_TRACE (PLUGIN);
  
! 	ObjectList::Iterator it = object_list.find (object);
! 	if (it != object_list.end ()) {
! 		object_list.erase (it);
! 		checkListLengthValid ();
! 		emit (valueChanged (this));
! 	}
  }
  
***************
*** 621,625 ****
  	RK_TRACE (PLUGIN);
  
! 	object_list->clear ();
  	return (addObjectValue (object));
  }
--- 635,639 ----
  	RK_TRACE (PLUGIN);
  
! 	object_list.clear ();
  	return (addObjectValue (object));
  }
***************
*** 631,634 ****
--- 645,660 ----
  
  	// TODO
+ /*
+ 	QValueList<RObject *> object_list;
+ 	int dims;
+ 	int min_length;
+ 	int max_length;
+ 	int min_num_objects;
+ 	int min_num_objects_if_any;
+ 	int max_num_objects;
+ 	QStringList classes;
+ 	QStringList types;
+ }; */
+ 
  }
  
***************
*** 636,640 ****
  	RK_TRACE (PLUGIN);
  
! 	return (object_list->first ());
  }
  
--- 662,666 ----
  	RK_TRACE (PLUGIN);
  
! 	return (object_list.first ());
  }
  
***************
*** 645,676 ****
  }
  
- /** reimplemented from RKComponentPropertyBase. Modifier "label" returns label. Modifier "shortname" returns short name. Modifier QString::null returns full name. If no object is set, returns an empty string */
  QString RKComponentPropertyRObjects::value (const QString &modifier) {
  	RK_TRACE (PLUGIN);
  
! //TODO!
! 	QString ret;
  	if (modifier.isEmpty ()) {
  	} else if (modifier == "shortname") {
  	} else if (modifier == "label") {
  	} else {
  		warnModifierNotRecognized (modifier);
  	}
! 	return ret;
  }
  
- /** reimplemented from RKComponentPropertyBase to convert to RObject with current constraints
- @returns 0 if no such object could be found or the object is invalid */
  bool RKComponentPropertyRObjects::setValue (const QString &value) {
  	RK_TRACE (PLUGIN);
  
  
  }
  
- /** reimplemented from RKComponentPropertyBase to test whether conversion to RObject, is possible with current constraints */
  bool RKComponentPropertyRObjects::isStringValid (const QString &value) {
  	RK_TRACE (PLUGIN);
  
  
  }
  
--- 671,730 ----
  }
  
  QString RKComponentPropertyRObjects::value (const QString &modifier) {
  	RK_TRACE (PLUGIN);
  
! 	QStringList ret;
  	if (modifier.isEmpty ()) {
+ 		for (ObjectList::const_iterator it = object_list.begin (); it != object_list.end ();++it) {
+ 			ret.append ((*it)->getFullName ());
+ 		}
  	} else if (modifier == "shortname") {
+ 		for (ObjectList::const_iterator it = object_list.begin (); it != object_list.end ();++it) {
+ 			ret.append ((*it)->getShortName ());
+ 		}
  	} else if (modifier == "label") {
+ 		for (ObjectList::const_iterator it = object_list.begin (); it != object_list.end ();++it) {
+ 			ret.append ((*it)->getLabel ());
+ 		}
  	} else {
  		warnModifierNotRecognized (modifier);
  	}
! 	return ret.join (separator);
  }
  
  bool RKComponentPropertyRObjects::setValue (const QString &value) {
  	RK_TRACE (PLUGIN);
  
+ 	object_list.clear ();
+ 
+ 	bool ok = true;
+ 	QStringList slist = QStringList::split (separator, value);
  
+ 	for (QStringList::const_iterator it = slist.begin (); it != slist.end (); ++it) {
+ 		RObject *obj = RKGlobals::rObjectList ()->findObject (value);
+ 		if (obj && isObjectValid (obj)) {
+ 			object_list.append (obj);
+ 		} else {
+ 			ok = false;
+ 		}
+ 	}
+ 
+ 	checkListLengthValid ();
+ 	return (isValid () && ok);
  }
  
  bool RKComponentPropertyRObjects::isStringValid (const QString &value) {
  	RK_TRACE (PLUGIN);
  
+ 	QStringList slist = QStringList::split (separator, value);
  
+ 	for (QStringList::const_iterator it = slist.begin (); it != slist.end (); ++it) {
+ 		RObject *obj = RKGlobals::rObjectList ()->findObject (value);
+ 		if (!(obj && isObjectValid (obj))) {
+ 			return false;
+ 		}
+ 	}
+ 
+ 	return true;
  }
  
***************
*** 679,723 ****
  	RK_TRACE (PLUGIN);
  
! 
! }
! 
! /** reimplemented from RKComponentPropertyBase to use special handling for object properties */
! void RKComponentPropertyRObjects::governorValueChanged (RKComponentPropertyBase *property) {
! 	RK_TRACE (PLUGIN);
  
  
  }
  
! /** to be connected to RKModificationTracker::objectRemoved (). This is so we get notified if the object currently selected is removed */
! void RKComponentPropertyRObjects::objectRemoved (RObject *object) {
  	RK_TRACE (PLUGIN);
  
! 
  }
  
- /** to be connected to RKModificationTracker::objectPropertiesChanged (). This is so we get notified if the object currently selected is changed */
  void RKComponentPropertyRObjects::objectPropertiesChanged (RObject *object) {
  	RK_TRACE (PLUGIN);
  
! 
  }
  
! void RKComponentPropertyRObjects::validizeAll () {
  	RK_TRACE (PLUGIN);
  
  
! }
  
! /*
! 	QValueList<RObject *> object_list;
! 	int dims;
! 	int min_length;
! 	int max_length;
! 	int min_num_objects;
! 	int min_num_objects_if_any;
! 	int max_num_objects;
! 	QStringList classes;
! 	QStringList types;
! }; */
  
  #include "rkcomponentproperties.moc"
--- 733,798 ----
  	RK_TRACE (PLUGIN);
  
! 	// TODO
! /*
! 	QValueList<RObject *> object_list;
! 	int dims;
! 	int min_length;
! 	int max_length;
! 	int min_num_objects;
! 	int min_num_objects_if_any;
! 	int max_num_objects;
! 	QStringList classes;
! 	QStringList types;
! }; */
  
  
  }
  
! void RKComponentPropertyRObjects::governorValueChanged (RKComponentPropertyBase *property) {
  	RK_TRACE (PLUGIN);
  
! 	if ((property->type () == PropertyRObjects) && governor_modifier.isEmpty ()) {
! 		object_list = static_cast <RKComponentPropertyRObjects *> (property)->objectList ();
! 		validizeAll (true);
! 		emit (valueChanged (this));
! 	} else {
! 		setValue (property->value (governor_modifier));
! 	}
  }
  
  void RKComponentPropertyRObjects::objectPropertiesChanged (RObject *object) {
  	RK_TRACE (PLUGIN);
  
! 	// if object list contains this object, check whether it is still valid. Otherwise remove it, revalidize and signal change.
! 	ObjectList::Iterator it = object_list.find (object);
! 	if (it != object_list.end ()) {
! 		if (!isObjectValid (object)) {
! 			object_list.erase (it);
! 			checkListLengthValid ();
! 			emit (valueChanged (this));
! 		}
! 	}
  }
  
! void RKComponentPropertyRObjects::validizeAll (bool silent) {
  	RK_TRACE (PLUGIN);
  
+ 	bool changes = false;
  
! 	ObjectList::Iterator it = object_list.begin ();
! 	while (it != object_list.end ()) {
! 		if (isObjectValid (*it)) {
! 			++it;
! 		} else {
! 			it = object_list.erase (it);		// it now points to the next object in the list
! 			changes = true;
! 		}
! 	}
  
! 	if (changes) {
! 		checkListLengthValid ();
! 		if (!silent) emit (valueChanged (this));
! 	}
! }
  
  #include "rkcomponentproperties.moc"

Index: rkcomponentproperties.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentproperties.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** rkcomponentproperties.h	30 Nov 2005 22:08:39 -0000	1.5
--- rkcomponentproperties.h	7 Dec 2005 16:55:48 -0000	1.6
***************
*** 218,221 ****
--- 218,223 ----
  	Q_OBJECT
  public:
+ /** for easier typing. A list of RObjects. Should probably be defined somewhere in core-dir instead. */
+ 	typedef QValueList<RObject *> ObjectList;
  /** constructor */
  	RKComponentPropertyRObjects (QObject *parent, bool required);
***************
*** 229,234 ****
  /** add an object value */
  	bool addObjectValue (RObject *object);
- /** remove an object value */
- 	void removeObjectValue (RObject *object);
  /** Set property to only accept certain classes. If you provide an empty list, all classes will be accepted*/
  	void setClassFilter (const QStringList &classes);
--- 231,234 ----
***************
*** 251,255 ****
  /** Get current list of objects. Do not modify this list! It is the very same list, the property uses internally!
  @returns an empty list if no valid object is selected */
! 	QValueList<RObject *> objectList ();
  /** set separator (used to concatenate object names/labels, etc. if more than one object is selected) */
  	void setSeparator (const QString &sep) { separator = sep; emit (valueChanged (this)); };
--- 251,255 ----
  /** Get current list of objects. Do not modify this list! It is the very same list, the property uses internally!
  @returns an empty list if no valid object is selected */
! 	ObjectList objectList ();
  /** set separator (used to concatenate object names/labels, etc. if more than one object is selected) */
  	void setSeparator (const QString &sep) { separator = sep; emit (valueChanged (this)); };
***************
*** 268,281 ****
  	void governorValueChanged (RKComponentPropertyBase *property);
  public slots:
! /** to be connected to RKModificationTracker::objectRemoved (). This is so we get notified if the object currently selected is removed */
! 	void objectRemoved (RObject *object);
  /** to be connected to RKModificationTracker::objectPropertiesChanged (). This is so we get notified if the object currently selected is changed */
  	void objectPropertiesChanged (RObject *object);
  private:
! /** check all objects currently in the list for validity. Remove invalid objects. Determine validity state depending on how many (valid) objects remain in the list. If the list was changed during validation, a valueChanged () signal is emitted */
! 	void validizeAll ();
  /** simple helper function: Check whether the number of objects currently selected (and only that!), and set the valid state accordingly */
  	void checkListLengthValid ();
! 	QValueList<RObject *> object_list;
  	int dims;
  	int min_length;
--- 268,281 ----
  	void governorValueChanged (RKComponentPropertyBase *property);
  public slots:
! /** remove an object value. to be connected to RKModificationTracker::objectRemoved (). This is so we get notified if the object currently selected is removed */
! 	void removeObjectValue (RObject *object);
  /** to be connected to RKModificationTracker::objectPropertiesChanged (). This is so we get notified if the object currently selected is changed */
  	void objectPropertiesChanged (RObject *object);
  private:
! /** check all objects currently in the list for validity. Remove invalid objects. Determine validity state depending on how many (valid) objects remain in the list. If the list was changed during validation, and silent!=false a valueChanged () signal is emitted */
! 	void validizeAll (bool silent=false);
  /** simple helper function: Check whether the number of objects currently selected (and only that!), and set the valid state accordingly */
  	void checkListLengthValid ();
! 	ObjectList object_list;
  	int dims;
  	int min_length;





More information about the rkward-tracker mailing list