Salome HOME
Merge remote-tracking branch 'remotes/origin/BR_2017' into BR_2017_PORTING
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PriorityTableModel.cxx
index 6e2e46cd14efa289ff6f55974fd52cf78f5d89bd..0b008616eb8ae6a49aee0c150043d076ce3f742e 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "HYDROGUI_PriorityTableModel.h"
 
-#include <HYDROData_LandCover.h>
+#include <HYDROGUI_DataObject.h>
 
 /**
   Constructor.
@@ -119,8 +119,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 +138,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 +155,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::MergeAltitudesType)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 +199,7 @@ int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) con
 void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
 {
   beginResetModel();
+  myPrevRules = myRules;
   myRules = theRules;
   endResetModel();
 }
@@ -218,7 +239,7 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection,
       break;
     case 3:
       {
-        if ( getObjectsKind() != KIND_LAND_COVER )
+        if ( getObjectsKind() != KIND_LAND_COVER_MAP )
           aData = tr( "BATHYMETRY" );
       }
       break;
@@ -238,6 +259,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 +340,8 @@ bool HYDROGUI_PriorityTableModel::createNewRule()
     aNewRule.Priority = aPriorityType;
     aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
 
+    myPrevRules = myRules;
+
     beginResetModel();
     myRules << aNewRule;
     endResetModel();
@@ -351,6 +376,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 +522,16 @@ 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();
+}
+
 /**
   Get type of objects for which rules are defined assuming,
   that all objects in the list have the same type.