Salome HOME
Upgrade to paraview 5.4
[modules/gui.git] / src / SUIT / SUIT_TreeModel.cxx
index a612095f58a8be62962174fb4e752c0d8f828b2b..dd02eb49725c1ade025831f152d7e44088c4acb3 100755 (executable)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // 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
@@ -500,6 +500,9 @@ SUIT_TreeModel::~SUIT_TreeModel()
 void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, const int custom_id )
 {
   bool found = false;
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+  beginResetModel();
+#endif
   for ( int i=0, n=myColumns.size(); i<n && !found; i++ ) {
     if ( name == myColumns[i].myName ) {
       myColumns[i].myIds.insert( group_id, custom_id );
@@ -515,7 +518,11 @@ void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, co
     int n = myColumns.size();
     myColumns.resize( n+1 );
     myColumns[n] = inf;
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+    endResetModel();
+#else
     reset();
+#endif
   }
 }
 
@@ -533,11 +540,18 @@ void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, co
 void SUIT_TreeModel::unregisterColumn( const int group_id, const QString& name )
 {
   for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+    beginResetModel();
+#endif
     if ( myColumns[i].myName == name ) {
       myColumns[i].myIds.remove( group_id );
       if ( myColumns[i].myIds.isEmpty() ) {
-       myColumns.remove( i );
-       reset();
+        myColumns.remove( i );
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+        endResetModel();
+#else
+        reset();
+#endif
       }
       break;
     }
@@ -711,34 +725,8 @@ void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState
 */
 void SUIT_TreeModel::setVisibilityStateForAll( Qtx::VisibilityState state )
 {
-  if ( state != Qtx::UnpresentableState ) {
-    VisibilityMap::ConstIterator it = myVisibilityMap.begin();
-    while ( it != myVisibilityMap.end() ) {
-      if ( it.value() != state )
-       setVisibilityState( it.key(), state );
-      it++;
-    }
-  }
-  else {
-    QList<QString> anIds = myVisibilityMap.keys();
-    myVisibilityMap.clear();
-    QList<QString>::ConstIterator it = anIds.begin();
-    while ( it != anIds.end() ) {
-      QModelIndexList lst;
-      if ( searcher() ) {
-       SUIT_DataObject* o = searcher()->findObject( *it );
-       if ( o ) lst << index( o );
-      }
-      else {
-       lst = match( index( 0, root()->customData( Qtx::IdType ).toInt() ), DisplayRole, (*it), 1, Qt::MatchExactly | Qt::MatchRecursive );
-      }
-      if ( !lst.isEmpty() ) {
-       QModelIndex idx = index( lst.first().row(), SUIT_DataObject::VisibilityId ,lst.first().parent() );
-       emit dataChanged( idx, idx );
-      }
-      it++;
-    }
-  }
+  foreach( QString id, myVisibilityMap.keys() )
+    setVisibilityState( id, state );
 }
 
 /*!
@@ -773,6 +761,10 @@ void SUIT_TreeModel::setRoot( SUIT_DataObject* r )
   if ( root() == r )
     return;
 
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+  beginResetModel();
+#endif
+
   if ( autoDeleteTree() ) {
     SUIT_DataObject::disconnect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject* ) ),
                                  this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
@@ -792,7 +784,11 @@ void SUIT_TreeModel::setRoot( SUIT_DataObject* r )
   myRoot = r;
 
   //initialize();
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+  endResetModel();
+#else
   reset();
+#endif
   emit modelUpdated();
 }
 
@@ -967,12 +963,15 @@ bool SUIT_TreeModel::setData( const QModelIndex& index,
         }
         break;
       case EditRole: {
-       QString val = value.toString();
+           QString val = value.toString();
+           bool mod = obj->name() != val;
         if ( !val.isEmpty() && obj->setName(val) ) {
           emit( dataChanged( index, index ) );
-         return true;
-       }
-       return false;
+          if (mod)
+            emit ( renamed(obj) );
+          return true;
+        }
+        return false;
         break;
       }
       default:
@@ -1627,7 +1626,7 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item, bool emitLayout
         fromIndexes.append( index( obj, i ));
         toIndexes.append(QModelIndex());
     }
-    changePersistentIndexList(fromIndexes, toIndexes); // Limitation: can lead to loss of selection
+    //changePersistentIndexList(fromIndexes, toIndexes); // Limitation: can lead to loss of selection
 
     emit dataChanged( toIndexes.first(), toIndexes.last() );
     obj->setModified(false);
@@ -1813,6 +1812,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( QObject* parent )
   connect( model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL(clicked( SUIT_DataObject*, int ) ) );
   connect( model, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
            this,  SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+  connect( model, SIGNAL( renamed( SUIT_DataObject* ) ), this, SIGNAL( renamed( SUIT_DataObject* ) ) );
   setSourceModel( model );
   setDynamicSortFilter( true );
 }
@@ -1831,6 +1831,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_DataObject* root, QObject* parent )
   connect( model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL( clicked( SUIT_DataObject*, int ) ) );
   connect( model, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
            this,  SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+  connect( model, SIGNAL( renamed( SUIT_DataObject* ) ), this, SIGNAL( renamed( SUIT_DataObject* ) ) );
   setSourceModel( model );
   setDynamicSortFilter( true );
 }
@@ -1848,6 +1849,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_AbstractModel* model, QObject* parent )
   connect( *model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL( clicked( SUIT_DataObject*, int ) ) );
   connect( *model, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
            this,   SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+  connect( *model, SIGNAL( renamed( SUIT_DataObject* ) ), this, SIGNAL( rename( SUIT_DataObject* ) ) );
   setSourceModel( *model );
   setDynamicSortFilter( true );
 }