Added class DeviceSettingSelflearning. DeviceSettingArctechSelflearning should subclass this class

This commit is contained in:
Micke Prag 2011-02-25 15:20:01 +00:00
parent 365eaee951
commit 5e5df3f656
3 changed files with 127 additions and 0 deletions

View file

@ -24,6 +24,7 @@ SET( telldus-gui_SRCS
devicesettingnexabell.cpp
devicesettingrisingsun.cpp
devicesettingsartano.cpp
devicesettingselflearning.cpp
devicesettingunitcode.cpp
devicesettingupm.cpp
devicesetting.cpp
@ -51,6 +52,7 @@ SET( telldus-gui_MOC_HDRS
devicesettingnexabell.h
devicesettingrisingsun.h
devicesettingsartano.h
devicesettingselflearning.h
devicesettingunitcode.h
devicesettingupm.h
devicesetting.h

View file

@ -0,0 +1,80 @@
//
// C++ Implementation: devicesettingselflearning
//
// Description:
//
//
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2011
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "devicesettingselflearning.h"
#include "device.h"
#include <QGridLayout>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
#include <time.h>
DeviceSettingSelflearning::DeviceSettingSelflearning(Device *device, QWidget *parent)
: DeviceSetting(device, parent)
{
QGridLayout *gridLayout = new QGridLayout(this);
gridLayout->setSpacing(6);
gridLayout->setMargin(9);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->addItem( new QSpacerItem(20, 109, QSizePolicy::Minimum, QSizePolicy::Expanding), 0, 0 );
QLabel *labelRemotecodeTitle = new QLabel(this);
labelRemotecodeTitle->setObjectName(QString::fromUtf8("labelRemotecodeTitle"));
labelRemotecodeTitle->setAlignment(Qt::AlignCenter);
labelRemotecodeTitle->setText( tr("Remote code") );
gridLayout->addWidget(labelRemotecodeTitle, 1, 0);
spinRemotecode = new QSpinBox(this);
spinRemotecode->setObjectName(QString::fromUtf8("unitcode"));
spinRemotecode->setMinimum(1);
spinRemotecode->setMaximum(67108863);
gridLayout->addWidget(spinRemotecode, 2, 0);
gridLayout->addItem( new QSpacerItem(20, 109, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0 );
spinRemotecode->setValue( device->parameter("house", "1").toInt() );
QPushButton *randomButton = new QPushButton( tr("Randomize"), this);
connect(randomButton, SIGNAL(clicked()), this, SLOT(randomizeCode()));
gridLayout->addWidget( randomButton, 3, 0 );
//Seed the random number generator at widget creation
srand( (unsigned int)time( NULL ) );
}
DeviceSettingSelflearning::~DeviceSettingSelflearning()
{
}
void DeviceSettingSelflearning::saveParameters() {
p_device->setParameter( "house", QString::number(spinRemotecode->value()) );
}
void DeviceSettingSelflearning::setValue( const QString &name, const QString &value ) {
if (name == "house") {
spinRemotecode->setValue(value.toInt());
}
}
void DeviceSettingSelflearning::setRemoteMinMax(int min, int max) {
spinRemotecode->setMinimum(min);
spinRemotecode->setMaximum(max);
}
void DeviceSettingSelflearning::randomizeCode() {
int randomNumber = rand() % spinRemotecode->maximum() + spinRemotecode->minimum(); //Generate ranom number between min and max
spinRemotecode->setValue(randomNumber);
}

View file

@ -0,0 +1,45 @@
//
// C++ Interface: devicesettingnexa
//
// Description:
//
//
// Author: Fredrik Jacobsson <fredrik.jacobsson@telldus.se>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef DEVICESETTINGSELFLEARNING_H
#define DEVICESETTINGSELFLEARNING_H
#include "devicesetting.h"
class QGridLayout;
class QSpinBox;
class QLabel;
/**
@author Micke Prag <micke.prag@telldus.se>
*/
class DeviceSettingSelflearning : public DeviceSetting
{
Q_OBJECT
public:
DeviceSettingSelflearning(Device *device, QWidget *parent = 0);
virtual ~DeviceSettingSelflearning();
virtual void setRemoteMinMax(int min, int max);
public slots:
virtual void saveParameters();
virtual void setValue( const QString &name, const QString &value );
protected slots:
void randomizeCode();
protected:
QSpinBox *spinRemotecode;
};
#endif