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_LandCoverDlg.h"
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_OrderedListWidget.h"
23 #include "HYDROGUI_ListSelector.h"
25 #include <LightApp_Application.h>
26 #include <LightApp_SelectionMgr.h>
31 #include <QListWidget>
32 #include <QPushButton>
34 HYDROGUI_LandCoverDlg::HYDROGUI_LandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle )
35 : HYDROGUI_BasicZoneDlg( theModule, theTitle,
36 tr( "LAND_COVER_NAME" ), tr( "NAME" ),
37 tr( "LAND_COVER_PARAMETERS" ), tr( "LAND_COVER_STRICKLER_TYPE" ) )
39 myPolylines = new HYDROGUI_OrderedListWidget( myPolylineFrame, 16 );
40 myPolylines->setHiddenObjectsShown(true);
41 myPolylines->setVisibilityIconShown(false);
42 myPolylines->setContentsMargins(QMargins());
43 myPolylines->setOrderingEnabled( true );
45 // Include/Exclude buttons
46 QFrame* aBtnsFrame = new QFrame( myPolylineFrame );
47 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
48 aBtnsLayout->setMargin( 5 );
49 aBtnsLayout->setSpacing( 5 );
50 aBtnsFrame->setLayout( aBtnsLayout );
51 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
52 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
54 // Fill the butons frame with two buttons
55 aBtnsLayout->addWidget( anAddBtn );
56 aBtnsLayout->addWidget( aRemoveBtn );
57 aBtnsLayout->addStretch( 1 );
59 QGridLayout* aPolyLayout = new QGridLayout( myPolylineFrame );
60 aPolyLayout->setMargin( 5 );
61 aPolyLayout->setSpacing( 5 );
62 aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ), 0, 0, 1, 2 );
63 aPolyLayout->addWidget( aBtnsFrame, 1, 0, 1, 1 );
64 aPolyLayout->addWidget( myPolylines, 1, 1, 1, 1 );
66 QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup );
67 aParamLayout->setMargin( 5 );
68 aParamLayout->setSpacing( 5 );
69 aParamLayout->addWidget( myPolylineFrame );
73 HYDROGUI_ListSelector* aListSelector =
74 new HYDROGUI_ListSelector( myPolylines, module()->getApp()->selectionMgr() );
75 aListSelector->setAutoBlock( true );
78 // Connect signals and slots
79 connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
80 connect( myPolylines, SIGNAL( orderPolylinesChanged() ), SLOT( onOrderPolylinesChanged() ) );
81 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addPolylines() ) );
82 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removePolylines() ) );
85 HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg()
89 void HYDROGUI_LandCoverDlg::reset()
91 bool isBlocked = blockSignals( true );
93 HYDROGUI_BasicZoneDlg::reset();
95 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
96 myPolylines->setObjects(anObject2VisibleList);
97 myPolylines->setOrderingEnabled( false );
99 blockSignals( isBlocked );
104 void HYDROGUI_LandCoverDlg::includePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
106 QStringList anIncludedPolylinesNames = myPolylines->getAllNames();
108 foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
110 if ( !anIncludedPolylinesNames.contains( aSelectedPolyline.first->GetName() ) )
111 myPolylines->addObject( aSelectedPolyline );
113 myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
116 void HYDROGUI_LandCoverDlg::excludePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
118 foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
119 myPolylines->removeObjectByName( aSelectedPolyline.first->GetName() );
120 myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
123 QStringList HYDROGUI_LandCoverDlg::getPolylineNames() const
125 return myPolylines->getAllNames();
128 QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
130 return myPolylines->getSelectedNames();
133 void HYDROGUI_LandCoverDlg::onZoneDefChanged()
135 if ( signalsBlocked() )
138 QStringList aPolylineNames = getPolylineNames();
139 emit CreatePreview( aPolylineNames );
142 void HYDROGUI_LandCoverDlg::onOrderPolylinesChanged()
144 // TODO: implement this method