Updated ValueHandling.

This commit is contained in:
Christoph Holzheuer
2026-01-07 17:13:35 +01:00
parent 7d43b0a694
commit 3bdc491830
17 changed files with 152 additions and 150 deletions

View File

@@ -37,6 +37,7 @@ li
windows
{
#LIBS += -L$$PWD/can_api -lmhstcan -lAdvapi32
message("Konfiguration für Windows.")
}
# You can make your code fail to compile if it uses deprecated APIs.

View File

@@ -63,11 +63,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale
// Hier bauen wir den String zusammen, den man sieht,
// wenn KEIN Editor offen ist.
// Format: "Label: Wert Einheit"
return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX");
return QString("%1: %2 %3").arg(bc.label, bc.formattedValue, "mmX");
}
else
{
qDebug() << " --- Nö!";
//qDebug() << " --- Nö!";
}
// Fallback für normale Strings/Zahlen
@@ -78,10 +78,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale
QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
/*
QVariant rawData = index.data(Qt::EditRole);
//if (!rawData.canConvert<BCValue*>())
return QStyledItemDelegate::createEditor(parent, option, index);
/*
const BCValue& bc = *rawData.value<BCValue*>();
// Nur bei Integern den Slider-Editor bauen
@@ -121,41 +122,50 @@ QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionVie
return container;
}
*/
return QStyledItemDelegate::createEditor(parent, option, index);
*/
}
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
{
/*
// Daten vom Model in den Editor laden
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
QSlider *slider = editor->findChild<QSlider*>("slider");
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
if (slider && lblUnit) {
if (slider && lblUnit)
{
bool olDriverState = slider->blockSignals(true);
slider->setValue(bc.visibleValue.toInt());
slider->setValue(bc.formattedValue.toInt());
slider->blockSignals(olDriverState);
lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3"));
} else {
lblUnit->setText(QString("%1 %2").arg(bc.formattedValue.toInt()).arg( "mm3"));
}
else
{
QStyledItemDelegate::setEditorData(editor, index);
}
*/
}
void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
{
/*
// Daten vom Editor zurück ins Model speichern (Beim Schließen)
QSlider *slider = editor->findChild<QSlider*>("slider");
if (slider) {
if (slider)
{
int value = slider->value();
model->setData(index, value, Qt::EditRole);
} else {
}
else
{
QStyledItemDelegate::setModelData(editor, model, index);
}
*/
}
void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
@@ -230,7 +240,8 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
{
/*
if (option.state & QStyle::State_Selected) {
if (option.state & QStyle::State_Selected)
{
// 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS)
QColor highlightColor = option.palette.highlight().color();
@@ -241,27 +252,30 @@ if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, highlightColor);
}
*/
const BCValue& valueX = *(_valueList[ index.row()].get());
int value = 50;//index.model()->data(index, Qt::DisplayRole).toInt();
const BCValue& bcValue = *(_valueList[ index.row()].get());
qDebug() << " --- paintSLider: " << bcValue.label << ": " << (int)bcValue.valueType;
// wenn Werte readOnly sind, dann brauchen keinen EditHint
if( bcValue.flags.testFlag(BCValue::Flag::ReadOnly) )
// || bcValue.valueType == BCValue::ValueType::Plain )
return;
// Hintergrund
if (option.state & QStyle::State_Selected)
{
painter->fillRect(option.rect, option.palette.highlight());
}
else
{
QColor bcColor = option.palette.color(QPalette::Base);
painter->fillRect(option.rect, bcColor);
}
// Text und kleiner Slider-Indikator zeichnen
// baby-Slider-Indikator zeichnen
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
//QRect textRect = option.rect.adjusted(8, 0, -120, 0);
QRect barRect = option.rect.adjusted
(
8,
@@ -275,10 +289,11 @@ if (option.state & QStyle::State_Selected) {
painter->setBrush(QColor(0xE0E0E0));
painter->drawRoundedRect(barRect, 2, 2);
QRect fillRect = barRect;
fillRect.setWidth(barRect.width() * valueX.calcRatio() );
// Anteil zwischen min und max berechnen
double ratio = bcValue.calcRatio();
barRect.setWidth(barRect.width() * ratio );
painter->setBrush(QColor(0x0078D4));
painter->drawRoundedRect(fillRect, 2, 2);
painter->drawRoundedRect(barRect, 2, 2);
painter->restore();

View File

@@ -72,7 +72,7 @@ signals:
//void viewUpdateNeeded();
private:
protected:
void updateRow(int row);
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
@@ -83,7 +83,6 @@ private:
QPropertyAnimation* _animation{};
private:
QHash<int, qreal> m_rowOpacities;
QHash<int, QVariantAnimation*> m_rowAnimations;

View File

@@ -77,7 +77,7 @@ const BCValueList& BCDeviceView::getValueListX()
*/
void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueList )
{
qDebug() << " --- onValueListReady: " << deviceID << ": " << valueList.size();
//qDebug() << " --- onValueListReady: " << deviceID << ": " << valueList.size();
if(_devideID == deviceID)
_valueModel.takeValueList( valueList );
}
@@ -87,9 +87,9 @@ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueLis
* @brief SLOT, der aufgerufen wird, wenn ein Value geändert wurde. Gibt dem ItemDelegate Bescheid.
*/
void BCDeviceView::onValueUpdated(int index, BCValue::State state, const QString& newVisibleValue )
void BCDeviceView::updateValue(int index, BCValue::Flag state, uint32_t rawValue )
{
_valueModel.onValueUpdated( index, state, newVisibleValue);
_valueModel.updateValue( index, state, rawValue );
_itemDelegate->onHighlightRow( index );
}

View File

@@ -53,14 +53,14 @@ public:
BCDevice::ID getDeviceID() const;
const BCValueList& getValueListX();
//BCValueModel &getValueModel();
bool hasContent();
void updateValue( int index, BCValue::Flag state, uint32_t rawValue );
public slots:
void onValueListReady( BCDevice::ID deviceID, BCValueList valueList );
void onValueUpdated( int index, BCValue::State state, const QString& newVisibleValue="" );
protected:

View File

@@ -87,7 +87,7 @@ TransmitResult BCDriverDummy::writeRawByte( uint32_t deviceID, uint8_t registerI
{
Q_UNUSED(deviceID)
Q_UNUSED(registerID)
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
//qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
return 0;
}

View File

@@ -30,7 +30,7 @@
***************************************************************************/
#include <QDebug>
#include <//qDebug>
#include <bcdrivertinycan.h>
#include <can_drv.h>
@@ -180,22 +180,22 @@ BCDriver::DriverStateResult BCDriverTinyCan::setConsoleSlaveMode()
uint32_t console = static_cast<uint32_t>(BCDevice::ID::Console);
uint8_t slaveFlag = static_cast<uint8_t> (BC::ID::Cons_Status_Slave);
qDebug() << "XXX BCDriverTinyCan::Driver Init: putting Console in slave mode ... ";
//qDebug() << "XXX BCDriverTinyCan::Driver Init: putting Console in slave mode ... ";
TransmitResult isSlave = 0;
// Already slave?
isSlave = readRawByte( console, slaveFlag );
if( isSlave.has_value() )
{
qDebug() << "Console responded: " << isSlave.value();
//qDebug() << "Console responded: " << isSlave.value();
if( isSlave.value() == 1 )
{
qDebug() << "Console already in slave mode. good!";
//qDebug() << "Console already in slave mode. good!";
return DriverState::DeviceReady;
}
}
qDebug() << "BCDriverTinyCan::BCDriverTinyCan::XXX Driver Init: putting Console in slave mode ... ";
//qDebug() << "BCDriverTinyCan::BCDriverTinyCan::XXX Driver Init: putting Console in slave mode ... ";
unsigned int retry = cTimeOuts;
@@ -237,7 +237,7 @@ void BCDriverTinyCan::resetDriver()
TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
{
qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! ";
//qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! ";
struct TCanMsg msg;
int err, retry = 20;
@@ -258,7 +258,7 @@ TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t register
bc::delay_millis( cTIMEOUT_MS );
if (timeout == -1)
qDebug() << "error: could not send value to node ";
//qDebug() << "error: could not send value to node ";
retry:
@@ -268,34 +268,34 @@ retry:
if (timeout == -1)
{
qDebug() << "error: no response from node";
//qDebug() << "error: no response from node";
return 0;
}
if ((err = CanReceive(0, &msg, 1)) > 0)
{
qDebug() << " retry: " << retry << " BIB:" << BC::ID::ID_Bib << " msg.Id: " << msg.Id << " msg.MsgLen: " << msg.MsgLen << " msg.MsgData[1]: " << msg.MsgData[1] << " reg: " << reg;
//qDebug() << " retry: " << retry << " BIB:" << BC::ID::ID_Bib << " msg.Id: " << msg.Id << " msg.MsgLen: " << msg.MsgLen << " msg.MsgData[1]: " << msg.MsgData[1] << " reg: " << reg;
if (--retry && (msg.Id != (uint32_t)BC::ID::ID_Bib|| msg.MsgLen != 4 || msg.MsgData[1] != reg))
goto retry;
if (!retry)
{
qDebug() << "XXX error: no response from node: " << err;
//qDebug() << "XXX error: no response from node: " << err;
return 0;
}
qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3];
//qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3];
return (unsigned int) msg.MsgData[3];
}
else
{
qDebug() << "Error:" <<err;
//qDebug() << "Error:" <<err;
}
return 0;
/*
//TransmitResult
qDebug() << " --- BCDriverTinyCan::readRawByte DriverState: " << getDriverState();
//qDebug() << " --- BCDriverTinyCan::readRawByte DriverState: " << getDriverState();
if( _driverState <DriverState::Opened )
return std::unexpected(QString("readRawValue error: driver not loaded." ) );
@@ -337,15 +337,15 @@ retry:
// message empfangen
int err = ::CanReceive( 0, &msg, 1 );
//qDebug() << "HÄÄ ?" << err << "reg: "<< registerID <<" timeOuts: " << timeOuts;
////qDebug() << "HÄÄ ?" << err << "reg: "<< registerID <<" timeOuts: " << timeOuts;
if( err < 0 )
//throw BCException( "getValue error: could not receive value" );
qDebug( "getValue error: could not receive value" );
//qDebug( "getValue error: could not receive value" );
//qDebug() << "HÄÄ 2" <<msg.Id;
//qDebug() << "HÄÄ 2" <<msg.MsgLen;
//qDebug() << "HÄÄ 2" <<msg.MsgData[1];
////qDebug() << "HÄÄ 2" <<msg.Id;
////qDebug() << "HÄÄ 2" <<msg.MsgLen;
////qDebug() << "HÄÄ 2" <<msg.MsgData[1];
//if( err > 0 )
if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != registerID ) )
@@ -354,7 +354,7 @@ retry:
if( !timeOuts )
return std::unexpected(QString("CAN response errror: timeout" ));
qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID;
//qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID;
return (uint32_t) msg.MsgData[3];
*/
}
@@ -367,7 +367,7 @@ TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registe
if( _driverState <DriverState::Opened )
return std::unexpected(QString("readRawValue error: driver not loaded." ) );
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
//qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
::TCanMsg msg;
int timeout_count = cTIMEOUT_COUNT;

View File

@@ -134,7 +134,6 @@ void BCDriverStateWidget::onDriverStateChanged(BCDriver::DriverState state, cons
{
_state = state;
qDebug() << " --- StateWidget: " << state << " - " << customMessage;
updateStyle();
}

View File

@@ -298,13 +298,13 @@ void BCMainWindow::onConnectButtonToggled(bool checked )
//_dataManager.setDriverConnectionState( checked );
}
void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue )
void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue )
{
qDebug() << "Reply: from: " << deviceID << " at: " << index << "finished. Success:" << (uint8_t)state << " on:" << newValue;
qDebug() << "Reply: from: " << deviceID << " at: " << index << "finished. Success:" << (uint8_t)state << " on:" << rawValue;
if( _devicePanels.contains( deviceID ) )
{
BCDeviceView& panel = *_devicePanels[deviceID];
panel.onValueUpdated( index, state, newValue );
panel.updateValue( index, state, rawValue );
}
}
@@ -332,7 +332,7 @@ void BCMainWindow::onSyncDeviceView()
{
qDebug() << " --- ### begin sync of value: " << QThread::currentThreadId() << " : " << value->label;
// wir setzen auf 'lesen'
value->state.setFlag( BCValue::State::ReadMe );
value->flags.setFlag( BCValue::Flag::ReadMe );
_syncButton->setEnabled( false );

View File

@@ -61,7 +61,7 @@ public slots:
void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" );
// Slots für Rückmeldungen vom Transmitter
void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" );
void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue );
void onValueQueueEmpty();
void onSyncDeviceView();

View File

@@ -31,7 +31,7 @@
#include <QThread>
#include <QDebug>
#include <//qDebug>
#include <QCoreApplication>
#include <bctransmitter.h>
@@ -56,7 +56,7 @@ BCTransmitter::BCTransmitter(QObject *parent)
void BCTransmitter::onToggleDriverConnection( bool connect )
{
qDebug() << " --- onToggleDriverConnection: " << connect;
//qDebug() << " --- onToggleDriverConnection: " << connect;
emit driverStateChanged(BCDriver::DriverState::Initialized, "BUSY!");
bc::delay_millis(350);
// kill all pending stuff
@@ -103,13 +103,13 @@ void BCTransmitter::connectCanDriver()
if( hwVersion.has_value() )
{
message = " ---- HAIL to the king!";
qDebug() << message;
//qDebug() << message;
// swap driver
_canDriver = &_tinyCanDriver;
}
else
{
qDebug() << "Console not responding";
//qDebug() << "Console not responding";
}
}
else
@@ -144,7 +144,7 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr)
// der aktuelle Auftragsblock abgearbeit wurde.
_valueQueue.enqueue( valuePtr );
qDebug() << " # #### ENQ: " <<_valueQueue.size();
//qDebug() << " # #### ENQ: " <<_valueQueue.size();
// Wir schicken den event gleich wieder weiter ...
QMetaObject::invokeMethod(this, "onProcessValue", Qt::QueuedConnection);
@@ -160,12 +160,12 @@ void BCTransmitter::onProcessValue()
if (_valueQueue.isEmpty())
{
//_isBusy = false;
qDebug() << " --- XXXXXXXXXX Warum so oft?";
//qDebug() << " --- XXXXXXXXXX Warum so oft?";
emit valueQueueEmpty();
break; // Schleife verlassen, warten auf neue Events
}
valuePtr =_valueQueue.dequeue();
qDebug() << " # #### DEQ: " <<_valueQueue.size();
//qDebug() << " # #### DEQ: " <<_valueQueue.size();
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
// Kosmetik
@@ -174,19 +174,20 @@ void BCTransmitter::onProcessValue()
// Kosmetik
//const BCValue& value = *(valuePtr.get());
qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label;
//qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label;
// Value ist 'under construction'
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::Locked );
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::Flag::Locked );
uint32_t devID = static_cast<uint32_t>(value.deviceID);
uint8_t regID = static_cast<uint8_t> (value.registerID);
QString newVisibleValue;
BCValue::State newState = BCValue::State::NoState;
// Für den Fehlerfall: Wir senden den alten Wert einfach zurück
uint32_t newValue = value.rawUIntValue;
BCValue::Flag newState = BCValue::Flag::Failed;;
if(value.state.testFlag( BCValue::State::WriteMe ) )
if(value.flags.testFlag( BCValue::Flag::WriteMe ) )
{
@@ -194,23 +195,18 @@ void BCTransmitter::onProcessValue()
// oder sollen wir hier beides erlauben ? readFlag & writeFlag ?
// Was kommt dann zuerst? Schreiben und lesen als verify ?
else if( value.state.testFlag( BCValue::State::ReadMe ) )
else if( value.flags.testFlag( BCValue::Flag::ReadMe ) )
{
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
TransmitResult result = value.isWord ? readWordValue( devID, regID ) : readByteValue( devID, regID );
TransmitResult result = value.isWord() ? readWordValue( devID, regID ) : readByteValue( devID, regID );
if( result.has_value() )
{
// quark! das gehört hier nicht hin!
newVisibleValue = value.formatValues( result.value() );
newState = BCValue::State::InSync;
}
else
{
newState = BCValue::State::Failed;
newState = BCValue::Flag::InSync;
newValue = result.value();
}
}
emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue );
emit valueUpdated( value.deviceID, value.indexRow, newState, newValue );
// __fix
//bc::processEventsFor(150);
@@ -223,7 +219,7 @@ void BCTransmitter::onProcessValue()
TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID )
{
//qDebug() << " --- YES: Read ByteValue: " << registerID;
////qDebug() << " --- YES: Read ByteValue: " << registerID;
// Wir lesen nur ein Byte und gut.
return _canDriver->readRawByte( deviceID, registerID );
}
@@ -231,7 +227,7 @@ TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t register
TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID )
{
//qDebug() << " --- YES: Read WordValue: " << registerID;
////qDebug() << " --- YES: Read WordValue: " << registerID;
uint32_t result{};
// hi byte Leseversuch.

View File

@@ -70,7 +70,7 @@ public slots:
signals:
void valueQueueEmpty();
void valueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" );
void valueUpdated(BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue );
void driverStateChanged( BCDriver::DriverState state, const QString& message="" );
private:

View File

@@ -41,18 +41,22 @@
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
: deviceID{deviceID_}, registerID{registerID_}
{
visibleValue = "--";
}
QString BCValue::formatValues( uint32_t value ) const
QString BCValue::formatValue() const
{
if( factor == 1 )
return QString::number( value );
return QString::number( rawUIntValue );
double result = value * factor;
double result = rawUIntValue * factor;
return QString::number(result, 'f', 2);
}
bool BCValue::isWord() const
{
return flags.testFlag(BCValue::Flag::IsWord);
}
double BCValue::calcRatio() const
{
@@ -73,7 +77,7 @@ double BCValue::calcRatio() const
return ratio;
// Die eigentliche Formel
ratio = ((rawValue - min) / range);
ratio = ((rawDoubleValue - min) / range);
//ratio = (int) qBound( min,ratio, max);
}
return ratio;
@@ -83,8 +87,8 @@ void BCValue::dumpValue() const
{
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
qDebug() << "visibleValue: " << visibleValue << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord;
qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord();
qDebug();
}

View File

@@ -72,46 +72,47 @@ public:
// später der Editor
enum class ValueType : uint8_t
{
Plain,
Plain, // nur lesen, sowas wie SerialNo
Bool,
Number,
Float
};
enum class State : uint8_t
enum class Flag : uint8_t
{
NoState = 0x00,
NoFlag = 0x00,
ReadMe = 0x01,
WriteMe = 0x02,
ReadOnly = 0x04,
Locked = 0x08,
Failed = 0x10,
InSync = 0x20,
OK = 0x40
OK = 0x40,
IsWord = 0x80
};
Q_DECLARE_FLAGS(States, State )
Q_DECLARE_FLAGS(Flags, Flag )
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );
QString formatValues( uint32_t value ) const;
QString formatValue() const;
double calcRatio() const;
void dumpValue() const;
bool isWord() const;
mutable States state{BCValue::State::ReadOnly};
mutable Flags flags{BCValue::Flag::ReadOnly};
BCDevice::ID deviceID{BCDevice::ID::Invalid};
BC::ID registerID{BC::ID::Invalid};
ValueType valueType{ValueType::Plain};
int indexRow{-1};
QString label;
mutable QString visibleValue;
mutable double rawValue;
bool isWord{false};
mutable double rawDoubleValue;
mutable uint32_t rawUIntValue;
QString unitLabel;
double factor{1};
OptDouble optMin;
OptDouble optMax;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States)
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)

