Added column 'Action' to DeviceWidget
This commit is contained in:
parent
582029b63c
commit
635e120847
15 changed files with 241 additions and 62 deletions
|
@ -1,46 +1,49 @@
|
||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
# Project created by QtCreator 2008-12-11T15:48:29
|
# Project created by QtCreator 2008-12-11T15:48:29
|
||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
DEFINES += TELLDUSGUI_LIBRARY
|
DEFINES += TELLDUSGUI_LIBRARY
|
||||||
SOURCES += telldusgui.cpp \
|
SOURCES += telldusgui.cpp \
|
||||||
devicewidget.cpp \
|
devicewidget.cpp \
|
||||||
devicemodel.cpp \
|
devicemodel.cpp \
|
||||||
device.cpp \
|
device.cpp \
|
||||||
editdevicedialog.cpp \
|
editdevicedialog.cpp \
|
||||||
vendordevicemodel.cpp \
|
vendordevicemodel.cpp \
|
||||||
vendordevicetreeitem.cpp \
|
vendordevicetreeitem.cpp \
|
||||||
devicesettingikea.cpp \
|
devicesettingikea.cpp \
|
||||||
devicesettingnexa.cpp \
|
devicesettingnexa.cpp \
|
||||||
devicesettingnexabell.cpp \
|
devicesettingnexabell.cpp \
|
||||||
devicesettingsartano.cpp \
|
devicesettingsartano.cpp \
|
||||||
devicesetting.cpp
|
devicesetting.cpp \
|
||||||
HEADERS += telldusgui.h \
|
methodwidget.cpp \
|
||||||
devicewidget.h \
|
deviceview.cpp
|
||||||
devicemodel.h \
|
HEADERS += telldusgui.h \
|
||||||
device.h \
|
devicewidget.h \
|
||||||
editdevicedialog.h \
|
devicemodel.h \
|
||||||
vendordevicemodel.h \
|
device.h \
|
||||||
vendordevicetreeitem.h \
|
editdevicedialog.h \
|
||||||
devicesettingikea.h \
|
vendordevicemodel.h \
|
||||||
devicesettingnexa.h \
|
vendordevicetreeitem.h \
|
||||||
devicesettingnexabell.h \
|
devicesettingikea.h \
|
||||||
devicesettingsartano.h \
|
devicesettingnexa.h \
|
||||||
devicesetting.h
|
devicesettingnexabell.h \
|
||||||
FORMS +=
|
devicesettingsartano.h \
|
||||||
macx {
|
devicesetting.h \
|
||||||
LIBS += -framework \
|
methodwidget.h \
|
||||||
telldus-core
|
deviceview.h
|
||||||
ICON = images/telldussetup.icns
|
FORMS +=
|
||||||
TARGET = TelldusGui
|
macx {
|
||||||
CONFIG += lib_bundle
|
LIBS += -framework \
|
||||||
}
|
telldus-core
|
||||||
!macx {
|
ICON = images/telldussetup.icns
|
||||||
LIBS += -l \
|
TARGET = TelldusGui
|
||||||
telldus-core
|
CONFIG += lib_bundle
|
||||||
TARGET = telldus-gui
|
}
|
||||||
}
|
!macx {
|
||||||
win32 {
|
LIBS += -l \
|
||||||
LIBS += -L .
|
telldus-core
|
||||||
}
|
TARGET = telldus-gui
|
||||||
RESOURCES += telldusgui.qrc
|
}
|
||||||
|
win32:LIBS += -L \
|
||||||
|
.
|
||||||
|
RESOURCES += telldusgui.qrc
|
||||||
|
|
|
@ -11,7 +11,8 @@ Device::Device(int id)
|
||||||
p_protocol(""),
|
p_protocol(""),
|
||||||
p_modelChanged(false),
|
p_modelChanged(false),
|
||||||
p_nameChanged(false),
|
p_nameChanged(false),
|
||||||
p_protocolChanged(false)
|
p_protocolChanged(false),
|
||||||
|
p_methods(0)
|
||||||
{
|
{
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
char *name = tdGetName(id);
|
char *name = tdGetName(id);
|
||||||
|
@ -73,6 +74,12 @@ const QString &Device::protocol() {
|
||||||
return p_protocol;
|
return p_protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Device::methods() const {
|
||||||
|
if (p_methods == 0) {
|
||||||
|
const_cast<Device*>(this)->updateMethods();
|
||||||
|
}
|
||||||
|
return p_methods;
|
||||||
|
}
|
||||||
|
|
||||||
Device *Device::getDevice( int id ) {
|
Device *Device::getDevice( int id ) {
|
||||||
|
|
||||||
|
@ -102,6 +109,7 @@ void Device::save() {
|
||||||
|
|
||||||
if (p_modelChanged) {
|
if (p_modelChanged) {
|
||||||
tdSetModel(p_id, p_model);
|
tdSetModel(p_id, p_model);
|
||||||
|
updateMethods();
|
||||||
p_modelChanged = false;
|
p_modelChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,3 +122,26 @@ void Device::save() {
|
||||||
emit deviceAdded(p_id);
|
emit deviceAdded(p_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::turnOff() {
|
||||||
|
tdTurnOff( p_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::turnOn() {
|
||||||
|
tdTurnOn( p_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::bell() {
|
||||||
|
tdBell( p_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::updateMethods() {
|
||||||
|
int methods = tdMethods(p_id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_BELL | TELLSTICK_DIM);
|
||||||
|
if (p_methods != methods) {
|
||||||
|
bool doEmit = (p_methods > 0);
|
||||||
|
p_methods = methods;
|
||||||
|
if (doEmit) {
|
||||||
|
emit methodsChanged( p_methods );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,20 +28,29 @@ public:
|
||||||
void setProtocol( const QString & protocol );
|
void setProtocol( const QString & protocol );
|
||||||
const QString &protocol();
|
const QString &protocol();
|
||||||
|
|
||||||
|
int methods() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void save();
|
void save();
|
||||||
|
void turnOff();
|
||||||
|
void turnOn();
|
||||||
|
void bell();
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceAdded( int id );
|
void deviceAdded( int id );
|
||||||
|
void methodsChanged( int newMethods );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device(int id);
|
Device(int id);
|
||||||
|
void updateMethods();
|
||||||
|
|
||||||
static QHash<int, Device *> devices;
|
static QHash<int, Device *> devices;
|
||||||
QHash<QString, QString> p_settings;
|
QHash<QString, QString> p_settings;
|
||||||
int p_id, p_model;
|
int p_id, p_model;
|
||||||
QString p_name, p_protocol;
|
QString p_name, p_protocol;
|
||||||
bool p_modelChanged, p_nameChanged, p_protocolChanged;
|
bool p_modelChanged, p_nameChanged, p_protocolChanged;
|
||||||
|
mutable int p_methods;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICE_H
|
#endif // DEVICE_H
|
||||||
|
|
|
@ -19,11 +19,11 @@ int DeviceModel::rowCount(const QModelIndex &) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceModel::columnCount(const QModelIndex &) const {
|
int DeviceModel::columnCount(const QModelIndex &) const {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeviceModel::data(const QModelIndex &index, int role) const {
|
QVariant DeviceModel::data(const QModelIndex &index, int role) const {
|
||||||
if (index.column() > 1) {
|
if (index.column() > 2) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ QVariant DeviceModel::data(const QModelIndex &index, int role) const {
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
return tr("on");
|
return tr("on");
|
||||||
} else if (role == Qt::DecorationRole) {
|
} else if (role == Qt::DecorationRole) {
|
||||||
return QIcon( ":/images/list-add.png" );
|
return QIcon( ":/images/devices.png" );
|
||||||
} else if (role == Qt::TextAlignmentRole) {
|
} else if (role == Qt::TextAlignmentRole) {
|
||||||
return Qt::AlignCenter;
|
return Qt::AlignCenter;
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,24 @@ QVariant DeviceModel::data(const QModelIndex &index, int role) const {
|
||||||
Device *device = this->device( index );
|
Device *device = this->device( index );
|
||||||
return device->name();
|
return device->name();
|
||||||
}
|
}
|
||||||
|
} else if (index.column() == 2) {
|
||||||
|
// if (role == Qt::DisplayRole) {
|
||||||
|
// Device *device = this->device( index );
|
||||||
|
// return device->methods();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Qt::ItemFlags DeviceModel::flags ( const QModelIndex & index ) const {
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return Qt::ItemIsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||||
|
}*/
|
||||||
|
|
||||||
QVariant DeviceModel::headerData ( int section, Qt::Orientation orientation, int role ) const {
|
QVariant DeviceModel::headerData ( int section, Qt::Orientation orientation, int role ) const {
|
||||||
if (orientation != Qt::Horizontal) {
|
if (orientation != Qt::Horizontal) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -59,6 +72,8 @@ QVariant DeviceModel::headerData ( int section, Qt::Orientation orientation, int
|
||||||
return tr("State");
|
return tr("State");
|
||||||
case 1:
|
case 1:
|
||||||
return tr("Device name");
|
return tr("Device name");
|
||||||
|
case 2:
|
||||||
|
return tr("Action");
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
|
@ -16,6 +16,7 @@ public:
|
||||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
|
// virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
|
||||||
|
|
||||||
virtual bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
|
virtual bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
|
||||||
|
|
||||||
|
|
32
telldus-gui/TelldusGui/deviceview.cpp
Normal file
32
telldus-gui/TelldusGui/deviceview.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include "deviceview.h"
|
||||||
|
#include "methodwidget.h"
|
||||||
|
#include "devicemodel.h"
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeviceView::DeviceView(QWidget *parent)
|
||||||
|
: QTableView(parent)
|
||||||
|
{
|
||||||
|
setAlternatingRowColors( true );
|
||||||
|
setShowGrid( false );
|
||||||
|
setSelectionBehavior( QAbstractItemView::SelectRows );
|
||||||
|
horizontalHeader()->setStretchLastSection( true );
|
||||||
|
verticalHeader()->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceView::setModel ( QAbstractItemModel * model ) {
|
||||||
|
QTableView::setModel( model );
|
||||||
|
rowsInserted(QModelIndex(), 0, model->rowCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceView::rowsInserted ( const QModelIndex & /*parent*/, int start, int end ) {
|
||||||
|
DeviceModel *model = qobject_cast<DeviceModel*>( this->model() );
|
||||||
|
if (!model) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = start; i < end; ++i) {
|
||||||
|
QModelIndex index = model->index( i, 2, QModelIndex() );
|
||||||
|
this->setIndexWidget( index, new MethodWidget( model->device(index), this ) );
|
||||||
|
}
|
||||||
|
}
|
17
telldus-gui/TelldusGui/deviceview.h
Normal file
17
telldus-gui/TelldusGui/deviceview.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef DEVICEVIEW_H
|
||||||
|
#define DEVICEVIEW_H
|
||||||
|
|
||||||
|
#include <QTableView>
|
||||||
|
|
||||||
|
class DeviceView : public QTableView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DeviceView( QWidget *parent = 0);
|
||||||
|
virtual void setModel ( QAbstractItemModel * model );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void rowsInserted ( const QModelIndex & parent, int start, int end );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEVIEW_H
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
|
||||||
#include "editdevicedialog.h"
|
#include "editdevicedialog.h"
|
||||||
|
#include "methodwidget.h"
|
||||||
|
|
||||||
DeviceWidget::DeviceWidget(QWidget *parent) :
|
DeviceWidget::DeviceWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
|
@ -19,13 +20,9 @@ DeviceWidget::DeviceWidget(QWidget *parent) :
|
||||||
deviceView.setModel( &model );
|
deviceView.setModel( &model );
|
||||||
deviceView.resizeColumnsToContents();
|
deviceView.resizeColumnsToContents();
|
||||||
deviceView.resizeRowsToContents();
|
deviceView.resizeRowsToContents();
|
||||||
deviceView.setAlternatingRowColors( true );
|
|
||||||
deviceView.setShowGrid( false );
|
|
||||||
deviceView.setSelectionBehavior( QAbstractItemView::SelectRows );
|
|
||||||
deviceView.horizontalHeader()->setStretchLastSection( true );
|
|
||||||
deviceView.verticalHeader()->hide();
|
|
||||||
connect( &deviceView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(listActivated(const QModelIndex &)) );
|
connect( &deviceView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(listActivated(const QModelIndex &)) );
|
||||||
|
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
layout->addWidget(&deviceView);
|
layout->addWidget(&deviceView);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QtGui/QTableView>
|
#include <QtGui/QTableView>
|
||||||
#include <QtGui/QToolButton>
|
#include <QtGui/QToolButton>
|
||||||
#include "devicemodel.h"
|
#include "devicemodel.h"
|
||||||
|
#include "deviceview.h"
|
||||||
|
|
||||||
|
|
||||||
class DeviceWidget : public QWidget {
|
class DeviceWidget : public QWidget {
|
||||||
|
@ -25,7 +26,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceModel model;
|
DeviceModel model;
|
||||||
QTableView deviceView;
|
DeviceView deviceView;
|
||||||
QToolButton addToolButton, removeToolButton, editToolButton;
|
QToolButton addToolButton, removeToolButton, editToolButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
BIN
telldus-gui/TelldusGui/images/bell.png
Normal file
BIN
telldus-gui/TelldusGui/images/bell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
telldus-gui/TelldusGui/images/turn-off.png
Normal file
BIN
telldus-gui/TelldusGui/images/turn-off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
telldus-gui/TelldusGui/images/turn-on.png
Normal file
BIN
telldus-gui/TelldusGui/images/turn-on.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
47
telldus-gui/TelldusGui/methodwidget.cpp
Normal file
47
telldus-gui/TelldusGui/methodwidget.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include "methodwidget.h"
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
#include <telldus-core.h>
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
MethodWidget::MethodWidget( Device *device, QWidget *parent )
|
||||||
|
:QWidget(parent),
|
||||||
|
turnOff( new QToolButton( this ) ),
|
||||||
|
turnOn( new QToolButton( this ) ),
|
||||||
|
bell( new QToolButton( this ) )
|
||||||
|
{
|
||||||
|
// this->setAutoFillBackground( true );
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||||
|
layout->setMargin(0);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
|
||||||
|
turnOff->setIcon( QIcon(":/images/turn-off.png") );
|
||||||
|
turnOff->setVisible( false );
|
||||||
|
layout->addWidget( turnOff );
|
||||||
|
|
||||||
|
turnOn->setIcon( QIcon(":/images/turn-on.png") );
|
||||||
|
turnOn->setVisible( false );
|
||||||
|
layout->addWidget( turnOn );
|
||||||
|
|
||||||
|
bell->setIcon( QIcon(":/images/bell.png") );
|
||||||
|
bell->setVisible( false );
|
||||||
|
layout->addWidget( bell );
|
||||||
|
|
||||||
|
connect(device, SIGNAL(methodsChanged(int)), this, SLOT(updateMethods(int)));
|
||||||
|
connect(turnOff, SIGNAL(clicked()), device, SLOT(turnOff()));
|
||||||
|
connect(turnOn, SIGNAL(clicked()), device, SLOT(turnOn()));
|
||||||
|
connect(bell, SIGNAL(clicked()), device, SLOT(bell()));
|
||||||
|
|
||||||
|
updateMethods(device->methods());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MethodWidget::updateMethods(int newMethods) {
|
||||||
|
turnOff->setVisible( newMethods & TELLSTICK_TURNOFF );
|
||||||
|
turnOn->setVisible( newMethods & TELLSTICK_TURNON );
|
||||||
|
bell->setVisible( newMethods & TELLSTICK_BELL );
|
||||||
|
// qDebug() << "Methods: " << newMethods;
|
||||||
|
}
|
||||||
|
|
23
telldus-gui/TelldusGui/methodwidget.h
Normal file
23
telldus-gui/TelldusGui/methodwidget.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef METHODWIDGET_H
|
||||||
|
#define METHODWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
class QToolButton;
|
||||||
|
|
||||||
|
class MethodWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MethodWidget( Device *device, QWidget *parent = 0 );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateMethods(int newMethods);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Device *device;
|
||||||
|
QToolButton *turnOff, *turnOn, *bell;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // METHODWIDGET_H
|
|
@ -1,23 +1,26 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/" >
|
<qresource prefix="/" >
|
||||||
<file>data/devices.xml</file>
|
<file>data/devices.xml</file>
|
||||||
<file>images/list-add.png</file>
|
<file>images/bell.png</file>
|
||||||
<file>images/list-edit.png</file>
|
<file>images/devices/143011.jpg</file>
|
||||||
<file>images/list-remove.png</file>
|
|
||||||
<file>images/devices/17-356.jpg</file>
|
|
||||||
<file>images/devices/14323.jpg</file>
|
<file>images/devices/14323.jpg</file>
|
||||||
<file>images/devices/14327.jpg</file>
|
<file>images/devices/14327.jpg</file>
|
||||||
<file>images/devices/51340.jpg</file>
|
|
||||||
<file>images/devices/143011.jpg</file>
|
|
||||||
<file>images/devices/145041.jpg</file>
|
<file>images/devices/145041.jpg</file>
|
||||||
<file>images/devices/145071.jpg</file>
|
<file>images/devices/145071.jpg</file>
|
||||||
<file>images/devices/145091.jpg</file>
|
<file>images/devices/145091.jpg</file>
|
||||||
|
<file>images/devices/17-356.jpg</file>
|
||||||
|
<file>images/devices/51340.jpg</file>
|
||||||
<file>images/devices/el2005.jpg</file>
|
<file>images/devices/el2005.jpg</file>
|
||||||
<file>images/devices/el2019.jpg</file>
|
<file>images/devices/el2019.jpg</file>
|
||||||
<file>images/devices/hdr.jpg</file>
|
<file>images/devices/hdr.jpg</file>
|
||||||
<file>images/devices/koppla.jpg</file>
|
<file>images/devices/koppla.jpg</file>
|
||||||
<file>images/devices/ml.jpg</file>
|
<file>images/devices/ml.jpg</file>
|
||||||
<file>images/devices/sycr.jpg</file>
|
<file>images/devices/sycr.jpg</file>
|
||||||
|
<file>images/list-add.png</file>
|
||||||
|
<file>images/list-edit.png</file>
|
||||||
|
<file>images/list-remove.png</file>
|
||||||
|
<file>images/turn-off.png</file>
|
||||||
|
<file>images/turn-on.png</file>
|
||||||
<file>images/vendors/ikea.jpg</file>
|
<file>images/vendors/ikea.jpg</file>
|
||||||
<file>images/vendors/intertechno.jpg</file>
|
<file>images/vendors/intertechno.jpg</file>
|
||||||
<file>images/vendors/nexa.jpg</file>
|
<file>images/vendors/nexa.jpg</file>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue