#include "HYDROGUI_LandCoverDlg.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_OrderedListWidget.h"
+#include "HYDROGUI_ListSelector.h"
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
#include <QListWidget>
+#include <QPushButton>
HYDROGUI_LandCoverDlg::HYDROGUI_LandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_BasicZoneDlg( theModule, theTitle,
tr( "LAND_COVER_NAME" ), tr( "NAME" ),
tr( "LAND_COVER_PARAMETERS" ), tr( "LAND_COVER_STRICKLER_TYPE" ) )
{
- myPolylines = new QListWidget( myPolylineFrame );
- myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
- myPolylines->setSelectionMode( QAbstractItemView::ExtendedSelection );
-
- QBoxLayout* aPolyLayout = new QVBoxLayout( myPolylineFrame );
+ myPolylines = new HYDROGUI_OrderedListWidget( myPolylineFrame, 16 );
+ myPolylines->setHiddenObjectsShown(true);
+ myPolylines->setVisibilityIconShown(false);
+ myPolylines->setContentsMargins(QMargins());
+ myPolylines->setOrderingEnabled( true );
+
+ // Include/Exclude buttons
+ QFrame* aBtnsFrame = new QFrame( myPolylineFrame );
+ QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
+ aBtnsLayout->setMargin( 0 );
+ aBtnsLayout->setSpacing( 5 );
+ aBtnsFrame->setLayout( aBtnsLayout );
+ QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
+ QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
+
+ // Fill the butons frame with two buttons
+ aBtnsLayout->addWidget( anAddBtn );
+ aBtnsLayout->addWidget( aRemoveBtn );
+ aBtnsLayout->addStretch( 1 );
+
+ QGridLayout* aPolyLayout = new QGridLayout( myPolylineFrame );
aPolyLayout->setMargin( 0 );
- aPolyLayout->setSpacing( 5 );
- aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ) );
- aPolyLayout->addWidget( myPolylines );
+ aPolyLayout->setSpacing( 10 );
+ aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ), 0, 0, 1, 2 );
+ aPolyLayout->addWidget( aBtnsFrame, 1, 0, 1, 1 );
+ aPolyLayout->addWidget( myPolylines, 1, 1, 1, 1 );
QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup );
aParamLayout->setMargin( 5 );
aParamLayout->setSpacing( 5 );
aParamLayout->addWidget( myPolylineFrame );
+ // Create selector
+ if ( module() ) {
+ HYDROGUI_ListSelector* aListSelector =
+ new HYDROGUI_ListSelector( myPolylines, module()->getApp()->selectionMgr() );
+ aListSelector->setAutoBlock( true );
+ }
+
// Connect signals and slots
connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
+ connect( myPolylines, SIGNAL( orderPolylinesChanged() ), SLOT( onOrderPolylinesChanged() ) );
+ connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addPolylines() ) );
+ connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removePolylines() ) );
}
HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg()
HYDROGUI_BasicZoneDlg::reset();
- myPolylines->clear();
+ HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
+ myPolylines->setObjects(anObject2VisibleList);
+ myPolylines->setOrderingEnabled( false );
blockSignals( isBlocked );
onZoneDefChanged();
}
-void HYDROGUI_LandCoverDlg::setPolylineNames( const QStringList& thePolylines )
+bool HYDROGUI_LandCoverDlg::includePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
{
- bool isBlocked = blockSignals( true );
+ QStringList anIncludedPolylinesNames = myPolylines->getAllNames();
- myPolylines->clear();
- myPolylines->addItems( thePolylines );
-
- blockSignals( isBlocked );
-}
-
-void HYDROGUI_LandCoverDlg::setSelectedPolylineNames( const QStringList& theSelectedPolylines )
-{
- bool anUpdateNeeded = false;
- for (int i =0; i< myPolylines->count(); i++)
+ bool aSetOfPolylinesChanged = false;
+ foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
{
- QListWidgetItem* anItem = myPolylines->item( i );
- if ( anItem )
+ if ( !anIncludedPolylinesNames.contains( aSelectedPolyline.first->GetName() ) )
{
- bool aIsSelected = anItem->isSelected();
- if ( theSelectedPolylines.contains( anItem->text() ) )
- {
- if ( !aIsSelected )
- {
- anUpdateNeeded = true;
- anItem->setSelected( true );
- }
- }
- else if ( aIsSelected )
- {
- anUpdateNeeded = true;
- anItem->setSelected( false );
- }
+ myPolylines->addObject( aSelectedPolyline );
+ aSetOfPolylinesChanged = true;
}
}
+ myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
- if ( anUpdateNeeded )
- onZoneDefChanged();
+ return aSetOfPolylinesChanged;
}
-QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
+bool HYDROGUI_LandCoverDlg::excludePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
{
- QStringList aSelectedPolylines;
+ bool aSetOfPolylinesChanged = !theSelectedPolylines.isEmpty();
+
+ foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
+ myPolylines->removeObjectByName( aSelectedPolyline.first->GetName() );
+ myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
- QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
- QList<QListWidgetItem*>::const_iterator anIt = aSelectedItems.begin(), aLast = aSelectedItems.end();
- for( ; anIt!=aLast; anIt++ )
- aSelectedPolylines.append( (*anIt)->text() );
+ return aSetOfPolylinesChanged;
+}
- return aSelectedPolylines;
+QStringList HYDROGUI_LandCoverDlg::getPolylineNames() const
+{
+ return myPolylines->getAllNames();
+}
+
+QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
+{
+ return myPolylines->getSelectedNames();
}
void HYDROGUI_LandCoverDlg::onZoneDefChanged()
if ( signalsBlocked() )
return;
- QStringList aPolylineNames = getSelectedPolylineNames();
+ QStringList aPolylineNames = getPolylineNames();
emit CreatePreview( aPolylineNames );
}
+
+void HYDROGUI_LandCoverDlg::onOrderPolylinesChanged()
+{
+ // TODO: implement this method
+}