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

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Dec 9 13:28:59 UTC 2005


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

Modified Files:
	rkcomponentproperties.cpp rkcomponentproperties.h 
Log Message:
A quick half-finished commit, before changing some things in RObject

Index: rkcomponentproperties.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentproperties.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** rkcomponentproperties.cpp	7 Dec 2005 16:55:48 -0000	1.6
--- rkcomponentproperties.cpp	9 Dec 2005 13:28:57 -0000	1.7
***************
*** 557,560 ****
--- 557,562 ----
  #include "../rkglobals.h"
  #include "../core/robjectlist.h"
+ #include "../core/rkvariable.h"
+ #include "../core/rcontainerobject.h"
  #include "../core/rkmodificationtracker.h"
  
***************
*** 644,660 ****
  	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;
  }; */
! 
  }
  
--- 646,705 ----
  	RK_TRACE (PLUGIN);
  
+ // TODO: this function could be made a lot more straightforward, if RObject would contain more information (via virtual functions). See TODO in RObject.
+ 
+ 	// first check dimensionality
+ 	if (dims >= 0) {
+ 		if (object->isVariable ()) {
+ 			RKVariable *var = static_cast<RKVariable *> (object);
+ 			if (var->getLength ()) {
+ 				if (dims != 1) return false;
+ 			} else {
+ 				if (dims != 0) return false;
+ 			}
+ 		} else if (object->isContainer ()) {
+ 			RContainerObject *cont = static_cast<RContainerObject *> (object);
+ 			if (cont->numDimensions () != dims) {
+ 				return false;
+ 			}
+ 		} else {
+ 			return false;
+ 		}
+ 	}
+ 	if ((min_length > 0) || (max_length >= 0)) {
+ 		// determine object length
+ 		int olength;
+ 		if (object->isVariable ()) {
+ 			olength = static_cast<RKVariable *> (object)->getLength ();
+ 		} else if (object->isContainer ()) {
+ 			if (static_cast<RContainerObject *> (object)->numDimensions ()) {
+ 				olength = static_cast<RContainerObject *> (object)->getDimension (0);
+ 			} else {
+ 				olength = 0;
+ 			}
+ 		}
+ 
+ 		// then check, whether length is valid
+ 		if ((min_length > 0) && (olength < min_length)) return false;
+ 		if ((max_length >= 0) && (olength > max_length)) return false;
+ 	}
+ 
+ 	// next, check classes
+ 	if (!classes.isEmpty ()) {
+ 		
+ 	}
+ 
+ 	// finally, check type
+ 	if (!types.isEmpty ()) {
+ 	}
+ 
  	// TODO
  /*
  	int dims;
  	int min_length;
  	int max_length;
  	QStringList classes;
  	QStringList types;
  }; */
! 	return true;
  }
  
***************
*** 729,750 ****
  }
  
- /** reimplemented from RKComponentPropertyBase to actually reconcile requirements with other object properties */
  void RKComponentPropertyRObjects::connectToGovernor (RKComponentPropertyBase *governor, const QString &modifier, bool reconcile_requirements) {
  	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;
! }; */
  
  
  }
  
