Salome HOME
refs #568: use ordered list view with selection synchronized with object browser...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PriorityTableModel.cxx
index fe83e5d50134098d23a815138f97984f5ffd6863..6e2e46cd14efa289ff6f55974fd52cf78f5d89bd 100644 (file)
 
 #include "HYDROGUI_PriorityTableModel.h"
 
+#include <HYDROData_LandCover.h>
 
 /**
   Constructor.
   @param theParent the parent object
 */
 HYDROGUI_PriorityTableModel::HYDROGUI_PriorityTableModel( QObject* theParent )
- : QAbstractTableModel( theParent )
+ : QAbstractTableModel( theParent ),
+   myColumnCount( 4 )
 {
 }
 
@@ -83,7 +85,7 @@ QVariant HYDROGUI_PriorityTableModel::data( const QModelIndex &theIndex, int the
     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 );
       }
@@ -122,9 +124,9 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
     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;
@@ -167,7 +169,7 @@ int HYDROGUI_PriorityTableModel::rowCount( const QModelIndex &theParent ) const
  */
 int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) const
 {
-  return 4;
+  return myColumnCount;
 }
 
 /**
@@ -215,7 +217,10 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection,
       aData = tr( "OBJECT2" );
       break;
     case 3:
-      aData = tr( "BATHYMETRY" );
+      {
+        if ( getObjectsKind() != KIND_LAND_COVER )
+          aData = tr( "BATHYMETRY" );
+      }
       break;
     };
   } else if ( theOrientation == Qt::Vertical ) {
@@ -229,7 +234,7 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection,
   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;
     
@@ -274,7 +279,7 @@ bool HYDROGUI_PriorityTableModel::createNewRule()
   // Try to find:
   // 1. the new pair of objects 
   // 2. the priority type corresponding to the objects order
-  Handle(HYDROData_Object) anObject1, anObject2;
+  Handle(HYDROData_Entity) anObject1, anObject2;
   HYDROData_PriorityType aPriorityType = GREATER;
 
   int aNbObjects = myObjects.count();
@@ -372,7 +377,7 @@ bool HYDROGUI_PriorityTableModel::removeAll()
  @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;
 
@@ -446,8 +451,8 @@ QString HYDROGUI_PriorityTableModel::mergeTypeToString( const int theMergeType )
   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;
 
@@ -472,11 +477,33 @@ QStringList HYDROGUI_PriorityTableModel::getAvailableObjectNames() const
 {
   QStringList aNames;
 
-  foreach ( const Handle(HYDROData_Object) anObj, myObjects ) {
+  foreach ( const Handle(HYDROData_Entity) anObj, myObjects ) {
     if ( !anObj.IsNull() ) {
       aNames << anObj->GetName();
     }
   }
 
   return aNames;
-}
\ No newline at end of file
+}
+
+/**
+  Set number of columns in the table.
+  @param theColumnCount the number of columns
+ */
+void HYDROGUI_PriorityTableModel::setColumnCount( int theColumnCount )
+{
+  myColumnCount = theColumnCount;
+}
+
+/**
+  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();
+}