1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_RecognizeContoursDlg.h"
24 #include <QListWidget>
25 #include <QVBoxLayout>
29 * \param theModule the module
30 * \param theTitle the panel title
32 HYDROGUI_RecognizeContoursDlg::HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle )
33 : HYDROGUI_InputPanel( theModule, theTitle )
36 QGroupBox* anImageGroup = new QGroupBox( tr( "ORIGINAL_IMAGE" ), mainFrame() );
37 QLabel* aNameLabel = new QLabel( tr("NAME") );
38 myImageName = new QLineEdit;
39 myImageName->setReadOnly( true );
41 QHBoxLayout* anImageLayout = new QHBoxLayout();
42 anImageLayout->addWidget( aNameLabel );
43 anImageLayout->addWidget( myImageName );
44 anImageGroup->setLayout( anImageLayout );
46 // List of recognized polylines
47 QGroupBox* aPolylinesGroup = new QGroupBox( tr( "RECOGNIZED_POLYLINES" ), mainFrame() );
48 myPolylines = new QListWidget( aPolylinesGroup );
49 myPolylines->setSelectionMode( QListWidget::ExtendedSelection );
50 myPolylines->setEditTriggers( QListWidget::NoEditTriggers );
51 myPolylines->setViewMode( QListWidget::ListMode );
52 myPolylines->setSortingEnabled( false );
54 QBoxLayout* aPolylinesLayout = new QVBoxLayout;
55 aPolylinesLayout->addWidget( myPolylines );
56 aPolylinesGroup->setLayout( aPolylinesLayout );
59 addWidget( anImageGroup );
60 addWidget( aPolylinesGroup );
63 connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
69 HYDROGUI_RecognizeContoursDlg::~HYDROGUI_RecognizeContoursDlg()
75 * \param theName the name
77 void HYDROGUI_RecognizeContoursDlg::setImageName( const QString& theName )
79 myImageName->setText( theName );
85 void HYDROGUI_RecognizeContoursDlg::reset()
92 * Refill the list of polylines names.
93 * \param theNames the list of names
95 void HYDROGUI_RecognizeContoursDlg::setPolylineNames( const QStringList& theNames )
98 myPolylines->addItems( theNames );
102 * Remove the given polyline names from the list.
103 * \param theNames the list of names
105 void HYDROGUI_RecognizeContoursDlg::removePolylineNames( const QStringList& theNames )
107 QList<QListWidgetItem*> aFoundItems;
109 foreach ( const QString& aName, theNames ) {
110 aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly );
111 foreach ( QListWidgetItem* anItem, aFoundItems ) {
112 anItem = myPolylines->takeItem( myPolylines->row( anItem ) );
119 * Select the given polyline names in the list.
120 * \param theNames the list of names
122 void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& theNames )
124 myPolylines->clearSelection();
126 foreach( const QString aName, theNames ) {
127 QList<QListWidgetItem*> anItems = myPolylines->findItems( aName, Qt::MatchExactly );
128 if ( anItems.count() == 1 ) {
129 anItems.first()->setSelected( true );
135 * Slot called when polyline names selection changed.
137 void HYDROGUI_RecognizeContoursDlg::onItemSelectionChanged()
139 emit selectionChanged( getSelectedtPolylineNames() );
143 * Get the list of selected polyline names.
144 * \return the list of names
146 QStringList HYDROGUI_RecognizeContoursDlg::getSelectedtPolylineNames() const
148 QStringList aSelectedNames;
150 QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
151 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
152 aSelectedNames << anItem->text();
155 return aSelectedNames;