X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_OrderedListWidget.cxx;h=b4bf9a1bc5b4ee6f2943eb7a30941261f538d3a8;hb=725562568b5fda2f805d2e761c755a98ebab7460;hp=1308378ffa1ccc2285c6abcf5ec53dfc4105d663;hpb=817365e15e087b3f6bf4db4e278599890d9378de;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index 1308378f..b4bf9a1b 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -37,12 +37,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 @@ -68,7 +70,7 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent ) SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); myTop = new QPushButton( this ); myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) ); - myTop->setIconSize( QSize( 32, 32 ) ); + myTop->setIconSize( QSize( theArrowIconSize, theArrowIconSize ) ); myTop->setToolTip( tr( "TOP_TLT" ) ); myUp = new QPushButton( this ); myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) ); @@ -112,6 +114,7 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent ) // Initialize setHiddenObjectsShown( true ); + setVisibilityIconShown( true ); } /** @@ -149,6 +152,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 @@ -162,6 +189,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 @@ -223,6 +262,48 @@ 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 @@ -259,4 +340,20 @@ HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const } return aSourceModel; +} + +/** + 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 + myTop->setEnabled( theIsToEnable ); + myUp->setEnabled( theIsToEnable ); + myDown->setEnabled( theIsToEnable ); + myBottom->setEnabled( theIsToEnable ); + + // enable/disable drag and drop + myList->setDragEnabled( theIsToEnable ); } \ No newline at end of file