Salome HOME
Import of shapefile - bug fixes; #refs 614
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PriorityTableModel.cxx
index c284d7927e94e306a413d6a9b216a4003569e272..684d3a53ea8e614b9194b1008931acb0db8d8cfa 100644 (file)
@@ -19,6 +19,7 @@
 #include "HYDROGUI_PriorityTableModel.h"
 
 #include <HYDROData_LandCover.h>
+#include <HYDROGUI_DataObject.h>
 
 /**
   Constructor.
@@ -119,8 +120,11 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
   }
 
   bool aRes = false;
-
+  
   if ( theRole ==  Qt::EditRole ) {
+    bool aRuleChanged = false;
+    myPrevRules = myRules;
+
     int aColumn = theIndex.column();
 
     if ( aColumn == 0 || aColumn == 2 ) {
@@ -135,9 +139,16 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
       if ( !anObject.IsNull() ) {
         HYDROData_CustomRule anEditedRule = myRules[aRow];
         
+        QString anEntryNew = HYDROGUI_DataObject::dataObjectEntry( anObject );
         if ( aColumn == 0 ) {
+          QString anEntryOld = HYDROGUI_DataObject::dataObjectEntry( anEditedRule.Object1 );
+          if ( anEntryOld != anEntryNew )
+            aRuleChanged = true;
           anEditedRule.Object1 = anObject;
         } else {
+          QString anEntryOld = HYDROGUI_DataObject::dataObjectEntry( anEditedRule.Object2 );
+          if ( anEntryOld != anEntryNew )
+            aRuleChanged = true;
           anEditedRule.Object2 = anObject;
         }
         
@@ -145,14 +156,24 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
           myRules[aRow] = anEditedRule;
           aRes = true;
         } else {
+          aRuleChanged = false;
           emit showError( tr("ALREADY_EXISTS") );
         }
       }
     } else if ( aColumn == 1 ) {
-      myRules[aRow].Priority = (HYDROData_PriorityType)theValue.toInt();
+      HYDROData_PriorityType aNewPriority = (HYDROData_PriorityType)theValue.toInt();
+      if ( myRules[aRow].Priority != aNewPriority )
+        aRuleChanged = true;
+      myRules[aRow].Priority = aNewPriority;
     } else if ( aColumn == 3 ) {
-      myRules[aRow].MergeType = (HYDROData_Zone::MergeType)theValue.toInt();;
+      HYDROData_Zone::MergeType aNewMergeType = (HYDROData_Zone::MergeType)theValue.toInt();
+      if ( myRules[aRow].MergeType != aNewMergeType )
+        aRuleChanged = true;
+      myRules[aRow].MergeType = aNewMergeType;
     }
+
+    if ( aRuleChanged )
+      emit ruleChanged();
   }
 
   return aRes;
@@ -179,6 +200,7 @@ int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) con
 void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
 {
   beginResetModel();
+  myPrevRules = myRules;
   myRules = theRules;
   endResetModel();
 }
@@ -238,6 +260,8 @@ void HYDROGUI_PriorityTableModel::setObjects( const QList<Handle(HYDROData_Entit
 {
   myObjects = theObjects;
     
+  myPrevRules = myRules;
+
   beginResetModel();
 
   // Remove rules which use objects which are no longer available
@@ -317,6 +341,8 @@ bool HYDROGUI_PriorityTableModel::createNewRule()
     aNewRule.Priority = aPriorityType;
     aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
 
+    myPrevRules = myRules;
+
     beginResetModel();
     myRules << aNewRule;
     endResetModel();
@@ -351,6 +377,8 @@ bool HYDROGUI_PriorityTableModel::removeRows ( int theRow, int theCount, const Q
     aLastRow = myRules.count() - 1;
   }
 
+  myPrevRules = myRules;
+
   beginRemoveRows( theParent, theRow, aLastRow );
 
   // Remove the corresponding rules
@@ -495,6 +523,17 @@ void HYDROGUI_PriorityTableModel::setColumnCount( int theColumnCount )
   myColumnCount = theColumnCount;
 }
 
+/**
+ Undo last change in the list of priority rules.
+ */
+void HYDROGUI_PriorityTableModel::undoLastChange()
+{
+  beginResetModel();
+  myRules = myPrevRules;
+  endResetModel();
+  reset();
+}
+
 /**
   Get type of objects for which rules are defined assuming,
   that all objects in the list have the same type.