Commit a8ff3d67 authored by schurade's avatar schurade
Browse files

[ADD] create control widgets for properties and connect them

parent fb016cc9
......@@ -13,8 +13,10 @@ SET( QT_LIBS ${QT_QTCORE_LIBRARY}
SET(GUI_QT4_MOC_HDRS
WMainWindow.h
WQtNavGLWidget.h
datasetbrowser/WQtCheckBox.h
datasetbrowser/WQtDatasetBrowser.h
datasetbrowser/WQtDSBWidget.h
datasetbrowser/WQtLineEdit.h
datasetbrowser/WQtNumberEdit.h
datasetbrowser/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 <string>
#include "WQtCheckBox.h"
WQtCheckBox::WQtCheckBox()
: QCheckBox()
{
m_name = "";
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( emitStateChanged() ) );
}
WQtCheckBox::~WQtCheckBox()
{
}
boost::signal2< void, std::string, bool >*WQtCheckBox::getboostSignal()
{
return &m_boostSignal;
}
void WQtCheckBox::setName( std::string name )
{
m_name = name;
}
void WQtCheckBox::emitStateChanged()
{
m_boostSignal( m_name, this->isChecked() );
}
//---------------------------------------------------------------------------
//
// 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 WQTCHECKBOX_H
#define WQTCHECKBOX_H
#include <string>
#include "../signalslib.hpp"
#include <QtGui/QCheckBox>
/**
* implements a QCheckBox with a boost signal
*/
class WQtCheckBox : public QCheckBox
{
Q_OBJECT
public:
/**
* standard constructor
*/
explicit WQtCheckBox();
/**
* destructor
*/
virtual ~WQtCheckBox();
/**
* \return the boost signal object
*/
boost::signal2< void, std::string, bool >* getboostSignal();
/**
* setter for name
*/
void setName( std::string name );
private:
std::string m_name;
boost::signal2< void, std::string, bool > m_boostSignal;
public slots:
void emitStateChanged();
};
#endif // WQTCHECKBOX_H
......@@ -55,12 +55,13 @@ QPushButton* WQtDSBWidget::addPushButton( std::string label )
}
QCheckBox* WQtDSBWidget::addCheckBox( std::string label, bool isChecked )
WQtCheckBox* WQtDSBWidget::addCheckBox( std::string label, bool isChecked )
{
int row = m_layout.rowCount();
QLabel* qlabel = new QLabel( label.c_str() );
QCheckBox* checkBox = new QCheckBox();
WQtCheckBox* checkBox = new WQtCheckBox();
checkBox->setName( label );
checkBox->setChecked( isChecked );
m_layout.addWidget( qlabel, row, 0 );
......@@ -72,12 +73,13 @@ QCheckBox* WQtDSBWidget::addCheckBox( std::string label, bool isChecked )
}
QLineEdit* WQtDSBWidget::addLineEdit( std::string label, std::string text )
WQtLineEdit* WQtDSBWidget::addLineEdit( std::string label, std::string text )
{
int row = m_layout.rowCount();
QLabel* qlabel = new QLabel( label.c_str() );
QLineEdit* lineEdit = new QLineEdit();
WQtLineEdit* lineEdit = new WQtLineEdit();
lineEdit->setName( label );
lineEdit->setText( QString( text.c_str() ) );
m_layout.addWidget( qlabel, row, 0 );
......@@ -94,7 +96,7 @@ WQtSliderWithEdit* WQtDSBWidget::addSliderInt( std::string label, int value, int
int row = m_layout.rowCount();
QLabel* qlabel = new QLabel( label.c_str() );
WQtSliderWithEdit* slider = new WQtSliderWithEdit();
WQtSliderWithEdit* slider = new WQtSliderWithEdit( label );
slider->setMin( min );
slider->setMax( max );
......
......@@ -27,17 +27,18 @@
#include <string>
#include <QtGui/QCheckBox>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSlider>
#include <QtGui/QWidget>
#include <QtGui/QLCDNumber>
#include "WQtCheckBox.h"
#include "WQtLineEdit.h"
#include "WQtSliderWithEdit.h"
/**
* container widget to contain the context widget for the dataset browser
*/
......@@ -64,12 +65,12 @@ public:
/**
* helper function to add a generic checkbox
*/
QCheckBox* addCheckBox( std::string label = "checkbox:", bool isChecked = false );
WQtCheckBox* addCheckBox( std::string label = "checkbox:", bool isChecked = false );
/**
* helper function to add a generic line edit
*/
QLineEdit* addLineEdit( std::string label = "edit text:", std::string text = "" );
WQtLineEdit* addLineEdit( std::string label = "edit text:", std::string text = "" );
/**
* helper function to add a slider with a connect line edit
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <iostream>
#include <map>
#include <string>
#include <QtCore/QList>
......@@ -31,6 +32,7 @@
#include "WQtDatasetBrowser.h"
#include "WQtNumberEdit.h"
#include "WQtCheckBox.h"
WQtDatasetBrowser::WQtDatasetBrowser( QWidget* parent )
: QDockWidget( parent )
......@@ -56,18 +58,6 @@ WQtDatasetBrowser::WQtDatasetBrowser( QWidget* parent )
buttonLayout->addWidget( m_downButton );
buttonLayout->addWidget( m_upButton );
//========================================================================
// TODO(Schurade): only for testing, will be removed soon
WQtDSBWidget* tab1 = new WQtDSBWidget( "settings" );
tab1->addPushButton( "button1" );
tab1->addPushButton( "button2" );
tab1->addCheckBox( "box1:", true );
tab1->addCheckBox( "box2:", false );
tab1->addLineEdit( "text:", "some text" );
tab1->addSliderInt( "slider:" , 50, 0, 100 );
addTabWidgetContent( tab1 );
//========================================================================
m_layout->addWidget( m_treeWidget );
m_layout->addLayout( buttonLayout );
m_layout->addWidget( m_tabWidget );
......@@ -111,12 +101,80 @@ WQtDatasetTreeItem* WQtDatasetBrowser::addDataset( boost::shared_ptr< WModule >
void WQtDatasetBrowser::selectTreeItem()
{
WLogger::getLogger()->addLogMessage( "tree item clicked: " );
WLogger::getLogger()->addLogMessage( std::string( m_treeWidget->selectedItems().at( 0 )->text( 0 ).toAscii() ) );
( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->emitSelect();
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
std::map < std::string, WProperty* >*props = module->getProperties()->getProperties();
std::map < std::string, WProperty* >::const_iterator propIt = props->begin();
WQtDSBWidget* tab1 = new WQtDSBWidget( "settings" );
while ( propIt != props->end() )
{
switch ( propIt->second->getType() )
{
case P_BOOL:
{
WQtCheckBox* box = tab1->addCheckBox( propIt->second->getName(), propIt->second->getValue<bool>() );
box->getboostSignal()->connect( boost::bind( &WQtDatasetBrowser::slotSetBoolProperty, this, _1, _2 ) );
break;
}
case P_CHAR:
break;
case P_UNSIGNED_CHAR:
break;
case P_INT:
{
WQtSliderWithEdit* slider = tab1->addSliderInt( propIt->second->getName(), propIt->second->getValue<int>(),
propIt->second->getMin<int>(), propIt->second->getMax<int>() );
slider->getboostSignal()->connect( boost::bind( &WQtDatasetBrowser::slotSetIntProperty, this, _1, _2 ) );
break;
}
case P_UNSIGNED_INT:
break;
case P_FLOAT:
break;
case P_DOUBLE:
break;
case P_STRING:
{
WQtLineEdit* edit = tab1->addLineEdit( propIt->second->getName(), propIt->second->getValue<std::string>() );
edit->getboostSignal()->connect( boost::bind( &WQtDatasetBrowser::slotSetStringProperty, this, _1, _2 ) );
break;
}
default:
break;
}
++propIt;
}
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak
m_tabWidget->clear();
addTabWidgetContent( tab1 );
}
void WQtDatasetBrowser::addTabWidgetContent( WQtDSBWidget* content )
{
m_tabWidget->addTab( content, content->getName() );
}
void WQtDatasetBrowser::slotSetIntProperty( std::string name, int value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<int>( name, value );
}
void WQtDatasetBrowser::slotSetBoolProperty( std::string name, bool value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<bool>( name, value );
}
void WQtDatasetBrowser::slotSetStringProperty( std::string name, std::string value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<std::string>( name, value );
if ( name == "name")
{
m_treeWidget->selectedItems().at( 0 )->setText( 0, QString( value.c_str() ) );
}
}
......@@ -81,6 +81,10 @@ protected:
private:
void slotSetIntProperty( std::string name, int value );
void slotSetBoolProperty( std::string name, bool value );
void slotSetStringProperty( std::string name, std::string value );
WQtTreeWidget* m_treeWidget;
QTabWidget* m_tabWidget;
QPushButton* m_downButton;
......
......@@ -46,3 +46,8 @@ void WQtDatasetTreeItem::emitSelect()
{
m_signalSelect();
}
boost::shared_ptr< WModule > WQtDatasetTreeItem::getModule()
{
return m_module;
}
......@@ -50,6 +50,11 @@ public:
*/
boost::signal0< void >* getSignalSelect();
/**
* get for the module pointer
*/
boost::shared_ptr< WModule >getModule();
/**
* helper function to signal this item has been selected
*/
......
//---------------------------------------------------------------------------
//
// 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 <string>
#include "WQtLineEdit.h"
WQtLineEdit::WQtLineEdit()
: QLineEdit()
{
m_name = "";
connect( this, SIGNAL( textEdited( QString ) ), this, SLOT( emitStateChanged() ) );
}
WQtLineEdit::~WQtLineEdit()
{
}
boost::signal2< void, std::string, std::string >*WQtLineEdit::getboostSignal()
{
return &m_boostSignal;
}
void WQtLineEdit::setName( std::string name )
{
m_name = name;
}
void WQtLineEdit::emitStateChanged()
{
std::string text = std::string( this->text().toLatin1() );
m_boostSignal( m_name, text );
}
//---------------------------------------------------------------------------
//
// 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 WQTLINEEDIT_H
#define WQTLINEEDIT_H
#include <string>
#include "../signalslib.hpp"
#include <QtGui/QLineEdit>
/**
* implements a QLineEdit with a boost signal
*/
class WQtLineEdit : public QLineEdit
{
Q_OBJECT
public:
/**
* standard constructor
*/
explicit WQtLineEdit();
/**
* destructor
*/
virtual ~WQtLineEdit();
/**
* \return the boost signal object
*/
boost::signal2< void, std::string, std::string >* getboostSignal();
/**
* setter for name
*/
void setName( std::string name );
private:
std::string m_name;
boost::signal2< void, std::string, std::string > m_boostSignal;
public slots:
void emitStateChanged();
};
#endif // WQTLINEEDIT_H
......@@ -22,6 +22,8 @@
//
//---------------------------------------------------------------------------
#include <string>
#include "WQtNumberEdit.h"
WQtNumberEdit::WQtNumberEdit( QWidget* parent )
......@@ -37,7 +39,7 @@ WQtNumberEdit::~WQtNumberEdit()
void WQtNumberEdit::setInt( int number )
{
setText( QString::number( number ) );
m_boostSignal( number );
m_boostSignal( m_name, number );
}
void WQtNumberEdit::numberChanged()
......@@ -47,17 +49,22 @@ void WQtNumberEdit::numberChanged()
if ( ok )
{
emit signalNumber( number );
m_boostSignal( number );
m_boostSignal( m_name, number );
}
else
{
setText( QString::number( 0 ) );
emit signalNumber( 0 );
m_boostSignal( 0 );
m_boostSignal( m_name, 0 );
}
}
boost::signal1< void, int >*WQtNumberEdit::getboostSignal()
boost::signal2< void, std::string, int >*WQtNumberEdit::getboostSignal()
{
return &m_boostSignal;
}
void WQtNumberEdit::setName( std::string name )
{
m_name = name;
}
......@@ -25,6 +25,8 @@
#ifndef WQTNUMBEREDIT_H
#define WQTNUMBEREDIT_H
#include <string>
#include "../signalslib.hpp"
#include <QtGui/QLineEdit>
......@@ -49,8 +51,12 @@ public:
/**
* getter for m_boostSignal
*/
boost::signal1< void, int >* getboostSignal();
boost::signal2< void, std::string, int >* getboostSignal();
/**
* setter for name
*/
void setName( std::string name );
public slots:
......@@ -63,7 +69,9 @@ signals:
protected:
private:
boost::signal1< void, int > m_boostSignal;
std::string m_name;
boost::signal2< void, std::string, int > m_boostSignal;
};
#endif // WQTNUMBEREDIT_H
......@@ -22,9 +22,11 @@
//
//---------------------------------------------------------------------------
#include <string>
#include "WQtSliderWithEdit.h"
WQtSliderWithEdit::WQtSliderWithEdit( QWidget* parent )
WQtSliderWithEdit::WQtSliderWithEdit( std::string name, QWidget* parent )
: QWidget( parent ),
m_slider( Qt::Horizontal ),
m_edit(),
......@@ -35,6 +37,7 @@ WQtSliderWithEdit::WQtSliderWithEdit( QWidget* parent )
m_edit.resize( 10, m_edit.size().height() );
m_edit.setMaximumWidth( 25 );
m_edit.setName( name );
setLayout( &m_layout );
......@@ -70,7 +73,7 @@ void WQtSliderWithEdit::setValue( int value )
m_slider.setValue( value );
}
boost::signal1< void, int >*WQtSliderWithEdit::getboostSignal()
boost::signal2< void, std::string, int >*WQtSliderWithEdit::getboostSignal()
{
return m_edit.getboostSignal();
}
......
......@@ -25,6 +25,8 @@
#ifndef WQTSLIDERWITHEDIT_H
#define WQTSLIDERWITHEDIT_H
#include <string>
#include "../signalslib.hpp"
#include "WQtNumberEdit.h"
......@@ -40,7 +42,7 @@ public: