Rework driver code, again.
This commit is contained in:
@@ -46,14 +46,18 @@
|
||||
BCMainWindow::BCMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
// WICHTIG: Registriere sowohl das Struct als auch die LISTE des Structs
|
||||
// __fix! in der Form nötig?
|
||||
qRegisterMetaType<BCValue>("BCValue");
|
||||
qRegisterMetaType<QList<BCValue>>("BCValueList");
|
||||
|
||||
setupUi(this);
|
||||
|
||||
// BESTE PRAXIS: QTimer::singleShot mit Lambda
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
// Wir schreiben den 'initMainWindow()' Aufruf mit Hilfe des
|
||||
// timers in die Event-Queue, damit er erst ausgeführt wird,
|
||||
// wenn das Fenster sichtbar ist.
|
||||
|
||||
QTimer::singleShot(0, this, [this]()
|
||||
{
|
||||
initMainWindow();
|
||||
});
|
||||
|
||||
@@ -88,13 +92,12 @@ void BCMainWindow::setHeaderLabel( const QString& headerText)
|
||||
void BCMainWindow::initMainWindow()
|
||||
{
|
||||
|
||||
// Lambda um die buttons mit ihren Actions zu verbinden
|
||||
auto configureAction = [&]( QToolButton* button, QAction* action, BCDevice::ID deviceID )
|
||||
{
|
||||
|
||||
// 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: die DeviceID muss aber explizit vom Lambda eingefanden werden.
|
||||
connect( action, &QAction::triggered, this, [this,deviceID]()
|
||||
@@ -114,11 +117,11 @@ void BCMainWindow::initMainWindow()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Wir wollen die Devices den Views zuordnen können
|
||||
_devicePanels[BCDevice::ID::Console] = _consolePanel;
|
||||
_devicePanels[BCDevice::ID::Battery] = _batteryPanel;
|
||||
_devicePanels[BCDevice::ID::Motor] = _motorPanel;
|
||||
_devicePanels[BCDevice::ID::Pimp] = _pimpPanel;
|
||||
|
||||
// Die actions an die Buttons binden
|
||||
configureAction(_motorButton, _motorAction, BCDevice::ID::Motor );
|
||||
@@ -161,7 +164,7 @@ void BCMainWindow::initMainWindow()
|
||||
|
||||
_worker.start();
|
||||
|
||||
bc::processEventsFor(2000);
|
||||
|
||||
|
||||
// die Daten des eBikes laden
|
||||
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
||||
|
||||
Reference in New Issue
Block a user