work on the BitSet ValueID

This commit is contained in:
Justin Hammond 2018-03-21 23:32:44 +08:00
parent 3f28433c7a
commit cd386efdd0
13 changed files with 203 additions and 43 deletions

@ -1 +1 @@
Subproject commit f69d2b97f167acd596c6b4afc4956fecb8da5a79
Subproject commit b3dc48718cb5d1895454579f2c7def8f8a35d582

View file

@ -28,6 +28,7 @@
#include <QMainWindow>
#include <QDateTime>
#include <iostream>
#include <QDebug>
#include "logwindow.h"
ozwAdminLog::ozwAdminLog()
@ -47,11 +48,14 @@ void ozwAdminLog::Write( OpenZWave::LogLevel _level, uint8 const _nodeId, char c
vsnprintf( lineBuf, sizeof(lineBuf), _format, _args );
va_end( saveargs );
}
// printf("Node %d: %s\n", _nodeId, lineBuf);
QString msg("Node: ");
msg.append(QString::number(_nodeId) + ": ");
msg.append(lineBuf);
emit newLogMsg(_level, _nodeId, msg);
if (_level < OpenZWave::LogLevel_StreamDetail) {
emit newLogMsg(_level, _nodeId, msg);
qDebug() << msg;
}
}

View file

@ -20,11 +20,14 @@
#include <QMessageBox>
#include <QDir>
#include <QDebug>
#include <QLoggingCategory>
#include "valueid.h"
int main(int argc, char *argv[])
{
QLoggingCategory::setFilterRules("default.debug=true");
qRegisterMetaType<QtValueID>();
qRegisterMetaType<uint8>("uint8");
qRegisterMetaType<QVector<int>>("QVector<int>");

View file

@ -213,6 +213,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->ui->val_config_tbl->setSelectionBehavior(QAbstractItemView::SelectRows);
this->ui->val_config_tbl->resizeColumnsToContents();
this->ui->val_config_tbl->resizeRowsToContents();
this->ui->val_config_tbl->horizontalHeader()->setStretchLastSection(true);
this->ui->val_config_tbl->verticalHeader()->hide();
this->ui->val_config_tbl->setSelectionMode(QAbstractItemView::SingleSelection);
@ -404,11 +405,13 @@ void MainWindow::NodeSelected(QModelIndex current,QModelIndex previous) {
this->ui->a_maxgroups->setText(QString::number(node->getNumGroups()));
for (int i = 1; i <= node->getNumGroups(); i++)
this->updateGroups(nodeid, i);
qDebug() << "doing config";
this->m_VFproxyModel_Config->setSourceModel(node->getValues());
qDebug() << "done config";
this->m_VFproxyModel_System->setSourceModel(node->getValues());
this->m_VFproxyModel_User->setSourceModel(node->getValues());
for (int i = 0; i < this->m_VFproxyModel_Config->rowCount(); ++i)
this->ui->val_config_tbl->openPersistentEditor(this->m_VFproxyModel_Config->index(i, 2));
this->ui->val_config_tbl->resizeColumnsToContents();
this->ui->val_config_tbl->resizeRowsToContents();
}

View file

@ -27,7 +27,7 @@
<item>
<widget class="QTabWidget" name="NodePane">
<property name="currentIndex">
<number>2</number>
<number>3</number>
</property>
<widget class="QWidget" name="n_info">
<attribute name="title">
@ -44,8 +44,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>573</width>
<height>468</height>
<width>604</width>
<height>535</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -289,8 +289,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>573</width>
<height>428</height>
<width>604</width>
<height>456</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -610,8 +610,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>588</width>
<height>276</height>
<width>618</width>
<height>291</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
@ -625,8 +625,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>564</width>
<height>184</height>
<width>600</width>
<height>205</height>
</rect>
</property>
<attribute name="label">
@ -643,8 +643,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>102</width>
<height>102</height>
<width>88</width>
<height>88</height>
</rect>
</property>
<attribute name="label">
@ -679,8 +679,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>588</width>
<height>276</height>
<width>618</width>
<height>291</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -717,8 +717,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>588</width>
<height>276</height>
<width>618</width>
<height>291</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
@ -757,7 +757,7 @@
<x>0</x>
<y>0</y>
<width>660</width>
<height>22</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View file

@ -162,7 +162,7 @@ bool QtValueIDList::removeRows(int position, int rows, const QModelIndex &index)
}
void QtValueIDList::addQtValueID(QtValueID *vid) {
qDebug() << "Adding Value";
//qDebug() << "Adding Value";
this->m_QtValueIDlist.append(vid);
beginInsertRows(QModelIndex(), this->m_QtValueIDlist.size(), this->m_QtValueIDlist.size());
endInsertRows();

View file

@ -66,8 +66,8 @@ uint8 QtValueID::GetType() const {
return this->m_vid.GetType();
}
QString QtValueID::GetLabel() const {
return OpenZWave::Manager::Get()->GetValueLabel(this->m_vid).c_str();
QString QtValueID::GetLabel(int32 pos) const {
return OpenZWave::Manager::Get()->GetValueLabel(this->m_vid, pos).c_str();
}
OpenZWave::ValueID const &QtValueID::getValueID() const {
@ -75,7 +75,7 @@ OpenZWave::ValueID const &QtValueID::getValueID() const {
}
QVariant QtValueID::getValue() {
qDebug() << "HomeID: " << this->GetHomeId();
//qDebug() << "HomeID: " << this->GetHomeId();
switch (this->GetType()) {
case OpenZWave::ValueID::ValueType_Bool: {
bool ret;
@ -118,7 +118,7 @@ QVariant QtValueID::getValue() {
break;
}
case OpenZWave::ValueID::ValueType_Schedule: {
qDebug() << "QtValueID getValue() Schedule todo";
qWarning() << "QtValueID getValue() Schedule todo";
break;
}
case OpenZWave::ValueID::ValueType_Short: {
@ -150,6 +150,22 @@ QVariant QtValueID::getValue() {
return QVariant();
break;
}
case OpenZWave::ValueID::ValueType_BitSet: {
uint8 size;
if (OpenZWave::Manager::Get()->GetBitSetSize(this->m_vid, &size)) {
QBitArray Values((8*size), false);
for (uint32 i = 0; i < (8 * size); i++) {
bool val;
if (OpenZWave::Manager::Get()->GetValueAsBitSet(this->m_vid, i+1, &val)) {
Values.setBit(i, val);
}
}
return Values;
}
qWarning() << "Couldn't Retrieve Value for BitSet";
return QVariant();
break;
}
}
}
@ -161,5 +177,21 @@ QStringList QtValueID::GetValueListItems() const {
} else {
return QStringList();
}
}
QBitArray QtValueID::GetBitMask() const {
QBitArray Items;
if (this->GetType() == OpenZWave::ValueID::ValueType_BitSet) {
int32 bitmask;
uint8 size;
if (OpenZWave::Manager::Get()->GetBitMask(this->m_vid, &bitmask) && OpenZWave::Manager::Get()->GetBitSetSize(this->m_vid, &size)) {
Items.resize(8*size);
Items.fill(false);
for (int32 i = 0; i < (8 *size); i++) {
Items.setBit(i, (bitmask & (1 << i)) ? true : false);
}
}
}
return Items;
}

View file

@ -20,6 +20,7 @@
#include <QObject>
#include <QHash>
#include <QAbstractTableModel>
#include <QBitArray>
#include "value_classes/ValueID.h"
@ -42,7 +43,8 @@ public:
OpenZWave::ValueID const &getValueID() const;
QVariant getValue();
QStringList GetValueListItems() const;
QString GetLabel() const;
QString GetLabel(int32 pos=-1) const;
QBitArray GetBitMask() const;
signals:

View file

@ -1,10 +1,12 @@
#include <QLineEdit>
#include <QCheckBox>
#include <QDebug>
#include <QApplication>
#include "valueiddelegate.h"
#include "valueid.h"
#include "bitsetwidget.h"
QString bit_array_to_string(const QBitArray& array);
ValueIDDelegate::ValueIDDelegate(QObject *parent) :
QStyledItemDelegate(parent)
@ -54,7 +56,6 @@ void ValueIDDelegate::paintCB(QPainter *painter, const QStyleOptionViewItem &opt
}
QWidget *ValueIDDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & /* option */,
const QModelIndex &index) const
@ -66,18 +67,34 @@ QWidget *ValueIDDelegate::createEditor(QWidget *parent,
// if (!isSupportedType(originalValue.type()))
// return 0;
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
QVariant value = index.model()->data(index, Qt::DisplayRole);
QtValueID *vid = qvariant_cast<QtValueID *>(value);
QWidget *widget;
return lineEdit;
if (vid->GetType() == OpenZWave::ValueID::ValueType_BitSet) {
BitSetWidget *cb = new BitSetWidget(parent);
// BitSetWidget *cb = new BitSetWidget();
//cb->setFrame(false);
widget = cb;
} else {
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
widget = lineEdit;
}
QAbstractItemModel *model = (QAbstractItemModel *)index.model();
model->setData(index, widget->sizeHint(), Qt::UserRole+100);
return widget;
}
void ValueIDDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QVariant value = index.model()->data(index, Qt::DisplayRole);
QtValueID *vid = qvariant_cast<QtValueID *>(value);
if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor))
lineEdit->setText(displayText(value, QLocale()));
if (BitSetWidget *bs = qobject_cast<BitSetWidget *>(editor))
bs->setValue(vid);
}
void ValueIDDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
@ -96,8 +113,8 @@ void ValueIDDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& locale ) const
{
QtValueID *vid = qvariant_cast<QtValueID *>(value);
qDebug() << "Display: " << vid->GetType();
qDebug() << "value: " << vid->getValue();
//qDebug() << "Display: " << vid->GetType();
//qDebug() << "value: " << vid->getValue();
switch (vid->GetType()) {
case OpenZWave::ValueID::ValueType_Bool:
case OpenZWave::ValueID::ValueType_Button: {
@ -110,7 +127,7 @@ QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& local
if (ok) {
return QString::number(val);
} else {
qDebug() << "byte Conversion Failed";
qWarning() << "byte Conversion Failed";
return QString::number((uint8)0);
}
break;
@ -121,7 +138,7 @@ QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& local
if (ok) {
return QString::number(val);
} else {
qDebug() << "Float Conversion Failed";
qWarning() << "Float Conversion Failed";
return QString::number((float)0);
}
break;
@ -132,7 +149,7 @@ QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& local
if (ok) {
return QString::number(val);
} else {
qDebug() << "Int Conversion Failed";
qWarning() << "Int Conversion Failed";
return QString::number((int)0);
}
break;
@ -143,13 +160,13 @@ QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& local
if (ok) {
return QString::number(val);
} else {
qDebug() << "Int Conversion Failed";
qWarning() << "Int Conversion Failed";
return QString::number((int)0);
}
break;
}
case OpenZWave::ValueID::ValueType_Schedule: {
qDebug() << "schedule todo";
qWarning() << "schedule todo";
break;
}
case OpenZWave::ValueID::ValueType_Short: {
@ -158,7 +175,7 @@ QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& local
if (ok) {
return QString::number(val);
} else {
qDebug() << "Short Conversion Failed";
qWarning() << "Short Conversion Failed";
return QString::number((short)0);
}
break;
@ -172,7 +189,43 @@ QString ValueIDDelegate::displayText(const QVariant &value, const QLocale& local
return vid->getValue().toString();
break;
}
case OpenZWave::ValueID::ValueType_BitSet: {
qDebug() << vid->GetBitMask();
qDebug() << vid->getValue();
qDebug() << bit_array_to_string(vid->getValue().toBitArray());
return bit_array_to_string(vid->getValue().toBitArray());
break;
}
}
qWarning() << "Unhandled ValueID Type";
return QString("returning <%1>").arg(vid->getValue().typeName());
}
void ValueIDDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
// if (index.column() == 2) {
// }
editor->setGeometry(option.rect);
}
QSize ValueIDDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
qDebug() << "size";
if (index.column() == 2) {
return index.model()->data(index, Qt::UserRole+100).toSize();
}
}
QString bit_array_to_string(const QBitArray& array)
{
QString str;
for(int i = 0;i < array.size();i++)
str += (array[i] ? "1" : "0");
return str;
}

