#include "HYDROGUI_Tool.h"
#include "HYDROGUI_Shape.h"
#include "HYDROGUI_Operation.h"
+#include "HYDROGUI_DataObject.h"
#include <AIS_InteractiveContext.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
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;
}
}
// 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;
#include <QSortFilterProxyModel>
+/**
+ 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 );
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" ) ) );
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 );
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 );
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();
}
}
+/**
+ Returns the ordered list of objects.
+ @return the list of objects
+*/
QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
{
QList<Handle(HYDROData_Entity)> anObjects;
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<QSortFilterProxyModel*>( myList->model() );
}
}
-void HYDROGUI_ZLevelsDlg::OnStateChanged()
+/**
+ Slot called on "All objects" check box state change.
+*/
+void HYDROGUI_ZLevelsDlg::onStateChanged()
{
QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
bool isAll = myAllObjects->isChecked();
aFilterModel->setFilterRegExp( anExpr );
}
+/**
+ Returns the list source model.
+ @return the source model
+*/
HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const
{
HYDROGUI_ZLevelsModel* aSourceModel = 0;
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;
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;
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;
reset();
}
+/**
+ Get objects list.
+ @return the list of objects ordered according to the model
+*/
HYDROGUI_ZLevelsModel::ObjectList HYDROGUI_ZLevelsModel::getObjects() const
{
ObjectList anObjects;
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;
return isVisible;
}
+/**
+*/
QVariant HYDROGUI_ZLevelsModel::headerData( int theSection,
Qt::Orientation theOrientation,
int theRole ) const
return QVariant();
}
+/**
+*/
Qt::ItemFlags HYDROGUI_ZLevelsModel::flags( const QModelIndex& theIndex ) const
{
Qt::ItemFlags aDefaultFlags = QAbstractListModel::flags( theIndex );
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<int> anIdsList = getIds( theIndices );
+ QList<int> anIdsList = getIds( theIndexes );
foreach( int anId, anIdsList )
aStream << anId;
return aMimeData;
}
+/**
+*/
QStringList HYDROGUI_ZLevelsModel::mimeTypes() const
{
QStringList aTypes;
return aTypes;
}
+/**
+*/
bool HYDROGUI_ZLevelsModel::dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
int theRow, int theColumn, const QModelIndex& theParent )
{
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<int> HYDROGUI_ZLevelsModel::getIds( const QModelIndexList& theIndexes, bool theIsToSort ) const
{
QList<int> anIds;
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 )
{
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<int>& theItems, const OpType theType,
bool theIsVisibleOnly, const int theDropItem )
{
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<int>& theItems,
const int theDropItem ) const
{
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 );
#include <SUIT_Desktop.h>
+/**
+ Constructor.
+ @param theModule the module
+*/
HYDROGUI_ZLevelsOp::HYDROGUI_ZLevelsOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule ),
myZLevelsDlg( NULL )
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() ) {
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;
}
+