-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
//
#include "HYDROGUI_ZLevelsDlg.h"
-#include "HYDROGUI_ZLevelsModel.h"
+
+#include "HYDROGUI_OrderedListWidget.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_ListSelector.h"
+
+#include "LightApp_Application.h"
+#include "LightApp_SelectionMgr.h"
#include <QCheckBox>
#include <QLayout>
-#include <QListView>
#include <QPushButton>
-#include <QSignalMapper>
-#include <QSortFilterProxyModel>
-HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
+/**
+ Constructor.
+ @param theParent the parent widget
+*/
+HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule )
: QDialog( theParent )
{
+ // Change windows flags to remove minimize button
+ Qt::WindowFlags aFlags = windowFlags();
+ aFlags |= Qt::CustomizeWindowHint;
+ aFlags &= ~Qt::WindowMinimizeButtonHint;
+ aFlags &= ~Qt::WindowMaximizeButtonHint;
+ setWindowFlags( aFlags );
+
+ // Dialog title
+ setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
+
+ // Main layout
QVBoxLayout* aMainLayout = new QVBoxLayout( this );
aMainLayout->setMargin( 5 );
+ aMainLayout->setSpacing( 5 );
- QHBoxLayout* aListLayout = new QHBoxLayout();
-
- myList = new QListView( this );
- myList->setSelectionMode( QAbstractItemView::ExtendedSelection );
- myList->setDragEnabled( true );
- myList->setAcceptDrops( true );
- myList->viewport()->setAcceptDrops( true );
- myList->setDropIndicatorShown( true );
- myList->setDragDropMode( QAbstractItemView::InternalMove );
-
- HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
- QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel();
- aFilteredModel->setSourceModel( aModel );
- aFilteredModel->setFilterKeyColumn( 0 );
- aFilteredModel->setFilterRole( HYDROGUI_VisibleRole );
-
- myList->setModel( aFilteredModel );
-
- myTop = new QPushButton( tr("TOP") );
- myUp = new QPushButton( tr("UP") );
- myDown = new QPushButton( tr("DOWN") );
- myBottom = new QPushButton( tr("BOTTOM") );
- QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
- aListButtonsLayout->addWidget( myTop );
- aListButtonsLayout->addWidget( myUp );
- aListButtonsLayout->addWidget( myDown );
- aListButtonsLayout->addWidget( myBottom );
- aListButtonsLayout->addStretch();
- aListLayout->addWidget( myList );
- aListLayout->addLayout( aListButtonsLayout );
- aMainLayout->addLayout( aListLayout );
+ // Ordered list widget
+ myListWidget = new HYDROGUI_OrderedListWidget( this );
+ // "All objects" check box
myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
- aMainLayout->addWidget( myAllObjects );
- QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
+ // Apply and close buttons
myApply = new QPushButton( tr("APPLY") );
+ myApply->setDefault( true );
myClose = new QPushButton( tr("CLOSE") );
+
+ // Layout
+ // apply and close buttons
+ QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
aDlgButtonsLayout->addWidget( myApply );
aDlgButtonsLayout->addWidget( myClose );
aDlgButtonsLayout->addStretch();
+ // main
+ aMainLayout->addWidget( myListWidget );
+ aMainLayout->addWidget( myAllObjects );
aMainLayout->addLayout( aDlgButtonsLayout );
- QSignalMapper* aSignalMapper = new QSignalMapper( this );
- aSignalMapper->setMapping( myTop, HYDROGUI_ZLevelsModel::Top );
- aSignalMapper->setMapping( myUp, HYDROGUI_ZLevelsModel::Up );
- aSignalMapper->setMapping( myDown, HYDROGUI_ZLevelsModel::Down );
- aSignalMapper->setMapping( myBottom, HYDROGUI_ZLevelsModel::Bottom );
- connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
- connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
- connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
- connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
- connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
+ // Connections
+ connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
- connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) );
+ connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
+ connect( myClose, SIGNAL( clicked() ), this, SLOT( reject() ) );
- connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
+ // Initialize
+ onStateChanged();
- OnStateChanged();
+ // Create selector
+ if ( theModule ) {
+ HYDROGUI_ListSelector* aListSelector =
+ new HYDROGUI_ListSelector( myListWidget, theModule->getApp()->selectionMgr() );
+ aListSelector->setAutoBlock( true );
+ }
}
+/**
+ Destructor.
+*/
HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
{
}
-void HYDROGUI_ZLevelsDlg::setObjects( const QList<QString>& theObjects )
+/**
+ Set the list of objects (which supposed to be ordered by the dialog).
+ @param theObjects the list of objects
+*/
+void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
{
- QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
- if( aFilterModel )
- {
- HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
- if( aModel ) {
- // TODO: to be reimplemented
- QList<QPair<QString, bool>> anObjects;
- for ( int i = 0; i < theObjects.count(); i++ ) {
- anObjects << QPair<QString, bool>( theObjects.at(i), i%2 == 0 );
- }
- aModel->setObjects( anObjects );
- }
- }
+ myListWidget->setObjects( theObjects );
}
-void HYDROGUI_ZLevelsDlg::onMove( int theType )
+/**
+ Returns the ordered list of objects.
+ @return the list of objects
+*/
+QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
{
- QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
- if( aFilterModel ) {
- HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
- if( aModel ) {
- QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
- QModelIndexList aSelectedSourceIndexes;
- foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
- aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
- }
- QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
- aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType,
- !myAllObjects->isChecked() );
- }
- }
+ return myListWidget->getObjects();
}
-void HYDROGUI_ZLevelsDlg::OnStateChanged()
+/**
+ Slot called on "All objects" check box state change.
+*/
+void HYDROGUI_ZLevelsDlg::onStateChanged()
{
- QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
bool isAll = myAllObjects->isChecked();
- QString anExpr = isAll ? "true|false" : "true";
- aFilterModel->setFilterRegExp( anExpr );
+
+ QString aToolTip = isAll ? tr( "ALL_OBJECTS_CHECKED_TLT" ) :
+ tr( "ALL_OBJECTS_UNCHECKED_TLT" );
+ myAllObjects->setToolTip( aToolTip );
+
+ myListWidget->setHiddenObjectsShown( isAll );
}