mirror of
https://github.com/Fishwaldo/qt-openzwave.git
synced 2025-07-09 22:58:18 +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 {
|
||||
system("$$PKG_CONFIG --exists openzwave"): USE_PKGCFG = TRUE
|
||||
isEmpty(OZW_LIB_PATH) {
|
||||
QT_CONFIG -= no-pkg-config
|
||||
CONFIG += link_pkgconfig
|
||||
packagesExist(libopenzwave) {
|
||||
message("Using Distribution copy of OpenZWave")
|
||||
if (USE_PKGCFG) {
|
||||
PKGCONFIG += openzwave
|
||||
message("Using Distribution copy of OZW")
|
||||
} else {
|
||||
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/)
|
||||
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
|
||||
} else {
|
||||
error("Can't Find a copy of OpenZwave")
|
||||
|
@ -24,7 +25,7 @@ unix {
|
|||
}
|
||||
} else {
|
||||
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
|
||||
message("Using OZW from Path Supplied in OZW_LIB_PATH varible: $$OZW_LIB_PATH" )
|
||||
} else {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
include(../qt-openzwave.pri)
|
||||
|
||||
QT -= gui
|
||||
QT += remoteobjects
|
||||
|
@ -18,10 +17,14 @@ CONFIG += silent
|
|||
|
||||
!versionAtLeast(QT_VERSION, 5.11.2):error("Use at least Qt version 5.11.2")
|
||||
|
||||
include(../qt-openzwave.pri)
|
||||
|
||||
|
||||
qtConfig(static) {
|
||||
# this is a static build
|
||||
}
|
||||
|
||||
#INCLUDEPATH += $$absolute_path($$top_srcdir/../open-zwave/cpp/src/)/
|
||||
|
||||
DEFINES += QTOPENZWAVE_LIBRARY
|
||||
|
||||
|
|
|
@ -119,8 +119,14 @@ Qt::ItemFlags QTOZW_ValueIds::flags(const QModelIndex &index) const {
|
|||
if (!index.isValid())
|
||||
return Qt::ItemIsEnabled;
|
||||
switch (static_cast<ValueIdColumns>(index.column())) {
|
||||
case Value:
|
||||
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
|
||||
case Value: {
|
||||
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:
|
||||
return QAbstractTableModel::flags(index);
|
||||
}
|
||||
|
@ -180,7 +186,6 @@ void QTOZW_ValueIds_internal::addValue(uint64_t _vidKey)
|
|||
qWarning() << "ValueID " << _vidKey << " Already Exists";
|
||||
return;
|
||||
}
|
||||
// QMap<int32_t, QMap<ValueIdColumns, QVariant> >
|
||||
QMap<ValueIdColumns, QVariant> newValue;
|
||||
newValue[QTOZW_ValueIds::ValueIDKey] = _vidKey;
|
||||
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";
|
||||
return;
|
||||
}
|
||||
QBitArray flag = this->m_valueData[row][QTOZW_ValueIds::ValueFlags].toBitArray();
|
||||
if (flag.at(_flags) != _value) {
|
||||
flag.setBit(_flags, _value);
|
||||
this->m_valueData[row][QTOZW_ValueIds::ValueFlags] = flag;
|
||||
if (this->m_valueData[row][QTOZW_ValueIds::ValueFlags].toBitArray().at(_flags) != _value) {
|
||||
QBitArray flags = this->m_valueData[row][QTOZW_ValueIds::ValueFlags].value<QBitArray>();
|
||||
flags.setBit(_flags, _value);
|
||||
this->m_valueData[row][QTOZW_ValueIds::ValueFlags] = flags;
|
||||
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->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
this->ui->configView->setItemDelegateForColumn(QTOZW_ValueIds::ValueIdColumns::Value, delegate);
|
||||
|
||||
|
||||
QTOZW_proxyValueModel *proxySystemValueModel = new QTOZW_proxyValueModel(this);
|
||||
proxySystemValueModel->setSourceModel(this->m_qtozwmanager->getValueModel());
|
||||
proxySystemValueModel->setSelectionModel(selectNodeModel);
|
||||
|
@ -96,6 +99,8 @@ void MainWindow::QTOZW_Ready() {
|
|||
this->ui->systemView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
this->ui->systemView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
this->ui->systemView->setItemDelegateForColumn(QTOZW_ValueIds::ValueIdColumns::Value, delegate);
|
||||
|
||||
|
||||
QTOZW_proxyAssociationModel *proxyAssociationModel = new QTOZW_proxyAssociationModel(this);
|
||||
proxyAssociationModel->setSourceModel(this->m_qtozwmanager->getAssociationModel());
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#include <QLabel>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include "qtozw_itemdelegate.h"
|
||||
|
@ -9,33 +6,88 @@
|
|||
QTOZW_ItemDelegate::QTOZW_ItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||
{
|
||||
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
|
||||
{
|
||||
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);
|
||||
QTOZW_ValueIDBitSet flags = flagsIndex.data().value<QTOZW_ValueIDBitSet>();
|
||||
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
|
||||
this->m_comboBox->addItems(val.labels);
|
||||
this->m_comboBox->setCurrentText(val.selectedItem);
|
||||
this->m_comboBox->resize(option.rect.size());
|
||||
qDebug() << flags.values;
|
||||
// if (flags.values.at(QTOZW_ValueIds::ValueIDFlags::ReadOnly) == true)
|
||||
// this->m_comboBox->setEnabled(false);
|
||||
painter->save();
|
||||
painter->translate(option.rect.topLeft());
|
||||
this->m_comboBox->render(painter, QPoint(), QRegion(), QWidget::DrawChildren);
|
||||
painter->restore();
|
||||
QBitArray flags = flagsIndex.data().value<QBitArray>();
|
||||
bool readOnly = flags.at(QTOZW_ValueIds::ValueIDFlags::ReadOnly);
|
||||
|
||||
switch (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>()) {
|
||||
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
|
||||
this->m_comboBox->setFrame(false);
|
||||
this->m_comboBox->addItems(val.labels);
|
||||
this->m_comboBox->setCurrentText(val.selectedItem);
|
||||
this->m_comboBox->resize(option.rect.size());
|
||||
this->m_comboBox->setEnabled(!readOnly);
|
||||
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
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
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 <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
|
||||
class QTOZW_ItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
|
@ -19,7 +21,9 @@ signals:
|
|||
public slots:
|
||||
|
||||
private:
|
||||
QComboBox* m_comboBox;
|
||||
QComboBox *m_comboBox;
|
||||
QCheckBox *m_checkBox;
|
||||
QSpinBox *m_spinBox;
|
||||
};
|
||||
|
||||
#endif // QTOZW_ITEMDELEGATE_H
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
include(../qt-openzwave.pri)
|
||||
|
||||
QT += widgets remoteobjects
|
||||
|
||||
|
@ -8,13 +7,16 @@ DEFINES += remote
|
|||
LIBS += -L../qt-openzwave/ -lqt-openzwave -lresolv
|
||||
INCLUDEPATH += ../qt-openzwave
|
||||
|
||||
include(../qt-openzwave.pri)
|
||||
|
||||
|
||||
macx {
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14
|
||||
ICON = res/ozw_logo.icns
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue