From c40f288aaa634c552b3e80fd38cebd1617265f89 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Thu, 8 Jan 2026 00:25:36 +0100 Subject: [PATCH] -- fy --- bcanimateddelegate.cpp | 39 ++++--------- bcanimateddelegate.h | 8 ++- bcguihelpers.cpp | 129 ++++++++++------------------------------- bctransmitter.cpp | 2 +- bcvalue.cpp | 6 +- bcvalue.h | 3 +- bcvaluemodel.cpp | 4 +- bcxmlloader.cpp | 59 +++++++++---------- resources/bikeinfo.xml | 56 +++++++++--------- 9 files changed, 110 insertions(+), 196 deletions(-) diff --git a/bcanimateddelegate.cpp b/bcanimateddelegate.cpp index 6904639..eaaef64 100644 --- a/bcanimateddelegate.cpp +++ b/bcanimateddelegate.cpp @@ -201,7 +201,7 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op { case 1: - if( m_rowOpacities.contains(row)) + if(_rowOpacities.contains(row)) paintHighlightRow(painter,option,index); break; @@ -221,7 +221,7 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption painter->save(); painter->setRenderHint(QPainter::Antialiasing); int row = index.row(); - qreal opacity = m_rowOpacities.value(row); + qreal opacity =_rowOpacities.value(row); painter->setOpacity(opacity); // Margin von 4px QRect itemRect = option.rect.adjusted(3, 3, -3, -3); @@ -238,21 +238,6 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - - /* - 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(); - - // 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt) - highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer) - - // 3. Zeichnen (Brush setzt die Füllfarbe) - painter->fillRect(option.rect, highlightColor); - } - */ - const BCValue& bcValue = *(_valueList[ index.row()].get()); qDebug() << " --- paintSLider: " << bcValue.label << ": " << (int)bcValue.valueType; @@ -303,10 +288,10 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt void BCAnimatedDelegate::onHighlightRow(int row) { // Alte Animation für diese Zeile stoppen falls vorhanden - if (m_rowAnimations.contains(row)) + if (_rowAnimations.contains(row)) { - m_rowAnimations[row]->stop(); - m_rowAnimations[row]->deleteLater(); + _rowAnimations[row]->stop(); + _rowAnimations[row]->deleteLater(); } // QVariantAnimation ist flexibler als QPropertyAnimation @@ -330,32 +315,32 @@ void BCAnimatedDelegate::onHighlightRow(int row) opacity = 1.0 - ((progress - 0.2) / 0.8); // 1->0 in 80% } - m_rowOpacities[row] = opacity; + _rowOpacities[row] = opacity; updateRow(row); }); connect(anim, &QVariantAnimation::finished, this, [this, row, anim]() { - m_rowOpacities.remove(row); - m_rowAnimations.remove(row); + _rowOpacities.remove(row); + _rowAnimations.remove(row); updateRow(row); anim->deleteLater(); }); - m_rowAnimations[row] = anim; + _rowAnimations[row] = anim; anim->start(QAbstractAnimation::DeleteWhenStopped); } // Optional: alle Highlights sofort clearen void BCAnimatedDelegate::clearAllHighlights() { - for(auto* anim : std::as_const(m_rowAnimations)) + for(auto* anim : std::as_const(_rowAnimations)) { anim->stop(); anim->deleteLater(); } - m_rowAnimations.clear(); - m_rowOpacities.clear(); + _rowAnimations.clear(); + _rowOpacities.clear(); if (_view) { diff --git a/bcanimateddelegate.h b/bcanimateddelegate.h index 0ff9b45..3751d50 100644 --- a/bcanimateddelegate.h +++ b/bcanimateddelegate.h @@ -78,14 +78,18 @@ protected: void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + // Das ist ein Quickhack, der Delegate sollte + // nichts über die Originaldaten wissen. Die + // Datenbeschaffung ist alleine Sache des Models. + const BCValueList& _valueList; QTableView* _view{}; QPropertyAnimation* _animation{}; - QHash m_rowOpacities; - QHash m_rowAnimations; + QHash _rowOpacities; + QHash _rowAnimations; }; diff --git a/bcguihelpers.cpp b/bcguihelpers.cpp index 1f575f0..356be06 100644 --- a/bcguihelpers.cpp +++ b/bcguihelpers.cpp @@ -39,27 +39,7 @@ BCThemeSwitchButton::BCThemeSwitchButton(QWidget *parent ) // Visuelles Setup: Flach, keine Ränder, Hand-Cursor setFlat(true); setCursor(Qt::PointingHandCursor); - setFixedSize(24, 24); // Kleiner Footprint im StatusBar - - // CSS: Transparent, damit es sich nahtlos in den StatusBar einfügt - // Schriftgröße etwas erhöhen, damit die Emojis gut erkennbar sind - - /* - setStyleSheet(R"( - BCThemeSwitchButton - { - border: none; - background-color: transparent; - font-size: 11pt; - } - BCThemeSwitchButton:Hover - { - background-color: rgba(128, 128, 128, 30); - border-radius: 24px; - } - )"); -*/ - // Initialer Status (Startet im Dark Mode -> zeigt Mond) + setFixedSize(24, 24); updateIcon(); connect(this, &QPushButton::clicked, this, &BCThemeSwitchButton::toggleMode); @@ -134,53 +114,9 @@ BCDriverStateWidget::BCDriverStateWidget(QWidget* parent) void BCDriverStateWidget::onDriverStateChanged(BCDriver::DriverState state, const QString& customMessage) { _state = state; - qDebug() << " --- StateWidget: " << state << " - " << customMessage; updateStyle(); } -/* -void BCDriverStateWidget::updateStyle() -{ - QString ledStyle; - QString labelColor; - QString toolTipText; - - switch (_state) - { - case BCDriver::DriverState::DeviceReady: - // FLUENT GREEN (Success) - ledStyle = "background-color: #107C10; border: 1px solid #0E600E;#FF5F1F; #FF8C00;<- das isses #FF6700"; - labelColor = "#FFFFFF"; // Weiß (Hervorgehoben) - toolTipText = "Verbindung erfolgreich hergestellt."; - break; - - case BCDriver::DriverState::Error: - // FLUENT RED (Critical) - ledStyle = "background-color: #C42B1C; border: 1px solid #A80000;"; - labelColor = "#FF99A4"; // Ein helleres Rot für Text, damit es auf Dunkel lesbar ist - toolTipText = "Kritischer Fehler bei der Verbindung!"; - break; - - default: - // FLUENT GRAY (Neutral) - // Wir machen es dunkelgrau mit hellem Rand -> "Ausgeschaltet"-Look - ledStyle = "background-color: #3B3B3B; border: 1px solid #606060;"; - labelColor = "#9E9E9E"; // Ausgegrauter Text - toolTipText = "System ist offline."; - break; - } - - // Styles anwenden (immer rund machen) - _led->setStyleSheet(ledStyle + "border-radius: 6px;"); - - // Textfarbe setzen - _label->setStyleSheet(QString("color: %1; font-weight: %2;") - .arg(labelColor) - .arg(_state == BCDriver::DriverState::DeviceReady ? "bold" : "normal")); - - setToolTip(toolTipText); -} -*/ void BCDriverStateWidget::updateStyle() { @@ -196,54 +132,49 @@ void BCDriverStateWidget::updateStyle() */ switch (_state) { - case BCDriver::DriverState::NotPresent: - // FLUENT GRAY (Neutral) - // Wir machen es dunkelgrau mit hellem Rand -> "Ausgeschaltet"-Look - ledStyle = "background-color: #3B3B3B; border: 1px solid #606060;"; - toolTipText = "Treiber nicht geladen."; - break; + case BCDriver::DriverState::NotPresent: + // FLUENT GRAY (Neutral) + // Wir machen es dunkelgrau mit hellem Rand -> "Ausgeschaltet"-Look + ledStyle = "background-color: #3B3B3B; border: 1px solid #606060;"; + toolTipText = "Treiber nicht geladen."; + break; - case BCDriver::DriverState::Error: - // FLUENT RED (Critical) - ledStyle = "background-color: #C42B1C; border: 1px solid #A80000;"; - toolTipText = "Fehler beim Laden des Treibers."; - break; + case BCDriver::DriverState::Error: + // FLUENT RED (Critical) + ledStyle = "background-color: #C42B1C; border: 1px solid #A80000;"; + toolTipText = "Fehler beim Laden des Treibers."; + break; - // hier: dll vorhanden, Treiber geladen - case BCDriver::DriverState::Loaded: - case BCDriver::DriverState::Initialized: - case BCDriver::DriverState::Opened: - // FLUENT RED (Critical) - ledStyle = "background-color: #FF8C00; border: 1px solid #A80000;"; - toolTipText = "Fehler beim Laden des Treibers."; - break; - - case BCDriver::DriverState::DeviceReady: - // FLUENT GREEN (Success) - ledStyle = "background-color: #107C10; border: 1px solid #0E600E;"; - toolTipText = "Verbindung erfolgreich hergestellt."; - break; + // hier: dll vorhanden, Treiber geladen + case BCDriver::DriverState::Loaded: + case BCDriver::DriverState::Initialized: + case BCDriver::DriverState::Opened: + // FLUENT RED (Critical) + ledStyle = "background-color: #FF8C00; border: 1px solid #A80000;"; + toolTipText = "Fehler beim Laden des Treibers."; + break; + case BCDriver::DriverState::DeviceReady: + // FLUENT GREEN (Success) + ledStyle = "background-color: #107C10; border: 1px solid #0E600E;"; + toolTipText = "Verbindung erfolgreich hergestellt."; + break; } // Styles anwenden (immer rund machen) _led->setStyleSheet(ledStyle + "border-radius: 6px;"); - - /* - // Textfarbe setzen - _setStyleSheet(QString("color: %1; font-weight: %2;") - .arg(labelColor) - .arg(_state == BCDriver::DriverState::DeviceReady ? "bold" : "normal")); - */ setToolTip(toolTipText); } + +/** + * @brief minimale click event + */ + void BCDriverStateWidget::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) - { emit clicked(); - } QWidget::mouseReleaseEvent(event); } diff --git a/bctransmitter.cpp b/bctransmitter.cpp index c76e30e..652b316 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -184,7 +184,7 @@ void BCTransmitter::onProcessValue() uint8_t regID = static_cast (value.registerID); // Für den Fehlerfall: Wir senden den alten Wert einfach zurück - uint32_t newValue = value.rawUIntValue; + uint32_t newValue = value.rawValue; BCValue::Flag newState = BCValue::Flag::Failed;; if(value.flags.testFlag( BCValue::Flag::WriteMe ) ) diff --git a/bcvalue.cpp b/bcvalue.cpp index 7016d27..d9334b8 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -47,9 +47,9 @@ BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_) QString BCValue::formatValue() const { if( factor == 1 ) - return QString::number( rawUIntValue ); + return QString::number( rawValue ); - double result = rawUIntValue * factor; + double result = rawValue * factor; return QString::number(result, 'f', 2); } @@ -77,7 +77,7 @@ double BCValue::calcRatio() const return ratio; // Die eigentliche Formel - ratio = ((rawDoubleValue - min) / range); + ratio = ((rawValue - min) / range); //ratio = (int) qBound( min,ratio, max); } return ratio; diff --git a/bcvalue.h b/bcvalue.h index 42d5c17..2645772 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -105,8 +105,7 @@ public: ValueType valueType{ValueType::Plain}; int indexRow{-1}; QString label; - mutable double rawDoubleValue; - mutable uint32_t rawUIntValue; + mutable uint32_t rawValue{}; QString unitLabel; double factor{1}; OptDouble optMin; diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index 1533b17..84babdc 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -88,7 +88,7 @@ void BCValueModel::updateValue(int row, BCValue::Flag state, uint32_t rawValue ) const BCValue& value = *(_valueList[row].get()); value.flags = state; - value.rawUIntValue = rawValue; + value.rawValue = rawValue; QModelIndex idx1 = index(row,1); QModelIndex idx2 = index(row,2); @@ -200,7 +200,7 @@ bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, in // Checken ob Int oder Double if (variant.canConvert()) { - value->rawUIntValue = variant.toInt(); + value->rawValue = variant.toInt(); } emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole}); diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index 3797015..8fc4280 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -60,7 +60,6 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName ) qDebug().noquote() << parts.join(" "); }; - QMetaEnum bcDeviceEnum{QMetaEnum::fromType()}; QFile file(fileName); @@ -88,22 +87,31 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName ) if (token == QXmlStreamReader::StartElement) { QString deviceType = _xml.attributes().value("Type"_L1).toString(); - //printAttrs (_xml); - // Wir wollen die Device-ID aus dem XML Tag ermitteln - const char* deviceKey = _xml.attributes().value("Type"_L1).toLatin1().constData(); - bool ok; - auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok); - //_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) ); - //if( optDeviceID.has_value()) - if(ok) - { - qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << optDeviceID; - //BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() ); - BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID ); - loadXmlBikeDeviceData(currentDeviceID); - } - } + + qDebug() << " --- FETCH 1: " << deviceType; + + // Wir wollen die Device-ID aus dem XML Tag ermitteln + if( deviceType.isEmpty() ) + { + printAttrs (_xml); + continue; + } + QByteArray byteArray = deviceType.toUtf8(); + const char* deviceKey = byteArray.constData(); + bool ok=false; + auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok); + //_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) ); + //if( optDeviceID.has_value()) + if(ok) + { + qDebug() << " --- FETCH 2: Device: " << deviceType << " : " << optDeviceID; + //BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() ); + BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID ); + loadXmlBikeDeviceData(currentDeviceID); + } + + } // if start element } } @@ -127,7 +135,6 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) printAttrs (_xml); Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1); - // temporäre Wertliste für neues Device BCValueList currentValues; @@ -135,7 +142,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) { if( _xml.attributes().hasAttribute(BCTags::ID) ) { - //qDebug() << " --- found: " << _xml.name() << " : " << _xml.attributes().value(BCTags::ID); + qDebug() << " --- found: " << _xml.name() << " : " << _xml.attributes().value(BCTags::ID); // füllen des Parameter packs BCValueParams params @@ -205,7 +212,8 @@ std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const B //std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); bool ok; static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; - int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok ); + QByteArray byteArray = params.ID.toUtf8(); + int IDVal = s_bcValueEnum.keyToValue( byteArray.constData(), &ok ); qDebug() << " --- should create: " << params.Label; //if( IDVal.has_value() ) if( ok ) @@ -218,25 +226,12 @@ std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const B setIfExists( params.Max, newValue.optMax ); //setIfExists( params.IsWord, newValue.isWord ); - - newValue.label = params.Label; newValue.unitLabel = params.UnitLabel; if( s_valueTypes.contains( params.ValueType ) ) newValue.valueType = s_valueTypes[params.ValueType]; - /* - QString ID; - QString Label; - QString UnitLabel; - QString Factor; - QString Min; - QString Max; - QString IsWord; - QString ValueType; - */ - qDebug() << " --- created: " << params.Label; newValue.dumpValue(); diff --git a/resources/bikeinfo.xml b/resources/bikeinfo.xml index 91bf859..694aab3 100644 --- a/resources/bikeinfo.xml +++ b/resources/bikeinfo.xml @@ -2,6 +2,21 @@ + + + + + + + + + + + + + + + @@ -27,41 +42,26 @@ - + - - - - - - - - - - - - - - -