View file

@ -10,11 +10,16 @@ public:
ValueIDDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
void paintCB(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paintBitSet(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE;
QString displayText(const QVariant &value, const QLocale& locale ) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#endif // VALUEIDDELEGATE_H

View file

@ -0,0 +1,34 @@
#include <QGroupBox>
#include <QCheckBox>
#include <QBitArray>
#include <QVBoxLayout>
#include <QVariant>
#include <QDebug>
#include "bitsetwidget.h"
BitSetWidget::BitSetWidget(QWidget *parent) :
QGroupBox(parent)
{
setAutoFillBackground(true);
//QGroupBox *groupBox = new QGroupBox;
QVBoxLayout *vbox = new QVBoxLayout;
vbox->setSpacing(0);
vbox->setMargin(0);
//groupBox->setSpacing(0);
//groupBox->setMargin(0);
this->setLayout(vbox);
//this->setCentralWidget(groupBox);
}
void BitSetWidget::setValue(QtValueID *vid) {
QBitArray ba = vid->getValue().toBitArray();
this->setTitle(vid->GetLabel());
for (int i = 0; i < ba.count(); ++i) {
QCheckBox *cb = new QCheckBox(vid->GetLabel(i), this);
cb->setChecked(ba.at(i));
cb->setProperty("index", i);
this->layout()->addWidget(cb);
qDebug() <<"done " << i;
}
}

View file

@ -0,0 +1,16 @@
#ifndef BITSETWIDGET_H
#define BITSETWIDGET_H
#include <QWidget>
#include <QGroupBox>
#include "valueid.h"
class BitSetWidget : public QGroupBox
{
Q_OBJECT
public:
BitSetWidget(QWidget *parent = NULL);
void setValue(QtValueID *);
};
#endif // BITSETWIDGET_H

View file

@ -13,13 +13,21 @@ TEMPLATE = lib
CONFIG += staticlib
SOURCES += widgets.cpp
SOURCES += widgets.cpp \
bitsetwidget.cpp
HEADERS += widgets.h
HEADERS += widgets.h \
bitsetwidget.h
FORMS += HelpEditorDlg.ui \
ListDialog.ui
INCLUDEPATH += ../devicedb-lib ../ozwadmin-main
unix {
INCLUDEPATH += $$top_srcdir/open-zwave/cpp/src/
}
macx: {
CONFIG += c++11
LIBS += -framework IOKit -framework CoreFoundation