From 6ec169685b405459c4e3a878b2d9f0abff95562f Mon Sep 17 00:00:00 2001 From: mzn Date: Wed, 5 Nov 2014 13:39:14 +0000 Subject: [PATCH] Bug #488: all rules are cleared after change order of Included objects. --- src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx | 38 ++++++++++++++------ src/HYDROGUI/HYDROGUI_PriorityTableModel.h | 1 + 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx index 22ae6a91..6d737e3a 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx @@ -236,15 +236,16 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection, void HYDROGUI_PriorityTableModel::setObjects( const QList& theObjects ) { myObjects = theObjects; - + beginResetModel(); // Remove rules which use objects which are no longer available + QStringList aNames = getAvailableObjectNames(); QMutableListIterator 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(); } } @@ -261,12 +262,13 @@ bool HYDROGUI_PriorityTableModel::createNewRule() if ( !canCreateNewRule() ) { return false; } - + // Existing pairs of object indexes + QStringList aNames = getAvailableObjectNames(); QList< QPair > 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( anIndex1, anIndex2 ); aRules << QPair( anIndex2, anIndex1 ); @@ -378,10 +380,9 @@ QStringList HYDROGUI_PriorityTableModel::getAvailablePairs( const Handle(HYDROD { 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; @@ -465,4 +466,21 @@ bool HYDROGUI_PriorityTableModel::isUsed( const Handle(HYDROData_Object)& theObj } 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 diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.h b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h index 666d72c5..f69190c1 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityTableModel.h +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h @@ -75,6 +75,7 @@ protected: const Handle(HYDROData_Object)& theObj2 ) const; QStringList getAvailablePairs( const Handle(HYDROData_Object)& theObject ) const; + QStringList getAvailableObjectNames() const; QString priorityToString( const int thePriority ) const; QString mergeTypeToString( const int theMergeType ) const; -- 2.39.2