--- 774,864 ----
  }
  
  void RKComponentPropertyRObjects::connectToGovernor (RKComponentPropertyBase *governor, const QString &modifier, bool reconcile_requirements) {
  	RK_TRACE (PLUGIN);
  
! 	RK_ASSERT (governor);
! 	connect (governor, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (governorValueChanged (RKComponentPropertyBase *)));
! 	governor_modifier = modifier;
! 
! 	// reconcile requirements if applicable
! 	if (reconcile_requirements && governor_modifier.isEmpty ()) {
! 		if (governor->type () == PropertyRObjects) {
! 			RKComponentPropertyRObjects *ogov = static_cast<RKComponentPropertyRObjects *> (governor); 	// convenience pointer
! 
! 			// reconcile dimensionality filter
! 			if (dims != -1) {
! 				if (ogov->dims == -1) {
! 					ogov->dims = dims;
! 				} else if (ogov->dims != dims) {
! 					RK_DO (qDebug ("Could not reconcile dimensionality in RObject properties"), PLUGIN, DL_WARNING);
! 				}
! 			}
! 			if (ogov->min_length < min_length) {
! 				ogov->min_length = min_length;
! 			}
! 			if (max_length != -1) {
! 				if (ogov->max_length > max_length) {
! 					ogov->max_length = max_length;
! 				}
! 			}
  
+ 			// reconcile number of objects filter
+ 			if (ogov->min_num_objects < min_num_objects) {
+ 				ogov->min_num_objects = min_num_objects;
+ 			}
+ 			if (ogov->min_num_objects_if_any < min_num_objects_if_any) {
+ 				ogov->min_num_objects_if_any = min_num_objects_if_any;
+ 			}
+ 			if (max_num_objects && (ogov->max_num_objects > max_num_objects)) {
+ 				ogov->max_num_objects = max_num_objects;
+ 			}
  
+ 			// reconcile class filter
+ 			if (!classes.isEmpty ()) {
+ 				if (ogov->classes.isEmpty ()) {
+ 					ogov->classes= classes;
+ 				} else {
+ 					QStringList::Iterator it = ogov->classes.begin ();
+ 					while (it != ogov->classes.end ()) {
+ 						if (classes.contains (*it)) {
+ 							++it;
+ 						} else {
+ 							ogov->classes.erase (it);		// automatically advances to the next item
+ 						}
+ 					}
+ 					if (ogov->classes.isEmpty ()) {
+ 						RK_DO (qDebug ("Incompatible class filters for RObject properties"), PLUGIN, DL_WARNING);
+ 						ogov->classes = classes;
+ 					}
+ 				}
+ 			}
+ 
+ 			// reconcile type filter
+ 			if (!types.isEmpty ()) {
+ 				if (ogov->types.isEmpty ()) {
+ 					ogov->types = types;
+ 				} else {
+ 					QStringList::Iterator it = ogov->types.begin ();
+ 					while (it != ogov->types.end ()) {
+ 						if (types.contains (*it)) {
+ 							++it;
+ 						} else {
+ 							ogov->types.erase (it);		// automatically advances to the next item
+ 						}
+ 					}
+ 					if (ogov->types.isEmpty ()) {
+ 						RK_DO (qDebug ("Incompatible type filters for RObject properties"), PLUGIN, DL_WARNING);
+ 						ogov->types = types;
+ 					}
+ 				}
+ 			}
+ 
+ 			// make governor recheck its values
+ 			ogov->validizeAll ();
+ 		}
+ 	}
+ 
+ 	// fetch current value
+ 	governorValueChanged (governor);
  }
  
***************
*** 796,798 ****
--- 910,924 ----
  }
  
+ void RKComponentPropertyRObjects::checkListLengthValid () {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	is_valid = true;	// innocent until proven guilty
+ 	if (min_num_objects || max_num_objects || min_num_objects_if_any) {
+ 		int len = object_list.count ();
+ 		if (len < min_num_objects) is_valid = false;
+ 		if (len && (len < min_num_objects_if_any)) is_valid = false;
+ 		if (max_num_objects && (len > max_num_objects)) is_valid = false;
+ 	}
+ }
+ 
  #include "rkcomponentproperties.moc"

Index: rkcomponentproperties.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentproperties.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** rkcomponentproperties.h	7 Dec 2005 16:55:48 -0000	1.6
--- rkcomponentproperties.h	9 Dec 2005 13:28:57 -0000	1.7
***************
*** 224,232 ****
  /** destructor */
  	~RKComponentPropertyRObjects ();
! /** how many objects can this property hold? Use default values (-1) to remove constraints
  @param min_num_objects Minimum number of objects for this property to be valid
  @param min_num_objects_if_any Some properties may be valid, if they hold either no objects at all, or at least a certain number of objects
  @param max_num_objects Maximum number of objects for this property to be valid */
! 	void setListLength (int min_num_objects=-1, int min_num_objects_if_any=-1, int max_num_objects=-1);
  /** add an object value */
  	bool addObjectValue (RObject *object);
--- 224,232 ----
  /** destructor */
  	~RKComponentPropertyRObjects ();
! /** how many objects can this property hold? Use default values (0) to remove constraints
  @param min_num_objects Minimum number of objects for this property to be valid
  @param min_num_objects_if_any Some properties may be valid, if they hold either no objects at all, or at least a certain number of objects
  @param max_num_objects Maximum number of objects for this property to be valid */
! 	void setListLength (int min_num_objects=0, int min_num_objects_if_any=0, int max_num_objects=0);
  /** add an object value */
  	bool addObjectValue (RObject *object);
***************
*** 285,288 ****
--- 285,289 ----
  	int max_num_objects;
  	QStringList classes;
+ /** TODO: use a list of enums instead for internal purposes! */
  	QStringList types;
  	QString separator;





More information about the rkward-tracker mailing list