#include "HYDROGUI_PriorityTableModel.h"
-#include <HYDROData_LandCover.h>
+#include <HYDROGUI_DataObject.h>
/**
Constructor.
}
bool aRes = false;
-
+
if ( theRole == Qt::EditRole ) {
+ bool aRuleChanged = false;
+ myPrevRules = myRules;
+
int aColumn = theIndex.column();
if ( aColumn == 0 || aColumn == 2 ) {
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;
}
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;
void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
{
beginResetModel();
+ myPrevRules = myRules;
myRules = theRules;
endResetModel();
}
break;
case 3:
{
- if ( getObjectsKind() != KIND_LAND_COVER )
+ if ( getObjectsKind() != KIND_LAND_COVER_MAP )
aData = tr( "BATHYMETRY" );
}
break;
{
myObjects = theObjects;
+ myPrevRules = myRules;
+
beginResetModel();
// Remove rules which use objects which are no longer available
aNewRule.Priority = aPriorityType;
aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
+ myPrevRules = myRules;
+
beginResetModel();
myRules << aNewRule;
endResetModel();
aLastRow = myRules.count() - 1;
}
+ myPrevRules = myRules;
+
beginRemoveRows( theParent, theRow, aLastRow );
// Remove the corresponding rules
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.