View File

@@ -81,29 +81,20 @@ void BCValueModel::takeValueList(BCValueList& newValueList)
* @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall
*/
void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString& newVisisbleValue )
void BCValueModel::updateValue(int row, BCValue::Flag state, uint32_t rawValue )
{
if( row > -1 && row < _valueList.size() )
{
const BCValue& value = *(_valueList[row].get());
QModelIndex idx = index(row,1);
//qDebug();
//qDebug() << " --- OLD:"<< newVisisbleValue;
//value.dumpValue();
value.flags = state;
value.rawUIntValue = rawValue;
value.state = state;
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue )
{
value.visibleValue = newVisisbleValue;
}
//qDebug() << " --- NEW: " << newVisisbleValue;
//value.dumpValue();
QModelIndex idx1 = index(row,1);
QModelIndex idx2 = index(row,2);
// wir schicken auf jeden fall einen update request
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
emit dataChanged(idx1, idx2, {Qt::DisplayRole, Qt::EditRole});
}
}
@@ -161,9 +152,9 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const
if( col == 1)
{
if( role == Qt::DisplayRole )
return QString("%1 %2").arg( value.visibleValue, value.unitLabel);
return QString("%1 %2").arg( value.formatValue(), value.unitLabel);
return value.visibleValue;
return value.formatValue();
}
return QVariant();
@@ -199,23 +190,19 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
}
bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int role)
bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, int role)
{
// __fix!
if (index.isValid() && role == Qt::EditRole)
{
BCValuePtr item = _valueList[index.row()];
BCValuePtr value = _valueList[index.row()];
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
// Checken ob Int oder Double
if (value.canConvert<double>())
if (variant.canConvert<int>())
{
item->visibleValue = value.toString();
value->rawUIntValue = variant.toInt();
}
_valueList[index.row()] = item;
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}

View File

@@ -66,9 +66,7 @@ public:
Qt::ItemFlags flags(const QModelIndex& index) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
public slots:
void onValueUpdated(int index, BCValue::State state, const QString& newVisisbleValue="" );
void updateValue(int row, BCValue::Flag state, uint32_t rawValue );
protected:

View File

@@ -214,7 +214,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
setIfExists( params.Factor, newValue.factor );
setIfExists( params.Min, newValue.optMin );
setIfExists( params.Max, newValue.optMax );
setIfExists( params.IsWord, newValue.isWord );
//setIfExists( params.IsWord, newValue.isWord );
newValue.label = params.Label;
newValue.unitLabel = params.UnitLabel;