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>
38 HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
39 : QDialog( theParent )
41 setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
43 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
44 aMainLayout->setMargin( 5 );
46 QHBoxLayout* aListLayout = new QHBoxLayout();
48 myList = new QListView( this );
49 myList->setSelectionMode( QAbstractItemView::ExtendedSelection );
50 myList->setDragEnabled( true );
51 myList->setAcceptDrops( true );
52 myList->viewport()->setAcceptDrops( true );
53 myList->setDropIndicatorShown( true );
54 myList->setDragDropMode( QAbstractItemView::InternalMove );
56 HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
57 QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel();
58 aFilteredModel->setSourceModel( aModel );
59 aFilteredModel->setFilterKeyColumn( 0 );
60 aFilteredModel->setFilterRole( HYDROGUI_VisibleRole );
62 myList->setModel( aFilteredModel );
64 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
65 myTop = new QToolButton;
66 myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
67 myTop->setIconSize( QSize( 32, 32 ) );
68 myUp = new QToolButton;
69 myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
70 myUp->setIconSize( myTop->iconSize() );
71 myDown = new QToolButton;
72 myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) );
73 myDown->setIconSize( myTop->iconSize() );
74 myBottom = new QToolButton;
75 myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) );
76 myBottom->setIconSize( myTop->iconSize() );
77 QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
78 aListButtonsLayout->addWidget( myTop );
79 aListButtonsLayout->addWidget( myUp );
80 aListButtonsLayout->addWidget( myDown );
81 aListButtonsLayout->addWidget( myBottom );
82 aListButtonsLayout->addStretch();
83 aListLayout->addWidget( myList );
84 aListLayout->addLayout( aListButtonsLayout );
85 aMainLayout->addLayout( aListLayout );
87 myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
88 aMainLayout->addWidget( myAllObjects );
90 QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
91 myApply = new QPushButton( tr("APPLY") );
92 myClose = new QPushButton( tr("CLOSE") );
93 aDlgButtonsLayout->addWidget( myApply );
94 aDlgButtonsLayout->addWidget( myClose );
95 aDlgButtonsLayout->addStretch();
96 aMainLayout->addLayout( aDlgButtonsLayout );
98 QSignalMapper* aSignalMapper = new QSignalMapper( this );
99 aSignalMapper->setMapping( myTop, HYDROGUI_ZLevelsModel::Top );
100 aSignalMapper->setMapping( myUp, HYDROGUI_ZLevelsModel::Up );
101 aSignalMapper->setMapping( myDown, HYDROGUI_ZLevelsModel::Down );
102 aSignalMapper->setMapping( myBottom, HYDROGUI_ZLevelsModel::Bottom );
103 connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
104 connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
105 connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
106 connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
107 connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
109 connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) );
111 connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
116 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
120 void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects )
122 HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
124 aModel->setObjects( theObjects );
128 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
130 QList<Handle(HYDROData_Entity)> anObjects;
132 HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
134 anObjects = aModel->getObjects();
140 void HYDROGUI_ZLevelsDlg::onMove( int theType )
142 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
144 HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
146 QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
147 QModelIndexList aSelectedSourceIndexes;
148 foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
149 aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
151 QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
152 aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType,
153 !myAllObjects->isChecked() );
158 void HYDROGUI_ZLevelsDlg::OnStateChanged()
160 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
161 bool isAll = myAllObjects->isChecked();
162 QString anExpr = isAll ? "true|false" : "true";
163 aFilterModel->setFilterRegExp( anExpr );
166 HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const
168 HYDROGUI_ZLevelsModel* aSourceModel = 0;
170 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
172 aSourceModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );