mirror of
https://github.com/Fishwaldo/qt-openzwave.git
synced 2025-07-10 15:18:21 +00:00
more work on the delegates - Almost Complete
This commit is contained in:
parent
f479abe2e2
commit
4f38d3d9e2
8 changed files with 109 additions and 37 deletions
|
@ -6,17 +6,18 @@ mac {
|
||||||
}
|
}
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
|
system("$$PKG_CONFIG --exists openzwave"): USE_PKGCFG = TRUE
|
||||||
isEmpty(OZW_LIB_PATH) {
|
isEmpty(OZW_LIB_PATH) {
|
||||||
QT_CONFIG -= no-pkg-config
|
QT_CONFIG -= no-pkg-config
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
packagesExist(libopenzwave) {
|
if (USE_PKGCFG) {
|
||||||
message("Using Distribution copy of OpenZWave")
|
|
||||||
PKGCONFIG += openzwave
|
PKGCONFIG += openzwave
|
||||||
|
message("Using Distribution copy of OZW")
|
||||||
} else {
|
} else {
|
||||||
exists( $$top_srcdir/../open-zwave/cpp/src/) {
|
exists( $$top_srcdir/../open-zwave/cpp/src/) {
|
||||||
message("Found Openzwave in $$absolute_path($$top_srcdir/../open-zwave/cpp/src)")
|
message("Found OZW in $$absolute_path($$top_srcdir/../open-zwave/cpp/src)")
|
||||||
OZW_LIB_PATH = $$absolute_path($$top_srcdir/../open-zwave/)
|
OZW_LIB_PATH = $$absolute_path($$top_srcdir/../open-zwave/)
|
||||||
INCLUDEPATH += $$absolute_path($$top_srcdir/../open-zwave/cpp/src/)
|
INCLUDEPATH += $$absolute_path($$top_srcdir/../open-zwave/cpp/src/)/
|
||||||
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/) -lopenzwave
|
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/) -lopenzwave
|
||||||
} else {
|
} else {
|
||||||
error("Can't Find a copy of OpenZwave")
|
error("Can't Find a copy of OpenZwave")
|
||||||
|
@ -24,7 +25,7 @@ unix {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exists($$OZW_LIB_PATH/cpp/src/) {
|
exists($$OZW_LIB_PATH/cpp/src/) {
|
||||||
INCLUDEPATH += $$absolute_path($$OZW_LIB_PATH/cpp/src/)
|
INCLUDEPATH += $$absolute_path($$OZW_LIB_PATH/cpp/src/)/
|
||||||
LIBS += -L$$absolute_path($$OZW_LIB_PATH) -lopenzwave
|
LIBS += -L$$absolute_path($$OZW_LIB_PATH) -lopenzwave
|
||||||
message("Using OZW from Path Supplied in OZW_LIB_PATH varible: $$OZW_LIB_PATH" )
|
message("Using OZW from Path Supplied in OZW_LIB_PATH varible: $$OZW_LIB_PATH" )
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
include(../qt-openzwave.pri)
|
|
||||||
|
|
||||||
QT -= gui
|
QT -= gui
|
||||||
QT += remoteobjects
|
QT += remoteobjects
|
||||||
|
@ -18,10 +17,14 @@ CONFIG += silent
|
||||||
|
|
||||||
!versionAtLeast(QT_VERSION, 5.11.2):error("Use at least Qt version 5.11.2")
|
!versionAtLeast(QT_VERSION, 5.11.2):error("Use at least Qt version 5.11.2")
|
||||||
|
|
||||||
|
include(../qt-openzwave.pri)
|
||||||
|
|
||||||
|
|
||||||
qtConfig(static) {
|
qtConfig(static) {
|
||||||
# this is a static build
|
# this is a static build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#INCLUDEPATH += $$absolute_path($$top_srcdir/../open-zwave/cpp/src/)/
|
||||||
|
|
||||||
DEFINES += QTOPENZWAVE_LIBRARY
|
DEFINES += QTOPENZWAVE_LIBRARY
|
||||||
|
|
||||||
|
|
|
@ -119,8 +119,14 @@ Qt::ItemFlags QTOZW_ValueIds::flags(const QModelIndex &index) const {
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return Qt::ItemIsEnabled;
|
return Qt::ItemIsEnabled;
|
||||||
switch (static_cast<ValueIdColumns>(index.column())) {
|
switch (static_cast<ValueIdColumns>(index.column())) {
|
||||||
case Value:
|
case Value: {
|
||||||
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
|
QBitArray flags = index.sibling(index.row(), ValueIdColumns::ValueFlags).data().value<QBitArray>();
|
||||||
|
if (flags.at(ValueIDFlags::ReadOnly) == true) {
|
||||||
|
return QAbstractTableModel::flags(index);
|
||||||
|
} else {
|
||||||
|
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return QAbstractTableModel::flags(index);
|
return QAbstractTableModel::flags(index);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +186,6 @@ void QTOZW_ValueIds_internal::addValue(uint64_t _vidKey)
|
||||||
qWarning() << "ValueID " << _vidKey << " Already Exists";
|
qWarning() << "ValueID " << _vidKey << " Already Exists";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// QMap<int32_t, QMap<ValueIdColumns, QVariant> >
|
|
||||||
QMap<ValueIdColumns, QVariant> newValue;
|
QMap<ValueIdColumns, QVariant> newValue;
|
||||||
newValue[QTOZW_ValueIds::ValueIDKey] = _vidKey;
|
newValue[QTOZW_ValueIds::ValueIDKey] = _vidKey;
|
||||||
QBitArray flags(static_cast<int>(ValueIDFlags::FlagCount));
|
QBitArray flags(static_cast<int>(ValueIDFlags::FlagCount));
|
||||||
|
@ -211,12 +216,11 @@ void QTOZW_ValueIds_internal::setValueFlags(uint64_t _vidKey, QTOZW_ValueIds::Va
|
||||||
qWarning() << "setValueFlags: Value " << _vidKey << " does not exist";
|
qWarning() << "setValueFlags: Value " << _vidKey << " does not exist";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QBitArray flag = this->m_valueData[row][QTOZW_ValueIds::ValueFlags].toBitArray();
|
if (this->m_valueData[row][QTOZW_ValueIds::ValueFlags].toBitArray().at(_flags) != _value) {
|
||||||
if (flag.at(_flags) != _value) {
|
QBitArray flags = this->m_valueData[row][QTOZW_ValueIds::ValueFlags].value<QBitArray>();
|
||||||
flag.setBit(_flags, _value);
|
flags.setBit(_flags, _value);
|
||||||
this->m_valueData[row][QTOZW_ValueIds::ValueFlags] = flag;
|
this->m_valueData[row][QTOZW_ValueIds::ValueFlags] = flags;
|
||||||
this->dataChanged(this->createIndex(row, QTOZW_ValueIds::ValueFlags), this->createIndex(row, QTOZW_ValueIds::ValueFlags));
|
this->dataChanged(this->createIndex(row, QTOZW_ValueIds::ValueFlags), this->createIndex(row, QTOZW_ValueIds::ValueFlags));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
setenv.sh
Normal file
1
setenv.sh
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:`pwd`/qt-openzwave"
|
|
@ -85,6 +85,9 @@ void MainWindow::QTOZW_Ready() {
|
||||||
this->ui->configView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
this->ui->configView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
this->ui->configView->setSelectionMode(QAbstractItemView::SingleSelection);
|
this->ui->configView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
||||||
|
this->ui->configView->setItemDelegateForColumn(QTOZW_ValueIds::ValueIdColumns::Value, delegate);
|
||||||
|
|
||||||
|
|
||||||
QTOZW_proxyValueModel *proxySystemValueModel = new QTOZW_proxyValueModel(this);
|
QTOZW_proxyValueModel *proxySystemValueModel = new QTOZW_proxyValueModel(this);
|
||||||
proxySystemValueModel->setSourceModel(this->m_qtozwmanager->getValueModel());
|
proxySystemValueModel->setSourceModel(this->m_qtozwmanager->getValueModel());
|
||||||
proxySystemValueModel->setSelectionModel(selectNodeModel);
|
proxySystemValueModel->setSelectionModel(selectNodeModel);
|
||||||
|
@ -96,6 +99,8 @@ void MainWindow::QTOZW_Ready() {
|
||||||
this->ui->systemView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
this->ui->systemView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
this->ui->systemView->setSelectionMode(QAbstractItemView::SingleSelection);
|
this->ui->systemView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
||||||
|
this->ui->systemView->setItemDelegateForColumn(QTOZW_ValueIds::ValueIdColumns::Value, delegate);
|
||||||
|
|
||||||
|
|
||||||
QTOZW_proxyAssociationModel *proxyAssociationModel = new QTOZW_proxyAssociationModel(this);
|
QTOZW_proxyAssociationModel *proxyAssociationModel = new QTOZW_proxyAssociationModel(this);
|
||||||
proxyAssociationModel->setSourceModel(this->m_qtozwmanager->getAssociationModel());
|
proxyAssociationModel->setSourceModel(this->m_qtozwmanager->getAssociationModel());
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#include <QLabel>
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "qtozw_itemdelegate.h"
|
#include "qtozw_itemdelegate.h"
|
||||||
|
@ -9,33 +6,88 @@
|
||||||
QTOZW_ItemDelegate::QTOZW_ItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
QTOZW_ItemDelegate::QTOZW_ItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
this->m_comboBox = new QComboBox();
|
this->m_comboBox = new QComboBox();
|
||||||
this->m_comboBox->setFrame(false);
|
this->m_checkBox = new QCheckBox();
|
||||||
|
this->m_spinBox = new QSpinBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QTOZW_ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void QTOZW_ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type);
|
QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type);
|
||||||
if (typeIndex.data() != QTOZW_ValueIds::ValueIdTypes::List) {
|
|
||||||
return QStyledItemDelegate::paint(painter, option, index);
|
|
||||||
}
|
|
||||||
QModelIndex flagsIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::ValueFlags);
|
QModelIndex flagsIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::ValueFlags);
|
||||||
QTOZW_ValueIDBitSet flags = flagsIndex.data().value<QTOZW_ValueIDBitSet>();
|
QBitArray flags = flagsIndex.data().value<QBitArray>();
|
||||||
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
|
bool readOnly = flags.at(QTOZW_ValueIds::ValueIDFlags::ReadOnly);
|
||||||
this->m_comboBox->addItems(val.labels);
|
|
||||||
this->m_comboBox->setCurrentText(val.selectedItem);
|
switch (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>()) {
|
||||||
this->m_comboBox->resize(option.rect.size());
|
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||||
qDebug() << flags.values;
|
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
|
||||||
// if (flags.values.at(QTOZW_ValueIds::ValueIDFlags::ReadOnly) == true)
|
this->m_comboBox->setFrame(false);
|
||||||
// this->m_comboBox->setEnabled(false);
|
this->m_comboBox->addItems(val.labels);
|
||||||
painter->save();
|
this->m_comboBox->setCurrentText(val.selectedItem);
|
||||||
painter->translate(option.rect.topLeft());
|
this->m_comboBox->resize(option.rect.size());
|
||||||
this->m_comboBox->render(painter, QPoint(), QRegion(), QWidget::DrawChildren);
|
this->m_comboBox->setEnabled(!readOnly);
|
||||||
painter->restore();
|
painter->save();
|
||||||
|
painter->translate(option.rect.topLeft());
|
||||||
|
this->m_comboBox->render(painter, QPoint(), QRegion(), QWidget::DrawChildren);
|
||||||
|
painter->restore();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Bool: {
|
||||||
|
this->m_checkBox->setChecked(index.data().value<bool>());
|
||||||
|
this->m_checkBox->setEnabled(!readOnly);
|
||||||
|
this->m_checkBox->resize(option.rect.size());
|
||||||
|
painter->save();
|
||||||
|
painter->translate(option.rect.topLeft());
|
||||||
|
this->m_checkBox->render(painter, QPoint(), QRegion(), QWidget::DrawChildren);
|
||||||
|
painter->restore();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Int:
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Byte:
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Short: {
|
||||||
|
this->m_spinBox->setValue(index.data().toInt());
|
||||||
|
this->m_spinBox->setEnabled(!readOnly);
|
||||||
|
this->m_spinBox->resize(option.rect.size());
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
this->m_spinBox->setRange(min, max);
|
||||||
|
painter->save();
|
||||||
|
painter->translate(option.rect.topLeft());
|
||||||
|
this->m_spinBox->render(painter, QPoint(), QRegion(), QWidget::DrawChildren);
|
||||||
|
painter->restore();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return QStyledItemDelegate::paint(painter, option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize QTOZW_ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize QTOZW_ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
return this->m_comboBox->minimumSizeHint();
|
QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type);
|
||||||
|
switch (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>()) {
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||||
|
return this->m_comboBox->minimumSizeHint();
|
||||||
|
}
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Bool: {
|
||||||
|
return this->m_checkBox->minimumSizeHint();
|
||||||
|
}
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Int:
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Byte:
|
||||||
|
case QTOZW_ValueIds::ValueIdTypes::Short: {
|
||||||
|
return this->m_spinBox->minimumSize();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QSpinBox>
|
||||||
|
|
||||||
class QTOZW_ItemDelegate : public QStyledItemDelegate
|
class QTOZW_ItemDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
|
@ -19,7 +21,9 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox* m_comboBox;
|
QComboBox *m_comboBox;
|
||||||
|
QCheckBox *m_checkBox;
|
||||||
|
QSpinBox *m_spinBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTOZW_ITEMDELEGATE_H
|
#endif // QTOZW_ITEMDELEGATE_H
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
include(../qt-openzwave.pri)
|
|
||||||
|
|
||||||
QT += widgets remoteobjects
|
QT += widgets remoteobjects
|
||||||
|
|
||||||
|
@ -8,13 +7,16 @@ DEFINES += remote
|
||||||
LIBS += -L../qt-openzwave/ -lqt-openzwave -lresolv
|
LIBS += -L../qt-openzwave/ -lqt-openzwave -lresolv
|
||||||
INCLUDEPATH += ../qt-openzwave
|
INCLUDEPATH += ../qt-openzwave
|
||||||
|
|
||||||
|
include(../qt-openzwave.pri)
|
||||||
|
|
||||||
|
|
||||||
macx {
|
macx {
|
||||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14
|
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14
|
||||||
ICON = res/ozw_logo.icns
|
ICON = res/ozw_logo.icns
|
||||||
}
|
}
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
QMAKE_POST_LINK += ln -s $$OZW_LIB_PATH/config config
|
QMAKE_POST_LINK += "if [ ! -e config ]; then ln -s $$OZW_LIB_PATH/config config; fi"
|
||||||
}
|
}
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue