Mini-Breakthrough: Animantion works.

This commit is contained in:
2025-12-29 20:10:05 +01:00
parent 4491e6fe57
commit 60be19a6ae
11 changed files with 282 additions and 284 deletions

View File

@@ -27,8 +27,8 @@ windows
SOURCES += \ SOURCES += \
bc.cpp \ bc.cpp \
bcdatamanager.cpp \ bcdatamanager.cpp \
bcdelegate.cpp \
bcdevicepanel.cpp \ bcdevicepanel.cpp \
bcitemdelegate.cpp \
bclegacy.cpp \ bclegacy.cpp \
bctransmitter.cpp \ bctransmitter.cpp \
bcvalue.cpp \ bcvalue.cpp \
@@ -45,8 +45,8 @@ HEADERS += \
bccandriver.h \ bccandriver.h \
bccandrivertinycan.h \ bccandrivertinycan.h \
bcdatamanager.h \ bcdatamanager.h \
bcdelegate.h \
bcdevicepanel.h \ bcdevicepanel.h \
bcitemdelegate.h \
bcmainwindow.h \ bcmainwindow.h \
bctransmitter.h \ bctransmitter.h \
bcvalue.h \ bcvalue.h \

View File

@@ -31,7 +31,7 @@
#include <bcdevicepanel.h> #include <bcdevicepanel.h>
#include <bcdelegate.h> #include <bcitemdelegate.h>
BCDevicePanel::BCDevicePanel(QWidget *parent) BCDevicePanel::BCDevicePanel(QWidget *parent)
: QWidget(parent) : QWidget(parent)
@@ -41,8 +41,10 @@ BCDevicePanel::BCDevicePanel(QWidget *parent)
//_valueView->resizeColumnsToContents(); //_valueView->resizeColumnsToContents();
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); //_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
BCDelegate* delegate = new BCDelegate( _valueModel.getValueList(), _valueView); // __fix! ziemlich wildes ge-pointere, hier
_valueView->setItemDelegate( delegate ); _itemDelegate = new BCItemDelegate( _valueModel.getValueList(), _valueView);
_valueView->setItemDelegate( _itemDelegate );
} }
@@ -78,10 +80,12 @@ const BCValueList& BCDevicePanel::getValueListX()
return _valueModel.getValueList(); return _valueModel.getValueList();
} }
/*
BCValueModel& BCDevicePanel::getValueModel() BCValueModel& BCDevicePanel::getValueModel()
{ {
return _valueModel; return _valueModel;
} }
*/
// __FIX ist das ok so? // __FIX ist das ok so?
void BCDevicePanel::onValueListReady( BCDevice::ID deviceID, BCValueList valueList ) void BCDevicePanel::onValueListReady( BCDevice::ID deviceID, BCValueList valueList )
@@ -91,5 +95,11 @@ void BCDevicePanel::onValueListReady( BCDevice::ID deviceID, BCValueList valueLi
_valueModel.takeValueList( valueList ); _valueModel.takeValueList( valueList );
} }
void BCDevicePanel::onValueUpdated(int index, BC::State state, const QString& newVisibleValue )
{
_valueModel.onValueUpdated( index,state,newVisibleValue);
_itemDelegate->onHighlightRow( index );
}

View File

@@ -36,6 +36,8 @@
#include <bcvaluemodel.h> #include <bcvaluemodel.h>
#include <ui_bcdevicepanel.h> #include <ui_bcdevicepanel.h>
class BCItemDelegate;
class BCDevicePanel : public QWidget, private Ui::BCDevicePanel class BCDevicePanel : public QWidget, private Ui::BCDevicePanel
{ {
Q_OBJECT Q_OBJECT
@@ -53,17 +55,18 @@ public:
QTableView* getValueView(); QTableView* getValueView();
const BCValueList& getValueListX(); const BCValueList& getValueListX();
BCValueModel &getValueModel(); //BCValueModel &getValueModel();
public slots: public slots:
void onValueListReady( BCDevice::ID deviceID, BCValueList valueList ); void onValueListReady( BCDevice::ID deviceID, BCValueList valueList );
void onValueUpdated( int index, BC::State state, const QString& newVisibleValue="" );
protected: protected:
BCDevice::ID _devideID{BCDevice::ID::Invalid}; BCDevice::ID _devideID{BCDevice::ID::Invalid};
BCValueModel _valueModel; BCValueModel _valueModel;
BCItemDelegate* _itemDelegate{};
}; };

View File

@@ -14,12 +14,27 @@
<string>Form</string> <string>Form</string>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color:green;</string> <string notr="true"/>
</property> </property>
<property name="headerText" stdset="0"> <property name="headerText" stdset="0">
<string>Fitze!</string> <string>Fitze!</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="_headerLabel"> <widget class="QLabel" name="_headerLabel">
<property name="minimumSize"> <property name="minimumSize">
@@ -39,7 +54,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color:#0000ff</string> <string notr="true">background-color:#eeeeee</string>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum> <enum>QFrame::Shape::NoFrame</enum>

View File

@@ -43,20 +43,20 @@
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QPainter> #include <QPainter>
#include "bcdelegate.h" #include "bcitemdelegate.h"
#include "bcvalue.h" #include "bcvalue.h"
#include "qapplication.h"
BCDelegate::BCDelegate(const BCValueList& valueList, QTableView* view)
BCItemDelegate::BCItemDelegate(const BCValueList& valueList, QTableView* view)
: QStyledItemDelegate{view}, _valueList{valueList}, _view{view} : QStyledItemDelegate{view}, _valueList{valueList}, _view{view}
{ {
} }
/*
QString BCDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
{ {
// Wir prüfen, ob im Variant unser Struct steckt // Wir prüfen, ob im Variant unser Struct steckt
if (dataValue.canConvert<const BCValue*>()) if (dataValue.canConvert<const BCValue*>())
@@ -76,9 +76,10 @@ QString BCDelegate::displayText(const QVariant& dataValue, const QLocale& locale
// Fallback für normale Strings/Zahlen // Fallback für normale Strings/Zahlen
return QStyledItemDelegate::displayText(dataValue, locale); return QStyledItemDelegate::displayText(dataValue, locale);
} }
*/
QWidget *BCDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
QVariant rawData = index.data(Qt::EditRole); QVariant rawData = index.data(Qt::EditRole);
//if (!rawData.canConvert<BCValue*>()) //if (!rawData.canConvert<BCValue*>())
@@ -128,7 +129,7 @@ QWidget *BCDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o
*/ */
} }
void BCDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const void BCItemDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
{ {
// Daten vom Model in den Editor laden // Daten vom Model in den Editor laden
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>(); const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
@@ -147,7 +148,7 @@ void BCDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
} }
} }
void BCDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const void BCItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
{ {
// Daten vom Editor zurück ins Model speichern (Beim Schließen) // Daten vom Editor zurück ins Model speichern (Beim Schließen)
QSlider *slider = editor->findChild<QSlider*>("slider"); QSlider *slider = editor->findChild<QSlider*>("slider");
@@ -160,13 +161,13 @@ void BCDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const
} }
} }
void BCDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const void BCItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
// __fix! // __fix!
editor->setGeometry(option.rect); editor->setGeometry(option.rect);
} }
QSize BCDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const QSize BCItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
return QStyledItemDelegate::sizeHint(option,index); return QStyledItemDelegate::sizeHint(option,index);
/* /*
@@ -180,34 +181,13 @@ QSize BCDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex
} }
void BCDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
/*
// 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen // 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
QStyledItemDelegate::paint(painter, option, index); QStyledItemDelegate::paint(painter, option, index);
// 2. Unser Custom-Overlay: Oranger Rahmen, wenn Zeile passt //QPen pen(QColor(255, 165, 0)); // Orange
if (index.row() == _highlightedRow)
{
painter->save();
qDebug() << " --- is highlight: " << index.row();
// Setup Stift
QPen pen(QColor(255, 165, 0)); // Orange
pen.setWidth(2);
painter->setPen(pen);
// Rechteck zeichnen (leicht eingezogen, damit es nicht abgeschnitten wird)
QRect rect = option.rect.adjusted(1, 1, -1, -1);
painter->drawRect(rect);
painter->restore();
}
*/
QStyledItemDelegate::paint(painter, option, index);
/* /*
if (index.row() == _highlightedRow && _opacity > 0.0) if (index.row() == _highlightedRow && _opacity > 0.0)
@@ -231,61 +211,70 @@ void BCDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, co
int row = index.row(); int row = index.row();
if (m_rowOpacities.contains(row)) if (index.column() == 1 )
{ {
/* qDebug() << " --- is highlight: " << row << " : " << index.column();
qreal opacity = m_rowOpacities.value(row); //if( m_rowOpacities.contains(row))
if (opacity > 0.01)
{ {
qDebug() << " --- PAINT highlight:";
//if ( m_rowOpacities.contains(row))
paintHighlightRow(painter,option,index);
}
}
}
/*
qreal opacity = m_rowOpacities.value(row);
if (opacity > 0.01)
{
painter->save(); painter->save();
painter->setOpacity(opacity); painter->setOpacity(opacity);
painter->fillRect(option.rect, QColor(255, 140, 0, 120)); painter->fillRect(option.rect, QColor(255, 140, 0, 120));
painter->restore(); painter->restore();
}
*/
paintHighlightRow(painter,option,index);
}
} }
*/
void BCDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
void BCItemDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
int row = index.row(); int row = index.row();
qreal opacity = m_rowOpacities.value(row); qreal opacity = m_rowOpacities.value(row);
painter->setOpacity(opacity); painter->setOpacity(opacity);
// Margin von 4px // Margin von 4px
QRect itemRect = option.rect.adjusted(4, 4, -4, -4); QRect itemRect = option.rect.adjusted(3, 3, -3, -3);
// Border von 2px berücksichtigen (nach innen) // Border von 2px berücksichtigen (nach innen)
QRect contentRect = itemRect.adjusted(2, 2, -2, -2); QRect contentRect = itemRect.adjusted(2, 2, -2, -2);
// painter->fillRect(contentRect,Qt::green);
/*
// Hintergrund (weiß) // Hintergrund (weiß)
painter->setBrush(Qt::white); painter->setBrush(Qt::white);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
painter->drawRoundedRect(itemRect, 8, 8); painter->drawRoundedRect(itemRect, 8, 8);
*/
// Border (2px solid #2196F3) // Border (2px solid #2196F3)
QPen borderPen( Qt::red, 2); QPen borderPen( Qt::red, 1);
painter->setPen(borderPen); painter->setPen(borderPen);
painter->setBrush(Qt::NoBrush); painter->setBrush(Qt::NoBrush);
painter->drawRoundedRect(itemRect, 8, 8); painter->drawRoundedRect(itemRect, 2, 2);
// Padding von 8px für den Content // Padding von 8px für den Content
QRect textRect = contentRect.adjusted(8, 8, -8, -8); //QRect textRect = contentRect.adjusted(8, 8, -8, -8);
/*
// Text zeichnen // Text zeichnen
painter->setPen(Qt::black); // oder option.palette.color(QPalette::Text) painter->setPen(Qt::black); // oder option.palette.color(QPalette::Text)
QString text = index.data(Qt::DisplayRole).toString(); QString text = index.data(Qt::DisplayRole).toString();
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text); painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
*/
painter->restore(); painter->restore();
} }
void BCDelegate::onHighlightRow(int row) void BCItemDelegate::onHighlightRow(int row)
{ {
qDebug() << " --- should highlight: " << row; qDebug() << " --- should highlight: " << row;
@@ -334,7 +323,7 @@ void BCDelegate::onHighlightRow(int row)
} }
// Optional: alle Highlights sofort clearen // Optional: alle Highlights sofort clearen
void BCDelegate::clearAllHighlights() void BCItemDelegate::clearAllHighlights()
{ {
for(auto* anim : std::as_const(m_rowAnimations)) for(auto* anim : std::as_const(m_rowAnimations))
{ {
@@ -350,11 +339,11 @@ void BCDelegate::clearAllHighlights()
} }
} }
void BCDelegate::updateRow(int row) void BCItemDelegate::updateRow(int row)
{ {
if (_view && _view->model() && row >= 0) if (_view && _view->model() && row >= 0)
{ {
QModelIndex idx = _view->model()->index(row, 0); QModelIndex idx = _view->model()->index(row,1);
QRect rect = _view->visualRect(idx); QRect rect = _view->visualRect(idx);
if (!rect.isEmpty()) { if (!rect.isEmpty()) {
_view->viewport()->update(rect); _view->viewport()->update(rect);
@@ -362,35 +351,3 @@ void BCDelegate::updateRow(int row)
} }
} }
QString BCDelegate::formatDisplayString(const QModelIndex& index) const
{
if (!index.isValid())
return QString();
QString displayStr;
/*
QString label = index.data(BCValueListModel::LabelRole).toString();
QVariant value = index.data(BCValueListModel::ValueRole);
QString unit = index.data(BCValueListModel::UnitRole).toString();
QString valueStr = value.toString();
// Formatierung für Zahlen
bool ok;
double numValue = value.toDouble(&ok);
if (ok) {
valueStr = QString::number(numValue, 'f', 2);
}
// Zusammensetzen des Anzeige-Strings
QString displayStr = label;
if (!displayStr.isEmpty() && !valueStr.isEmpty())
displayStr += ": ";
displayStr += valueStr;
if (!unit.isEmpty())
displayStr += " " + unit;
*/
return displayStr;
}

View File

@@ -30,8 +30,8 @@
***************************************************************************/ ***************************************************************************/
#ifndef BCDELEGATE_H #ifndef BCITEMDELEGATE_H
#define BCDELEGATE_H #define BCITEMDELEGATE_H
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
@@ -40,16 +40,15 @@ class QVariantAnimation;
class QTableView; class QTableView;
class BCValueList; class BCValueList;
class BCDelegate : public QStyledItemDelegate class BCItemDelegate : public QStyledItemDelegate
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(qreal highlightOpacity READ highlightOpacity WRITE setHighlightOpacity)
public: public:
explicit BCDelegate(const BCValueList& valueList, QTableView* view ); explicit BCItemDelegate(const BCValueList& valueList, QTableView* view );
QString displayText(const QVariant& dataValue, const QLocale& locale) const override; // QString displayText(const QVariant& dataValue, const QLocale& locale) const override;
// Zuständig für den Edit-Modus (Doppelklick) // Zuständig für den Edit-Modus (Doppelklick)
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const override;
@@ -60,6 +59,7 @@ public:
QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex& index) const override; QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex& index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override;
/*
qreal highlightOpacity() const qreal highlightOpacity() const
{ {
return _opacity; return _opacity;
@@ -72,6 +72,7 @@ public:
// __fix! unsinn! // __fix! unsinn!
emit viewUpdateNeeded(); emit viewUpdateNeeded();
} }
*/
void clearAllHighlights(); void clearAllHighlights();
@@ -82,19 +83,18 @@ public slots:
signals: signals:
void viewUpdateNeeded(); //void viewUpdateNeeded();
private: private:
void updateRow(int row); void updateRow(int row);
QString formatDisplayString(const QModelIndex& index) const;
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
const BCValueList& _valueList; const BCValueList& _valueList;
QTableView* _view{}; QTableView* _view{};
int _highlightedRow{-1}; //int _highlightedRow{-1};
qreal _opacity{1.0}; //qreal _opacity{1.0};
QPropertyAnimation* _animation{}; QPropertyAnimation* _animation{};
@@ -106,4 +106,4 @@ private:
}; };
#endif // BCDELEGATE_H #endif // BCITEMDELEGATE_H

View File

@@ -34,7 +34,7 @@
#include "qassert.h" #include "qassert.h"
#include <bcmainwindow.h> #include <bcmainwindow.h>
#include <bcdelegate.h> #include <bcitemdelegate.h>
#include <ui_bcmainwindow.h> #include <ui_bcmainwindow.h>
@@ -114,17 +114,11 @@ void BCMainWindow::initMainWindow()
configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery, "Battery Settings"_L1 ); configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery, "Battery Settings"_L1 );
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp, "Pimp my Ride"_L1 ); configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp, "Pimp my Ride"_L1 );
/* /*
BCDelegate* _delegate = new BCDelegate( _valueView);
//_delegate = new AnimatedDelegate(_valueView );
_valueView->setItemDelegate( _delegate );
// Verwendung: // Verwendung:
connect(_delegate, &BCDelegate::viewUpdateNeeded, _valueView->viewport(), QOverload<>::of(&QWidget::update)); connect(_delegate, &BCItemDelegate::viewUpdateNeeded, _valueView->viewport(), QOverload<>::of(&QWidget::update));
//_valueView->setItemDelegate(_delegate); //_valueView->setItemDelegate(_delegate);
@@ -140,7 +134,7 @@ void BCMainWindow::initMainWindow()
// besser: model::emit dataChanged // besser: model::emit dataChanged
// also: emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole, ValueRole}); // also: emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole, ValueRole});
//connect( &_dataManager, &BCMainWindow::valueTouched, _delegate, &BCDelegate::onHighlightRow ); //connect( &_dataManager, &BCMainWindow::valueTouched, _delegate, &BCItemDelegate::onHighlightRow );
connect( _connectButton, &QToolButton::clicked, &_transmitter, &BCTransmitter::onToggleConnectionState ); connect( _connectButton, &QToolButton::clicked, &_transmitter, &BCTransmitter::onToggleConnectionState );
connect( _syncButton, &QToolButton::clicked, this, &BCMainWindow::onSyncFromDevice ); connect( _syncButton, &QToolButton::clicked, this, &BCMainWindow::onSyncFromDevice );
@@ -222,10 +216,8 @@ void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BC::State st
if( _devicePanels.contains( deviceID ) ) if( _devicePanels.contains( deviceID ) )
{ {
BCDevicePanel& panel = *_devicePanels[deviceID]; BCDevicePanel& panel = *_devicePanels[deviceID];
panel.getValueModel().onValueUpdated( index, state, newValue ); panel.onValueUpdated( index, state, newValue );
} }
//_devicePanels;
} }
void BCMainWindow::onRunnerMessage(const QString &msg) void BCMainWindow::onRunnerMessage(const QString &msg)
@@ -258,7 +250,7 @@ void BCMainWindow::onSyncFromDevice()
emit sendValueCommand( BC::OpID::ReadValue, &value); emit sendValueCommand( BC::OpID::ReadValue, &value);
emit valueTouched( value.indexRow ); emit valueTouched( value.indexRow );
bc::processEventsFor(500); bc::processEventsFor(50);

View File

@@ -14,6 +14,15 @@
<string>BCMainWindow</string> <string>BCMainWindow</string>
</property> </property>
<widget class="QWidget" name="_centralwidget"> <widget class="QWidget" name="_centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="_headerLabel">
<property name="text">
<string>Bionx Control</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QWidget" name="_buttonWidget" native="true"> <widget class="QWidget" name="_buttonWidget" native="true">
@@ -154,6 +163,8 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget> </widget>
<widget class="QStatusBar" name="_statusbar"/> <widget class="QStatusBar" name="_statusbar"/>
<action name="_pimpAction"> <action name="_pimpAction">

View File

@@ -88,9 +88,6 @@ void BCTransmitter::enqueueValueOp(BC::OpID opID, const BCValue* value)
QMutexLocker locker(&_mutex); QMutexLocker locker(&_mutex);
_valueQueue.enqueue( value ); _valueQueue.enqueue( value );
// Logging (Thread-safe via Signal)
//emit messageLogged(QString("Command %1 queued.").arg(cmd.label));
// wir wollen nicht den ganzen Value verschicken, erstrecht // wir wollen nicht den ganzen Value verschicken, erstrecht
// wollen wir den Value in verschiedenen Threads gleichzeitig // wollen wir den Value in verschiedenen Threads gleichzeitig
// in die Hand nehmen, also hantieren wir nur mit den Inidizes. // in die Hand nehmen, also hantieren wir nur mit den Inidizes.
@@ -133,7 +130,7 @@ void BCTransmitter::processValueOp( BC::OpID opID )
// Abkürzung // Abkürzung
const BCValue& val = *currentValue; const BCValue& val = *currentValue;
// Value ist 'under construction' // Value ist 'under construction'
emit valueUpdated( val.deviceID, val.indexRow, BC::State::Locked ); //emit valueUpdated( val.deviceID, val.indexRow, BC::State::Locked );
if( opID == BC::OpID::ReadValue ) if( opID == BC::OpID::ReadValue )
{ {
QString result = currentValue->readRawValueX( *this ); QString result = currentValue->readRawValueX( *this );
@@ -151,8 +148,6 @@ void BCTransmitter::processValueOp( BC::OpID opID )
qDebug() << " --- OUCH!"; qDebug() << " --- OUCH!";
} }
//emit valueStateChanged(cmd.id, true); //emit valueStateChanged(cmd.id, true);
//emit valueStateChanged(0, true); //emit valueStateChanged(0, true);
} }

View File

@@ -136,6 +136,7 @@ public:
// Copy Assignment Operator // Copy Assignment Operator
BCValueList& operator=(const BCValueList& other) BCValueList& operator=(const BCValueList& other)
{ {
qDebug() << "BC copy assignment: " << this;
QList<BCValue>::operator=( other ); QList<BCValue>::operator=( other );
return *this; return *this;
} }
@@ -143,6 +144,7 @@ public:
// Move Assignment Operator // Move Assignment Operator
BCValueList& operator=(BCValueList&& other) noexcept BCValueList& operator=(BCValueList&& other) noexcept
{ {
qDebug() << "BC move assignment: " << this;
QList<BCValue>::operator=( other ); QList<BCValue>::operator=( other );
return *this; return *this;
} }

View File

@@ -31,6 +31,7 @@
#include <bcvaluemodel.h> #include <bcvaluemodel.h>
#include <bcvaluetype.h>
/** /**
* @brief Konstruktor, ohne Besonderheiten * @brief Konstruktor, ohne Besonderheiten
@@ -94,7 +95,7 @@ void BCValueModel::takeValueList(BCValueList& newValueList)
void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newVisisbleValue ) void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newVisisbleValue )
{ {
qDebug() << " Panel update: " << newVisisbleValue; qDebug() << " BCValueModel::onValueUpdated update: " << newVisisbleValue;
if( row > -1 && row < _valueList.size() ) if( row > -1 && row < _valueList.size() )
{ {
const BCValue& value = _valueList[row]; const BCValue& value = _valueList[row];
@@ -160,41 +161,53 @@ QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int
/** /**
* @brief Gibt die Model-Daten zurück. Das Model Gibt hier, unabhängig von der DataRole, immer das * @brief Gibt die Model-Daten zurück.
* gesamte BCValue Object zurück. Die Umsetzung von Status- und Typeinfromationen in GUI-Elemente
* findet nicht hier, sondern im BCDelagate statt.
*/ */
QVariant BCValueModel::data(const QModelIndex& index, int role) const QVariant BCValueModel::data(const QModelIndex& index, int role) const
{ {
Q_UNUSED(role) Q_UNUSED(role)
int row = index.row();
int col = index.column();
bool wrongRole = ( role != Qt::DisplayRole && role != Qt::EditRole);
if (wrongRole || !index.isValid() || row >= _valueList.size() )
return QVariant();
const BCValue& value = _valueList.at( row );
if( col == 0 )
return value.label;
if( col == 1)
{
if( role == Qt::DisplayRole )
return QString("%1 %2").arg( value.visibleValue, value.valueType->unitLabel);
return value.visibleValue;
}
return QVariant();
/* /*
Das Model Gibt hier, unabhängig von der DataRole, immer das
* gesamte BCValue Object zurück. Die Umsetzung von Status- und Typeinfromationen in GUI-Elemente
* findet nicht hier, sondern im BCDelagate statt.
// falsch! wie geben hier doch ordentlich die einzelwerte zurück
// Bonus: Rechtsbündig für Zahlen // Bonus: Rechtsbündig für Zahlen
if (role == Qt::TextAlignmentRole && (index.column() == 0 || index.column() == 2)) { if (role == Qt::TextAlignmentRole && (index.column() == 0 || index.column() == 2)) {
return Qt::AlignRight | Qt::AlignVCenter; return Qt::AlignRight | Qt::AlignVCenter;
} }
return QVariant(); //return QVariant::fromValue( entry );
*/
int row = index.row();
if (!index.isValid() || row >= _valueList.size())
return QVariant(); return QVariant();
const BCValue* entry = &_valueList.at( row );
return QVariant::fromValue( entry );
/*
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
if( col == 0 )
return entry.label;
else if( col == 1 )
return entry.visibleValue;
}
*/ */
} }