void HYDROGUI_PriorityTableModel::setObjects( const QList<Handle(HYDROData_Object)>& theObjects )
{
myObjects = theObjects;
-
+
beginResetModel();
// Remove rules which use objects which are no longer available
+ QStringList aNames = getAvailableObjectNames();
QMutableListIterator<HYDROData_CustomRule> anIter( myRules );
while ( anIter.hasNext() ) {
HYDROData_CustomRule aRule = anIter.next();
- if ( !myObjects.contains( aRule.Object1 ) ||
- !myObjects.contains( aRule.Object2 ) ) {
+ if ( !aNames.contains( aRule.Object1->GetName() ) ||
+ !aNames.contains( aRule.Object2->GetName() ) ) {
anIter.remove();
}
}
if ( !canCreateNewRule() ) {
return false;
}
-
+
// Existing pairs of object indexes
+ QStringList aNames = getAvailableObjectNames();
QList< QPair<int, int> > aRules;
foreach( const HYDROData_CustomRule& aRule, getRules() ) {
- int anIndex1 = myObjects.indexOf( aRule.Object1 );
- int anIndex2 = myObjects.indexOf( aRule.Object2 );
+ int anIndex1 = aNames.indexOf( aRule.Object1->GetName() );
+ int anIndex2 = aNames.indexOf( aRule.Object2->GetName() );
if ( anIndex1 >= 0 && anIndex2 >= 0 ) {
aRules << QPair<int, int>( anIndex1, anIndex2 );
aRules << QPair<int, int>( anIndex2, anIndex1 );
{
QStringList aNames;
- foreach ( const Handle(HYDROData_Object) anObj, myObjects ) {
- if ( !anObj.IsNull() && anObj->GetName() != theObject->GetName() ) {
- aNames << anObj->GetName();
- }
+ if ( !theObject.IsNull() ) {
+ aNames = getAvailableObjectNames();
+ aNames.removeAll( theObject->GetName() );
}
return aNames;
}
return isUsed;
+}
+
+/**
+ Get available object names.
+ @return the list of object names
+ */
+QStringList HYDROGUI_PriorityTableModel::getAvailableObjectNames() const
+{
+ QStringList aNames;
+
+ foreach ( const Handle(HYDROData_Object) anObj, myObjects ) {
+ if ( !anObj.IsNull() ) {
+ aNames << anObj->GetName();
+ }
+ }
+
+ return aNames;
}
\ No newline at end of file