Fixed actions.

This commit is contained in:
2025-12-26 23:37:15 +01:00
parent b7092ed3a5
commit a12fde26ef
3 changed files with 28 additions and 13 deletions

View File

@@ -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;
}

View File

@@ -68,6 +68,7 @@ protected:
using BCDevicePanels = QMap<BCDevice::ID, BCDevicePanel*>;
BCDevicePanels _devicePanels;
BCDevicePanel* _currentPanel{};
};

View File

@@ -131,7 +131,7 @@
</widget>
</item>
<item>
<widget class="QStackedWidget" name="_controlWidget">
<widget class="QStackedWidget" name="_stackedWidget">
<property name="minimumSize">
<size>
<width>200</width>
@@ -139,7 +139,7 @@
</size>
</property>
<property name="currentIndex">
<number>3</number>
<number>2</number>
</property>
<widget class="BCDevicePanel" name="_consolePanel"/>
<widget class="BCDevicePanel" name="_motorPanel"/>