HYDROGUI_BathymetryBoundsOp.h
HYDROGUI_TranslateObstacleDlg.h
HYDROGUI_TranslateObstacleOp.h
+ HYDROGUI_ZLevelsModel.h
+ HYDROGUI_ZLevelsDlg.h
)
QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
HYDROGUI_BathymetryBoundsOp.cxx
HYDROGUI_TranslateObstacleDlg.cxx
HYDROGUI_TranslateObstacleOp.cxx
+ HYDROGUI_ZLevelsModel.cxx
+ HYDROGUI_ZLevelsDlg.cxx
)
add_definitions(
SET(GUI_DATA ${GUIPNG_DATA} ${GUIXML_DATA})
INSTALL(FILES ${GUI_DATA} DESTINATION ${SALOME_HYDRO_INSTALL_RES_DATA})
+# tests
+if(SALOME_BUILD_TESTS)
+
+ set(TEST_HEADERS
+ test_HYDROGUI_ZLevelsModel.h
+ )
+
+ set(TEST_SOURCES
+ test_HYDROGUI_Main.cxx
+ test_HYDROGUI_ZLevelsModel.cxx
+ )
+
+ set(TEST_EXE test_HYDROGUI)
+ include(../../CMake/CPPUnitTests.cmake)
+ target_link_libraries(test_HYDROGUI ${CAS_OCAF} ${CAS_MODELER} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} HYDROData HYDROGUI)
+
+endif(SALOME_BUILD_TESTS)
+
--- /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_ZLevelsDlg.h"
+#include "HYDROGUI_ZLevelsModel.h"
+
+#include <QCheckBox>
+#include <QLayout>
+#include <QListView>
+#include <QPushButton>
+#include <QSignalMapper>
+#include <QSortFilterProxyModel>
+
+
+HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
+: QDialog( theParent )
+{
+ QVBoxLayout* aMainLayout = new QVBoxLayout( this );
+ aMainLayout->setMargin( 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 );
+
+ myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
+ aMainLayout->addWidget( myAllObjects );
+
+ QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
+ myApply = new QPushButton( tr("APPLY") );
+ myClose = new QPushButton( tr("CLOSE") );
+ aDlgButtonsLayout->addWidget( myApply );
+ aDlgButtonsLayout->addWidget( myClose );
+ aDlgButtonsLayout->addStretch();
+ 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 ) ) );
+
+ connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) );
+
+ connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
+
+ OnStateChanged();
+}
+
+HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
+{
+}
+
+void HYDROGUI_ZLevelsDlg::setObjects( const QList<QString>& 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 );
+ }
+ }
+}
+
+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() );
+ }
+ }
+}
+
+void HYDROGUI_ZLevelsDlg::OnStateChanged()
+{
+ QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+ bool isAll = myAllObjects->isChecked();
+ QString anExpr = isAll ? "true|false" : "true";
+ aFilterModel->setFilterRegExp( anExpr );
+}
--- /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_ZLEVELSPANEL_H
+#define HYDROGUI_ZLEVELSPANEL_H
+
+#include <QDialog>
+
+class QCheckBox;
+class QListView;
+class QPushButton;
+
+/**
+ * \class HYDROGUI_ZLevelsDlg
+ * \brief The class representing widget for managing Z levels
+ */
+class HYDROGUI_ZLevelsDlg : public QDialog
+{
+ Q_OBJECT
+
+public:
+ HYDROGUI_ZLevelsDlg( QWidget* theParent );
+ virtual ~HYDROGUI_ZLevelsDlg();
+
+ void setObjects( const QList<QString>& theObjects );
+
+private slots:
+ void onMove( int theType );
+ void OnStateChanged();
+
+private:
+ QListView* myList;
+ QPushButton* myTop;
+ QPushButton* myUp;
+ QPushButton* myDown;
+ QPushButton* myBottom;
+ QCheckBox* myAllObjects;
+ QPushButton* myApply;
+ QPushButton* myClose;
+};
+
+#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 <QMimeData>
+
+const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list";
+
+HYDROGUI_ZLevelsModel::HYDROGUI_ZLevelsModel( QObject* theParent )
+ : QAbstractListModel( theParent )
+{
+ myEmpty = QPixmap( 16, 16 );
+ myEmpty.fill( Qt::white );
+ myEye = QPixmap( "eye.png" );//TODO: loading from resources
+ setSupportedDragActions( Qt::MoveAction | Qt::CopyAction );
+}
+
+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;
+ 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();
+}
+
+void HYDROGUI_ZLevelsModel::setObjects( const QList<QPair<QString, bool>>& theObjects )
+{
+ myObjects = theObjects;
+
+ reset();
+}
+
+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& theIndices ) const
+{
+ QMimeData* aMimeData = new QMimeData();
+ QByteArray anEncodedData;
+ QDataStream aStream( &anEncodedData, QIODevice::WriteOnly );
+
+ QList<int> anIdsList = getIds( theIndices );
+ 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;
+ }
+ move( anIdsList, DragAndDrop, aDropItemId );
+ return true;
+}
+
+Qt::DropActions HYDROGUI_ZLevelsModel::supportedDropActions() const
+{
+ return Qt::MoveAction | Qt::CopyAction;
+}
+
+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;
+}
+
+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;
+
+ switch ( theType ) {
+ case Up:
+ 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:
+ if ( theItem > 0 ) {
+ aDestinationIndex = 0;
+ }
+ break;
+ case Bottom:
+ if ( theItem < myObjects.count() - 1 ) {
+ aDestinationIndex = myObjects.count() - 1;
+ }
+ break;
+ }
+
+ if ( aDestinationIndex >= 0 && aDestinationIndex < myObjects.count() ) {
+ int aDestinationRow = (theType == Up || theType == Top) ? aDestinationIndex : aDestinationIndex + 1;
+ if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestinationRow ) ) {
+ myObjects.move( theItem, aDestinationIndex );
+ endMoveRows();
+ aRes = true;
+ }
+ }
+
+ return aRes;
+}
+
+bool HYDROGUI_ZLevelsModel::move( const QList<int>& theItems, const OpType theType,
+ bool theIsVisibleOnly, const int theDropItem )
+{
+ bool aRes = true;
+
+ bool isReverse = theType == Top || theType == Down;
+ QListIterator<int> anIt( theItems );
+ int aShift = 0;
+ if ( isReverse ) {
+ anIt.toBack();
+ while ( anIt.hasPrevious() ) {
+ int anId = anIt.previous();
+ if ( theType == Top ) {
+ anId += aShift;
+ aShift++;
+ }
+ if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
+ aRes = false;
+ break;
+ }
+ }
+ } else {
+ while ( anIt.hasNext() ) {
+ int anId = anIt.next();
+ if ( theType == Bottom ) {
+ anId -= aShift;
+ aShift++;
+ }
+ if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
+ aRes = false;
+ break;
+ }
+ }
+ }
+
+ // reset(); //TODO dataChanged?
+
+ return aRes;
+}
+
--- /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 <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 HYDROGUI_ZLevelsModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ enum OpType { Top, Up, Down, Bottom, DragAndDrop };
+
+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& theIndices ) 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 QList<QPair<QString, bool>>& theObjects );
+
+ 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;
+
+private:
+ QList<QPair<QString, bool>> myObjects;
+ QPixmap myEmpty, myEye;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestRunner.h>
+#include <cppunit/TextTestProgressListener.h>
+#include <stdexcept>
+
+int
+ main( int argc, char* argv[] )
+{
+ std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
+
+ // Create the event manager and test controller
+ CppUnit::TestResult controller;
+
+ // Add a listener that colllects test result
+ CppUnit::TestResultCollector result;
+ controller.addListener( &result );
+
+ // Add a listener that print dots as test run.
+ CppUnit::TextTestProgressListener progress;
+ controller.addListener( &progress );
+
+ CppUnit::TestFactoryRegistry& registry =
+ CppUnit::TestFactoryRegistry::getRegistry();
+ // Add the top suite to the test runner
+ CppUnit::TestRunner runner;
+ runner.addTest( registry.makeTest() );
+ try
+ {
+ std::cout << "Running " << testPath;
+ runner.run( controller, testPath );
+
+ std::cerr << std::endl;
+
+ // Print test in a compiler compatible format.
+ CppUnit::CompilerOutputter outputter( &result, std::cerr );
+ outputter.write();
+ }
+ catch ( std::invalid_argument &e ) // Test path not resolved
+ {
+ std::cerr << std::endl
+ << "ERROR: " << e.what()
+ << std::endl;
+ return 0;
+ }
+
+ return result.wasSuccessful() ? 0 : 1;
+}
--- /dev/null
+#include<test_HYDROGUI_ZLevelsModel.h>
+
+
+void test_HYDROGUI_ZLevelsModel::testMoveUp()
+{
+ CPPUNIT_ASSERT(1 == 2);
+}
--- /dev/null
+#include <cppunit/extensions/HelperMacros.h>
+
+class test_HYDROGUI_ZLevelsModel : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(test_HYDROGUI_ZLevelsModel);
+ CPPUNIT_TEST(testMoveUp);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+
+public:
+
+ // checks move up
+ void testMoveUp();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ZLevelsModel);
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_HYDROGUI_ZLevelsModel, "HYDROGUI_ZLevelsModel");
+++ /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_ZLevelsDlg.h"
-#include "HYDROGUI_ZLevelsModel.h"
-
-#include <QCheckBox>
-#include <QLayout>
-#include <QListView>
-#include <QPushButton>
-#include <QSignalMapper>
-#include <QSortFilterProxyModel>
-
-
-HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
-: QDialog( theParent )
-{
- QVBoxLayout* aMainLayout = new QVBoxLayout( this );
- aMainLayout->setMargin( 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 );
-
- myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
- aMainLayout->addWidget( myAllObjects );
-
- QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
- myApply = new QPushButton( tr("APPLY") );
- myClose = new QPushButton( tr("CLOSE") );
- aDlgButtonsLayout->addWidget( myApply );
- aDlgButtonsLayout->addWidget( myClose );
- aDlgButtonsLayout->addStretch();
- 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 ) ) );
-
- connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) );
-
- connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
-
- OnStateChanged();
-}
-
-HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
-{
-}
-
-void HYDROGUI_ZLevelsDlg::setObjects( const QList<QString>& 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 );
- }
- }
-}
-
-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() );
- }
- }
-}
-
-void HYDROGUI_ZLevelsDlg::OnStateChanged()
-{
- QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
- bool isAll = myAllObjects->isChecked();
- QString anExpr = isAll ? "true|false" : "true";
- aFilterModel->setFilterRegExp( anExpr );
-}
+++ /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_ZLEVELSPANEL_H
-#define HYDROGUI_ZLEVELSPANEL_H
-
-#include <QDialog>
-
-class QCheckBox;
-class QListView;
-class QPushButton;
-
-/**
- * \class HYDROGUI_ZLevelsDlg
- * \brief The class representing widget for managing Z levels
- */
-class HYDROGUI_ZLevelsDlg : public QDialog
-{
- Q_OBJECT
-
-public:
- HYDROGUI_ZLevelsDlg( QWidget* theParent );
- virtual ~HYDROGUI_ZLevelsDlg();
-
- void setObjects( const QList<QString>& theObjects );
-
-private slots:
- void onMove( int theType );
- void OnStateChanged();
-
-private:
- QListView* myList;
- QPushButton* myTop;
- QPushButton* myUp;
- QPushButton* myDown;
- QPushButton* myBottom;
- QCheckBox* myAllObjects;
- QPushButton* myApply;
- QPushButton* myClose;
-};
-
-#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 <QMimeData>
-
-const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list";
-
-HYDROGUI_ZLevelsModel::HYDROGUI_ZLevelsModel( QObject* theParent )
- : QAbstractListModel( theParent )
-{
- myEmpty = QPixmap( 16, 16 );
- myEmpty.fill( Qt::white );
- myEye = QPixmap( "eye.png" );//TODO: loading from resources
- setSupportedDragActions( Qt::MoveAction | Qt::CopyAction );
-}
-
-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;
- 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();
-}
-
-void HYDROGUI_ZLevelsModel::setObjects( const QList<QPair<QString, bool>>& theObjects )
-{
- myObjects = theObjects;
-
- reset();
-}
-
-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& theIndices ) const
-{
- QMimeData* aMimeData = new QMimeData();
- QByteArray anEncodedData;
- QDataStream aStream( &anEncodedData, QIODevice::WriteOnly );
-
- QList<int> anIdsList = getIds( theIndices );
- 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;
- }
- move( anIdsList, DragAndDrop, aDropItemId );
- return true;
-}
-
-Qt::DropActions HYDROGUI_ZLevelsModel::supportedDropActions() const
-{
- return Qt::MoveAction | Qt::CopyAction;
-}
-
-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;
-}
-
-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;
-
- switch ( theType ) {
- case Up:
- 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:
- if ( theItem > 0 ) {
- aDestinationIndex = 0;
- }
- break;
- case Bottom:
- if ( theItem < myObjects.count() - 1 ) {
- aDestinationIndex = myObjects.count() - 1;
- }
- break;
- }
-
- if ( aDestinationIndex >= 0 && aDestinationIndex < myObjects.count() ) {
- int aDestinationRow = (theType == Up || theType == Top) ? aDestinationIndex : aDestinationIndex + 1;
- if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestinationRow ) ) {
- myObjects.move( theItem, aDestinationIndex );
- endMoveRows();
- aRes = true;
- }
- }
-
- return aRes;
-}
-
-bool HYDROGUI_ZLevelsModel::move( const QList<int>& theItems, const OpType theType,
- bool theIsVisibleOnly, const int theDropItem )
-{
- bool aRes = true;
-
- bool isReverse = theType == Top || theType == Down;
- QListIterator<int> anIt( theItems );
- int aShift = 0;
- if ( isReverse ) {
- anIt.toBack();
- while ( anIt.hasPrevious() ) {
- int anId = anIt.previous();
- if ( theType == Top ) {
- anId += aShift;
- aShift++;
- }
- if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
- aRes = false;
- break;
- }
- }
- } else {
- while ( anIt.hasNext() ) {
- int anId = anIt.next();
- if ( theType == Bottom ) {
- anId -= aShift;
- aShift++;
- }
- if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) {
- aRes = false;
- break;
- }
- }
- }
-
- // reset(); //TODO dataChanged?
-
- return aRes;
-}
-
+++ /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 <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 HYDROGUI_ZLevelsModel : public QAbstractListModel
-{
- Q_OBJECT
-
-public:
- enum OpType { Top, Up, Down, Bottom, DragAndDrop };
-
-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& theIndices ) 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 QList<QPair<QString, bool>>& theObjects );
-
- 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;
-
-private:
- QList<QPair<QString, bool>> myObjects;
- QPixmap myEmpty, myEye;
-};
-
-#endif
\ No newline at end of file
+++ /dev/null
-call "%VS90COMNTOOLS%..\..\VC\vcvarsall.bat" x86
-SET appendix="Visual Studio 9 2008"
-
-@SET PDIR=..\..\..\..\..\PRODUCTSD
-call %PDIR%\env_compile.bat
-
-echo %PATH%
-
-qmake -tp vc -spec win32-msvc2008 zlevel.pro -r
+++ /dev/null
-#include "HYDROGUI_ZLevelsDlg.h"
-
-#include <QApplication>
-
-int main( int argc, char** argv ){
- QApplication app(argc, argv);
-
- HYDROGUI_ZLevelsDlg* aDlg = new HYDROGUI_ZLevelsDlg( 0 );
- QList< QString > anObjects;
- anObjects << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H";
- aDlg->setObjects( anObjects );
- aDlg->show();
-
- return app.exec();
-}
\ No newline at end of file
+++ /dev/null
-HEADERS = HYDROGUI_ZLevelsDlg.h HYDROGUI_ZLevelsModel.h
-
-SOURCES = main.cpp HYDROGUI_ZLevelsDlg.cxx HYDROGUI_ZLevelsModel.cxx
-CONFIG += qt
-
-TEMPLATE = app