HYDROGUI_BathymetryBoundsOp.h
HYDROGUI_TranslateObstacleDlg.h
HYDROGUI_TranslateObstacleOp.h
- HYDROGUI_ZLevelsModel.h
+ HYDROGUI_ListModel.h
HYDROGUI_ZLevelsDlg.h
HYDROGUI_ZLevelsOp.h
+ HYDROGUI_OrderedListWidget.h
+ HYDROGUI_ListSelector.h
)
QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
HYDROGUI_BathymetryBoundsOp.cxx
HYDROGUI_TranslateObstacleDlg.cxx
HYDROGUI_TranslateObstacleOp.cxx
- HYDROGUI_ZLevelsModel.cxx
+ HYDROGUI_ListModel.cxx
HYDROGUI_ZLevelsDlg.cxx
HYDROGUI_ZLevelsOp.cxx
+ HYDROGUI_OrderedListWidget.cxx
+ HYDROGUI_ListSelector.cxx
)
add_definitions(
if(SALOME_BUILD_TESTS)
set(TEST_HEADERS
- test_HYDROGUI_ZLevelsModel.h
+ test_HYDROGUI_ListModel.h
)
set(TEST_SOURCES
test_HYDROGUI_Main.cxx
- test_HYDROGUI_ZLevelsModel.cxx
+ test_HYDROGUI_ListModel.cxx
)
set(TEST_EXE test_HYDROGUI)
--- /dev/null
+// Copyright (C) 2007-2013 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ListModel.h"
+
+#include "HYDROGUI_DataObject.h"
+
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+
+#include <QMimeData>
+
+const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list";
+
+
+/**
+ Constructor.
+ @param theParent the parent object
+*/
+HYDROGUI_ListModel::HYDROGUI_ListModel( QObject* theParent )
+ : QAbstractListModel( theParent )
+{
+ // Get resource manager
+ SUIT_ResourceMgr* aResMgr = 0;
+ SUIT_Session* aSession = SUIT_Session::session();
+ if ( aSession ) {
+ aResMgr = SUIT_Session::session()->resourceMgr();
+ }
+
+ // Define eye icon and empty icon
+ myEmpty = QPixmap( 16, 16 );
+ myEmpty.fill( Qt::white );
+ if ( aResMgr ) {
+ myEye = aResMgr->loadPixmap( "HYDRO", tr( "EYE_ICO" ) );
+ } else {
+ myEye = QPixmap( 16, 16 );
+ myEye.fill( Qt::black );
+ }
+
+ // Set the supported drag actions for the items in the model
+ setSupportedDragActions( Qt::MoveAction | Qt::CopyAction );
+}
+
+/**
+ Destructor.
+*/
+HYDROGUI_ListModel::~HYDROGUI_ListModel()
+{
+}
+
+/**
+*/
+QVariant HYDROGUI_ListModel::data( const QModelIndex &theIndex, int theRole ) const
+{
+ QVariant aVariant;
+
+ int aRow = theIndex.row();
+ int aColumn = theIndex.column();
+
+ switch( theRole )
+ {
+ case Qt::DisplayRole:
+ {
+ if( aColumn==0 && aRow >=0 && aRow < myObjects.count() )
+ return myObjects.at( aRow ).first->GetName();
+ else
+ return QVariant();
+ }
+ break;
+
+ case Qt::DecorationRole:
+ {
+ if( aColumn==0 && aRow >=0 && aRow < myObjects.count() )
+ {
+ bool isVisible = isObjectVisible( aRow );
+ if( isVisible )
+ return myEye;
+ else
+ return myEmpty;
+ }
+ return QVariant();
+ }
+ break;
+
+ case HYDROGUI_VisibleRole:
+ {
+ bool isVisible = isObjectVisible( aRow );
+ return QVariant( isVisible ).toString();
+ }
+ break;
+ case HYDROGUI_EntryRole:
+ {
+ if( aColumn==0 && aRow >=0 && aRow < myObjects.count() ) {
+ aVariant = HYDROGUI_DataObject::dataObjectEntry( myObjects.at( aRow ).first );
+ }
+ }
+ break;
+ }
+
+ return aVariant;
+}
+
+/**
+*/
+int HYDROGUI_ListModel::rowCount( const QModelIndex &theParent ) const
+{
+ return myObjects.count();
+}
+
+/**
+ Set objects list.
+ @param theObjects the list of pairs (object; object visibility)
+*/
+void HYDROGUI_ListModel::setObjects( const Object2VisibleList& theObjects )
+{
+ myObjects = theObjects;
+
+ reset();
+}
+
+/**
+ Get objects list.
+ @return the list of objects ordered according to the model
+*/
+HYDROGUI_ListModel::ObjectList HYDROGUI_ListModel::getObjects() const
+{
+ ObjectList anObjects;
+
+ foreach( const Object2Visible& anItem, myObjects ) {
+ anObjects << anItem.first;
+ }
+
+ return anObjects;
+}
+
+/**
+ Check if the object is visible.
+ @param theIndex the object index
+ @return true if the object is visible, false - otherwise
+*/
+bool HYDROGUI_ListModel::isObjectVisible( int theIndex ) const
+{
+ bool isVisible = false;
+
+ if ( theIndex >= 0 && theIndex < myObjects.count() ) {
+ isVisible = myObjects.at( theIndex ).second;
+ }
+
+ return isVisible;
+}
+
+/**
+*/
+QVariant HYDROGUI_ListModel::headerData( int theSection,
+ Qt::Orientation theOrientation,
+ int theRole ) const
+{
+ if( theOrientation==Qt::Horizontal && theRole==Qt::DisplayRole )
+ {
+ switch( theSection )
+ {
+ case 0:
+ return tr( "VISIBLE" );
+ case 1:
+ return tr( "OBJECT_NAME" );
+ };
+ }
+ return QVariant();
+}
+
+/**
+*/
+Qt::ItemFlags HYDROGUI_ListModel::flags( const QModelIndex& theIndex ) const
+{
+ Qt::ItemFlags aDefaultFlags = QAbstractListModel::flags( theIndex );
+ if( theIndex.isValid() )
+ return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | aDefaultFlags;
+ else
+ return Qt::ItemIsDropEnabled | aDefaultFlags;
+}
+
+/**
+*/
+QMimeData* HYDROGUI_ListModel::mimeData( const QModelIndexList& theIndexes ) const
+{
+ QMimeData* aMimeData = new QMimeData();
+ QByteArray anEncodedData;
+ QDataStream aStream( &anEncodedData, QIODevice::WriteOnly );
+
+ QList<int> anIdsList = getIds( theIndexes );
+ foreach( int anId, anIdsList )
+ aStream << anId;
+
+ aMimeData->setData( OBJ_LIST_MIME_TYPE, anEncodedData );
+ return aMimeData;
+}
+
+/**
+*/
+QStringList HYDROGUI_ListModel::mimeTypes() const
+{
+ QStringList aTypes;
+ aTypes << OBJ_LIST_MIME_TYPE;
+ return aTypes;
+}
+
+/**
+*/
+bool HYDROGUI_ListModel::dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
+ int theRow, int theColumn, const QModelIndex& theParent )
+{
+ if( theAction == Qt::IgnoreAction)
+ return true;
+
+ if( !theData->hasFormat( OBJ_LIST_MIME_TYPE ))
+ return false;
+
+ if( theColumn > 0 )
+ return false;
+
+ int aDropItemId = theParent.row();
+
+ QByteArray anEncodedData = theData->data( OBJ_LIST_MIME_TYPE );
+ QDataStream aStream( &anEncodedData, QIODevice::ReadOnly );
+ QList<int> anIdsList;
+ while( !aStream.atEnd() )
+ {
+ int anId;
+ aStream >> anId;
+ anIdsList << anId;
+ }
+ qSort( anIdsList ); // TODO should be moved?
+ move( anIdsList, DragAndDrop, false, aDropItemId ); //TODO set visibility?
+ return true;
+}
+
+/**
+*/
+Qt::DropActions HYDROGUI_ListModel::supportedDropActions() const
+{
+ return Qt::MoveAction | Qt::CopyAction;
+}
+
+/**
+ Get list of ids by the list model indexes.
+ @param theIsToSort defines if the list of ids should be sorted in ascending order
+ @return the list of ids
+*/
+QList<int> HYDROGUI_ListModel::getIds( const QModelIndexList& theIndexes, bool theIsToSort ) const
+{
+ QList<int> anIds;
+ foreach( const QModelIndex& anIndex, theIndexes ) {
+ anIds << anIndex.row();
+ }
+
+ if ( theIsToSort ) {
+ qSort( anIds );
+ }
+
+ return anIds;
+}
+
+/**
+ Move the item.
+ @param theItem the item id to move
+ @param theType the move operation type
+ @param theIsVisibleOnly indicates if do move relating to the visible objects only
+ @param theDropItem the drop item id ( used for drag and drop obly )
+ @return true in case of success
+*/
+bool HYDROGUI_ListModel::move( const int theItem, const OpType theType,
+ bool theIsVisibleOnly, const int theDropItem )
+{
+ bool aRes = false;
+ if ( theItem < 0 || theItem >= myObjects.count() ) {
+ return aRes;
+ }
+
+ int aDestinationIndex = -1;
+ bool isInsertBefore = false;
+
+ switch ( theType ) {
+ case Up:
+ isInsertBefore = true;
+ if ( theItem > 0 ) {
+ aDestinationIndex = theItem - 1;
+ if ( theIsVisibleOnly ) {
+ while ( aDestinationIndex >= 0 && !isObjectVisible( aDestinationIndex ) ) {
+ aDestinationIndex--;
+ }
+ }
+ }
+ break;
+ case Down:
+ if ( theItem < myObjects.count() - 1 ) {
+ aDestinationIndex = theItem + 1;
+ if ( theIsVisibleOnly ) {
+ while ( aDestinationIndex < myObjects.count() && !isObjectVisible( aDestinationIndex ) ) {
+ aDestinationIndex++;
+ }
+ }
+ }
+ break;
+ case Top:
+ isInsertBefore = true;
+ if ( theItem > 0 ) {
+ aDestinationIndex = 0;
+ }
+ break;
+ case Bottom:
+ if ( theItem < myObjects.count() - 1 ) {
+ aDestinationIndex = myObjects.count() - 1;
+ }
+ break;
+ case DragAndDrop:
+ if ( theItem > theDropItem ) {
+ isInsertBefore = true;
+ aDestinationIndex = theDropItem;
+ } else {
+ aDestinationIndex = theDropItem - 1;
+ }
+ break;
+ }
+
+ if ( aDestinationIndex >= 0 && aDestinationIndex < myObjects.count() ) {
+ int aDestinationRow = isInsertBefore ? aDestinationIndex : aDestinationIndex + 1;
+ if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestinationRow ) ) {
+ myObjects.move( theItem, aDestinationIndex );
+ endMoveRows();
+ aRes = true;
+ }
+ }
+
+ return aRes;
+}
+
+/**
+ Move the items.
+ @param theItems the list of item ids to move
+ @param theType the move operation type
+ @param theIsVisibleOnly indicates if do move relating to the visible objects only
+ @param theDropItem the drop item id ( used for drag and drop obly )
+ @return true in case of success
+*/
+bool HYDROGUI_ListModel::move( const QList<int>& theItems, const OpType theType,
+ bool theIsVisibleOnly, const int theDropItem )
+{
+ bool aRes = true;
+
+ QListIterator<int> anIt( theItems );
+ int aDragShift = 0;
+
+ switch ( theType ) {
+ case Top:
+ case Down:
+ // reverse order
+ anIt.toBack();
+ while ( anIt.hasPrevious() ) {
+ int anId = anIt.previous();
+ if ( theType == Top ) {
+ anId += aDragShift;
+ aDragShift++;
+ }
+ if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
+ aRes = false;
+ break;
+ }
+ }
+ break;
+ case Bottom:
+ case Up:
+ // direct order
+ while ( anIt.hasNext() ) {
+ int anId = anIt.next();
+ if ( theType == Bottom ) {
+ anId -= aDragShift;
+ aDragShift++;
+ }
+ if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
+ aRes = false;
+ break;
+ }
+ }
+ break;
+ case DragAndDrop:
+ // direct order
+ aRes = isDragAndDropAllowed( theItems, theDropItem );
+ if ( aRes ) {
+ int aDropShift = 0;
+ int aDropItem = theDropItem;
+ while ( anIt.hasNext() ) {
+ int anId = anIt.next();
+ aDropItem = theDropItem + aDropShift;
+ if ( anId > aDropItem ) {
+ aDragShift = 0;
+ aDropShift++;
+ } else {
+ anId -= aDragShift;
+ if ( ( aDropItem - anId ) != 1 ) {
+ aDragShift++;
+ }
+ }
+ move( anId, theType, theIsVisibleOnly, aDropItem );
+ }
+ }
+ break;
+ default:
+ aRes = false;
+ }
+
+ return aRes;
+}
+
+/**
+ Check if drag and drop operation allowed.
+ @param theItems the list of dragged item ids
+ @param theDropItem the drop item id
+ @return true if drag and drop allowed
+*/
+bool HYDROGUI_ListModel::isDragAndDropAllowed( const QList<int>& theItems,
+ const int theDropItem ) const
+{
+ bool isAllowed = false;
+
+ if ( theDropItem >= 0 && theDropItem < myObjects.count() &&
+ !theItems.empty() && theItems.count() < myObjects.count() &&
+ !theItems.contains( theDropItem )) {
+ isAllowed = true;
+ }
+
+ return isAllowed;
+}
--- /dev/null
+// Copyright (C) 2007-2013 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_ListModel_H
+#define HYDROGUI_ListModel_H
+
+#include <HYDROGUI.h>
+#include <HYDROData_Entity.h>
+#include <QAbstractListModel>
+#include <QPixmap>
+
+const int HYDROGUI_VisibleRole = Qt::UserRole + 1;
+const int HYDROGUI_EntryRole = Qt::UserRole + 2;
+
+/**
+ * \class HYDROGUI_ListModel
+ * \brief The class representing custom list model for the Z levels
+ */
+class HYDRO_EXPORT HYDROGUI_ListModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ enum OpType { Top, Up, Down, Bottom, DragAndDrop };
+
+ typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
+ typedef QList<Object2Visible> Object2VisibleList;
+ typedef QList<Handle(HYDROData_Entity)> ObjectList;
+
+public:
+ HYDROGUI_ListModel( QObject* theParent = 0 );
+ virtual ~HYDROGUI_ListModel();
+
+ virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;
+
+ virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
+
+ virtual QVariant headerData( int theSection,
+ Qt::Orientation theOrientation,
+ int theRole = Qt::DisplayRole ) const;
+ virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const;
+ virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const;
+ virtual QStringList mimeTypes() const;
+ virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
+ int theRow, int theColumn, const QModelIndex& theParent );
+ virtual Qt::DropActions supportedDropActions() const;
+
+ QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
+
+ void setObjects( const Object2VisibleList& theObjects );
+ ObjectList getObjects() const;
+
+ bool move( const int theItem, const OpType theType, bool theIsVisibleOnly,
+ const int theDropItem = -1 );
+ bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
+ const int theDropItem = -1 );
+
+protected:
+ bool isObjectVisible( int theIndex ) const;
+ bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
+
+private:
+ friend class test_HYDROGUI_ListModel;
+
+ Object2VisibleList myObjects;
+ QPixmap myEmpty, myEye;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2007-2013 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ListSelector.h"
+
+#include "HYDROGUI_OrderedListWidget.h"
+
+#include <LightApp_DataOwner.h>
+
+
+HYDROGUI_ListSelector::HYDROGUI_ListSelector( HYDROGUI_OrderedListWidget* theListWidget,
+ SUIT_SelectionMgr* theSelectionMgr )
+: SUIT_Selector( theSelectionMgr, theListWidget ),
+ myListWidget( theListWidget )
+{
+ if ( myListWidget ) {
+ connect( myListWidget, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
+ }
+}
+
+/**
+ Destructor.
+*/
+HYDROGUI_ListSelector::~HYDROGUI_ListSelector()
+{
+}
+
+/*!
+ Get selector type.
+ @return the selector type
+*/
+QString HYDROGUI_ListSelector::type() const
+{
+ return "ListSelector";
+}
+
+/**
+*/
+void HYDROGUI_ListSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
+{
+ QStringList aSelectedEntries = myListWidget->getSelectedEntries();
+
+ foreach ( const QString& anEntry, aSelectedEntries ) {
+ if ( !anEntry.isEmpty() ) {
+ theList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anEntry ) ) );
+ }
+ }
+}
+
+/**
+*/
+void HYDROGUI_ListSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
+{
+ if ( !myListWidget ) {
+ return;
+ }
+
+ QStringList aSelectedEntries;
+ SUIT_DataOwnerPtrList::const_iterator anIt = theList.begin();
+ for ( ; anIt != theList.end(); ++anIt ) {
+ const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>( (*anIt).operator->() );
+ if ( anOwner ) {
+ aSelectedEntries << anOwner->entry();
+ }
+ }
+
+ myListWidget->setSelectedEntries( aSelectedEntries );
+}
+
+/**
+ Called when the list selection is changed.
+*/
+void HYDROGUI_ListSelector::onSelectionChanged()
+{
+ selectionChanged();
+}
--- /dev/null
+// Copyright (C) 2007-2013 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_LISTSELECTOR_H
+#define HYDROGUI_LISTSELECTOR_H
+
+#include <SUIT_Selector.h>
+
+#include <QObject>
+
+class HYDROGUI_OrderedListWidget;
+
+
+/**
+ * \class HYDROGUI_ListSelector
+ * \brief The special selector for ordered list of objects.
+ */
+class HYDROGUI_ListSelector : public QObject, public SUIT_Selector
+{
+ Q_OBJECT
+
+public:
+ HYDROGUI_ListSelector( HYDROGUI_OrderedListWidget* theListWidget,
+ SUIT_SelectionMgr* theSelectionMgr );
+ virtual ~HYDROGUI_ListSelector();
+
+ virtual QString type() const;
+
+protected:
+ virtual void getSelection( SUIT_DataOwnerPtrList& ) const;
+ virtual void setSelection( const SUIT_DataOwnerPtrList& );
+
+private slots:
+ void onSelectionChanged();
+
+private:
+ HYDROGUI_OrderedListWidget* myListWidget; ///< the ordered list widget
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_OrderedListWidget.h"
+
+#include "HYDROGUI_ListModel.h"
+
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+
+#include <QLayout>
+#include <QListView>
+#include <QToolButton>
+#include <QSignalMapper>
+#include <QSortFilterProxyModel>
+
+
+/**
+ Constructor.
+ @param theParent the parent widget
+*/
+HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent )
+: QWidget( theParent )
+{
+ // Main layout
+ QHBoxLayout* aMainLayout = new QHBoxLayout( this );
+ aMainLayout->setSpacing( 5 );
+
+ // List view
+ 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_ListModel* aModel = new HYDROGUI_ListModel();
+ QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel();
+ aFilteredModel->setSourceModel( aModel );
+ aFilteredModel->setFilterKeyColumn( 0 );
+ aFilteredModel->setFilterRole( HYDROGUI_VisibleRole );
+
+ myList->setModel( aFilteredModel );
+
+ // Buttons top, up, down, bottom
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ myTop = new QToolButton;
+ myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
+ myTop->setIconSize( QSize( 32, 32 ) );
+ myUp = new QToolButton;
+ myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
+ myUp->setIconSize( myTop->iconSize() );
+ myDown = new QToolButton;
+ myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) );
+ myDown->setIconSize( myTop->iconSize() );
+ myBottom = new QToolButton;
+ myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) );
+ myBottom->setIconSize( myTop->iconSize() );
+
+ // Layout
+ // buttons
+ QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
+ aListButtonsLayout->addWidget( myTop );
+ aListButtonsLayout->addWidget( myUp );
+ aListButtonsLayout->addWidget( myDown );
+ aListButtonsLayout->addWidget( myBottom );
+ aListButtonsLayout->addStretch();
+ // main
+ aMainLayout->addWidget( myList );
+ aMainLayout->addLayout( aListButtonsLayout );
+
+ // Connections
+ QSignalMapper* aSignalMapper = new QSignalMapper( this );
+ aSignalMapper->setMapping( myTop, HYDROGUI_ListModel::Top );
+ aSignalMapper->setMapping( myUp, HYDROGUI_ListModel::Up );
+ aSignalMapper->setMapping( myDown, HYDROGUI_ListModel::Down );
+ aSignalMapper->setMapping( myBottom, HYDROGUI_ListModel::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 ) ) );
+
+ connect ( myList->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
+ this, SIGNAL( selectionChanged() ) );
+
+ // Initialize
+ setHiddenObjectsShown( true );
+}
+
+/**
+ Destructor.
+*/
+HYDROGUI_OrderedListWidget::~HYDROGUI_OrderedListWidget()
+{
+}
+
+/**
+ Set the list of objects (which supposed to be ordered by the widget).
+ @param theObjects the list of pairs (object; visibility)
+*/
+void HYDROGUI_OrderedListWidget::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
+{
+ HYDROGUI_ListModel* aModel = getSourceModel();
+ if( aModel ) {
+ aModel->setObjects( theObjects );
+ }
+}
+
+/**
+ Returns the ordered list of objects.
+ @return the list of objects
+*/
+QList<Handle(HYDROData_Entity)> HYDROGUI_OrderedListWidget::getObjects() const
+{
+ QList<Handle(HYDROData_Entity)> anObjects;
+
+ HYDROGUI_ListModel* aModel = getSourceModel();
+ if( aModel ) {
+ anObjects = aModel->getObjects();
+ }
+
+ return anObjects;
+}
+
+/**
+ Set whether the hidden objects are presented in the list.
+ @param theIsToShow if true - the hidden objects will be shown in the list
+*/
+void HYDROGUI_OrderedListWidget::setHiddenObjectsShown( const bool theIsToShow )
+{
+ myIsHiddenObjectsShown = theIsToShow;
+
+ QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+ QString anExpr = theIsToShow ? "true|false" : "true";
+ aFilterModel->setFilterRegExp( anExpr );
+}
+
+/**
+ Get entries of the selected objects.
+ @return the list of entries
+*/
+QStringList HYDROGUI_OrderedListWidget::getSelectedEntries() const
+{
+ QStringList anEntries;
+
+ QSortFilterProxyModel* aFilterModel =
+ dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+ if( aFilterModel ) {
+ HYDROGUI_ListModel* aSourceModel =
+ dynamic_cast<HYDROGUI_ListModel*>( aFilterModel->sourceModel() );
+ if ( aSourceModel ) {
+ QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
+ foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
+ QModelIndex aSourceIndex = aFilterModel->mapToSource( anIndex );
+ QString anEntry = aSourceModel->data( aSourceIndex, HYDROGUI_EntryRole ).toString();
+ anEntries << anEntry;
+ }
+ }
+ }
+
+ return anEntries;
+}
+
+/**
+ Set objects with the given entries selected (other objects will deselected).
+ @param theEntries the list of entries
+*/
+void HYDROGUI_OrderedListWidget::setSelectedEntries( const QStringList& theEntries ) const
+{
+ QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+ if( !aFilterModel ) {
+ return;
+ }
+ HYDROGUI_ListModel* aSourceModel = dynamic_cast<HYDROGUI_ListModel*>( aFilterModel->sourceModel() );
+ if ( !aSourceModel ) {
+ return;
+ }
+ QItemSelectionModel* aSelectionModel = myList->selectionModel();
+ if ( !aSelectionModel ) {
+ return;
+ }
+
+ for ( int aRow = 0 ; aRow < aSourceModel->rowCount() ; aRow++ ) {
+ QModelIndex anIndex = aSourceModel->index( aRow, 0 );
+ if ( !anIndex.isValid() ) {
+ continue;
+ }
+
+ QString anEntry = aSourceModel->data( anIndex, HYDROGUI_EntryRole ).toString();
+
+ bool isToSelect = theEntries.contains( anEntry );
+ QModelIndex aProxyModelIndex = aFilterModel->mapFromSource( anIndex );
+ QItemSelectionModel::SelectionFlags aSelectionFlags =
+ isToSelect ? QItemSelectionModel::Select : QItemSelectionModel::Deselect;
+ aSelectionModel->select( aProxyModelIndex, aSelectionFlags );
+ }
+}
+
+/**
+ Slot called on top, up, down and bottom button click.
+ @param theType the move operation type
+*/
+void HYDROGUI_OrderedListWidget::onMove( int theType )
+{
+ QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+ if( aFilterModel ) {
+ HYDROGUI_ListModel* aModel = dynamic_cast<HYDROGUI_ListModel*>( 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_ListModel::OpType )theType,
+ !myIsHiddenObjectsShown );
+ }
+ }
+}
+
+/**
+ Returns the list source model.
+ @return the source model
+*/
+HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const
+{
+ HYDROGUI_ListModel* aSourceModel = 0;
+
+ QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+ if( aFilterModel ) {
+ aSourceModel = dynamic_cast<HYDROGUI_ListModel*>( aFilterModel->sourceModel() );
+ }
+
+ return aSourceModel;
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2007-2013 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_ORDEREDLISTWIDGET_H
+#define HYDROGUI_ORDEREDLISTWIDGET_H
+
+#include "HYDROGUI_ListModel.h"
+
+#include <QWidget>
+
+class QListView;
+class QToolButton;
+
+/**
+ * \class HYDROGUI_OrderedListWidget
+ * \brief The class representing widget for managing list of objects.
+ *
+ * The widget represents a list and a set of buttons (top, up, down and bottom)
+ * providing the possibility to change the list items order.
+ */
+class HYDRO_EXPORT HYDROGUI_OrderedListWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ HYDROGUI_OrderedListWidget( QWidget* theParent );
+ virtual ~HYDROGUI_OrderedListWidget();
+
+ void setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects );
+ HYDROGUI_ListModel::ObjectList getObjects() const;
+
+ void setHiddenObjectsShown( const bool theIsToShow );
+
+ QStringList getSelectedEntries() const;
+ void setSelectedEntries( const QStringList& theEntries ) const;
+
+signals:
+ void selectionChanged();
+
+private slots:
+ void onMove( int theType );
+
+private:
+ HYDROGUI_ListModel* getSourceModel() const;
+
+private:
+ QListView* myList; ///< the list view
+ QToolButton* myTop; ///< the move on top button
+ QToolButton* myUp; ///< the move up button
+ QToolButton* myDown; ///< the move down button
+ QToolButton* myBottom; ///< the move on bottom button
+
+ bool myIsHiddenObjectsShown; ///< the show hidden objects in the list indicator
+};
+
+#endif
//
#include "HYDROGUI_ZLevelsDlg.h"
-#include "HYDROGUI_ZLevelsModel.h"
-#include <SUIT_Session.h>
-#include <SUIT_ResourceMgr.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 <QToolButton>
-#include <QSignalMapper>
-#include <QSortFilterProxyModel>
/**
Constructor.
@param theParent the parent widget
*/
-HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
+HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule )
: QDialog( theParent )
{
// Dialog title
aMainLayout->setMargin( 5 );
aMainLayout->setSpacing( 5 );
- // List and buttons top, up, down, bottom
- QHBoxLayout* aListLayout = new QHBoxLayout();
-
- // list
- 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 );
-
- // buttons top, up, down, bottom
- SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
- myTop = new QToolButton;
- myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
- myTop->setIconSize( QSize( 32, 32 ) );
- myUp = new QToolButton;
- myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
- myUp->setIconSize( myTop->iconSize() );
- myDown = new QToolButton;
- myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) );
- myDown->setIconSize( myTop->iconSize() );
- myBottom = new QToolButton;
- myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) );
- myBottom->setIconSize( myTop->iconSize() );
-
- 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 );
// Apply and close buttons
- QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
myApply = new QPushButton( tr("APPLY") );
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 );
// Connections
- 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 ) ) );
-
connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
// Initialize
onStateChanged();
+
+ // Create selector
+ if ( theModule ) {
+ new HYDROGUI_ListSelector( myListWidget, theModule->getApp()->selectionMgr() );
+ }
}
/**
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_ZLevelsModel::Object2VisibleList& theObjects )
+void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
{
- HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
- if( aModel ) {
- aModel->setObjects( theObjects );
- }
+ myListWidget->setObjects( theObjects );
}
/**
*/
QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
{
- QList<Handle(HYDROData_Entity)> anObjects;
-
- HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
- if( aModel ) {
- anObjects = aModel->getObjects();
- }
-
- return anObjects;
-}
-
-/**
- Slot called on top, up, down and bottom button click.
- @param theType the move operation type
-*/
-void HYDROGUI_ZLevelsDlg::onMove( int theType )
-{
- 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()
{
- QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
bool isAll = myAllObjects->isChecked();
- QString anExpr = isAll ? "true|false" : "true";
- aFilterModel->setFilterRegExp( anExpr );
+ myListWidget->setHiddenObjectsShown( isAll );
}
-
-/**
- Returns the list source model.
- @return the source model
-*/
-HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const
-{
- HYDROGUI_ZLevelsModel* aSourceModel = 0;
-
- QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
- if( aFilterModel ) {
- aSourceModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
- }
-
- return aSourceModel;
-}
\ No newline at end of file
#ifndef HYDROGUI_ZLEVELSPANEL_H
#define HYDROGUI_ZLEVELSPANEL_H
-#include "HYDROGUI_ZLevelsModel.h"
+#include "HYDROGUI_ListModel.h"
#include <QDialog>
+class HYDROGUI_OrderedListWidget;
+class HYDROGUI_Module;
+
class QCheckBox;
-class QListView;
class QPushButton;
-class QToolButton;
+
/**
* \class HYDROGUI_ZLevelsDlg
- * \brief The class representing widget for managing Z levels
+ * \brief The class representing dialog for managing Z levels
*/
class HYDRO_EXPORT HYDROGUI_ZLevelsDlg : public QDialog
{
Q_OBJECT
public:
- HYDROGUI_ZLevelsDlg( QWidget* theParent );
+ HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule );
virtual ~HYDROGUI_ZLevelsDlg();
- void setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects );
- HYDROGUI_ZLevelsModel::ObjectList getObjects() const;
+ void setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects );
+ HYDROGUI_ListModel::ObjectList getObjects() const;
signals:
void applyOrder();
private slots:
- void onMove( int theType );
void onStateChanged();
private:
- HYDROGUI_ZLevelsModel* getListSourceModel() const;
-
-private:
- QListView* myList;
- QToolButton* myTop;
- QToolButton* myUp;
- QToolButton* myDown;
- QToolButton* myBottom;
- QCheckBox* myAllObjects;
- QPushButton* myApply;
- QPushButton* myClose;
+ HYDROGUI_OrderedListWidget* myListWidget; ///< the ordered list widget
+ QCheckBox* myAllObjects; ///< the show all objects button
+ QPushButton* myApply; ///< the apply changes button
+ QPushButton* myClose; ///< the close dialog button
};
#endif
+++ /dev/null
-// Copyright (C) 2007-2013 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.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#include "HYDROGUI_ZLevelsModel.h"
-
-#include <SUIT_Session.h>
-#include <SUIT_ResourceMgr.h>
-
-#include <QMimeData>
-
-const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list";
-
-
-/**
- Constructor.
- @param theParent the parent object
-*/
-HYDROGUI_ZLevelsModel::HYDROGUI_ZLevelsModel( QObject* theParent )
- : QAbstractListModel( theParent )
-{
- // Get resource manager
- SUIT_ResourceMgr* aResMgr = 0;
- SUIT_Session* aSession = SUIT_Session::session();
- if ( aSession ) {
- aResMgr = SUIT_Session::session()->resourceMgr();
- }
-
- // Define eye icon and empty icon
- myEmpty = QPixmap( 16, 16 );
- myEmpty.fill( Qt::white );
- if ( aResMgr ) {
- myEye = aResMgr->loadPixmap( "HYDRO", tr( "EYE_ICO" ) );
- } else {
- myEye = QPixmap( 16, 16 );
- myEye.fill( Qt::black );
- }
-
- // Set the supported drag actions for the items in the model
- setSupportedDragActions( Qt::MoveAction | Qt::CopyAction );
-}
-
-/**
- Destructor.
-*/
-HYDROGUI_ZLevelsModel::~HYDROGUI_ZLevelsModel()
-{
-}
-
-/**
-*/
-QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) const
-{
- QVariant aVariant;
-
- int aRow = theIndex.row();
- int aColumn = theIndex.column();
-
- switch( theRole )
- {
- case Qt::DisplayRole:
- {
- if( aColumn==0 && aRow >=0 && aRow < myObjects.count() )
- return myObjects.at( aRow ).first->GetName();
- else
- return QVariant();
- }
- break;
-
- case Qt::DecorationRole:
- {
- if( aColumn==0 && aRow >=0 && aRow < myObjects.count() )
- {
- bool isVisible = isObjectVisible( aRow );
- if( isVisible )
- return myEye;
- else
- return myEmpty;
- }
- return QVariant();
- }
- break;
-
- case HYDROGUI_VisibleRole:
- {
- bool isVisible = isObjectVisible( aRow );
- return QVariant( isVisible ).toString();
- }
- break;
- }
-
- return aVariant;
-}
-
-/**
-*/
-int HYDROGUI_ZLevelsModel::rowCount( const QModelIndex &theParent ) const
-{
- return myObjects.count();
-}
-
-/**
- Set objects list.
- @param theObjects the list of pairs (object; object visibility)
-*/
-void HYDROGUI_ZLevelsModel::setObjects( const Object2VisibleList& theObjects )
-{
- myObjects = theObjects;
-
- reset();
-}
-
-/**
- Get objects list.
- @return the list of objects ordered according to the model
-*/
-HYDROGUI_ZLevelsModel::ObjectList HYDROGUI_ZLevelsModel::getObjects() const
-{
- ObjectList anObjects;
-
- foreach( const Object2Visible& anItem, myObjects ) {
- anObjects << anItem.first;
- }
-
- return anObjects;
-}
-
-/**
- Check if the object is visible.
- @param theIndex the object index
- @return true if the object is visible, false - otherwise
-*/
-bool HYDROGUI_ZLevelsModel::isObjectVisible( int theIndex ) const
-{
- bool isVisible = false;
-
- if ( theIndex >= 0 && theIndex < myObjects.count() ) {
- isVisible = myObjects.at( theIndex ).second;
- }
-
- return isVisible;
-}
-
-/**
-*/
-QVariant HYDROGUI_ZLevelsModel::headerData( int theSection,
- Qt::Orientation theOrientation,
- int theRole ) const
-{
- if( theOrientation==Qt::Horizontal && theRole==Qt::DisplayRole )
- {
- switch( theSection )
- {
- case 0:
- return tr( "VISIBLE" );
- case 1:
- return tr( "OBJECT_NAME" );
- };
- }
- return QVariant();
-}
-
-/**
-*/
-Qt::ItemFlags HYDROGUI_ZLevelsModel::flags( const QModelIndex& theIndex ) const
-{
- Qt::ItemFlags aDefaultFlags = QAbstractListModel::flags( theIndex );
- if( theIndex.isValid() )
- return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | aDefaultFlags;
- else
- return Qt::ItemIsDropEnabled | aDefaultFlags;
-}
-
-/**
-*/
-QMimeData* HYDROGUI_ZLevelsModel::mimeData( const QModelIndexList& theIndexes ) const
-{
- QMimeData* aMimeData = new QMimeData();
- QByteArray anEncodedData;
- QDataStream aStream( &anEncodedData, QIODevice::WriteOnly );
-
- QList<int> anIdsList = getIds( theIndexes );
- foreach( int anId, anIdsList )
- aStream << anId;
-
- aMimeData->setData( OBJ_LIST_MIME_TYPE, anEncodedData );
- return aMimeData;
-}
-
-/**
-*/
-QStringList HYDROGUI_ZLevelsModel::mimeTypes() const
-{
- QStringList aTypes;
- aTypes << OBJ_LIST_MIME_TYPE;
- return aTypes;
-}
-
-/**
-*/
-bool HYDROGUI_ZLevelsModel::dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
- int theRow, int theColumn, const QModelIndex& theParent )
-{
- if( theAction == Qt::IgnoreAction)
- return true;
-
- if( !theData->hasFormat( OBJ_LIST_MIME_TYPE ))
- return false;
-
- if( theColumn > 0 )
- return false;
-
- int aDropItemId = theParent.row();
-
- QByteArray anEncodedData = theData->data( OBJ_LIST_MIME_TYPE );
- QDataStream aStream( &anEncodedData, QIODevice::ReadOnly );
- QList<int> anIdsList;
- while( !aStream.atEnd() )
- {
- int anId;
- aStream >> anId;
- anIdsList << anId;
- }
- qSort( anIdsList ); // TODO should be moved?
- move( anIdsList, DragAndDrop, false, aDropItemId ); //TODO set visibility?
- return true;
-}
-
-/**
-*/
-Qt::DropActions HYDROGUI_ZLevelsModel::supportedDropActions() const
-{
- return Qt::MoveAction | Qt::CopyAction;
-}
-
-/**
- Get list of ids by the list model indexes.
- @param theIsToSort defines if the list of ids should be sorted in ascending order
- @return the list of ids
-*/
-QList<int> HYDROGUI_ZLevelsModel::getIds( const QModelIndexList& theIndexes, bool theIsToSort ) const
-{
- QList<int> anIds;
- foreach( const QModelIndex& anIndex, theIndexes ) {
- anIds << anIndex.row();
- }
-
- if ( theIsToSort ) {
- qSort( anIds );
- }
-
- return anIds;
-}
-
-/**
- Move the item.
- @param theItem the item id to move
- @param theType the move operation type
- @param theIsVisibleOnly indicates if do move relating to the visible objects only
- @param theDropItem the drop item id ( used for drag and drop obly )
- @return true in case of success
-*/
-bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType,
- bool theIsVisibleOnly, const int theDropItem )
-{
- bool aRes = false;
- if ( theItem < 0 || theItem >= myObjects.count() ) {
- return aRes;
- }
-
- int aDestinationIndex = -1;
- bool isInsertBefore = false;
-
- switch ( theType ) {
- case Up:
- isInsertBefore = true;
- if ( theItem > 0 ) {
- aDestinationIndex = theItem - 1;
- if ( theIsVisibleOnly ) {
- while ( aDestinationIndex >= 0 && !isObjectVisible( aDestinationIndex ) ) {
- aDestinationIndex--;
- }
- }
- }
- break;
- case Down:
- if ( theItem < myObjects.count() - 1 ) {
- aDestinationIndex = theItem + 1;
- if ( theIsVisibleOnly ) {
- while ( aDestinationIndex < myObjects.count() && !isObjectVisible( aDestinationIndex ) ) {
- aDestinationIndex++;
- }
- }
- }
- break;
- case Top:
- isInsertBefore = true;
- if ( theItem > 0 ) {
- aDestinationIndex = 0;
- }
- break;
- case Bottom:
- if ( theItem < myObjects.count() - 1 ) {
- aDestinationIndex = myObjects.count() - 1;
- }
- break;
- case DragAndDrop:
- if ( theItem > theDropItem ) {
- isInsertBefore = true;
- aDestinationIndex = theDropItem;
- } else {
- aDestinationIndex = theDropItem - 1;
- }
- break;
- }
-
- if ( aDestinationIndex >= 0 && aDestinationIndex < myObjects.count() ) {
- int aDestinationRow = isInsertBefore ? aDestinationIndex : aDestinationIndex + 1;
- if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestinationRow ) ) {
- myObjects.move( theItem, aDestinationIndex );
- endMoveRows();
- aRes = true;
- }
- }
-
- return aRes;
-}
-
-/**
- Move the items.
- @param theItems the list of item ids to move
- @param theType the move operation type
- @param theIsVisibleOnly indicates if do move relating to the visible objects only
- @param theDropItem the drop item id ( used for drag and drop obly )
- @return true in case of success
-*/
-bool HYDROGUI_ZLevelsModel::move( const QList<int>& theItems, const OpType theType,
- bool theIsVisibleOnly, const int theDropItem )
-{
- bool aRes = true;
-
- QListIterator<int> anIt( theItems );
- int aDragShift = 0;
-
- switch ( theType ) {
- case Top:
- case Down:
- // reverse order
- anIt.toBack();
- while ( anIt.hasPrevious() ) {
- int anId = anIt.previous();
- if ( theType == Top ) {
- anId += aDragShift;
- aDragShift++;
- }
- if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
- aRes = false;
- break;
- }
- }
- break;
- case Bottom:
- case Up:
- // direct order
- while ( anIt.hasNext() ) {
- int anId = anIt.next();
- if ( theType == Bottom ) {
- anId -= aDragShift;
- aDragShift++;
- }
- if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
- aRes = false;
- break;
- }
- }
- break;
- case DragAndDrop:
- // direct order
- aRes = isDragAndDropAllowed( theItems, theDropItem );
- if ( aRes ) {
- int aDropShift = 0;
- int aDropItem = theDropItem;
- while ( anIt.hasNext() ) {
- int anId = anIt.next();
- aDropItem = theDropItem + aDropShift;
- if ( anId > aDropItem ) {
- aDragShift = 0;
- aDropShift++;
- } else {
- anId -= aDragShift;
- if ( ( aDropItem - anId ) != 1 ) {
- aDragShift++;
- }
- }
- move( anId, theType, theIsVisibleOnly, aDropItem );
- }
- }
- break;
- default:
- aRes = false;
- }
-
- return aRes;
-}
-
-/**
- Check if drag and drop operation allowed.
- @param theItems the list of dragged item ids
- @param theDropItem the drop item id
- @return true if drag and drop allowed
-*/
-bool HYDROGUI_ZLevelsModel::isDragAndDropAllowed( const QList<int>& theItems,
- const int theDropItem ) const
-{
- bool isAllowed = false;
-
- if ( theDropItem >= 0 && theDropItem < myObjects.count() &&
- !theItems.empty() && theItems.count() < myObjects.count() &&
- !theItems.contains( theDropItem )) {
- isAllowed = true;
- }
-
- return isAllowed;
-}
+++ /dev/null
-// Copyright (C) 2007-2013 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.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#ifndef HYDROGUI_ZLEVELSMODEL_H
-#define HYDROGUI_ZLEVELSMODEL_H
-
-#include <HYDROGUI.h>
-#include <HYDROData_Entity.h>
-#include <QAbstractListModel>
-#include <QPixmap>
-
-const int HYDROGUI_VisibleRole = Qt::UserRole + 1;
-
-/**
- * \class HYDROGUI_ZLevelsModel
- * \brief The class representing custom list model for the Z levels
- */
-class HYDRO_EXPORT HYDROGUI_ZLevelsModel : public QAbstractListModel
-{
- Q_OBJECT
-
-public:
- enum OpType { Top, Up, Down, Bottom, DragAndDrop };
-
- typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
- typedef QList<Object2Visible> Object2VisibleList;
- typedef QList<Handle(HYDROData_Entity)> ObjectList;
-
-public:
- HYDROGUI_ZLevelsModel( QObject* theParent = 0 );
- virtual ~HYDROGUI_ZLevelsModel();
-
- virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;
-
- virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
-
- virtual QVariant headerData( int theSection,
- Qt::Orientation theOrientation,
- int theRole = Qt::DisplayRole ) const;
- virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const;
- virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const;
- virtual QStringList mimeTypes() const;
- virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
- int theRow, int theColumn, const QModelIndex& theParent );
- virtual Qt::DropActions supportedDropActions() const;
-
- QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
-
- void setObjects( const Object2VisibleList& theObjects );
- ObjectList getObjects() const;
-
- bool move( const int theItem, const OpType theType, bool theIsVisibleOnly,
- const int theDropItem = -1 );
- bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
- const int theDropItem = -1 );
-
-protected:
- bool isObjectVisible( int theIndex ) const;
- bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
-
-private:
- friend class test_HYDROGUI_ZLevelsModel;
-
- Object2VisibleList myObjects;
- QPixmap myEmpty, myEye;
-};
-
-#endif
\ No newline at end of file
#include "HYDROGUI_Module.h"
#include "HYDROGUI_Tool.h"
#include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_ListSelector.h"
#include <HYDROData_Entity.h>
HYDROGUI_Operation::startOperation();
// Prepare the list of objects
- HYDROGUI_ZLevelsModel::Object2VisibleList anObject2VisibleList;
+ HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
// get the document
Handle(HYDROData_Document) aDoc = doc();
Handle(HYDROData_Entity) anObject = anIter.Value();
if ( !anObject.IsNull() ) {
bool isVisible = module()->isObjectVisible( anActiveOCCViewId, anObject );
- anObject2VisibleList << HYDROGUI_ZLevelsModel::Object2Visible( anObject, isVisible );
+ anObject2VisibleList << HYDROGUI_ListModel::Object2Visible( anObject, isVisible );
}
}
}
// Show the dialog
- myZLevelsDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop() );
- myZLevelsDlg->setModal( true );
+ if ( !myZLevelsDlg ) {
+ //TODO: delete dialog each time?
+ myZLevelsDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop(), module() );
+ connect( myZLevelsDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) );
+ connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+ }
myZLevelsDlg->setObjects( anObject2VisibleList );
- //TODO: check
- connect( myZLevelsDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) );
- connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
-
myZLevelsDlg->exec();
}
if ( myZLevelsDlg ) {
Handle(HYDROData_Document) aDoc = doc();
if( !aDoc.IsNull() ) {
- HYDROGUI_ZLevelsModel::ObjectList anObjects = myZLevelsDlg->getObjects();
+ HYDROGUI_ListModel::ObjectList anObjects = myZLevelsDlg->getObjects();
HYDROData_SequenceOfObjects anOrderedObjects;
foreach ( const Handle(HYDROData_Entity) anObject, anObjects ) {
anOrderedObjects.Append( anObject );
--- /dev/null
+
+#undef HYDROGUI_EXPORTS
+
+#include <test_HYDROGUI_ListModel.h>
+#include <HYDROData_Document.h>
+#include <HYDROGUI_ListModel.h>
+
+Handle_HYDROData_Document GetDocument()
+{
+ return HYDROData_Document::Document( 0 );
+}
+
+HYDROGUI_ListModel::Object2VisibleList CreateTestObjects( int theObjCount )
+{
+ HYDROGUI_ListModel::Object2VisibleList anObjects;
+
+ for( int i=0; i<theObjCount; i++ )
+ {
+ Handle_HYDROData_Entity anObj = GetDocument()->CreateObject( KIND_IMMERSIBLE_ZONE );
+
+ std::string aName = " ";
+ aName[0] = 'A' + i;
+ anObj->SetName( QString::fromStdString( aName ) );
+
+ bool isVisible = i%2==0;
+
+ anObjects.append( HYDROGUI_ListModel::Object2Visible( anObj, isVisible ) );
+ }
+ return anObjects;
+}
+
+std::string test_HYDROGUI_ListModel::GetObjects( HYDROGUI_ListModel* theModel ) const
+{
+ std::string anObjects;
+ for( int i=0, n=theModel->myObjects.size(); i<n; i++ )
+ {
+ std::string anObjName = theModel->myObjects[i].first->GetName().toStdString();
+ if( theModel->isObjectVisible( i ) )
+ anObjName = "*" + anObjName;
+ if( i>0 )
+ anObjects += ", ";
+ anObjects += anObjName;
+ }
+ return anObjects;
+}
+
+/**
+ Test move up algorithm.
+*/
+void test_HYDROGUI_ListModel::testMoveUp()
+{
+ HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel();
+ aModel->setObjects( CreateTestObjects( 6 ) );
+ const HYDROGUI_ListModel::OpType anUp = HYDROGUI_ListModel::Up;
+
+ // 0. Check the initial state
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 1. [ *A ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 2. [ *A, B ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 3. [ *A, *C ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 2, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 4. [ *A, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 5, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 5. [ F ] X 6 times / ALL OBJECTS
+ aModel->move( QList<int>() << 5, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, F, *E" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 4, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, F, D, *E" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 3, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 2, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, B, *C, D, *E" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 1, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 0, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) );
+
+ // 6. [ *A, B ] / ALL OBJECTS
+ aModel->move( QList<int>() << 1 << 2, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) );
+
+ // 7. [ B, *C, *E ] / ALL OBJECTS
+ aModel->move( QList<int>() << 1 << 3 << 5, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, F, *E, D" ), GetObjects( aModel ) );
+
+ // 8. [ *A, *C, F, *E, D ] / ALL OBJECTS
+ aModel->move( QList<int>() << 1 << 2 << 3 << 4 << 5, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, F, *E, D, B" ), GetObjects( aModel ) );
+
+ // 9. [ *E ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 3, anUp, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, *E, *C, F, D, B" ), GetObjects( aModel ) );
+
+ // 10. [ *E, *C ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 1 << 2, anUp, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, *A, F, D, B" ), GetObjects( aModel ) );
+
+ // 11. [ *A, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 2 << 3, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, *C, D, B" ), GetObjects( aModel ) );
+
+ // 12. [ *A, *C ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 1 << 3, anUp, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B" ), GetObjects( aModel ) );
+
+ // 13. [] / ALL OBJECTS
+ aModel->move( QList<int>(), anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) );
+
+ // 14. [ *A, *C, *E, F, D, B ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, anUp, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) );
+
+ delete aModel;
+}
+
+/**
+ Test move on top algorithm.
+*/
+void test_HYDROGUI_ListModel::testMoveOnTop()
+{
+ HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel();
+ aModel->setObjects( CreateTestObjects( 6 ) );
+ const HYDROGUI_ListModel::OpType aTop = HYDROGUI_ListModel::Top;
+
+ // 0. Check the initial state
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 1. [ *A ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 2. [ *A ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 0, aTop, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 3. [ F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 5, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) );
+
+ // 4. [ *E ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 5, aTop, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) );
+
+ // 5. [ *E, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) );
+
+ // 6. [ *E, *A ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 2, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, B, *C, D" ), GetObjects( aModel ) );
+
+ // 7. [ *A, F, *C ] / ALL OBJECTS
+ aModel->move( QList<int>() << 1 << 2 << 4, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *C, *E, B, D" ), GetObjects( aModel ) );
+
+ // 8. [ F, *C, *E, B, D ] / ALL OBJECTS
+ aModel->move( QList<int>() << 1 << 2 << 3 << 4 << 5, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) );
+
+ // 9. [] / ALL OBJECTS
+ aModel->move( QList<int>(), aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) );
+
+ // 10. [*F, *C, *E, B, D, *A] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, aTop, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) );
+
+ delete aModel;
+}
+
+/**
+ Test move down algorithm.
+*/
+void test_HYDROGUI_ListModel::testMoveDown()
+{
+ HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel();
+ aModel->setObjects( CreateTestObjects( 6 ) );
+ const HYDROGUI_ListModel::OpType aDown = HYDROGUI_ListModel::Down;
+
+ // 0. Check the initial state
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 1. [ F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 5, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 2. [ *E, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 4 << 5, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 3. [ D, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 3 << 5, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 4. [ *A, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 5, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 5. [ *A ] X 6 times / ALL OBJECTS
+ aModel->move( QList<int>() << 0, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, D, *E, F" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 1, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *A, D, *E, F" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 2, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 3, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, *A, F" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 4, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) );
+ aModel->move( QList<int>() << 5, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) );
+
+ // 6. [ *E, *F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 3 << 4, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) );
+
+ // 7. [ B, D, *E ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 2 << 4, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*C, B, *A, D, F, *E" ), GetObjects( aModel ) );
+
+ // 8. [ *C, B, *A, D, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, B, *A, D, F" ), GetObjects( aModel ) );
+
+ // 9. [ *C ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 1, aDown, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, B, *A, *C, D, F" ), GetObjects( aModel ) );
+
+ // 10. [ *E, *A ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 0 << 2, aDown, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) );
+
+ // 11. [ *E, *A ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 2 << 3, aDown, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) );
+
+ // 12. [ *C, *E, *A ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 1 << 2 << 3, aDown, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) );
+
+ // 13. [] / ALL OBJECTS
+ aModel->move( QList<int>(), aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) );
+
+ // 14. [ B, *C, *E, *A, D, F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, aDown, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) );
+
+ delete aModel;
+}
+
+/**
+ Test move on bottom algorithm.
+*/
+void test_HYDROGUI_ListModel::testMoveOnBottom()
+{
+ HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel();
+ aModel->setObjects( CreateTestObjects( 6 ) );
+ const HYDROGUI_ListModel::OpType aBottom = HYDROGUI_ListModel::Bottom;
+
+ // 0. Check the initial state
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 1. [ F ] / ALL OBJECTS
+ aModel->move( QList<int>() << 5, aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 2. [ F ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 5, aBottom, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
+
+ // 3. [ *A ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0, aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) );
+
+ // 4. [ *C ] / VISIBLE OBJECTS
+ aModel->move( QList<int>() << 1, aBottom, true );
+ CPPUNIT_ASSERT_EQUAL( std::string( "B, D, *E, F, *A, *C" ), GetObjects( aModel ) );
+
+ // 5. [ B, D ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1, aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *C, B, D" ), GetObjects( aModel ) );
+
+ // 6. [ *C, *D ] / ALL OBJECTS
+ aModel->move( QList<int>() << 3 << 5, aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) );
+
+ // 7. [ *E, *A, *C ] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 2 << 4, aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, B, D, *E, *A, *C" ), GetObjects( aModel ) );
+
+ // 8. [ B, D, *E, *A ] / ALL OBJECTS
+ aModel->move( QList<int>() << 1 << 2 << 3 << 4 , aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) );
+
+ // 9. [] / ALL OBJECTS
+ aModel->move( QList<int>(), aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) );
+
+ // 10. [F, *C, B, D, *E, *A] / ALL OBJECTS
+ aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, aBottom, false );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) );
+
+ delete aModel;
+}
+
+/**
+ Test drag and drop algorithm.
+*/
+void test_HYDROGUI_ListModel::testDragAndDrop()
+{
+ HYDROGUI_ListModel* aModel = new HYDROGUI_ListModel();
+ aModel->setObjects( CreateTestObjects( 8 ) );
+ const HYDROGUI_ListModel::OpType aDnD = HYDROGUI_ListModel::DragAndDrop;
+
+ // 0. Check the initial state
+ std::string anInitialState = std::string( "*A, B, *C, D, *E, F, *G, H" );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 1. [] -> B ( i=1 )
+ bool aRes = aModel->move( QList<int>(), aDnD, false, 1 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 2. ALL -> B ( i=1 )
+ QList<int> anAll;
+ anAll << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7;
+ aRes = aModel->move( anAll, aDnD, false, 1 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 3. [D, *E, *G] -> D : drop item is among dragged items ( at the beginning )
+ aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 3 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 4. [D, *E, *G] -> *E : drop item is among dragged items ( in the middle )
+ aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 4 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 5. [D, *E, *G] -> *G : drop item is among dragged items ( at the end )
+ aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 6 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 6. [D, *E, *G] -> -1 : drop item index is out of range ( less than zero )
+ aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, -1 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 7. [D, *E, *G] -> -1 : drop item index is out of range ( more than than (list length - 1) )
+ aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 8 );
+ CPPUNIT_ASSERT_EQUAL( false, aRes );
+ CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+ // 8. [D, *E, *G] -> B ( i = 1 )
+ aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 1 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, *G, B, *C, F, H" ), GetObjects( aModel ) );
+
+ // 9. [*E, F] -> *G
+ aRes = aModel->move( QList<int>() << 2 << 6, aDnD, false, 3 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, F, *G, B, *C, H" ), GetObjects( aModel ) );
+
+ // 10. [*E, F, *G] -> *A
+ aRes = aModel->move( QList<int>() << 2 << 3 << 4, aDnD, false, 0 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *G, *A, D, B, *C, H" ), GetObjects( aModel ) );
+
+ // 11. [*G, D, *C, H] -> B
+ aRes = aModel->move( QList<int>() << 2 << 4 << 6 << 7, aDnD, false, 5 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *G, D, *C, H, B" ), GetObjects( aModel ) );
+
+ // 12. [F, *A, *G, D, *C, H, B] -> *E
+ QList<int> anAllWithoutFirst;
+ anAllWithoutFirst << 1 << 2 << 3 << 4 << 5 << 6 << 7;
+ aRes = aModel->move( anAllWithoutFirst, aDnD, false, 0 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
+
+ // 13. [*A, *G] -> D : no changes
+ aRes = aModel->move( QList<int>() << 1 << 2, aDnD, false, 3 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
+
+ // 14. [F, *G] -> D
+ aRes = aModel->move( QList<int>() << 0 << 2, aDnD, false, 3 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
+
+ // 15. [*A, *G, *C, H, *E] -> D
+ aRes = aModel->move( QList<int>() << 0 << 2 << 4 << 5 << 7, aDnD, false, 3 );
+ CPPUNIT_ASSERT_EQUAL( true, aRes );
+ CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, *C, H, *E, D, B" ), GetObjects( aModel ) );
+}
\ No newline at end of file
--- /dev/null
+#include <cppunit/extensions/HelperMacros.h>
+
+class HYDROGUI_ListModel;
+
+class test_HYDROGUI_ListModel : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(test_HYDROGUI_ListModel);
+ CPPUNIT_TEST(testMoveUp);
+ CPPUNIT_TEST(testMoveOnTop);
+ CPPUNIT_TEST(testMoveDown);
+ CPPUNIT_TEST(testMoveOnBottom);
+ CPPUNIT_TEST(testDragAndDrop);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ std::string GetObjects( HYDROGUI_ListModel* theModel ) const;
+
+public:
+ void testMoveUp();
+ void testMoveOnTop();
+ void testMoveDown();
+ void testMoveOnBottom();
+ void testDragAndDrop();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ListModel);
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_ListModel, "HYDROGUI_ListModel");
+++ /dev/null
-
-#undef HYDROGUI_EXPORTS
-
-#include <test_HYDROGUI_ZLevelsModel.h>
-#include <HYDROData_Document.h>
-#include <HYDROGUI_ZLevelsModel.h>
-
-Handle_HYDROData_Document GetDocument()
-{
- return HYDROData_Document::Document( 0 );
-}
-
-HYDROGUI_ZLevelsModel::Object2VisibleList CreateTestObjects( int theObjCount )
-{
- HYDROGUI_ZLevelsModel::Object2VisibleList anObjects;
-
- for( int i=0; i<theObjCount; i++ )
- {
- Handle_HYDROData_Entity anObj = GetDocument()->CreateObject( KIND_IMMERSIBLE_ZONE );
-
- std::string aName = " ";
- aName[0] = 'A' + i;
- anObj->SetName( QString::fromStdString( aName ) );
-
- bool isVisible = i%2==0;
-
- anObjects.append( HYDROGUI_ZLevelsModel::Object2Visible( anObj, isVisible ) );
- }
- return anObjects;
-}
-
-std::string test_HYDROGUI_ZLevelsModel::GetObjects( HYDROGUI_ZLevelsModel* theModel ) const
-{
- std::string anObjects;
- for( int i=0, n=theModel->myObjects.size(); i<n; i++ )
- {
- std::string anObjName = theModel->myObjects[i].first->GetName().toStdString();
- if( theModel->isObjectVisible( i ) )
- anObjName = "*" + anObjName;
- if( i>0 )
- anObjects += ", ";
- anObjects += anObjName;
- }
- return anObjects;
-}
-
-/**
- Test move up algorithm.
-*/
-void test_HYDROGUI_ZLevelsModel::testMoveUp()
-{
- HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
- aModel->setObjects( CreateTestObjects( 6 ) );
- const HYDROGUI_ZLevelsModel::OpType anUp = HYDROGUI_ZLevelsModel::Up;
-
- // 0. Check the initial state
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 1. [ *A ] / ALL OBJECTS
- aModel->move( QList<int>() << 0, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 2. [ *A, B ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 3. [ *A, *C ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 2, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 4. [ *A, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 5, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 5. [ F ] X 6 times / ALL OBJECTS
- aModel->move( QList<int>() << 5, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, F, *E" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 4, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, F, D, *E" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 3, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 2, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, B, *C, D, *E" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 1, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 0, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) );
-
- // 6. [ *A, B ] / ALL OBJECTS
- aModel->move( QList<int>() << 1 << 2, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) );
-
- // 7. [ B, *C, *E ] / ALL OBJECTS
- aModel->move( QList<int>() << 1 << 3 << 5, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, F, *E, D" ), GetObjects( aModel ) );
-
- // 8. [ *A, *C, F, *E, D ] / ALL OBJECTS
- aModel->move( QList<int>() << 1 << 2 << 3 << 4 << 5, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, F, *E, D, B" ), GetObjects( aModel ) );
-
- // 9. [ *E ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 3, anUp, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, *E, *C, F, D, B" ), GetObjects( aModel ) );
-
- // 10. [ *E, *C ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 1 << 2, anUp, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, *A, F, D, B" ), GetObjects( aModel ) );
-
- // 11. [ *A, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 2 << 3, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, *C, D, B" ), GetObjects( aModel ) );
-
- // 12. [ *A, *C ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 1 << 3, anUp, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B" ), GetObjects( aModel ) );
-
- // 13. [] / ALL OBJECTS
- aModel->move( QList<int>(), anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) );
-
- // 14. [ *A, *C, *E, F, D, B ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, anUp, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) );
-
- delete aModel;
-}
-
-/**
- Test move on top algorithm.
-*/
-void test_HYDROGUI_ZLevelsModel::testMoveOnTop()
-{
- HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
- aModel->setObjects( CreateTestObjects( 6 ) );
- const HYDROGUI_ZLevelsModel::OpType aTop = HYDROGUI_ZLevelsModel::Top;
-
- // 0. Check the initial state
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 1. [ *A ] / ALL OBJECTS
- aModel->move( QList<int>() << 0, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 2. [ *A ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 0, aTop, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 3. [ F ] / ALL OBJECTS
- aModel->move( QList<int>() << 5, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) );
-
- // 4. [ *E ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 5, aTop, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) );
-
- // 5. [ *E, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) );
-
- // 6. [ *E, *A ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 2, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, B, *C, D" ), GetObjects( aModel ) );
-
- // 7. [ *A, F, *C ] / ALL OBJECTS
- aModel->move( QList<int>() << 1 << 2 << 4, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *C, *E, B, D" ), GetObjects( aModel ) );
-
- // 8. [ F, *C, *E, B, D ] / ALL OBJECTS
- aModel->move( QList<int>() << 1 << 2 << 3 << 4 << 5, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) );
-
- // 9. [] / ALL OBJECTS
- aModel->move( QList<int>(), aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) );
-
- // 10. [*F, *C, *E, B, D, *A] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, aTop, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) );
-
- delete aModel;
-}
-
-/**
- Test move down algorithm.
-*/
-void test_HYDROGUI_ZLevelsModel::testMoveDown()
-{
- HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
- aModel->setObjects( CreateTestObjects( 6 ) );
- const HYDROGUI_ZLevelsModel::OpType aDown = HYDROGUI_ZLevelsModel::Down;
-
- // 0. Check the initial state
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 1. [ F ] / ALL OBJECTS
- aModel->move( QList<int>() << 5, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 2. [ *E, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 4 << 5, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 3. [ D, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 3 << 5, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 4. [ *A, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 5, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 5. [ *A ] X 6 times / ALL OBJECTS
- aModel->move( QList<int>() << 0, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, D, *E, F" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 1, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *A, D, *E, F" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 2, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 3, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, *A, F" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 4, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) );
- aModel->move( QList<int>() << 5, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) );
-
- // 6. [ *E, *F ] / ALL OBJECTS
- aModel->move( QList<int>() << 3 << 4, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) );
-
- // 7. [ B, D, *E ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 2 << 4, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*C, B, *A, D, F, *E" ), GetObjects( aModel ) );
-
- // 8. [ *C, B, *A, D, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, B, *A, D, F" ), GetObjects( aModel ) );
-
- // 9. [ *C ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 1, aDown, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, B, *A, *C, D, F" ), GetObjects( aModel ) );
-
- // 10. [ *E, *A ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 0 << 2, aDown, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) );
-
- // 11. [ *E, *A ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 2 << 3, aDown, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) );
-
- // 12. [ *C, *E, *A ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 1 << 2 << 3, aDown, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) );
-
- // 13. [] / ALL OBJECTS
- aModel->move( QList<int>(), aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) );
-
- // 14. [ B, *C, *E, *A, D, F ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, aDown, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) );
-
- delete aModel;
-}
-
-/**
- Test move on bottom algorithm.
-*/
-void test_HYDROGUI_ZLevelsModel::testMoveOnBottom()
-{
- HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
- aModel->setObjects( CreateTestObjects( 6 ) );
- const HYDROGUI_ZLevelsModel::OpType aBottom = HYDROGUI_ZLevelsModel::Bottom;
-
- // 0. Check the initial state
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 1. [ F ] / ALL OBJECTS
- aModel->move( QList<int>() << 5, aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 2. [ F ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 5, aBottom, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) );
-
- // 3. [ *A ] / ALL OBJECTS
- aModel->move( QList<int>() << 0, aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) );
-
- // 4. [ *C ] / VISIBLE OBJECTS
- aModel->move( QList<int>() << 1, aBottom, true );
- CPPUNIT_ASSERT_EQUAL( std::string( "B, D, *E, F, *A, *C" ), GetObjects( aModel ) );
-
- // 5. [ B, D ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1, aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *C, B, D" ), GetObjects( aModel ) );
-
- // 6. [ *C, *D ] / ALL OBJECTS
- aModel->move( QList<int>() << 3 << 5, aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) );
-
- // 7. [ *E, *A, *C ] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 2 << 4, aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, B, D, *E, *A, *C" ), GetObjects( aModel ) );
-
- // 8. [ B, D, *E, *A ] / ALL OBJECTS
- aModel->move( QList<int>() << 1 << 2 << 3 << 4 , aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) );
-
- // 9. [] / ALL OBJECTS
- aModel->move( QList<int>(), aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) );
-
- // 10. [F, *C, B, D, *E, *A] / ALL OBJECTS
- aModel->move( QList<int>() << 0 << 1 << 2 << 3 << 4 << 5, aBottom, false );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) );
-
- delete aModel;
-}
-
-/**
- Test drag and drop algorithm.
-*/
-void test_HYDROGUI_ZLevelsModel::testDragAndDrop()
-{
- HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
- aModel->setObjects( CreateTestObjects( 8 ) );
- const HYDROGUI_ZLevelsModel::OpType aDnD = HYDROGUI_ZLevelsModel::DragAndDrop;
-
- // 0. Check the initial state
- std::string anInitialState = std::string( "*A, B, *C, D, *E, F, *G, H" );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 1. [] -> B ( i=1 )
- bool aRes = aModel->move( QList<int>(), aDnD, false, 1 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 2. ALL -> B ( i=1 )
- QList<int> anAll;
- anAll << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7;
- aRes = aModel->move( anAll, aDnD, false, 1 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 3. [D, *E, *G] -> D : drop item is among dragged items ( at the beginning )
- aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 3 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 4. [D, *E, *G] -> *E : drop item is among dragged items ( in the middle )
- aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 4 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 5. [D, *E, *G] -> *G : drop item is among dragged items ( at the end )
- aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 6 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 6. [D, *E, *G] -> -1 : drop item index is out of range ( less than zero )
- aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, -1 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 7. [D, *E, *G] -> -1 : drop item index is out of range ( more than than (list length - 1) )
- aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 8 );
- CPPUNIT_ASSERT_EQUAL( false, aRes );
- CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
-
- // 8. [D, *E, *G] -> B ( i = 1 )
- aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 1 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, *G, B, *C, F, H" ), GetObjects( aModel ) );
-
- // 9. [*E, F] -> *G
- aRes = aModel->move( QList<int>() << 2 << 6, aDnD, false, 3 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, F, *G, B, *C, H" ), GetObjects( aModel ) );
-
- // 10. [*E, F, *G] -> *A
- aRes = aModel->move( QList<int>() << 2 << 3 << 4, aDnD, false, 0 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *G, *A, D, B, *C, H" ), GetObjects( aModel ) );
-
- // 11. [*G, D, *C, H] -> B
- aRes = aModel->move( QList<int>() << 2 << 4 << 6 << 7, aDnD, false, 5 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *G, D, *C, H, B" ), GetObjects( aModel ) );
-
- // 12. [F, *A, *G, D, *C, H, B] -> *E
- QList<int> anAllWithoutFirst;
- anAllWithoutFirst << 1 << 2 << 3 << 4 << 5 << 6 << 7;
- aRes = aModel->move( anAllWithoutFirst, aDnD, false, 0 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
-
- // 13. [*A, *G] -> D : no changes
- aRes = aModel->move( QList<int>() << 1 << 2, aDnD, false, 3 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
-
- // 14. [F, *G] -> D
- aRes = aModel->move( QList<int>() << 0 << 2, aDnD, false, 3 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
-
- // 15. [*A, *G, *C, H, *E] -> D
- aRes = aModel->move( QList<int>() << 0 << 2 << 4 << 5 << 7, aDnD, false, 3 );
- CPPUNIT_ASSERT_EQUAL( true, aRes );
- CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, *C, H, *E, D, B" ), GetObjects( aModel ) );
-}
\ No newline at end of file
+++ /dev/null
-#include <cppunit/extensions/HelperMacros.h>
-
-class HYDROGUI_ZLevelsModel;
-
-class test_HYDROGUI_ZLevelsModel : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(test_HYDROGUI_ZLevelsModel);
- CPPUNIT_TEST(testMoveUp);
- CPPUNIT_TEST(testMoveOnTop);
- CPPUNIT_TEST(testMoveDown);
- CPPUNIT_TEST(testMoveOnBottom);
- CPPUNIT_TEST(testDragAndDrop);
- CPPUNIT_TEST_SUITE_END();
-
-private:
- std::string GetObjects( HYDROGUI_ZLevelsModel* theModel ) const;
-
-public:
- void testMoveUp();
- void testMoveOnTop();
- void testMoveDown();
- void testMoveOnBottom();
- void testDragAndDrop();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ZLevelsModel);
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_ZLevelsModel, "HYDROGUI_ZLevelsModel");