Commit 699bd3f6 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - selection property widgets and selection properties can now be modified while in use.

parent 70f74c5b
......@@ -74,26 +74,8 @@ WPropertySelectionWidget::WPropertySelectionWidget( WPropSelection property, QGr
// Lists are used if the selection of multiple elements is allowed
if ( m_selectionProperty->countConstraint( PC_SELECTONLYONE ) != 0 )
{
// TODO(all): how to show the icon inside a combobox?
m_combo = new QComboBox( &m_parameterWidgets );
// add all items from the selection set:
WItemSelector s = m_selectionProperty->get();
for ( size_t i = 0; i < s.sizeAll(); ++i )
{
m_combo->addItem( QString::fromStdString( s.atAll( i ).name ) );
// if there is an icon -> show it
if ( s.atAll( i ).icon )
{
// scale the pixmap to a maximum size if larger
QPixmap pix = ensureSize( QPixmap( s.atAll( i ).icon ) );
// set icon
m_combo->setItemIcon( i, QIcon( pix ) );
m_combo->setIconSize( QSize( pix.width(), pix.height() ) );
}
}
// layout
m_layout.addWidget( m_combo, 0, 0 );
......@@ -105,46 +87,6 @@ WPropertySelectionWidget::WPropertySelectionWidget( WPropSelection property, QGr
m_list = new QListWidget( &m_parameterWidgets );
m_list->setSelectionMode( QAbstractItemView::ExtendedSelection );
// add all items from the selection set:
WItemSelector s = m_selectionProperty->get();
for ( size_t i = 0; i < s.sizeAll(); ++i )
{
// Create a custom widget which contains the name and description
QWidget* widget = new QWidget( m_list );
QGridLayout* layoutWidget = new QGridLayout();
int column = 0;
// if there is an icon -> show it
if ( s.atAll( i ).icon )
{
QLabel* icon = new QLabel();
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ); // <-- scale it down
icon->setSizePolicy( sizePolicy );
icon->setPixmap( ensureSize( QPixmap( s.atAll( i ).icon ) ) );
layoutWidget->addWidget( icon, 0, 0, 2, 1 );
++column;
}
// Add Name and Description
layoutWidget->addWidget( new QLabel( "<b>" + QString::fromStdString( s.atAll( i ).name )+ "</b>" ), 0, column );
// if there is no description -> no widget added to save space
if ( !s.atAll( i ).description.empty() )
{
layoutWidget->addWidget( new QLabel( QString::fromStdString( s.atAll( i ).description ) ), 1, column );
}
layoutWidget->setSizeConstraint( QLayout::SetMaximumSize );
widget->setLayout( layoutWidget );
// add Item
QListWidgetItem* item = new QListWidgetItem();
item->setSizeHint( widget->sizeHint() );
m_list->addItem( item );
m_list->setItemWidget( item, widget );
m_list->setMinimumHeight( 150 );
}
// layout
m_layout.addWidget( m_list, 0, 0 );
......@@ -195,6 +137,27 @@ void WPropertySelectionWidget::update()
//apply selection
if ( m_combo )
{
disconnect( m_combo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboSelectionChanged( int ) ) );
m_combo->clear();
// add all items from the selection set:
WItemSelector s = m_selectionProperty->get();
for ( size_t i = 0; i < s.sizeAll(); ++i )
{
m_combo->addItem( QString::fromStdString( s.atAll( i ).name ) );
// if there is an icon -> show it
if ( s.atAll( i ).icon )
{
// scale the pixmap to a maximum size if larger
QPixmap pix = ensureSize( QPixmap( s.atAll( i ).icon ) );
// set icon
m_combo->setItemIcon( i, QIcon( pix ) );
m_combo->setIconSize( QSize( pix.width(), pix.height() ) );
}
}
// mark the currently selected item. Just take care that there might be no item selected.
if ( s.size() == 0 )
{
......@@ -205,17 +168,63 @@ void WPropertySelectionWidget::update()
// as there is the SELECTONLYONE constraint -> if something is selected, it always is the first one
m_combo->setCurrentIndex( s.getItemIndexOfSelected( 0 ) );
}
connect( m_combo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboSelectionChanged( int ) ) );
}
else
{
disconnect( m_list, SIGNAL( itemSelectionChanged() ), this, SLOT( listSelectionChanged() ) );
m_list->clearSelection();
m_list->clear();
// select all items
// add all items from the selection set:
WItemSelector s = m_selectionProperty->get();
for ( size_t i = 0; i < s.sizeAll(); ++i )
{
// Create a custom widget which contains the name and description
QWidget* widget = new QWidget( m_list );
QGridLayout* layoutWidget = new QGridLayout();
int column = 0;
// if there is an icon -> show it
if ( s.atAll( i ).icon )
{
QLabel* icon = new QLabel();
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ); // <-- scale it down
icon->setSizePolicy( sizePolicy );
icon->setPixmap( ensureSize( QPixmap( s.atAll( i ).icon ) ) );
layoutWidget->addWidget( icon, 0, 0, 2, 1 );
++column;
}
// Add Name and Description
layoutWidget->addWidget( new QLabel( "<b>" + QString::fromStdString( s.atAll( i ).name )+ "</b>" ), 0, column );
// if there is no description -> no widget added to save space
if ( !s.atAll( i ).description.empty() )
{
layoutWidget->addWidget( new QLabel( QString::fromStdString( s.atAll( i ).description ) ), 1, column );
}
layoutWidget->setSizeConstraint( QLayout::SetMaximumSize );
widget->setLayout( layoutWidget );
// add Item
QListWidgetItem* item = new QListWidgetItem();
item->setSizeHint( widget->sizeHint() );
m_list->addItem( item );
m_list->setItemWidget( item, widget );
m_list->setMinimumHeight( 150 );
}
// select all items
for ( size_t i = 0; i < s.size(); ++i )
{
m_list->item( s.getItemIndexOfSelected( i ) )->setSelected( true );
}
connect( m_list, SIGNAL( itemSelectionChanged() ), this, SLOT( listSelectionChanged() ) );
}
m_update = false;
......
......@@ -565,6 +565,14 @@ void WMTemplate::moduleMain()
// Now that the trigger has the state "triggered", a time consuming operation can be done here.
debugLog() << "User triggered an important and time consuming operation.";
// We can exchange the list used for selection properties. This of course invalidates the current user selection. You should avoid
// changing this too often and too fast as it might confuse the user.
boost::shared_ptr< WItemSelection > possibleSelections = boost::shared_ptr< WItemSelection >( new WItemSelection() );
possibleSelections->addItem( "Beer2", "Cold and fresh.", template_bier_xpm ); // NOTE: you can add XPM images here.
possibleSelections->addItem( "Steaks2", "Medium please.", template_steak_xpm );
possibleSelections->addItem( "Sausages2", "With Sauerkraut.", template_wurst_xpm );
m_aSingleSelection->set( possibleSelections->getSelectorFirst() );
// Update the output property
m_aTriggerOutput->set( WPVBaseTypes::PV_TRIGGER_TRIGGERED );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment