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"
29 #include <QPushButton>
30 #include <QSignalMapper>
31 #include <QSortFilterProxyModel>
34 HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
35 : QDialog( theParent )
37 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
38 aMainLayout->setMargin( 5 );
40 QHBoxLayout* aListLayout = new QHBoxLayout();
42 myList = new QListView( this );
43 myList->setSelectionMode( QAbstractItemView::ExtendedSelection );
44 myList->setDragEnabled( true );
45 myList->setAcceptDrops( true );
46 myList->viewport()->setAcceptDrops( true );
47 myList->setDropIndicatorShown( true );
48 myList->setDragDropMode( QAbstractItemView::InternalMove );
50 HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
51 QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel();
52 aFilteredModel->setSourceModel( aModel );
53 aFilteredModel->setFilterKeyColumn( 0 );
54 aFilteredModel->setFilterRole( HYDROGUI_VisibleRole );
56 myList->setModel( aFilteredModel );
58 myTop = new QPushButton( tr("TOP") );
59 myUp = new QPushButton( tr("UP") );
60 myDown = new QPushButton( tr("DOWN") );
61 myBottom = new QPushButton( tr("BOTTOM") );
62 QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
63 aListButtonsLayout->addWidget( myTop );
64 aListButtonsLayout->addWidget( myUp );
65 aListButtonsLayout->addWidget( myDown );
66 aListButtonsLayout->addWidget( myBottom );
67 aListButtonsLayout->addStretch();
68 aListLayout->addWidget( myList );
69 aListLayout->addLayout( aListButtonsLayout );
70 aMainLayout->addLayout( aListLayout );
72 myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
73 aMainLayout->addWidget( myAllObjects );
75 QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
76 myApply = new QPushButton( tr("APPLY") );
77 myClose = new QPushButton( tr("CLOSE") );
78 aDlgButtonsLayout->addWidget( myApply );
79 aDlgButtonsLayout->addWidget( myClose );
80 aDlgButtonsLayout->addStretch();
81 aMainLayout->addLayout( aDlgButtonsLayout );
83 QSignalMapper* aSignalMapper = new QSignalMapper( this );
84 aSignalMapper->setMapping( myTop, HYDROGUI_ZLevelsModel::Top );
85 aSignalMapper->setMapping( myUp, HYDROGUI_ZLevelsModel::Up );
86 aSignalMapper->setMapping( myDown, HYDROGUI_ZLevelsModel::Down );
87 aSignalMapper->setMapping( myBottom, HYDROGUI_ZLevelsModel::Bottom );
88 connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
89 connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
90 connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
91 connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
92 connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
94 connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) );
96 connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
101 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
105 void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects )
107 HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
109 aModel->setObjects( theObjects );
113 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
115 QList<Handle(HYDROData_Entity)> anObjects;
117 HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
119 anObjects = aModel->getObjects();
125 void HYDROGUI_ZLevelsDlg::onMove( int theType )
127 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
129 HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
131 QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
132 QModelIndexList aSelectedSourceIndexes;
133 foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
134 aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
136 QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
137 aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType,
138 !myAllObjects->isChecked() );
143 void HYDROGUI_ZLevelsDlg::OnStateChanged()
145 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
146 bool isAll = myAllObjects->isChecked();
147 QString anExpr = isAll ? "true|false" : "true";
148 aFilterModel->setFilterRegExp( anExpr );
151 HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const
153 HYDROGUI_ZLevelsModel* aSourceModel = 0;
155 QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
157 aSourceModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );