1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ZLevelsDlg.h"
24 #include "HYDROGUI_ZLevelsModel.h"
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
32 #include <QPushButton>
33 #include <QToolButton>
34 #include <QSignalMapper>
35 #include <QSortFilterProxyModel>
40 @param theParent the parent widget
42 HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
43 : QDialog( theParent )
46 setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
49 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
50 aMainLayout->setMargin( 5 );
51 aMainLayout->setSpacing( 5 );
53 // List and buttons top, up, down, bottom
54 QHBoxLayout* aListLayout = new QHBoxLayout();
57 myList = new QListView( this );
58 myList->setSelectionMode( QAbstractItemView::ExtendedSelection );
59 myList->setDragEnabled( true );
60 myList->setAcceptDrops( true );
61 myList->viewport()->setAcceptDrops( true );
62 myList->setDropIndicatorShown( true );
63 myList->setDragDropMode( QAbstractItemView::InternalMove );
65 HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
66 QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel();
67 aFilteredModel->setSourceModel( aModel );
68 aFilteredModel->setFilterKeyColumn( 0 );
69 aFilteredModel->setFilterRole( HYDROGUI_VisibleRole );
71 myList->setModel( aFilteredModel );
73 // buttons top, up, down, bottom
74 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
75 myTop = new QToolButton;
76 myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
77 myTop->setIconSize( QSize( 32, 32 ) );
78 myUp = new QToolButton;
79 myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
80 myUp->setIconSize( myTop->iconSize() );
81 myDown = new QToolButton;
82 myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) );
83 myDown->setIconSize( myTop->iconSize() );
84 myBottom = new QToolButton;
85 myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) );
86 myBottom->setIconSize( myTop->iconSize() );
88 QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
89 aListButtonsLayout->addWidget( myTop );
90 aListButtonsLayout->addWidget( myUp );
91 aListButtonsLayout->addWidget( myDown );
92 aListButtonsLayout->addWidget( myBottom );
93 aListButtonsLayout->addStretch();
94 aListLayout->addWidget( myList );
96 aListLayout->addLayout( aListButtonsLayout );
97 aMainLayout->addLayout( aListLayout );
99 // "All objects" check box
100 myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
101 aMainLayout->addWidget( myAllObjects );
103 // Apply and close buttons
104 QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
105 myApply = new QPushButton( tr("APPLY") );
106 myClose = new QPushButton( tr("CLOSE") );
107 aDlgButtonsLayout->addWidget( myApply );
108 aDlgButtonsLayout->addWidget( myClose );
109 aDlgButtonsLayout->addStretch();
111 aMainLayout->addLayout( aDlgButtonsLayout );
114 QSignalMapper* aSignalMapper = new QSignalMapper( this );
115 aSignalMapper->setMapping( myTop, HYDROGUI_ZLevelsModel::Top );
116 aSignalMapper->setMapping( myUp, HYDROGUI_ZLevelsModel::Up );
117 aSignalMapper->setMapping( myDown, HYDROGUI_ZLevelsModel::Down );
118 aSignalMapper->setMapping( myBottom, HYDROGUI_ZLevelsModel::Bottom );
119 connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
120 connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
121 connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
122 connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
123 connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
125 connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
127 connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
128 connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
137 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
142 Set the list of objects (which supposed to be ordered by the dialog).
143 @param theObjects the list of objects
145 void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects )
147 HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
149 aModel->setObjects( theObjects );
154 Returns the ordered list of objects.
155 @return the list of objects
157 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
159 QList<Handle(HYDROData_Entity)> anObjects;
161 HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
163 anObjects = aModel->getObjects();
170 Slot called on top, up, down and bottom button click.
171 @param theType the move operation type
173 void HYDROGUI_ZLevelsDlg::onMove( int theType )
175 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
177 HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
179 QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
180 QModelIndexList aSelectedSourceIndexes;
181 foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
182 aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
184 QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
185 aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType,
186 !myAllObjects->isChecked() );
192 Slot called on "All objects" check box state change.
194 void HYDROGUI_ZLevelsDlg::onStateChanged()
196 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
197 bool isAll = myAllObjects->isChecked();
198 QString anExpr = isAll ? "true|false" : "true";
199 aFilterModel->setFilterRegExp( anExpr );
203 Returns the list source model.
204 @return the source model
206 HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const
208 HYDROGUI_ZLevelsModel* aSourceModel = 0;
210 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
212 aSourceModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );