From a12fde26ef93e671846ad57840af0dc652eb92db Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Fri, 26 Dec 2025 23:37:15 +0100 Subject: [PATCH] Fixed actions. --- bcmainwindow.cpp | 36 +++++++++++++++++++++++++----------- bcmainwindow.h | 1 + bcmainwindow.ui | 4 ++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index bfcd3a2..84d6c15 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -74,16 +74,25 @@ void BCMainWindow::initData() }; */ - auto configureAction = [&]( QToolButton* button, QAction* action, BCDevice::ID deviceID ) + auto configureAction = [&]( QToolButton* button, QAction* action, BCDevice::ID deviceID, const QString& panelTitle="" ) { + // Action an den Button binden button->setDefaultAction( action); + // old school, not used connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered ); connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled ); - // new way - connect( action, &QAction::triggered, this, [&] + // new way: die DeviceID muss aber explizit vom Lambda eingefanden werden. + connect( action, &QAction::triggered, this, [this,deviceID]() { onShowDevicePanel( deviceID ); }); + // den Panels ihren title geben + if( _devicePanels.contains(deviceID) ) + { + _devicePanels[deviceID]->setHeaderText( panelTitle ); + } + + }; // Wir wollen die Devices den Views zuordnen können @@ -92,10 +101,10 @@ void BCMainWindow::initData() _devicePanels[BCDevice::ID::Motor] = _motorPanel; // Die actions an die Buttons binden - configureAction(_motorButton, _motorAction, BCDevice::ID::Motor ); - configureAction(_consoleButton, _consoleAction, BCDevice::ID::Console ); - configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery ); - configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp ); + configureAction(_motorButton, _motorAction, BCDevice::ID::Motor, "Motor Settings"_L1 ); + configureAction(_consoleButton, _consoleAction, BCDevice::ID::Console, "Console Settings"_L1 ); + configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery, "Battery Settings"_L1 ); + configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp, "Pimp my Ride"_L1 ); // Die Daten und auch die Datenmodelle für die Views werden @@ -162,20 +171,25 @@ void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID ) qDebug() << " --- onShowDevicePanel:" << deviceID; if( _devicePanels.contains( deviceID ) ) { - //const BCValueList& newValueList = _dataManager.getCurrentValueList(); - //_devicePanels[deviceID]->setValueList( newValueList ); + BCDevicePanel* nxtPanel = _devicePanels[deviceID]; + if( nxtPanel != _currentPanel ) + { + _stackedWidget->setCurrentWidget( nxtPanel ); + _currentPanel = nxtPanel; + // knopf auch abschalten? + } } } void BCMainWindow::onActionButtonTriggered( bool checked) { - qDebug() << " --- onActionButtonTriggered: " << checked; + //qDebug() << " --- onActionButtonTriggered: " << checked; } void BCMainWindow::onActionButtonToggled( bool checked) { - qDebug() << " --- onActionButtonToggled: " << checked; + //qDebug() << " --- onActionButtonToggled: " << checked; } diff --git a/bcmainwindow.h b/bcmainwindow.h index f9cd4d8..dc9196f 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -68,6 +68,7 @@ protected: using BCDevicePanels = QMap; BCDevicePanels _devicePanels; + BCDevicePanel* _currentPanel{}; }; diff --git a/bcmainwindow.ui b/bcmainwindow.ui index 7b5cd02..6d131d4 100644 --- a/bcmainwindow.ui +++ b/bcmainwindow.ui @@ -131,7 +131,7 @@ - + 200 @@ -139,7 +139,7 @@ - 3 + 2