From: mzn Date: Mon, 24 Mar 2014 14:04:19 +0000 (+0000) Subject: Start using new display order from the data model. X-Git-Tag: BR_hydro_v1_0_1~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=470bdde9364bf1ddbf1c9c0435199380b9e74398;p=modules%2Fhydro.git Start using new display order from the data model. --- diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 64ef551a..d373be03 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -27,6 +27,7 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_Shape.h" #include "HYDROGUI_Operation.h" +#include "HYDROGUI_DataObject.h" #include #include @@ -161,21 +162,31 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, if( aCtx.IsNull() ) return; - // Sort objects by display order ( needed for Z layers assignment only ) - HYDROData_SequenceOfObjects anObjects; - int aMaxIndex = -1; - for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Entity) anObj = theObjs.Value( i ); - if ( anObj.IsNull() || anObj->IsRemoved() ) { - continue; - } - int aDisplayOrderIndex = module()->getObjectDisplayOrder( (size_t)aViewer, anObj ); - if ( aDisplayOrderIndex > aMaxIndex ) { - anObjects.Append( anObj ); - aMaxIndex = aDisplayOrderIndex; - } else { - anObjects.Prepend( anObj ); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( module()->getStudyId() ); + if ( !aDoc ) + return; + + // Assign Z layer indexes + aDoc->Show( theObjs ); + + // TODO: implement sorting in another way + // Sort objects by display order ( needed for Z layers assignment only ) + HYDROData_SequenceOfObjects anObjects = theObjs; + HYDROData_SequenceOfObjects anOrderedToDisplay; + HYDROData_SequenceOfObjects anAllOrdered = aDoc->GetObjectsLayerOrder(); + for ( int i = 1, n = anAllOrdered.Length(); i <= n; i++ ) { + QString anAllEntry = HYDROGUI_DataObject::dataObjectEntry( anAllOrdered.Value( i ) ); + + for ( int j = 1; j <= anObjects.Length(); j++ ) { + Handle(HYDROData_Entity) anObj = anObjects.Value( j ); + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObj ); + if ( anEntry != anAllEntry ) { + continue; + } + anObjects.Remove( j ); + anOrderedToDisplay.Prepend( anObj ); + break; } } @@ -186,9 +197,9 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, // Display int i = 1; - for ( int n = anObjects.Length(); i <= n; i++ ) + for ( int n = anOrderedToDisplay.Length(); i <= n; i++ ) { - Handle(HYDROData_Entity) anObj = anObjects.Value( i ); + Handle(HYDROData_Entity) anObj = anOrderedToDisplay.Value( i ); if ( anObj.IsNull() || anObj->IsRemoved() ) continue; diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx index 9e85de97..ed33f6d0 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx @@ -35,16 +35,25 @@ #include +/** + Constructor. + @param theParent the parent widget +*/ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) : QDialog( theParent ) { + // Dialog title setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) ); + // Main layout QVBoxLayout* aMainLayout = new QVBoxLayout( this ); aMainLayout->setMargin( 5 ); + aMainLayout->setSpacing( 5 ); + // List and buttons top, up, down, bottom QHBoxLayout* aListLayout = new QHBoxLayout(); + // list myList = new QListView( this ); myList->setSelectionMode( QAbstractItemView::ExtendedSelection ); myList->setDragEnabled( true ); @@ -61,6 +70,7 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) myList->setModel( aFilteredModel ); + // buttons top, up, down, bottom SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); myTop = new QToolButton; myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) ); @@ -74,6 +84,7 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) myBottom = new QToolButton; myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) ); myBottom->setIconSize( myTop->iconSize() ); + QVBoxLayout* aListButtonsLayout = new QVBoxLayout(); aListButtonsLayout->addWidget( myTop ); aListButtonsLayout->addWidget( myUp ); @@ -81,20 +92,25 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) aListButtonsLayout->addWidget( myBottom ); aListButtonsLayout->addStretch(); aListLayout->addWidget( myList ); + aListLayout->addLayout( aListButtonsLayout ); aMainLayout->addLayout( aListLayout ); + // "All objects" check box myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) ); aMainLayout->addWidget( myAllObjects ); + // Apply and close buttons QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout(); myApply = new QPushButton( tr("APPLY") ); myClose = new QPushButton( tr("CLOSE") ); aDlgButtonsLayout->addWidget( myApply ); aDlgButtonsLayout->addWidget( myClose ); aDlgButtonsLayout->addStretch(); + aMainLayout->addLayout( aDlgButtonsLayout ); + // Connections QSignalMapper* aSignalMapper = new QSignalMapper( this ); aSignalMapper->setMapping( myTop, HYDROGUI_ZLevelsModel::Top ); aSignalMapper->setMapping( myUp, HYDROGUI_ZLevelsModel::Up ); @@ -106,17 +122,26 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) ); - connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) ); + connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) ); + connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) ); connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) ); - OnStateChanged(); + // Initialize + onStateChanged(); } +/** + Destructor. +*/ HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg() { } +/** + Set the list of objects (which supposed to be ordered by the dialog). + @param theObjects the list of objects +*/ void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects ) { HYDROGUI_ZLevelsModel* aModel = getListSourceModel(); @@ -125,6 +150,10 @@ void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2Visibl } } +/** + Returns the ordered list of objects. + @return the list of objects +*/ QList HYDROGUI_ZLevelsDlg::getObjects() const { QList anObjects; @@ -137,6 +166,10 @@ QList HYDROGUI_ZLevelsDlg::getObjects() const return anObjects; } +/** + Slot called on top, up, down and bottom button click. + @param theType the move operation type +*/ void HYDROGUI_ZLevelsDlg::onMove( int theType ) { QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); @@ -155,7 +188,10 @@ void HYDROGUI_ZLevelsDlg::onMove( int theType ) } } -void HYDROGUI_ZLevelsDlg::OnStateChanged() +/** + Slot called on "All objects" check box state change. +*/ +void HYDROGUI_ZLevelsDlg::onStateChanged() { QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); bool isAll = myAllObjects->isChecked(); @@ -163,6 +199,10 @@ void HYDROGUI_ZLevelsDlg::OnStateChanged() aFilterModel->setFilterRegExp( anExpr ); } +/** + Returns the list source model. + @return the source model +*/ HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const { HYDROGUI_ZLevelsModel* aSourceModel = 0; diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h index e67dcc38..be41085a 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h @@ -47,9 +47,12 @@ public: void setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects ); HYDROGUI_ZLevelsModel::ObjectList getObjects() const; +signals: + void applyOrder(); + private slots: void onMove( int theType ); - void OnStateChanged(); + void onStateChanged(); private: HYDROGUI_ZLevelsModel* getListSourceModel() const; diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx index 20fb48f5..326d167d 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx @@ -29,21 +29,44 @@ const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list"; + +/** + Constructor. + @param theParent the parent object +*/ HYDROGUI_ZLevelsModel::HYDROGUI_ZLevelsModel( QObject* theParent ) : QAbstractListModel( theParent ) { - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + // Get resource manager + SUIT_ResourceMgr* aResMgr = 0; + SUIT_Session* aSession = SUIT_Session::session(); + if ( aSession ) { + aResMgr = SUIT_Session::session()->resourceMgr(); + } + // Define eye icon and empty icon myEmpty = QPixmap( 16, 16 ); myEmpty.fill( Qt::white ); - myEye = aResMgr->loadPixmap( "HYDRO", tr( "EYE_ICO" ) ); + if ( aResMgr ) { + myEye = aResMgr->loadPixmap( "HYDRO", tr( "EYE_ICO" ) ); + } else { + myEye = QPixmap( 16, 16 ); + myEye.fill( Qt::black ); + } + + // Set the supported drag actions for the items in the model setSupportedDragActions( Qt::MoveAction | Qt::CopyAction ); } +/** + Destructor. +*/ HYDROGUI_ZLevelsModel::~HYDROGUI_ZLevelsModel() { } +/** +*/ QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) const { QVariant aVariant; @@ -87,11 +110,17 @@ QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) return aVariant; } +/** +*/ int HYDROGUI_ZLevelsModel::rowCount( const QModelIndex &theParent ) const { return myObjects.count(); } +/** + Set objects list. + @param theObjects the list of pairs (object; object visibility) +*/ void HYDROGUI_ZLevelsModel::setObjects( const Object2VisibleList& theObjects ) { myObjects = theObjects; @@ -99,6 +128,10 @@ void HYDROGUI_ZLevelsModel::setObjects( const Object2VisibleList& theObjects ) reset(); } +/** + Get objects list. + @return the list of objects ordered according to the model +*/ HYDROGUI_ZLevelsModel::ObjectList HYDROGUI_ZLevelsModel::getObjects() const { ObjectList anObjects; @@ -110,6 +143,11 @@ HYDROGUI_ZLevelsModel::ObjectList HYDROGUI_ZLevelsModel::getObjects() const return anObjects; } +/** + Check if the object is visible. + @param theIndex the object index + @return true if the object is visible, false - otherwise +*/ bool HYDROGUI_ZLevelsModel::isObjectVisible( int theIndex ) const { bool isVisible = false; @@ -121,6 +159,8 @@ bool HYDROGUI_ZLevelsModel::isObjectVisible( int theIndex ) const return isVisible; } +/** +*/ QVariant HYDROGUI_ZLevelsModel::headerData( int theSection, Qt::Orientation theOrientation, int theRole ) const @@ -138,6 +178,8 @@ QVariant HYDROGUI_ZLevelsModel::headerData( int theSection, return QVariant(); } +/** +*/ Qt::ItemFlags HYDROGUI_ZLevelsModel::flags( const QModelIndex& theIndex ) const { Qt::ItemFlags aDefaultFlags = QAbstractListModel::flags( theIndex ); @@ -147,13 +189,15 @@ Qt::ItemFlags HYDROGUI_ZLevelsModel::flags( const QModelIndex& theIndex ) const return Qt::ItemIsDropEnabled | aDefaultFlags; } -QMimeData* HYDROGUI_ZLevelsModel::mimeData( const QModelIndexList& theIndices ) const +/** +*/ +QMimeData* HYDROGUI_ZLevelsModel::mimeData( const QModelIndexList& theIndexes ) const { QMimeData* aMimeData = new QMimeData(); QByteArray anEncodedData; QDataStream aStream( &anEncodedData, QIODevice::WriteOnly ); - QList anIdsList = getIds( theIndices ); + QList anIdsList = getIds( theIndexes ); foreach( int anId, anIdsList ) aStream << anId; @@ -161,6 +205,8 @@ QMimeData* HYDROGUI_ZLevelsModel::mimeData( const QModelIndexList& theIndices ) return aMimeData; } +/** +*/ QStringList HYDROGUI_ZLevelsModel::mimeTypes() const { QStringList aTypes; @@ -168,6 +214,8 @@ QStringList HYDROGUI_ZLevelsModel::mimeTypes() const return aTypes; } +/** +*/ bool HYDROGUI_ZLevelsModel::dropMimeData( const QMimeData* theData, Qt::DropAction theAction, int theRow, int theColumn, const QModelIndex& theParent ) { @@ -196,11 +244,18 @@ bool HYDROGUI_ZLevelsModel::dropMimeData( const QMimeData* theData, Qt::DropActi return true; } +/** +*/ Qt::DropActions HYDROGUI_ZLevelsModel::supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } +/** + Get list of ids by the list model indexes. + @param theIsToSort defines if the list of ids should be sorted in ascending order + @return the list of ids +*/ QList HYDROGUI_ZLevelsModel::getIds( const QModelIndexList& theIndexes, bool theIsToSort ) const { QList anIds; @@ -215,6 +270,14 @@ QList HYDROGUI_ZLevelsModel::getIds( const QModelIndexList& theIndexes, boo return anIds; } +/** + Move the item. + @param theItem the item id to move + @param theType the move operation type + @param theIsVisibleOnly indicates if do move relating to the visible objects only + @param theDropItem the drop item id ( used for drag and drop obly ) + @return true in case of success +*/ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, bool theIsVisibleOnly, const int theDropItem ) { @@ -281,6 +344,14 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, return aRes; } +/** + Move the items. + @param theItems the list of item ids to move + @param theType the move operation type + @param theIsVisibleOnly indicates if do move relating to the visible objects only + @param theDropItem the drop item id ( used for drag and drop obly ) + @return true in case of success +*/ bool HYDROGUI_ZLevelsModel::move( const QList& theItems, const OpType theType, bool theIsVisibleOnly, const int theDropItem ) { @@ -350,6 +421,12 @@ bool HYDROGUI_ZLevelsModel::move( const QList& theItems, const OpType theTy return aRes; } +/** + Check if drag and drop operation allowed. + @param theItems the list of dragged item ids + @param theDropItem the drop item id + @return true if drag and drop allowed +*/ bool HYDROGUI_ZLevelsModel::isDragAndDropAllowed( const QList& theItems, const int theDropItem ) const { diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h index e1585abd..356de24b 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h @@ -57,7 +57,7 @@ public: Qt::Orientation theOrientation, int theRole = Qt::DisplayRole ) const; virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const; - virtual QMimeData* mimeData( const QModelIndexList& theIndices ) const; + virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const; virtual QStringList mimeTypes() const; virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction, int theRow, int theColumn, const QModelIndex& theParent ); diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx index 61f318b9..085b8e98 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx @@ -35,6 +35,10 @@ #include +/** + Constructor. + @param theModule the module +*/ HYDROGUI_ZLevelsOp::HYDROGUI_ZLevelsOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ), myZLevelsDlg( NULL ) @@ -42,23 +46,29 @@ HYDROGUI_ZLevelsOp::HYDROGUI_ZLevelsOp( HYDROGUI_Module* theModule ) setName( tr( "SET_Z_LEVELS" ) ); } +/** + Destructor. +*/ HYDROGUI_ZLevelsOp::~HYDROGUI_ZLevelsOp() { } +/** +*/ void HYDROGUI_ZLevelsOp::startOperation() { HYDROGUI_Operation::startOperation(); + // Prepare the list of objects HYDROGUI_ZLevelsModel::Object2VisibleList anObject2VisibleList; - // Get the document + // get the document Handle(HYDROData_Document) aDoc = doc(); if( !aDoc.IsNull() ) { - // Get active OCC view id + // get active OCC view id size_t anActiveOCCViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); - // Get objects list + // get objects list HYDROData_SequenceOfObjects aSeqOfObjects = aDoc->GetObjectsLayerOrder( Standard_True ); HYDROData_SequenceOfObjects::Iterator anIter( aSeqOfObjects ); for ( ; anIter.More(); anIter.Next() ) { @@ -75,16 +85,36 @@ void HYDROGUI_ZLevelsOp::startOperation() myZLevelsDlg->setModal( true ); myZLevelsDlg->setObjects( anObject2VisibleList ); - //TODO: reimplement - connect( myZLevelsDlg, SIGNAL( accepted() ), this, SLOT( commit() ) ); - connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( abort() ) ); + //TODO: check + connect( myZLevelsDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) ); + connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) ); myZLevelsDlg->exec(); } +/** +*/ bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { - // TODO - return false; + bool aRes = false; + + if ( myZLevelsDlg ) { + Handle(HYDROData_Document) aDoc = doc(); + if( !aDoc.IsNull() ) { + HYDROGUI_ZLevelsModel::ObjectList anObjects = myZLevelsDlg->getObjects(); + HYDROData_SequenceOfObjects anOrderedObjects; + foreach ( const Handle(HYDROData_Entity) anObject, anObjects ) { + anOrderedObjects.Append( anObject ); + } + + aDoc->SetObjectsLayerOrder( anOrderedObjects ); + + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + aRes = true; + } + } + + return aRes; } +