From: mzn Date: Wed, 24 Jun 2015 15:48:12 +0000 (+0300) Subject: refs #509: Create stream - no synchronization between object browser and input panel X-Git-Tag: v1.4.2~38 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0a7eda57debce16a9abb594be8f564024d7a4f2a;p=modules%2Fhydro.git refs #509: Create stream - no synchronization between object browser and input panel --- diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index 1b551cfc..c17903a3 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -62,48 +62,53 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent, int myList->setModel( aFilteredModel ); - // Buttons top, up, down, bottom - 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" ) ); - - // 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() ) ); @@ -352,10 +357,12 @@ HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const void HYDROGUI_OrderedListWidget::setOrderingEnabled( const bool theIsToEnable ) { // enable/disable arrow buttons - myTop->setEnabled( theIsToEnable ); - myUp->setEnabled( theIsToEnable ); - myDown->setEnabled( theIsToEnable ); - myBottom->setEnabled( theIsToEnable ); + 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 ); diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx index 8b4f7050..95f0750b 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx @@ -18,8 +18,16 @@ #include "HYDROGUI_StreamDlg.h" +#include "HYDROGUI_ListSelector.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_OrderedListWidget.h" #include "HYDROGUI_Tool.h" +#include + +#include +#include + #include #include #include @@ -51,12 +59,12 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) ); anAxisLayout->addWidget( myAxes ); - myProfiles = new QListWidget( aParamGroup ); - myProfiles->setSelectionMode( QListWidget::ExtendedSelection ); - myProfiles->setEditTriggers( QListWidget::NoEditTriggers ); - myProfiles->setViewMode( QListWidget::ListMode ); - myProfiles->setSortingEnabled( false ); - + myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 ); + myProfiles->setHiddenObjectsShown(true); + myProfiles->setVisibilityIconShown(false); + myProfiles->setContentsMargins(QMargins()); + myProfiles->setOrderingEnabled( false ); + myAddButton = new QPushButton( aParamGroup ); myAddButton->setText( tr("ADD") ); myRemoveButton = new QPushButton( aParamGroup ); @@ -80,6 +88,13 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin addWidget( aParamGroup ); addStretch(); + // Create selector + if ( module() ) { + HYDROGUI_ListSelector* aListSelector = + new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() ); + aListSelector->setAutoBlock( true ); + } + // Connect signals and slots connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) ); @@ -98,7 +113,7 @@ void HYDROGUI_StreamDlg::reset() myObjectName->clear(); myAxes->clear(); - myProfiles->clear(); + myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() ); myAddButton->setEnabled( false ); myRemoveButton->setEnabled( false ); @@ -149,13 +164,18 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles ) myProfiles->setUpdatesEnabled( false ); - myProfiles->clear(); + HYDROGUI_ListModel::Object2VisibleList aProfiles; foreach ( const QString& aProfileName, theProfiles ) { - QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles ); - aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); + Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) ); + if ( !anObject.IsNull() ) { + aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) ); + } } - myRemoveButton->setEnabled( myProfiles->count() > 0 ); + myProfiles->setObjects( aProfiles ); + + myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 ); myProfiles->setUpdatesEnabled( true ); @@ -164,15 +184,7 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles ) void HYDROGUI_StreamDlg::onRemoveProfiles() { - QStringList aSelectedProfiles; - - QList aSelectedItems = myProfiles->selectedItems(); - foreach( const QListWidgetItem* anItem, aSelectedItems ) { - QString aProfileName = anItem->text(); - if ( !aProfileName.isEmpty() ) { - aSelectedProfiles << aProfileName; - } - } + QStringList aSelectedProfiles = myProfiles->getSelectedNames(); emit RemoveProfiles( aSelectedProfiles ); } diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.h b/src/HYDROGUI/HYDROGUI_StreamDlg.h index 06ffcf1f..a9679f4e 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.h +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.h @@ -21,6 +21,8 @@ #include "HYDROGUI_InputPanel.h" +class HYDROGUI_OrderedListWidget; + class QComboBox; class QGroupBox; class QLineEdit; @@ -59,10 +61,10 @@ private: QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; - QComboBox* myAxes; - QListWidget* myProfiles; - QPushButton* myRemoveButton; - QPushButton* myAddButton; + QComboBox* myAxes; + HYDROGUI_OrderedListWidget* myProfiles; + QPushButton* myRemoveButton; + QPushButton* myAddButton; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index d11ea2c3..6162acb8 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -435,20 +435,7 @@ void HYDROGUI_StreamOp::onAddProfiles() void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove ) { QStringList aToRemove = theProfilesToRemove; - - // Take the Object Browser selection into account - HYDROData_SequenceOfObjects aSelectedObjects = HYDROGUI_Tool::GetSelectedObjects( module() ); - for( int i = 1, n = aSelectedObjects.Length(); i <= n; i++ ) - { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aSelectedObjects.Value( i ) ); - if ( aProfile.IsNull() ) - continue; - - QString aProfileName = aProfile->GetName(); - aToRemove.append( aProfileName ); - } - + aToRemove.removeDuplicates(); if ( aToRemove.isEmpty() ) return;