Commit d509226a authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added Matrix4x4 Property widget.

parent 3cb3a191
......@@ -29,6 +29,7 @@ SET(GUI_QT4_MOC_HDRS
controlPanel/WPropertyTriggerWidget.h
controlPanel/WPropertySelectionWidget.h
controlPanel/WPropertyPositionWidget.h
controlPanel/WPropertyMatrix4X4Widget.h
controlPanel/WQtControlPanel.h
controlPanel/WQtPropertyGroupWidget.h
controlPanel/WQtTreeWidget.h
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <sstream>
#include <cmath>
#include <string>
#include <boost/lexical_cast.hpp>
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "WPropertyMatrix4X4Widget.h"
WPropertyMatrix4X4Widget::WPropertyMatrix4X4Widget( WPropMatrix4X4 property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_matrixProperty( property ),
m_layout( &m_parameterWidgets ),
m_asText( &m_informationWidgets ),
m_infoLayout( &m_informationWidgets )
{
// initialize members
for ( size_t row = 0; row < 4; ++row )
{
QHBoxLayout* h = new QHBoxLayout();
for ( size_t col = 0; col < 4; ++col )
{
size_t i = row * 4 + col;
m_edits[ i ].setParent( &m_parameterWidgets );
m_edits[ i ].resize( m_edits[ i ].minimumSizeHint().width() * 2.0, m_edits[ i ].size().height() );
connect( &m_edits[ i ], SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
connect( &m_edits[ i ], SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
h->addWidget( &m_edits[ i ] );
}
m_layout.addLayout( h );
}
m_parameterWidgets.setLayout( &m_layout );
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout.addWidget( &m_asText );
m_informationWidgets.setLayout( &m_infoLayout );
update();
}
WPropertyMatrix4X4Widget::~WPropertyMatrix4X4Widget()
{
// cleanup
}
void WPropertyMatrix4X4Widget::update()
{
// set the values
WPVBaseTypes::PV_MATRIX4X4 m = m_matrixProperty->get();
for ( size_t row = 0; row < 4; ++row )
{
for ( size_t col = 0; col < 4; ++col )
{
size_t i = row * 4 + col;
m_edits[ i ].setText( QString::fromStdString( boost::lexical_cast< std::string >( m( row, col ) ) ) );
}
}
// do not forget to update the label
m_asText.setText( QString::fromStdString( wmath::toString( m_matrixProperty->get() ) ) );
}
void WPropertyMatrix4X4Widget::editChanged()
{
setPropertyFromWidgets();
}
void WPropertyMatrix4X4Widget::textEdited( const QString& /*text*/ )
{
setPropertyFromWidgets( true );
}
void WPropertyMatrix4X4Widget::setPropertyFromWidgets( bool validateOnly )
{
// grab all the values
bool valid = true;
// create a new matrix
WPVBaseTypes::PV_MATRIX4X4 m;
for ( size_t row = 0; row < 4; ++row )
{
for ( size_t col = 0; col < 4; ++col )
{
size_t i = row * 4 + col;
// check validity
bool tmp;
double value = m_edits[ i ].text().toDouble( &tmp );
valid = valid && tmp;
m( row, col ) = value;
}
}
if ( !valid )
{
invalidate();
return;
}
// set/validate to the property
if ( validateOnly )
{
invalidate( !m_matrixProperty->accept( m ) );
}
else
{
invalidate( !m_matrixProperty->set( m ) ); // NOTE: set automatically checks the validity of the value
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WPROPERTYMATRIX4X4WIDGET_H
#define WPROPERTYMATRIX4X4WIDGET_H
#include <string>
#include <QtGui/QLineEdit>
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
#include "WPropertyWidget.h"
/**
* Implements a property widget for MATRIX4X4.
*/
class WPropertyMatrix4X4Widget: public WPropertyWidget
{
Q_OBJECT
public:
/**
* Constructor. Creates a new widget appropriate for the specified property.
*
* \param property the property to handle
* \param parent the parent widget.
* \param propertyGrid the grid used to layout the labels and property widgets
*/
WPropertyMatrix4X4Widget( WPropMatrix4X4 property, QGridLayout* propertyGrid, QWidget* parent = 0 );
/**
* Destructor.
*/
virtual ~WPropertyMatrix4X4Widget();
protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/**
* The integer property represented by this widget.
*/
WPropMatrix4X4 m_matrixProperty;
/**
* The edit field showing the value of the slider
*/
QLineEdit m_edits[16];
/**
* Layout used to position the label and the widgets
*/
QVBoxLayout m_layout;
/**
* Used to show the property as text.
*/
QLabel m_asText;
/**
* The layout used for the pure output (information properties)
*/
QHBoxLayout m_infoLayout;
/**
* Updates the property using the edit X Y and Z widgets.
*
* \param validateOnly true if the prop should not really be set. Just validated.
*/
void setPropertyFromWidgets( bool validateOnly = false );
private:
public slots:
/**
* Called whenever the edit field changes
*/
void editChanged();
/**
* Called when the text in m_edit changes.
*
* \param text
*/
void textEdited( const QString& text );
};
#endif // WPROPERTYMATRIX4X4WIDGET_H
......@@ -177,7 +177,7 @@ WQtControlPanel::~WQtControlPanel()
void WQtControlPanel::connectSlots()
{
connect( m_moduleTreeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( selectTreeItem() ) );
connect( m_moduleTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( changeTreeItem() ) );
connect( m_moduleTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( changeTreeItem( QTreeWidgetItem*, int ) ) );
connect( m_moduleTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), m_roiTreeWidget, SLOT( clearSelection() ) );
connect( m_roiTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( selectRoiTreeItem() ) );
connect( m_roiTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), m_moduleTreeWidget, SLOT( clearSelection() ) );
......@@ -499,6 +499,7 @@ WQtDatasetTreeItem* WQtControlPanel::addDataset( boost::shared_ptr< WModule > mo
WQtDatasetTreeItem* item = subject->addDatasetItem( module );
m_moduleTreeWidget->setCurrentItem( item );
item->setDisabled( true );
item->setExpanded( true );
return item;
}
......@@ -833,6 +834,9 @@ WQtPropertyGroupWidget* WQtControlPanel::buildPropWidget( boost::shared_ptr< WP
case PV_GROUP:
tab->addGroup( buildPropWidget( ( *iter )->toPropGroup() ) );
break;
case PV_MATRIX4X4:
tab->addProp( ( *iter )->toPropMatrix4X4() );
break;
default:
WLogger::getLogger()->addLogMessage( "This property type is not yet supported.", "ControlPanel", LL_WARNING );
break;
......@@ -948,18 +952,12 @@ void WQtControlPanel::createCompatibleButtons( boost::shared_ptr< WModule > modu
}
}
void WQtControlPanel::changeTreeItem()
void WQtControlPanel::changeTreeItem( QTreeWidgetItem* item, int /* column */ )
{
if ( m_moduleTreeWidget->selectedItems().size() == 1 && m_moduleTreeWidget->selectedItems().at( 0 )->type() == DATASET )
WQtTreeItem* witem = dynamic_cast< WQtTreeItem* >( item );
if ( witem )
{
boost::shared_ptr< WModule > module =( static_cast< WQtDatasetTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
module->getProperties()->getProperty( "active" )->toPropBool()->set( m_moduleTreeWidget->selectedItems().at( 0 )->checkState( 0 ) );
}
else if ( m_moduleTreeWidget->selectedItems().size() == 1 && m_moduleTreeWidget->selectedItems().at( 0 )->type() == MODULE )
{
boost::shared_ptr< WModule > module =( static_cast< WQtModuleTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
module->getProperties()->getProperty( "active" )->toPropBool()->set( m_moduleTreeWidget->selectedItems().at( 0 )->checkState( 0 ) );
witem->handleCheckStateChange();
}
}
......@@ -1096,3 +1094,4 @@ void WQtControlPanel::handleDragDrop()
{
WLogger::getLogger()->addLogMessage( "Drag and drop handler not implemented yet!", "ControlPanel", LL_DEBUG );
}
......@@ -325,7 +325,13 @@ private slots:
/**
* function gets called when a change to a tree item, eg. check box status, occurs
*/
void changeTreeItem();
/**
* Function gets change when a change to a tree item occurs.
*
* \param item the item
* \param column column index
*/
void changeTreeItem( QTreeWidgetItem* item, int column );
/**
* delete a ROI tree item
......
......@@ -104,6 +104,13 @@ WPropertyPositionWidget* WQtPropertyGroupWidget::addProp( WPropPosition property
return new WPropertyPositionWidget( property, m_controlLayout, this );
}
WPropertyMatrix4X4Widget* WQtPropertyGroupWidget::addProp( WPropMatrix4X4 property )
{
++m_numberOfWidgets;
return new WPropertyMatrix4X4Widget( property, m_controlLayout, this );
}
WPropertySelectionWidget* WQtPropertyGroupWidget::addProp( WPropSelection property )
{
++m_numberOfWidgets;
......
......@@ -39,6 +39,7 @@
#include "WPropertyTriggerWidget.h"
#include "WPropertySelectionWidget.h"
#include "WPropertyPositionWidget.h"
#include "WPropertyMatrix4X4Widget.h"
#include "../../../common/WPropertyVariable.h"
......@@ -156,6 +157,15 @@ public:
*/
WPropertyTriggerWidget* addProp( WPropTrigger property );
/**
* Adds a new trigger property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyMatrix4X4Widget* addProp( WPropMatrix4X4 property );
/**
* Adds an widget containing another property group to this widget. It encloses it with a GroupBox.
*
......
......@@ -222,6 +222,16 @@ void WQtTreeItem::updateState()
QCoreApplication::postEvent( WQt4Gui::getMainWindow()->getControlPanel(), new WModuleDeleteEvent( this ) );
}
// active ?
if ( m_module->getProperties()->getProperty( "active" )->toPropBool()->get() )
{
setCheckState( 0, Qt::Checked );
}
else
{
setCheckState( 0, Qt::Unchecked );
}
// update tooltip
updateTooltip( progress );
}
......@@ -260,3 +270,16 @@ void WQtTreeItem::setHandledOutput( std::string out )
m_handledOutput = out;
}
void WQtTreeItem::handleCheckStateChange()
{
// active ?
if ( checkState( 0 ) == Qt::Checked )
{
m_module->getProperties()->getProperty( "active" )->toPropBool()->set( true );
}
else
{
m_module->getProperties()->getProperty( "active" )->toPropBool()->set( false );
}
}
......@@ -104,6 +104,10 @@ public:
*/
void setHandledOutput( std::string out );
/**
* Handle changes in check state.
*/
virtual void handleCheckStateChange();
public slots:
......
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