Cleanups.

This commit is contained in:
2025-12-31 16:30:03 +01:00
parent ce207b7146
commit d0476f8d6f
9 changed files with 163 additions and 66 deletions

View File

@@ -2,7 +2,7 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++20
CONFIG += c++23
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
@@ -27,7 +27,6 @@ windows
SOURCES += \
bc.cpp \
bcanimateddelegate.cpp \
bcdatamanager.cpp \
bcdeviceview.cpp \
bcdriver.cpp \
bcdrivertinycan.cpp \
@@ -36,6 +35,7 @@ SOURCES += \
bcvalue.cpp \
bcvaluemodel.cpp \
bcvaluetype.cpp \
bcxmlloader.cpp \
lib/can_drv_win.c \
main.cpp \
bcmainwindow.cpp
@@ -43,7 +43,6 @@ SOURCES += \
HEADERS += \
bc.h \
bcanimateddelegate.h \
bcdatamanager.h \
bcdeviceview.h \
bcdriver.h \
bcdrivertinycan.h \
@@ -51,7 +50,8 @@ HEADERS += \
bctransmitter.h \
bcvalue.h \
bcvaluemodel.h \
bcvaluetype.h
bcvaluetype.h \
bcxmlloader.h
FORMS += \
bcmainwindow.ui

View File

@@ -55,6 +55,8 @@ public:
const BCValueList& getValueListX();
//BCValueModel &getValueModel();
bool hasContent();
public slots:
void onValueListReady( BCDevice::ID deviceID, BCValueList valueList );

View File

@@ -49,7 +49,7 @@ BCDriver::DriverState BCDriverTinyCan::loadDriver()
//qDebug() << "CanBusControl " << cbc::Version << '\n' << "based on BigXionFlasher (c) 2011-2013 by Thomas Koenig <info@bigxionflasher.org> - www.bigxionflasher.org";
struct ::TDeviceStatus status;
struct ::TDeviceStatus canDevicestatus;
if( ::LoadDriver( NULL ) < 0 )
throw BCException( "Driver Error: 'LoadDriver'" );
@@ -64,14 +64,14 @@ BCDriver::DriverState BCDriverTinyCan::loadDriver()
::CanSetSpeed( 0, CAN_125K_BIT );
::CanSetMode( 0, OP_CAN_START, CAN_CMD_ALL_CLEAR );
::CanGetDeviceStatus( 0, &status );
::CanGetDeviceStatus( 0, &canDevicestatus );
setState(BCDriver::DriverState::Initialized);
if( status.DrvStatus < DRV_STATUS_CAN_OPEN )
if( canDevicestatus.DrvStatus < DRV_STATUS_CAN_OPEN )
throw BCException( "Driver Error: could not open device." );
if( status.CanStatus == CAN_STATUS_BUS_OFF )
if( canDevicestatus.CanStatus == CAN_STATUS_BUS_OFF )
{
::CanSetMode( 0, OP_CAN_RESET, CAN_CMD_NONE );
throw BCException( "Driver Error: CAN Status 'BusOff'" );

View File

@@ -107,7 +107,7 @@ void BCMainWindow::initMainWindow()
// Wenn ein Device (entspricht einem Datenmodel) fertig eingelesen wurde,
// wird es weitergereicht.
// Problem: alle Panels bekommen alle Datenmodelle angeboten.
connect( &_dataManager, &BCDataManager::valueListReady, currentPanel, &BCDeviceView::onValueListReady );
connect( &_dataManager, &BCXmlLoader::valueListReady, currentPanel, &BCDeviceView::onValueListReady );
}
};
@@ -122,28 +122,30 @@ void BCMainWindow::initMainWindow()
configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery );
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp );
/*
bool m_isDarkMode = false;
QString icon = m_isDarkMode ? "☀️" : "🌙";
fitzeButton->setText(icon);
// Verwendung:
QString style = QString(
"QPushButton {"
" background-color: %1;"
" border: 1px solid %2;"
" border-radius: 6px;"
" font-size: 12pt;"
" padding: 0px;"
"}"
"QPushButton:hover {"
" background-color: %3;"
"}"
).arg(m_isDarkMode ? "#2B2B2B" : "#FFFFFF")
.arg(m_isDarkMode ? "#3F3F3F" : "#E1DFDD")
.arg(m_isDarkMode ? "#3A3A3A" : "#F9F9F9");
connect(_delegate, &BCAnimatedDelegate::viewUpdateNeeded, _valueView->viewport(), QOverload<>::of(&QWidget::update));
//_valueView->setItemDelegate(_delegate);
// Highlight mit Fade-Out:
//_delegate->onHighlightRow(2); // 2 Sekunden Fade
BCTransmitter* transmitter = _dataManager.getTransmitter();
*/
//_delegate->onHighlightRow(2); // 2 Sekunden Fade
fitzeButton->setStyleSheet(style);
// besser: model::emit dataChanged
// also: emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole, ValueRole});
//connect( &_dataManager, &BCMainWindow::valueTouched, _delegate, &BCAnimatedDelegate::onHighlightRow );
connect( _connectButton, &QToolButton::clicked, &_transmitter, &BCTransmitter::onToggleConnectionState );
connect( _connectButton, &QToolButton::clicked, &_transmitter, &BCTransmitter::onToggleConnectionState );
connect( _syncButton, &QToolButton::clicked, this, &BCMainWindow::onSyncFromDevice );
connect( &_transmitter, &BCTransmitter::valueUpdated, this, &BCMainWindow::onValueUpdated );
@@ -156,8 +158,8 @@ void BCMainWindow::initMainWindow()
connect(this, &BCMainWindow::requestValueUpdate, &_transmitter, &BCTransmitter::enqueueValueOp);
// B) Ergebnisse empfangen (Runner -> Manager)
//connect(&_transmitter, &BCTransmitter::valueStateChanged, this, &BCDataManager::onvalueStateChanged);
//connect(&_transmitter, &BCTransmitter::messageLogged, this, &BCDataManager::onRunnerMessage);
//connect(&_transmitter, &BCTransmitter::valueStateChanged, this, &BCXmlLoader::onvalueStateChanged);
//connect(&_transmitter, &BCTransmitter::messageLogged, this, &BCXmlLoader::onRunnerMessage);
// C) Aufräumen: Wenn Thread endet, lösche den Runner
connect(&_worker, &QThread::finished, &_transmitter, &QObject::deleteLater);
@@ -204,16 +206,7 @@ void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
}
}
void BCMainWindow::onActionButtonTriggered( bool checked)
{
//qDebug() << " --- onActionButtonTriggered: " << checked;
}
void BCMainWindow::onActionButtonToggled( bool checked)
{
//qDebug() << " --- onActionButtonToggled: " << checked;
}
void BCMainWindow::onConnectButtonToggled(bool checked )
@@ -232,7 +225,11 @@ void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::Sta
}
// __fix move this to devicePanel??
/**
* @brief SLOT, der aufgerufen wird, um das akutelle Device (Battery, Motor, ... )
* zu synchronisieren, d.h. die aktuellen Werte über den CAN-Bus abzufragen.
*/
void BCMainWindow::onSyncFromDevice()
{

View File

@@ -36,7 +36,7 @@
#include <QMainWindow>
#include <ui_bcmainwindow.h>
#include <bcdatamanager.h>
#include <bcxmlloader.h>
class BCDeviceView;
@@ -55,8 +55,6 @@ public slots:
//void onValueListReady( BCDevice::ID deviceID );
void onShowDevicePanel( BCDevice::ID deviceID );
void onActionButtonTriggered( bool checked);
void onActionButtonToggled( bool checked);
void onConnectButtonToggled(bool active );
// Slots für Rückmeldungen vom Runner
@@ -74,7 +72,7 @@ protected:
void initMainWindow();
BCDataManager _dataManager;
BCXmlLoader _dataManager;
// Wir brauchen eine Verbindung zwischen den Views
// und dem Device, das sie darstellen.

View File

@@ -169,6 +169,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fitzeButton">
<property name="text">
<string>Fitze</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -39,14 +39,14 @@
#include <QApplication>
#include <QElapsedTimer>
#include <bcdatamanager.h>
#include <bcxmlloader.h>
#include <bcvaluetype.h>
using namespace Qt::StringLiterals;
BCDataManager::BCDataManager(QObject *parent)
BCXmlLoader::BCXmlLoader(QObject *parent)
: QObject(parent)
{
@@ -56,14 +56,8 @@ BCDataManager::BCDataManager(QObject *parent)
}
BCDataManager::~BCDataManager()
{
}
void BCDataManager::loadXmlBikeData( const QString& fileName )
void BCXmlLoader::loadXmlBikeData( const QString& fileName )
{
auto printAttrs = [](const QXmlStreamReader& xml)
{
@@ -79,6 +73,8 @@ void BCDataManager::loadXmlBikeData( const QString& fileName )
return;
*/
QMetaEnum bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
@@ -108,7 +104,7 @@ void BCDataManager::loadXmlBikeData( const QString& fileName )
// Wir wollen die Device-ID aus dem XML Tag ermitteln
const char* deviceKey = _xml.attributes().value("Type"_L1).toLatin1().constData();
/*
auto optDeviceID = _bcDeviceEnum.keyToValue64(deviceKey);
auto optDeviceID = bcDeviceEnum.keyToValue64(deviceKey);
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
if( optDeviceID.has_value())
{
@@ -118,7 +114,7 @@ void BCDataManager::loadXmlBikeData( const QString& fileName )
}
*/
bool ok;
auto optDeviceID = _bcDeviceEnum.keyToValue(deviceKey,&ok);
auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok);
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
//if( optDeviceID.has_value())
if(ok)
@@ -147,7 +143,7 @@ void BCDataManager::loadXmlBikeData( const QString& fileName )
}
void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
{
auto printAttrs = [](const QXmlStreamReader& xml)
{
@@ -200,7 +196,7 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
}
std::optional<BCValue> BCDataManager::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
std::optional<BCValue> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
{
/*
@@ -256,7 +252,7 @@ std::optional<BCValue> BCDataManager::makeDataValue( BCDevice::ID deviceID, cons
}
// --- NEU: Speichern mit QXmlStreamWriter ---
void BCDataManager::saveBikeData()
void BCXmlLoader::saveBikeData()
{
/*
QString fileName = QFileDialog::getSaveFileName(this, "XML speichern", "", "XML Files (*.xml)");

View File

@@ -30,8 +30,8 @@
***************************************************************************/
#ifndef BCDATAMANAGER_H
#define BCDATAMANAGER_H
#ifndef BCXMLLOADER_H
#define BCXMLLOADER_H
#include <QHash>
#include <QXmlStreamReader>
@@ -44,17 +44,14 @@
#include <bctransmitter.h>
class BCDataManager : public QObject
class BCXmlLoader : public QObject
{
Q_OBJECT
public:
BCDataManager( QObject* parent = nullptr);
virtual ~BCDataManager();
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
BCXmlLoader( QObject* parent = nullptr);
virtual ~BCXmlLoader() = default;
public slots:
@@ -80,10 +77,10 @@ protected:
std::optional<BCValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
QXmlStreamReader _xml;
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
};
#endif // BCDATAMANAGER_H
#endif // BCXMLLOADER_H

100
main.cpp
View File

@@ -34,8 +34,108 @@
#include <QFile>
#include <QDebug>
#include <QPushButton>
#include <QStatusBar>
#include <bcmainwindow.h>
class ThemeSwitchButton : public QPushButton {
Q_OBJECT
public:
explicit ThemeSwitchButton(QWidget *parent = nullptr)
: QPushButton(parent), m_isDarkMode(true)
{
// 1. Visuelles Setup: Flach, keine Ränder, Hand-Cursor
setFlat(true);
setCursor(Qt::PointingHandCursor);
setFixedSize(32, 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"(
QPushButton {
border: none;
background-color: transparent;
font-size: 14pt;
}
QPushButton:hover {
background-color: rgba(128, 128, 128, 30); /* Leichter Hover-Effekt */
border-radius: 4px;
}
)");
// 2. Initialer Status (Startet im Dark Mode -> zeigt Mond)
updateIcon();
// 3. Klick verbinden
connect(this, &QPushButton::clicked, this, &ThemeSwitchButton::toggle);
}
signals:
void themeChanged(bool isDark);
private slots:
void toggle() {
m_isDarkMode = !m_isDarkMode;
updateIcon();
emit themeChanged(m_isDarkMode);
}
private:
void updateIcon() {
// Logik:
// Ist Dark Mode an? Zeige Mond (oder Sonne, je nach Geschmack).
// Hier: Zeige das Symbol des AKTUELLEN Modus.
setText(m_isDarkMode ? "🌙" : "☀️");
setToolTip(m_isDarkMode ? "Switch to Light Mode" : "Switch to Dark Mode");
}
bool m_isDarkMode;
};
/*
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr)
: QMainWindow(parent)
{
setWindowTitle("Fluent Theme Switcher");
resize(800, 600);
// --- STATUSBAR SETUP ---
QStatusBar *statBar = statusBar();
// Optional: Normale Nachricht links
statBar->showMessage("Ready");
// 1. Unseren Switcher erstellen
ThemeSwitchButton *themeBtn = new ThemeSwitchButton(this);
// 2. WICHTIG: Rechts hinzufügen
statBar->addPermanentWidget(themeBtn);
// 3. Signal verbinden: Button klick -> Theme ändern
connect(themeBtn, &ThemeSwitchButton::themeChanged, this, [this](bool isDark){
if (isDark) {
applyFluentDarkTheme(*qApp); // Funktion von vorhin
statusBar()->showMessage("Dark Mode Activated", 3000);
} else {
applyFluentLightTheme(*qApp); // Funktion von vorhin
statusBar()->showMessage("Light Mode Activated", 3000);
}
});
// Initiale Anwendung (Dark Mode)
applyFluentDarkTheme(*qApp);
}
};
*/
bool setApplicationStyleSheet( QAnyStringView path )
{
QFile styleFile( path.toString() );