diff --git a/qt-openzwave/qtozwmanager.cpp b/qt-openzwave/qtozwmanager.cpp index bce787c..b5ecd46 100644 --- a/qt-openzwave/qtozwmanager.cpp +++ b/qt-openzwave/qtozwmanager.cpp @@ -37,7 +37,7 @@ QTOZWManager_Internal::QTOZWManager_Internal(QObject *parent) this->m_options->AddOptionInt( "SaveLogLevel", OpenZWave::LogLevel_Detail ); this->m_options->AddOptionInt( "QueueLogLevel", OpenZWave::LogLevel_Debug ); this->m_options->AddOptionInt( "DumpTrigger", OpenZWave::LogLevel_Error ); - this->m_options->AddOptionBool("ConsoleOutput", false); + this->m_options->AddOptionBool("ConsoleOutput", true); this->m_options->AddOptionInt( "PollInterval", 500 ); this->m_options->AddOptionBool( "IntervalBetweenPolls", true ); this->m_options->AddOptionBool( "ValidateValueChanges", true); diff --git a/qt-openzwave/qtozwvalueidmodel.cpp b/qt-openzwave/qtozwvalueidmodel.cpp index 2993d74..02832bb 100644 --- a/qt-openzwave/qtozwvalueidmodel.cpp +++ b/qt-openzwave/qtozwvalueidmodel.cpp @@ -135,6 +135,7 @@ bool QTOZW_ValueIds::setData(const QModelIndex &index, const QVariant &value, in if (role != Qt::EditRole) { return false; } + switch (static_cast(index.column())) { case Value: if (this->m_valueData[index.row()][static_cast(index.column())] != value) { diff --git a/simpleclient/bitsetwidget.cpp b/simpleclient/bitsetwidget.cpp new file mode 100644 index 0000000..0b80da7 --- /dev/null +++ b/simpleclient/bitsetwidget.cpp @@ -0,0 +1,14 @@ +#include "bitsetwidget.h" +#include "ui_bitsetwidget.h" + +BitSetWidget::BitSetWidget(QWidget *parent) : + QFrame(parent), + ui(new Ui::BitSetWidget) +{ + ui->setupUi(this); +} + +BitSetWidget::~BitSetWidget() +{ + delete ui; +} diff --git a/simpleclient/bitsetwidget.h b/simpleclient/bitsetwidget.h new file mode 100644 index 0000000..f3a9c62 --- /dev/null +++ b/simpleclient/bitsetwidget.h @@ -0,0 +1,22 @@ +#ifndef BITSETWIDGET_H +#define BITSETWIDGET_H + +#include + +namespace Ui { +class BitSetWidget; +} + +class BitSetWidget : public QFrame +{ + Q_OBJECT + +public: + explicit BitSetWidget(QWidget *parent = nullptr); + ~BitSetWidget(); + +private: + Ui::BitSetWidget *ui; +}; + +#endif // BITSETWIDGET_H diff --git a/simpleclient/bitsetwidget.ui b/simpleclient/bitsetwidget.ui new file mode 100644 index 0000000..05223f7 --- /dev/null +++ b/simpleclient/bitsetwidget.ui @@ -0,0 +1,19 @@ + + + BitSetWidget + + + + 0 + 0 + 640 + 480 + + + + Frame + + + + + diff --git a/simpleclient/mainwindow.cpp b/simpleclient/mainwindow.cpp index c822eae..18a1d57 100644 --- a/simpleclient/mainwindow.cpp +++ b/simpleclient/mainwindow.cpp @@ -85,6 +85,8 @@ void MainWindow::QTOZW_Ready() { this->ui->configView->verticalHeader()->hide(); this->ui->configView->setSelectionBehavior(QAbstractItemView::SelectRows); this->ui->configView->setSelectionMode(QAbstractItemView::SingleSelection); + this->ui->configView->setEditTriggers(QAbstractItemView::AllEditTriggers); + this->ui->configView->setItemDelegateForColumn(QTOZW_ValueIds::ValueIdColumns::Value, delegate); @@ -99,6 +101,8 @@ void MainWindow::QTOZW_Ready() { this->ui->systemView->verticalHeader()->hide(); this->ui->systemView->setSelectionBehavior(QAbstractItemView::SelectRows); this->ui->systemView->setSelectionMode(QAbstractItemView::SingleSelection); + this->ui->systemView->setEditTriggers(QAbstractItemView::AllEditTriggers); + this->ui->systemView->setItemDelegateForColumn(QTOZW_ValueIds::ValueIdColumns::Value, delegate); diff --git a/simpleclient/qtozw_itemdelegate.cpp b/simpleclient/qtozw_itemdelegate.cpp index 39390a5..223e0f2 100644 --- a/simpleclient/qtozw_itemdelegate.cpp +++ b/simpleclient/qtozw_itemdelegate.cpp @@ -8,6 +8,18 @@ QTOZW_ItemDelegate::QTOZW_ItemDelegate(QObject *parent) : QStyledItemDelegate(pa { } +QString BitSettoQString(QBitArray ba) { + QString result; + for (int i = 0; i < ba.size(); ++i) { + if (ba.testBit(i)) + result[i] = '1'; + else + result[i] = '0'; + } + result.prepend("0b"); + return result; +} + void QTOZW_ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type); @@ -39,9 +51,15 @@ void QTOZW_ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op if (readOnly) cbOption.state |= QStyle::State_ReadOnly; QApplication::style()->drawControl(QStyle::CE_CheckBox, &cbOption, painter); - break; } + case QTOZW_ValueIds::ValueIdTypes::BitSet: { + QStyleOptionViewItem itemOption(option); + initStyleOption(&itemOption, index); + itemOption.text = BitSettoQString(index.data().value().values); + qDebug() << itemOption.text; + QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &itemOption, painter); + } #if 0 case QTOZW_ValueIds::ValueIdTypes::Int: case QTOZW_ValueIds::ValueIdTypes::Byte: @@ -115,7 +133,18 @@ QWidget *QTOZW_ItemDelegate::createEditor(QWidget *parent, const QStyleOptionVie connect(editor, &QComboBox::currentTextChanged, this, &QTOZW_ItemDelegate::commitAndCloseEditor); return editor; } - + case QTOZW_ValueIds::ValueIdTypes::Bool: { + QCheckBox *editor = new QCheckBox(parent); + editor->setAutoFillBackground(true); + return editor; + } + case QTOZW_ValueIds::ValueIdTypes::Int: + case QTOZW_ValueIds::ValueIdTypes::Short: + case QTOZW_ValueIds::ValueIdTypes::Byte: { + QSpinBox *editor = new QSpinBox(parent); + editor->setAutoFillBackground(true); + return editor; + } default: return QStyledItemDelegate::createEditor(parent, option, index); @@ -140,6 +169,30 @@ void QTOZW_ItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index cb->showPopup(); break; } + case QTOZW_ValueIds::ValueIdTypes::Bool: { + QCheckBox *cb = static_cast(editor); + bool value = index.data().toBool(); + cb->setChecked(value); + break; + } + case QTOZW_ValueIds::ValueIdTypes::Int: + case QTOZW_ValueIds::ValueIdTypes::Short: + case QTOZW_ValueIds::ValueIdTypes::Byte: { + QSpinBox *sb = qobject_cast(editor); + int min = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Min).data().toInt(); + int max = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Max).data().toInt(); + if (typeIndex.data().value() == QTOZW_ValueIds::ValueIdTypes::Int) { + max = qMin(max, std::numeric_limits::max()); + } else if (typeIndex.data().value() == QTOZW_ValueIds::ValueIdTypes::Byte) { + max = qMin(static_cast(max), std::numeric_limits::max()); + } else if (typeIndex.data().value() == QTOZW_ValueIds::ValueIdTypes::Short) { + max = qMin(static_cast(max), std::numeric_limits::max()); + } + sb->setRange(min, max); + sb->setValue(index.data().toInt()); + break; + } + default: QStyledItemDelegate::setEditorData(editor, index); } @@ -151,3 +204,45 @@ void QTOZW_ItemDelegate::commitAndCloseEditor() { emit closeEditor(editor); } +void QTOZW_ItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const +{ + QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type); + switch (typeIndex.data().value()) { + case QTOZW_ValueIds::ValueIdTypes::List: { + QComboBox* cb = qobject_cast(editor); + if (!cb) + throw std::logic_error("editor is not a combo box"); + QTOZW_ValueIDList val = index.data().value(); + if (val.selectedItem != cb->currentText()) { + val.selectedItem = cb->currentText(); + model->setData(index, QVariant::fromValue(val), Qt::EditRole); + } + break; + } + case QTOZW_ValueIds::ValueIdTypes::Bool: { + QCheckBox* cb = qobject_cast(editor); + if (!cb) + throw std::logic_error("editor is not a checkbox"); + bool value = index.data().toBool(); + if (value != cb->isChecked()) { + model->setData(index, cb->isChecked(), Qt::EditRole); + } + break; + } + case QTOZW_ValueIds::ValueIdTypes::Int: + case QTOZW_ValueIds::ValueIdTypes::Short: + case QTOZW_ValueIds::ValueIdTypes::Byte: { + QSpinBox* sb = qobject_cast(editor); + if (!sb) + throw std::logic_error("Editor is not a spinbox"); + int value = index.data().toInt(); + if (value != sb->value()) { + model->setData(index, sb->value(), Qt::EditRole); + } + break; + } + + default: + break; + } +} diff --git a/simpleclient/qtozw_itemdelegate.h b/simpleclient/qtozw_itemdelegate.h index 62f1dec..5dd5b4f 100644 --- a/simpleclient/qtozw_itemdelegate.h +++ b/simpleclient/qtozw_itemdelegate.h @@ -16,6 +16,8 @@ public: QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; + void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override; + private slots: void commitAndCloseEditor(); diff --git a/simpleclient/simpleclient.pro b/simpleclient/simpleclient.pro index 9c6423c..e933b40 100644 --- a/simpleclient/simpleclient.pro +++ b/simpleclient/simpleclient.pro @@ -23,15 +23,18 @@ win32 { RC_ICONS += res/ozw_logo.ico } FORMS += \ + bitsetwidget.ui \ mainwindow.ui \ startup.ui SOURCES = main.cpp \ + bitsetwidget.cpp \ mainwindow.cpp \ qtozw_itemdelegate.cpp \ startup.cpp HEADERS += \ + bitsetwidget.h \ mainwindow.h \ qtozw_itemdelegate.h \ startup.h