#include <QApplication>
#include <QHash>
-SUIT_AbstractModel::SUIT_AbstractModel()
+SUIT_AbstractModel::SUIT_AbstractModel() : mySearcher( 0 )
{
}
return dynamic_cast<const QObject*>( this );
}
+SUIT_DataSearcher* SUIT_AbstractModel::searcher() const
+{
+ return mySearcher;
+}
-
-
+void SUIT_AbstractModel::setSearcher( SUIT_DataSearcher* s )
+{
+ mySearcher = s;
+}
/*!
void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, const int custom_id )
{
bool found = false;
- for( int i=0, n=myColumns.size(); i<n && !found; i++ )
- if( name==myColumns[i].myName )
- {
- myColumns[i].myIds.insert( group_id, custom_id );
- found = true;
- }
- if( !found )
- {
- ColumnInfo inf;
- inf.myName = name;
- inf.myIds.insert( group_id, custom_id );
- inf.myAppropriate = Qtx::Shown;
- inf.myHeaderFlags = Qtx::ShowAll;
- int n = myColumns.size();
- myColumns.resize( n+1 );
- myColumns[n] = inf;
- reset();
+ for ( int i=0, n=myColumns.size(); i<n && !found; i++ ) {
+ if ( name == myColumns[i].myName ) {
+ myColumns[i].myIds.insert( group_id, custom_id );
+ found = true;
+ }
+ }
+ if ( !found ) {
+ ColumnInfo inf;
+ inf.myName = name;
+ inf.myIds.insert( group_id, custom_id );
+ inf.myAppropriate = Qtx::Shown;
+ inf.myHeaderFlags = Qtx::ShowAll;
+ int n = myColumns.size();
+ myColumns.resize( n+1 );
+ myColumns[n] = inf;
+ reset();
}
}
*/
void SUIT_TreeModel::unregisterColumn( const int group_id, const QString& name )
{
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name )
- {
- myColumns[i].myIds.remove( group_id );
- if( myColumns[i].myIds.isEmpty() )
- {
- myColumns.remove( i );
- reset();
- }
- break;
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name ) {
+ myColumns[i].myIds.remove( group_id );
+ if ( myColumns[i].myIds.isEmpty() ) {
+ myColumns.remove( i );
+ reset();
+ }
+ break;
}
+ }
}
/*!
*/
void SUIT_TreeModel::setColumnIcon( const QString& name, const QPixmap& icon )
{
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name )
- {
- myColumns[i].myIcon = icon;
- break;
- }
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name ) {
+ myColumns[i].myIcon = icon;
+ break;
+ }
+ }
}
/*!
QPixmap SUIT_TreeModel::columnIcon( const QString& name ) const
{
QPixmap res;
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name )
- {
- res = myColumns[i].myIcon;
- break;
- }
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name ) {
+ res = myColumns[i].myIcon;
+ break;
+ }
+ }
return res;
}
*/
void SUIT_TreeModel::setAppropriate( const QString& name, const Qtx::Appropriate appr )
{
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name && myColumns[i].myAppropriate != appr )
- {
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name && myColumns[i].myAppropriate != appr ) {
myColumns[i].myAppropriate = appr;
emit headerDataChanged( Qt::Horizontal, i, i );
break;
}
+ }
}
/*!
Qtx::Appropriate SUIT_TreeModel::appropriate( const QString& name ) const
{
Qtx::Appropriate appr = Qtx::Shown;
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name )
- {
- appr = myColumns[i].myAppropriate;
- break;
- }
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name ) {
+ appr = myColumns[i].myAppropriate;
+ break;
+ }
+ }
return appr;
}
\param flags - header flags
*/
-void SUIT_TreeModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) {
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name && myColumns[i].myHeaderFlags != flags )
- {
+void SUIT_TreeModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags )
+{
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name && myColumns[i].myHeaderFlags != flags ) {
myColumns[i].myHeaderFlags = flags;
emit headerDataChanged( Qt::Horizontal, i, i );
break;
}
+ }
}
/*!
\param name - column name
\return header flags
*/
-Qtx::HeaderViewFlags SUIT_TreeModel::headerFlags( const QString& name ) const {
+Qtx::HeaderViewFlags SUIT_TreeModel::headerFlags( const QString& name ) const
+{
Qtx::HeaderViewFlags flags;
- for( int i=0, n=myColumns.size(); i<n; i++ )
- if( myColumns[i].myName==name )
- {
- flags = myColumns[i].myHeaderFlags;
- break;
- }
+ for ( int i = 0, n = myColumns.size(); i < n; i++ ) {
+ if ( myColumns[i].myName == name ) {
+ flags = myColumns[i].myHeaderFlags;
+ break;
+ }
+ }
return flags;
}
\param id - column name
\param state - visible state
*/
-void SUIT_TreeModel::setVisibilityState(const QString& id, Qtx::VisibilityState state) {
- if(myVisibilityMap.contains(id) && myVisibilityMap.value(id) == state)
+void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState state )
+{
+ VisibilityMap::const_iterator it = myVisibilityMap.find( id );
+ if ( it != myVisibilityMap.end() && it.value() == state )
return;
bool needSignal = false;
- if(state != Qtx::UnpresentableState) {
- myVisibilityMap.insert(id, state);
+ if ( state != Qtx::UnpresentableState ) {
+ myVisibilityMap.insert( id, state );
needSignal = true;
}
else {
- int nb = myVisibilityMap.remove(id);
- if(nb > 0)
- needSignal = true;
+ needSignal = myVisibilityMap.remove( id ) > 0;
}
- if(needSignal) {
- QModelIndexList lst = match(index(0,root()->customData(Qtx::IdType).toInt()), DisplayRole, id, 1, Qt::MatchExactly | Qt::MatchRecursive);
- if(!lst.isEmpty()) {
- QModelIndex idx = index(lst[0].row(), SUIT_DataObject::VisibilityId ,lst[0].parent());
- emit dataChanged(idx,idx);
+ if ( needSignal ) {
+ QModelIndexList lst;
+ if ( searcher() ) {
+ SUIT_DataObject* o = searcher()->findObject( id );
+ if ( o ) lst << index( o );
+ }
+ else {
+ lst = match( index( 0, root()->customData( Qtx::IdType ).toInt() ), DisplayRole, id, 1, Qt::MatchExactly | Qt::MatchRecursive );
+ }
+ if ( !lst.isEmpty() ) {
+ QModelIndex idx = index( lst.first().row(), SUIT_DataObject::VisibilityId, lst.first().parent() );
+ emit dataChanged( idx, idx );
}
}
}
\param id - column name
\param state - visible state
*/
-void SUIT_TreeModel::setVisibilityStateForAll(Qtx::VisibilityState state) {
- if(state != Qtx::UnpresentableState) {
+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);
+ while ( it != myVisibilityMap.end() ) {
+ if ( it.value() != state )
+ setVisibilityState( it.key(), state );
it++;
}
- } else {
+ }
+ else {
QList<QString> anIds = myVisibilityMap.keys();
myVisibilityMap.clear();
QList<QString>::ConstIterator it = anIds.begin();
- while(it != anIds.end()){
- QModelIndexList lst = match(index(0,root()->customData(Qtx::IdType).toInt()), DisplayRole, (*it), 1, Qt::MatchExactly | Qt::MatchRecursive);
- if(!lst.isEmpty()) {
- QModelIndex idx = index(lst[0].row(), SUIT_DataObject::VisibilityId ,lst[0].parent());
- emit dataChanged(idx,idx);
+ 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++;
}
\param id - column name
\return visible state
*/
-Qtx::VisibilityState SUIT_TreeModel::visibilityState(const QString& id) const {
- if(myVisibilityMap.contains(id))
- return myVisibilityMap.value(id);
- else
- return Qtx::UnpresentableState;
+Qtx::VisibilityState SUIT_TreeModel::visibilityState( const QString& id ) const
+{
+ VisibilityMap::const_iterator it = myVisibilityMap.find( id );
+ return it != myVisibilityMap.end() ? it.value() : Qtx::UnpresentableState;
}
/*!
return mySortingEnabled;
}
+SUIT_DataSearcher* SUIT_ProxyModel::searcher() const
+{
+ return treeModel() ? treeModel()->searcher() : 0;
+}
+
+void SUIT_ProxyModel::setSearcher( SUIT_DataSearcher* s )
+{
+ if ( treeModel() ) treeModel()->setSearcher( s );
+}
+
/*!
\brief Get item delegate for the model.
\return new item delegate
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Exception)
-using namespace std;
+//#define NOTIFY_BY_EVENT
class ObserverEvent : public QEvent
{
fillEntryMap();
}
+ SUIT_DataObject* findObject( const char* theID ) const
+ {
+ EntryMap::const_iterator it = entry2SuitObject.find( theID );
+ return it != entry2SuitObject.end() ? it->second : 0;
+ }
+
virtual void notifyObserverID(const char* theID, CORBA::Long event)
{
+#ifdef NOTIFY_BY_EVENT
QCoreApplication::postEvent(this,new ObserverEvent(theID,event));
+#else
+ notifyObserverID_real(theID,event);
+#endif
}
virtual bool event(QEvent *event)
{
if (event->type() == QEvent::User )
- {
- //START_TIMING(notify);
- notifyObserverID_real(static_cast<ObserverEvent *>(event)->_anID.c_str(),static_cast<ObserverEvent *>(event)->_event);
- //END_TIMING(notify,100);
- }
+ {
+ //START_TIMING(notify);
+ notifyObserverID_real(static_cast<ObserverEvent *>(event)->_anID.c_str(),static_cast<ObserverEvent *>(event)->_event);
+ //END_TIMING(notify,100);
+ }
return true;
}
- void notifyObserverID_real(const char* theID, CORBA::Long event)
+ void notifyObserverID_real(const std::string& theID, long event)
{
SalomeApp_DataObject* suit_obj;
return;
}
_PTR(SObject) obj = myStudyDS->FindObjectID( theID );
- std::string entry_str = theID;
- int last2Pnt_pos = entry_str.rfind( ":" );
- std::string parent_id = entry_str.substr( 0, last2Pnt_pos );
- int tag = atoi( entry_str.substr( last2Pnt_pos+1 ).c_str() );
+ int last2Pnt_pos = theID.rfind( ":" );
+ std::string parent_id = theID.substr( 0, last2Pnt_pos );
+ int tag = atoi( theID.substr( last2Pnt_pos+1 ).c_str() );
if ( parent_id.length() == 3 ) // "0:1" - root item?
{
// It's probably a SComponent
_PTR(SComponent) aSComp = obj->GetFatherComponent();
- if ( aSComp && !aSComp->IsNull() && aSComp->GetID() == entry_str )
+ if ( aSComp && !aSComp->IsNull() && aSComp->GetID() == theID )
suit_obj = new SalomeApp_ModuleObject( aSComp );
else
suit_obj = new SalomeApp_DataObject( obj );
std::string obj_id = parent_id.substr( 4 );
std::string anID;
- string::size_type debut = 0;
- string::size_type fin;
+ std::string::size_type debut = 0;
+ std::string::size_type fin;
SalomeApp_DataObject* anObj = dynamic_cast<SalomeApp_DataObject*>( myStudy->root() );
while ( 1 )
{
suit_obj = it->second;
/* Define visibility state */
- if( suit_obj ) {
+ bool isComponent = dynamic_cast<SalomeApp_ModuleObject*>( suit_obj ) != 0;
+ if ( suit_obj && !isComponent ) {
QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType());
- if(!moduleTitle.isEmpty()) {
+ if (!moduleTitle.isEmpty()) {
LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false);
-
- if(aDisplayer && !myStudy->isComponent(theID)) {
- if(aDisplayer->canBeDisplayed(theID)) {
- myStudy->setVisibilityState( theID, Qtx::HiddenState );
+ if(aDisplayer) {
+ if(aDisplayer->canBeDisplayed(theID.c_str())) {
+ myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState );
//MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!");
} else
MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
setIsSaved(true);
}
+LightApp_DataObject* SalomeApp_Study::findObjectByEntry( const QString& theEntry )
+{
+ LightApp_DataObject* o = dynamic_cast<LightApp_DataObject*>( myObserver ? myObserver->findObject( theEntry.toLatin1().constData() ) : 0 );
+ return o;
+}
+
/*!
Deletes all references to object
\param obj - object