diff --git a/BionxControl.pro b/BionxControl.pro index a4a9d74..dc36b74 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -30,7 +30,6 @@ SOURCES += \ bcdelegate.cpp \ bcdevicepanel.cpp \ bclegacy.cpp \ - bctoolbutton.cpp \ bctransmitter.cpp \ bcvalue.cpp \ bcvaluemodel.cpp \ @@ -49,7 +48,6 @@ HEADERS += \ bcdelegate.h \ bcdevicepanel.h \ bcmainwindow.h \ - bctoolbutton.h \ bctransmitter.h \ bcvalue.h \ bcvaluemodel.h \ diff --git a/bcdelegate.cpp b/bcdelegate.cpp index e669770..0a30bbe 100644 --- a/bcdelegate.cpp +++ b/bcdelegate.cpp @@ -49,8 +49,8 @@ -BCDelegate::BCDelegate(QTableView* view) - : QStyledItemDelegate(view), _view{view} +BCDelegate::BCDelegate(const BCValueList& valueList, QTableView* view) + : QStyledItemDelegate{view}, _valueList{valueList}, _view{view} { } @@ -59,10 +59,10 @@ BCDelegate::BCDelegate(QTableView* view) QString BCDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const { // Wir prüfen, ob im Variant unser Struct steckt - if (dataValue.canConvert()) + if (dataValue.canConvert()) { - BCValue& bc = *dataValue.value(); - qDebug() << " --- YES: " << bc.label; + const BCValue& bc = *dataValue.value(); + //qDebug() << " --- YES: " << bc.label; // Hier bauen wir den String zusammen, den man sieht, // wenn KEIN Editor offen ist. // Format: "Label: Wert Einheit" @@ -70,7 +70,7 @@ QString BCDelegate::displayText(const QVariant& dataValue, const QLocale& locale } else { - //qDebug() << " --- Nö!"; + qDebug() << " --- Nö!"; } // Fallback für normale Strings/Zahlen @@ -162,6 +162,7 @@ void BCDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const void BCDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const { + // __fix! editor->setGeometry(option.rect); } @@ -181,11 +182,12 @@ QSize BCDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex void BCDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + /* // 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen QStyledItemDelegate::paint(painter, option, index); - // 2. Unser Custom-Overly: Oranger Rahmen, wenn Zeile passt + // 2. Unser Custom-Overlay: Oranger Rahmen, wenn Zeile passt if (index.row() == _highlightedRow) { painter->save(); diff --git a/bcdelegate.h b/bcdelegate.h index 56f432b..924ab97 100644 --- a/bcdelegate.h +++ b/bcdelegate.h @@ -38,6 +38,7 @@ class QPropertyAnimation; class QVariantAnimation; class QTableView; +class BCValueList; class BCDelegate : public QStyledItemDelegate { @@ -46,7 +47,7 @@ class BCDelegate : public QStyledItemDelegate public: - explicit BCDelegate(QTableView* view ); + explicit BCDelegate(const BCValueList& valueList, QTableView* view ); QString displayText(const QVariant& dataValue, const QLocale& locale) const override; @@ -89,9 +90,12 @@ private: QString formatDisplayString(const QModelIndex& index) const; void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + const BCValueList& _valueList; + QTableView* _view{}; + int _highlightedRow{-1}; qreal _opacity{1.0}; - QTableView* _view{}; + QPropertyAnimation* _animation{}; private: diff --git a/bcdevicepanel.cpp b/bcdevicepanel.cpp index 9e35a73..e61a836 100644 --- a/bcdevicepanel.cpp +++ b/bcdevicepanel.cpp @@ -39,8 +39,10 @@ BCDevicePanel::BCDevicePanel(QWidget *parent) setupUi(this); _valueView->setModel( &_valueModel ); //_valueView->resizeColumnsToContents(); - _valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - _valueView->setItemDelegate( new BCDelegate( _valueView) ); + //_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + + BCDelegate* delegate = new BCDelegate( _valueModel.getValueList(), _valueView); + _valueView->setItemDelegate( delegate ); } diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index 759c12b..b6fc2e8 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -30,6 +30,8 @@ ***************************************************************************/ +//#include + #include "qassert.h" #include #include @@ -38,7 +40,7 @@ /** * @brief Das Mainwindow erzeugen - * @param parent + * @param parent Das Elternwidget */ BCMainWindow::BCMainWindow(QWidget *parent) @@ -54,30 +56,24 @@ BCMainWindow::BCMainWindow(QWidget *parent) } + +/** + * @brief Destruktor. Räumt den Workthread auf. + */ + BCMainWindow::~BCMainWindow() { _worker.quit(); // Event Loop stoppen _worker.wait(); // Warten bis Thread wirklich fertig ist } + +/** + * @brief Initialisiert alle Komponenten des MainWindows. + */ + void BCMainWindow::initMainWindow() { - // Die Daten und auch die Datenmodelle für die Views werden - // vom DataManager verwaltet und an die Views weitergereicht. - - /* - auto setDeviceModel = [&]( BCDevice::ID deviceID, BCDevicePanel* panel ) - { - auto model = _dataManager.getModel( deviceID ); - if( model) - { - QAbstractItemView* valueView = panel->getValueView(); - valueView->setModel( *model ); - //valueView->resizeColumnsToContents(); - //_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - } - }; -*/ auto configureAction = [&]( QToolButton* button, QAction* action, BCDevice::ID deviceID, const QString& panelTitle="" ) { @@ -145,8 +141,8 @@ void BCMainWindow::initMainWindow() // besser: model::emit dataChanged // also: emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole, ValueRole}); //connect( &_dataManager, &BCMainWindow::valueTouched, _delegate, &BCDelegate::onHighlightRow ); - connect( _connectButton, &QPushButton::clicked, &_transmitter, &BCTransmitter::onToggleConnectionState ); - connect( _syncButton, &QPushButton::clicked, this, &BCMainWindow::onSyncFromDevice ); + connect( _connectButton, &QToolButton::clicked, &_transmitter, &BCTransmitter::onToggleConnectionState ); + connect( _syncButton, &QToolButton::clicked, this, &BCMainWindow::onSyncFromDevice ); connect( &_transmitter, &BCTransmitter::valueUpdated, this, &BCMainWindow::onValueUpdated ); diff --git a/bcmainwindow.ui b/bcmainwindow.ui index eedd493..f17f588 100644 --- a/bcmainwindow.ui +++ b/bcmainwindow.ui @@ -22,7 +22,7 @@ - + 64 @@ -41,7 +41,7 @@ - + 64 @@ -60,7 +60,7 @@ - + 64 @@ -79,7 +79,7 @@ - + 64 @@ -111,14 +111,14 @@ - + Sync - - + + Connect @@ -242,11 +242,6 @@
bcdevicepanel.h
1 - - BCToolButton - QToolButton -
bctoolbutton.h
-
diff --git a/bctoolbutton.cpp b/bctoolbutton.cpp deleted file mode 100644 index df8595a..0000000 --- a/bctoolbutton.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - - BionxControl - Copyright © 2025 christoph holzheuer - christoph.holzheuer@gmail.com - - Using: - - mhs_can_drv.c - © 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany - Klaus Demlehner, klaus@mhs-elektronik.de - @see www.mhs-elektronik.de - - Based on Bionx data type descriptions from: - - BigXionFlasher USB V 0.2.4 rev. 97 - © 2011-2013 by Thomas Koenig - @see www.bigxionflasher.org - - Bionx Bike Info - © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) - @see www.ts-soft.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - @see https://github.com/bikemike/bionx-bikeinfo - - ***************************************************************************/ - - -#include - -#include - - - -BCToolButton::BCToolButton(QWidget* parent) - : QToolButton(parent) -{ - qDebug() << " --- dis cant work: " << objectName(); - //setDefaultAction( -} diff --git a/bctoolbutton.h b/bctoolbutton.h deleted file mode 100644 index 2944f2c..0000000 --- a/bctoolbutton.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - - BionxControl - Copyright © 2025 christoph holzheuer - christoph.holzheuer@gmail.com - - Using: - - mhs_can_drv.c - © 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany - Klaus Demlehner, klaus@mhs-elektronik.de - @see www.mhs-elektronik.de - - Based on Bionx data type descriptions from: - - BigXionFlasher USB V 0.2.4 rev. 97 - © 2011-2013 by Thomas Koenig - @see www.bigxionflasher.org - - Bionx Bike Info - © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) - @see www.ts-soft.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - @see https://github.com/bikemike/bionx-bikeinfo - - ***************************************************************************/ - - -#ifndef BCTOOLBUTTON_H -#define BCTOOLBUTTON_H - -#include - -class BCToolButton : public QToolButton -{ -public: - - BCToolButton( QWidget* parent=nullptr ); - -}; - -#endif // BCTOOLBUTTON_H diff --git a/bcvalue.h b/bcvalue.h index 652875b..240f9c1 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -43,7 +43,7 @@ /* Werte haben verschiedene Längen (1,2 und 4 Byte) und werder auf unterschiedliche Art und Weise - ausgelesen und geschrieben (Siehe BCValueTypeWord). Sin können also Wert-Typen zugeordnet werden. Ein Werttyp + ausgelesen und geschrieben (Siehe BCValueTypeWord). Sie können also Wert-Typen zugeordnet werden. Ein Werttyp lässet über eine ID identifizieren, die mit der phyikalische Einheit des Wertes überschneiden kann, aber nicht muss: : Km/h, kWh, BCValueTypeWord ... bilden eigene Typen, SoC, Assistence Level sind auch eigene Typen, Teilen sich jedoch die Einheit '%'. @@ -56,6 +56,10 @@ */ +/** + * @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche + * Datenübertragung auf Treiberebene. + */ class BCAbstractTransmitter { @@ -101,9 +105,9 @@ public: //mutable std::optional rawValue; }; -// ?? ist das nötig? -Q_DECLARE_METATYPE(BCValue*) +Q_DECLARE_METATYPE(const BCValue*) +//Q_DECLARE_METATYPE(const BCValue&) //using BCValueList = QList; diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index c032ba0..a78470b 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -140,10 +140,6 @@ int BCValueModel::columnCount(const QModelIndex& parent) const /** * @brief Gibt die Header-Einträge zurück - * @param section - * @param orientation - * @param role - * @return */ QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -162,9 +158,18 @@ 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 + * 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 { -/* + Q_UNUSED(role) + + /* // Bonus: Rechtsbündig für Zahlen if (role == Qt::TextAlignmentRole && (index.column() == 0 || index.column() == 2)) { return Qt::AlignRight | Qt::AlignVCenter; @@ -172,14 +177,14 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const return QVariant(); */ - int row = index.row(); - int col = index.column(); + int row = index.row(); if (!index.isValid() || row >= _valueList.size()) return QVariant(); + const BCValue* entry = &_valueList.at( row ); + return QVariant::fromValue( entry ); - const BCValue& entry = _valueList.at( row ); - + /* if (role == Qt::DisplayRole || role == Qt::EditRole) { if( col == 0 ) @@ -187,8 +192,9 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const else if( col == 1 ) return entry.visibleValue; } + */ + - return QVariant(); }