Skip to content
Snippets Groups Projects
Commit 153430bb authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH : Add QListWidget class

parent 825c4432
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbWrapperQtWidgetListViewParameter.h"
#include "otbWrapperQtWidgetParameterLabel.h"
#include "otbWrapperQtWidgetParameterFactory.h"
namespace otb
{
namespace Wrapper
{
QtWidgetListViewParameter::QtWidgetListViewParameter(ListViewParameter* param, QtWidgetModel* m)
: QtWidgetParameterBase(m),
m_ListViewParam(param)
{
}
QtWidgetListViewParameter::~QtWidgetListViewParameter()
{
}
void QtWidgetListViewParameter::DoUpdateGUI()
{
// remove all the items set before
while(m_ListView->takeItem(0))
{
m_ListView->removeItemWidget( m_ListView->takeItem(0) );
}
for (unsigned int i = 0; i < m_ListViewParam->GetNbChoices(); ++i)
{
// Add listBox items
QString key = QString::fromStdString( m_ListViewParam->GetChoiceKey(i) );
m_ListView->addItem( key);
}
// Update the combobox value
unsigned int value = m_ListViewParam->GetValue( );
m_ListView->setCurrentRow(value);
}
void QtWidgetListViewParameter::DoCreateWidget()
{
m_ListView = new QListWidget();
m_ListView->setToolTip(m_ListViewParam->GetDescription());
m_ListView->setSelectionMode(QAbstractItemView::MultiSelection);
connect( m_ListView, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItems()) );
connect( GetModel(), SIGNAL(UpdateGui()), this, SLOT(UpdateGUI() ) );
m_VLayout = new QHBoxLayout;
m_VLayout->setContentsMargins(0, 0, 0, 0);
m_VLayout->addWidget(m_ListView);
this->setLayout(m_VLayout);
}
void QtWidgetListViewParameter::SelectedItems()
{
// Clear previous item selected
m_SelectedItems.clear();
// Item changed (check if selected or not)
for (int idx = 0; idx < m_ListView->count(); ++idx)
{
if (m_ListView->item(idx)->isSelected())
{
m_SelectedItems.push_back(idx);
}
}
m_ListViewParam->SetSelectedItems(m_SelectedItems);
}
}
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbWrapperQtWidgetListViewParameter_h
#define __otbWrapperQtWidgetListViewParameter_h
#include <QtGui>
#include "otbWrapperListViewParameter.h"
#include "otbWrapperParameterGroup.h"
#include "otbWrapperQtWidgetParameterBase.h"
namespace otb
{
namespace Wrapper
{
/** \class
* \brief
*/
class QtWidgetListViewParameter : public QtWidgetParameterBase
{
Q_OBJECT
public:
QtWidgetListViewParameter(ListViewParameter*, QtWidgetModel*);
virtual ~QtWidgetListViewParameter();
std::vector<int> GetSelectedItems()
{
return m_SelectedItems;
}
protected slots:
void SelectedItems();
private:
QtWidgetListViewParameter(const QtWidgetListViewParameter&); //purposely not implemented
void operator=(const QtWidgetListViewParameter&); //purposely not implemented
virtual void DoCreateWidget();
virtual void DoUpdateGUI();
ListViewParameter::Pointer m_ListViewParam;
QListWidget* m_ListView;
QHBoxLayout* m_VLayout;
std::vector<int> m_SelectedItems;
};
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment