-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, 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
void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, const int custom_id )
{
bool found = false;
+ beginResetModel();
for ( int i=0, n=myColumns.size(); i<n && !found; i++ ) {
if ( name == myColumns[i].myName ) {
myColumns[i].myIds.insert( group_id, custom_id );
int n = myColumns.size();
myColumns.resize( n+1 );
myColumns[n] = inf;
- reset();
+ endResetModel();
}
}
void SUIT_TreeModel::unregisterColumn( const int group_id, const QString& name )
{
for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ beginResetModel();
if ( myColumns[i].myName == name ) {
myColumns[i].myIds.remove( group_id );
if ( myColumns[i].myIds.isEmpty() ) {
- myColumns.remove( i );
- reset();
+ myColumns.remove( i );
+ endResetModel();
}
break;
}
*/
Qtx::HeaderViewFlags SUIT_TreeModel::headerFlags( const QString& name ) const
{
- Qtx::HeaderViewFlags flags;
+ Qtx::HeaderViewFlags flags = Qtx::ShowNone;
for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
if ( myColumns[i].myName == name ) {
flags = myColumns[i].myHeaderFlags;
*/
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 );
}
/*!
{
if ( root() == r )
return;
+ beginResetModel();
if ( autoDeleteTree() ) {
SUIT_DataObject::disconnect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject* ) ),
myRoot = r;
//initialize();
- reset();
+ endResetModel();
emit modelUpdated();
}
}
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:
}
bool SUIT_TreeModel::dropMimeData( const QMimeData* data, Qt::DropAction action,
- int row, int column, const QModelIndex& parent )
+ int row, int /*column*/, const QModelIndex& parent )
{
if ( action == Qt::IgnoreAction )
// do nothing with data
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 );
}
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 );
}
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 );
}
QSize SUIT_ItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QSize size = QItemDelegate::sizeHint ( option, index );
-#if QT_VERSION >= 0x040500
size.setHeight( size.height() + 1 );
-#endif
return size;
}