-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015 EDF-R&D
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "HYDROGUI_PriorityTableModel.h"
+#include <HYDROData_LandCover.h>
+#include <HYDROGUI_DataObject.h>
/**
Constructor.
@param theParent the parent object
*/
HYDROGUI_PriorityTableModel::HYDROGUI_PriorityTableModel( QObject* theParent )
- : QAbstractTableModel( theParent )
+ : QAbstractTableModel( theParent ),
+ myColumnCount( 4 )
{
}
if ( aColumn == 0 || aColumn == 2 ) {
QStringList aNames;
HYDROData_CustomRule aRule = myRules.at( aRow );
- Handle(HYDROData_Object) aUsedObject = aColumn == 0 ? aRule.Object2 : aRule.Object1;
+ Handle(HYDROData_Entity) aUsedObject = aColumn == 0 ? aRule.Object2 : aRule.Object1;
if ( !aUsedObject.IsNull() ) {
aNames = getAvailablePairs( aUsedObject );
}
}
bool aRes = false;
-
+
if ( theRole == Qt::EditRole ) {
+ bool aRuleChanged = false;
+ myPrevRules = myRules;
+
int aColumn = theIndex.column();
if ( aColumn == 0 || aColumn == 2 ) {
- Handle(HYDROData_Object) anObject;
+ Handle(HYDROData_Entity) anObject;
QString anObjName = theValue.toString();
- foreach ( const Handle(HYDROData_Object) anObj, myObjects ) {
+ foreach ( const Handle(HYDROData_Entity) anObj, myObjects ) {
if ( anObj->GetName() == anObjName ) {
anObject = anObj;
break;
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;
*/
int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) const
{
- return 4;
+ return myColumnCount;
}
/**
void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
{
beginResetModel();
+ myPrevRules = myRules;
myRules = theRules;
endResetModel();
}
aData = tr( "OBJECT2" );
break;
case 3:
- aData = tr( "BATHYMETRY" );
+ {
+ if ( getObjectsKind() != KIND_LAND_COVER )
+ aData = tr( "BATHYMETRY" );
+ }
break;
};
} else if ( theOrientation == Qt::Vertical ) {
}
/**
- Set objects which could be used for rules.
- @param theObjects the list of objects
+ Set objects which could be used for rules definition.
+ @param theObjects the ordered list of objects
*/
-void HYDROGUI_PriorityTableModel::setObjects( const QList<Handle(HYDROData_Object)>& theObjects )
+void HYDROGUI_PriorityTableModel::setObjects( const QList<Handle(HYDROData_Entity)>& theObjects )
{
myObjects = theObjects;
+
+ myPrevRules = myRules;
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
- QList<QPair<int, int>> aRules;
+ 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 );
}
}
- // Try to find new pair of objects
- Handle(HYDROData_Object) anObject1, anObject2;
+ // Try to find:
+ // 1. the new pair of objects
+ // 2. the priority type corresponding to the objects order
+ Handle(HYDROData_Entity) anObject1, anObject2;
+ HYDROData_PriorityType aPriorityType = GREATER;
int aNbObjects = myObjects.count();
for ( int anIndex1 = 0; anIndex1 < aNbObjects; anIndex1++ ) {
if ( !aRules.contains( QPair<int, int>( anIndex1, anIndex2 ) ) ) {
anObject1 = myObjects.at( anIndex1 );
anObject2 = myObjects.at( anIndex2 );
+ if ( anIndex1 > anIndex2 ) {
+ aPriorityType = LESS;
+ }
isFound = true;
break;
}
HYDROData_CustomRule aNewRule;
aNewRule.Object1 = anObject1;
aNewRule.Object2 = anObject2;
- aNewRule.Priority = LESS;
+ 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
@param theObject the object
@return the list of object names
*/
-QStringList HYDROGUI_PriorityTableModel::getAvailablePairs( const Handle(HYDROData_Object)& theObject ) const
+QStringList HYDROGUI_PriorityTableModel::getAvailablePairs( const Handle(HYDROData_Entity)& theObject ) const
{
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;
Check if the given pair of objects is already used.
@return true if the pair is used
*/
-bool HYDROGUI_PriorityTableModel::isUsed( const Handle(HYDROData_Object)& theObj1,
- const Handle(HYDROData_Object)& theObj2 ) const
+bool HYDROGUI_PriorityTableModel::isUsed( const Handle(HYDROData_Entity)& theObj1,
+ const Handle(HYDROData_Entity)& theObj2 ) const
{
bool isUsed = false;
}
return isUsed;
-}
\ No newline at end of file
+}
+
+/**
+ Get available object names.
+ @return the list of object names
+ */
+QStringList HYDROGUI_PriorityTableModel::getAvailableObjectNames() const
+{
+ QStringList aNames;
+
+ foreach ( const Handle(HYDROData_Entity) anObj, myObjects ) {
+ if ( !anObj.IsNull() ) {
+ aNames << anObj->GetName();
+ }
+ }
+
+ return aNames;
+}
+
+/**
+ Set number of columns in the table.
+ @param theColumnCount the number of columns
+ */
+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.
+ @return the type of objects
+ */
+const ObjectKind HYDROGUI_PriorityTableModel::getObjectsKind() const
+{
+ if ( myObjects.isEmpty() )
+ return KIND_UNKNOWN;
+
+ return myObjects.at( 0 )->GetKind();
+}