@ -1,26 +1,41 @@
@@ -1,26 +1,41 @@
# include <QHBoxLayout>
# include <QGridLayout>
# include <QPushButton>
# include "QGCParamWidget.h"
# include "UASInterface.h"
# include <QDebug>
QGCParamWidget : : QGCParamWidget ( UASInterface * uas , QWidget * parent ) :
QWidget ( parent ) ,
mav ( uas ) ,
components ( new QMap < int , QTreeWidgetItem * > ( ) )
QWidget ( parent ) ,
mav ( uas ) ,
components ( new QMap < int , QTreeWidgetItem * > ( ) )
{
// Create tree widget
tree = new QTreeWidget ( this ) ;
tree - > setColumnWidth ( 0 , 150 ) ;
// Set tree widget as widget onto this component
QHBox Layout * horizontalLayout ;
QGrid Layout * horizontalLayout ;
//form->setAutoFillBackground(false);
horizontalLayout = new QHBox Layout ( this ) ;
horizontalLayout - > setSpacing ( 0 ) ;
horizontalLayout = new QGrid Layout ( this ) ;
horizontalLayout - > setSpacing ( 6 ) ;
horizontalLayout - > setMargin ( 0 ) ;
horizontalLayout - > setSizeConstraint ( QLayout : : SetMinimumSize ) ;
horizontalLayout - > addWidget ( tree ) ;
horizontalLayout - > addWidget ( tree , 0 , 0 , 1 , 3 ) ;
QPushButton * readButton = new QPushButton ( tr ( " Read " ) ) ;
connect ( readButton , SIGNAL ( clicked ( ) ) , this , SLOT ( requestParameterList ( ) ) ) ;
horizontalLayout - > addWidget ( readButton , 1 , 0 ) ;
QPushButton * setButton = new QPushButton ( tr ( " Set (RAM) " ) ) ;
connect ( setButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setParameters ( ) ) ) ;
horizontalLayout - > addWidget ( setButton , 1 , 1 ) ;
QPushButton * writeButton = new QPushButton ( tr ( " Write (Disk) " ) ) ;
connect ( writeButton , SIGNAL ( clicked ( ) ) , this , SLOT ( writeParameters ( ) ) ) ;
horizontalLayout - > addWidget ( writeButton , 1 , 2 ) ;
// Set layout
this - > setLayout ( horizontalLayout ) ;
// Set header
@ -29,6 +44,11 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) :
@@ -29,6 +44,11 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) :
headerItems . append ( " Value " ) ;
tree - > setHeaderLabels ( headerItems ) ;
tree - > setColumnCount ( 2 ) ;
// Connect signals/slots
connect ( this , SIGNAL ( parameterChanged ( int , QString , float ) ) , mav , SLOT ( setParameter ( int , QString , float ) ) ) ;
// New parameters from UAS
connect ( uas , SIGNAL ( parameterChanged ( int , int , QString , float ) ) , this , SLOT ( addParameter ( int , int , QString , float ) ) ) ;
}
UASInterface * QGCParamWidget : : getUAS ( )
@ -42,8 +62,9 @@ UASInterface* QGCParamWidget::getUAS()
@@ -42,8 +62,9 @@ UASInterface* QGCParamWidget::getUAS()
* @ param component id of the component
* @ param componentName human friendly name of the component
*/
void QGCParamWidget : : addComponent ( int component , QString componentName )
void QGCParamWidget : : addComponent ( int uas , int component , QString componentName )
{
Q_UNUSED ( uas ) ;
QStringList list ;
list . append ( componentName ) ;
list . append ( QString : : number ( component ) ) ;
@ -58,8 +79,14 @@ void QGCParamWidget::addComponent(int component, QString componentName)
@@ -58,8 +79,14 @@ void QGCParamWidget::addComponent(int component, QString componentName)
}
}
void QGCParamWidget : : addParameter ( int component , QString parameterName , float value )
/**
* @ param uas System which has the component
* @ param component id of the component
* @ param parameterName human friendly name of the parameter
*/
void QGCParamWidget : : addParameter ( int uas , int component , QString parameterName , float value )
{
Q_UNUSED ( uas ) ;
// Insert parameter into map
//tree->appendParam(component, parameterName, value);
QStringList plist ;
@ -70,12 +97,49 @@ void QGCParamWidget::addParameter(int component, QString parameterName, float va
@@ -70,12 +97,49 @@ void QGCParamWidget::addParameter(int component, QString parameterName, float va
// Get component
if ( ! components - > contains ( component ) )
{
addComponent ( component , " Component # " + QString : : number ( component ) ) ;
addComponent ( uas , component , " Component # " + QString : : number ( component ) ) ;
}
components - > value ( component ) - > addChild ( item ) ;
item - > setFlags ( item - > flags ( ) | Qt : : ItemIsEditable ) ;
//connect(item, SIGNAL())
tree - > expandAll ( ) ;
tree - > update ( ) ;
}
void QGCParamWidget : : requestParameterList ( )
{
mav - > requestParameters ( ) ;
// Clear view
clear ( ) ;
}
/**
* @ param component the subsystem which has the parameter
* @ param parameterName name of the parameter , as delivered by the system
* @ param value value of the parameter
*/
void QGCParamWidget : : setParameter ( int component , QString parameterName , float value )
{
}
void QGCParamWidget : : setParameters ( )
{
//mav->setParameter(component, parameterName, value);
// Iterate through all components, through all parameters and emit them
/*QMap<int, QTreeWidgetItem>::iterator i;
for ( i = components - > begin ( ) ; i ! = components - > end ( ) ; + + i )
{
int compid = i . key ( ) ;
i . value ( ) - > children ( ) ;
} */
}
void QGCParamWidget : : writeParameters ( )
{
mav - > writeParameters ( ) ;
}
void QGCParamWidget : : clear ( )
{
tree - > clear ( ) ;