X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_OrderedListWidget.cxx;h=c17903a3b67f415d202c00af34d0df081614f63a;hb=d37ac478f4055b8698aa200b8878af2cb6af5e45;hp=671102d0d141b165bb680101bf3192a1b8aa2d19;hpb=f52e5973a9c5d2a9cb98d77e585eba71ac606c5b;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index 671102d0..c17903a3 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // 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 @@ -29,7 +25,7 @@ #include #include -#include +#include #include #include @@ -37,12 +33,14 @@ /** Constructor. @param theParent the parent widget + @param theIconSize the icon size for arrow buttons */ -HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent ) +HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent, int theArrowIconSize ) : QWidget( theParent ) { // Main layout QHBoxLayout* aMainLayout = new QHBoxLayout( this ); + aMainLayout->setMargin( 0 ); aMainLayout->setSpacing( 5 ); // List view @@ -64,50 +62,60 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( 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" ) ) ); - myTop->setIconSize( QSize( 32, 32 ) ); - myUp = new QToolButton; - myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) ); - myUp->setIconSize( myTop->iconSize() ); - myDown = new QToolButton; - myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) ); - myDown->setIconSize( myTop->iconSize() ); - myBottom = new QToolButton; - myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) ); - myBottom->setIconSize( myTop->iconSize() ); - - // Layout - // buttons - QVBoxLayout* aListButtonsLayout = new QVBoxLayout(); - aListButtonsLayout->addWidget( myTop ); - aListButtonsLayout->addWidget( myUp ); - aListButtonsLayout->addWidget( myDown ); - aListButtonsLayout->addWidget( myBottom ); - aListButtonsLayout->addStretch(); - // main + // Add list to the main layout aMainLayout->addWidget( myList ); - aMainLayout->addLayout( aListButtonsLayout ); - - // Connections - QSignalMapper* aSignalMapper = new QSignalMapper( this ); - aSignalMapper->setMapping( myTop, HYDROGUI_ListModel::Top ); - aSignalMapper->setMapping( myUp, HYDROGUI_ListModel::Up ); - aSignalMapper->setMapping( myDown, HYDROGUI_ListModel::Down ); - aSignalMapper->setMapping( myBottom, HYDROGUI_ListModel::Bottom ); - connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); - connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); - connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); - connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); - connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) ); + + // Buttons top, up, down, bottom + if ( theArrowIconSize > 0 ) { + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + myTop = new QPushButton( this ); + myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) ); + myTop->setIconSize( QSize( theArrowIconSize, theArrowIconSize ) ); + myTop->setToolTip( tr( "TOP_TLT" ) ); + myUp = new QPushButton( this ); + myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) ); + myUp->setIconSize( myTop->iconSize() ); + myUp->setToolTip( tr( "UP_TLT" ) ); + myDown = new QPushButton( this ); + myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) ); + myDown->setIconSize( myTop->iconSize() ); + myDown->setToolTip( tr( "DOWN_TLT" ) ); + myBottom = new QPushButton( this ); + myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) ); + myBottom->setIconSize( myTop->iconSize() ); + myBottom->setToolTip( tr( "BOTTOM_TLT" ) ); + + // Add buttons to the main layout + QVBoxLayout* aListButtonsLayout = new QVBoxLayout(); + aListButtonsLayout->addWidget( myTop ); + aListButtonsLayout->addWidget( myUp ); + aListButtonsLayout->addWidget( myDown ); + aListButtonsLayout->addWidget( myBottom ); + aListButtonsLayout->addStretch(); + + aMainLayout->addLayout( aListButtonsLayout ); + + // Buttons connections + QSignalMapper* aSignalMapper = new QSignalMapper( this ); + aSignalMapper->setMapping( myTop, HYDROGUI_ListModel::Top ); + aSignalMapper->setMapping( myUp, HYDROGUI_ListModel::Up ); + aSignalMapper->setMapping( myDown, HYDROGUI_ListModel::Down ); + aSignalMapper->setMapping( myBottom, HYDROGUI_ListModel::Bottom ); + connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); + connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); + connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); + connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) ); + connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) ); + } else { + myTop = myUp = myDown = myBottom = 0; + } connect ( myList->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this, SIGNAL( selectionChanged() ) ); // Initialize setHiddenObjectsShown( true ); + setVisibilityIconShown( true ); } /** @@ -145,6 +153,30 @@ QList HYDROGUI_OrderedListWidget::getObjects() const return anObjects; } +/** + Add the object to the end of the list. + @param theObjects the pair (object; visibility) +*/ +void HYDROGUI_OrderedListWidget::addObject( const HYDROGUI_ListModel::Object2Visible& theObject ) +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) { + aModel->addObject(theObject); + } +} + +/** + Remove the object from the list. + @param theObjectName the name of the object to remove +*/ +void HYDROGUI_OrderedListWidget::removeObjectByName( const QString& theObjectName ) +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) { + aModel->removeObjectByName(theObjectName); + } +} + /** Set whether the hidden objects are presented in the list. @param theIsToShow if true - the hidden objects will be shown in the list @@ -158,6 +190,18 @@ void HYDROGUI_OrderedListWidget::setHiddenObjectsShown( const bool theIsToShow ) aFilterModel->setFilterRegExp( anExpr ); } +/** + Set whether the visibility icon (eye icon) are presented in the list. + @param theIsToShow if true - the eye icon will be shown in the list +*/ +void HYDROGUI_OrderedListWidget::setVisibilityIconShown( const bool theIsToShow ) +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) { + aModel->setDecorationEnabled( theIsToShow ); + } +} + /** Get entries of the selected objects. @return the list of entries @@ -219,12 +263,56 @@ void HYDROGUI_OrderedListWidget::setSelectedEntries( const QStringList& theEntri } } +/** + Get names of the selected objects. + @return the list of names +*/ +QStringList HYDROGUI_OrderedListWidget::getSelectedNames() const +{ + QStringList aNames; + + QSortFilterProxyModel* aFilterModel = + dynamic_cast( myList->model() ); + if ( aFilterModel ) { + HYDROGUI_ListModel* aSourceModel = + dynamic_cast( aFilterModel->sourceModel() ); + if ( aSourceModel ) { + QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes(); + foreach ( const QModelIndex& anIndex, aSelectedIndexes ) { + QModelIndex aSourceIndex = aFilterModel->mapToSource( anIndex ); + QString anEntry = aSourceModel->data( aSourceIndex, Qt::DisplayRole ).toString(); + aNames << anEntry; + } + } + } + + return aNames; +} + +/** + Get names of all objects. + @return the list of names +*/ +QStringList HYDROGUI_OrderedListWidget::getAllNames() const +{ + QStringList aNames; + + + foreach ( const Handle(HYDROData_Entity)& anObject, getObjects() ) { + aNames << anObject->GetName(); + } + + return aNames; +} + /** Slot called on top, up, down and bottom button click. @param theType the move operation type */ void HYDROGUI_OrderedListWidget::onMove( int theType ) { + bool isMoved = false; + QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); if( aFilterModel ) { HYDROGUI_ListModel* aModel = dynamic_cast( aFilterModel->sourceModel() ); @@ -235,10 +323,15 @@ void HYDROGUI_OrderedListWidget::onMove( int theType ) aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex ); } QList aSelectedIds = aModel->getIds( aSelectedSourceIndexes ); - aModel->move( aSelectedIds, ( HYDROGUI_ListModel::OpType )theType, - !myIsHiddenObjectsShown ); + isMoved = aModel->move( aSelectedIds, ( HYDROGUI_ListModel::OpType )theType, + !myIsHiddenObjectsShown ); } } + + if ( isMoved ) + { + emit orderChanged(); + } } /** @@ -255,4 +348,29 @@ HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const } return aSourceModel; -} \ No newline at end of file +} + +/** + Enable/disable ordering (i.e. enable/disable arrow buttons and drag and drop). + @param theIsToEnable if true - ordering will bw enabled +*/ +void HYDROGUI_OrderedListWidget::setOrderingEnabled( const bool theIsToEnable ) +{ + // enable/disable arrow buttons + if ( myTop && myUp && myDown && myBottom ) { + myTop->setEnabled( theIsToEnable ); + myUp->setEnabled( theIsToEnable ); + myDown->setEnabled( theIsToEnable ); + myBottom->setEnabled( theIsToEnable ); + } + + // enable/disable drag and drop + myList->setDragEnabled( theIsToEnable ); +} + +void HYDROGUI_OrderedListWidget::undoLastMove() +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) + aModel->undoLastMove(); +}