mirror of
https://github.com/Fishwaldo/qt-openzwave.git
synced 2025-07-09 14:48:20 +00:00
more delegates - Start work on BitSet
This commit is contained in:
parent
d8c375c8ca
commit
879d86206c
9 changed files with 163 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -135,6 +135,7 @@ bool QTOZW_ValueIds::setData(const QModelIndex &index, const QVariant &value, in
|
|||
if (role != Qt::EditRole) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (static_cast<ValueIdColumns>(index.column())) {
|
||||
case Value:
|
||||
if (this->m_valueData[index.row()][static_cast<ValueIdColumns>(index.column())] != value) {
|
||||
|
|
14
simpleclient/bitsetwidget.cpp
Normal file
14
simpleclient/bitsetwidget.cpp
Normal file
|
@ -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;
|
||||
}
|
22
simpleclient/bitsetwidget.h
Normal file
22
simpleclient/bitsetwidget.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef BITSETWIDGET_H
|
||||
#define BITSETWIDGET_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
namespace Ui {
|
||||
class BitSetWidget;
|
||||
}
|
||||
|
||||
class BitSetWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BitSetWidget(QWidget *parent = nullptr);
|
||||
~BitSetWidget();
|
||||
|
||||
private:
|
||||
Ui::BitSetWidget *ui;
|
||||
};
|
||||
|
||||
#endif // BITSETWIDGET_H
|
19
simpleclient/bitsetwidget.ui
Normal file
19
simpleclient/bitsetwidget.ui
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BitSetWidget</class>
|
||||
<widget class="QFrame" name="BitSetWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>480</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<QTOZW_ValueIDBitSet>().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<QCheckBox*>(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<QSpinBox *>(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>() == QTOZW_ValueIds::ValueIdTypes::Int) {
|
||||
max = qMin(max, std::numeric_limits<int>::max());
|
||||
} else if (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>() == QTOZW_ValueIds::ValueIdTypes::Byte) {
|
||||
max = qMin(static_cast<uint8_t>(max), std::numeric_limits<uint8_t>::max());
|
||||
} else if (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>() == QTOZW_ValueIds::ValueIdTypes::Short) {
|
||||
max = qMin(static_cast<uint16_t>(max), std::numeric_limits<uint16_t>::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<QTOZW_ValueIds::ValueIdTypes>()) {
|
||||
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||
QComboBox* cb = qobject_cast<QComboBox*>(editor);
|
||||
if (!cb)
|
||||
throw std::logic_error("editor is not a combo box");
|
||||
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
|
||||
if (val.selectedItem != cb->currentText()) {
|
||||
val.selectedItem = cb->currentText();
|
||||
model->setData(index, QVariant::fromValue<QTOZW_ValueIDList>(val), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Bool: {
|
||||
QCheckBox* cb = qobject_cast<QCheckBox *>(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<QSpinBox *>(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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue