Added & configured actions.
This commit is contained in:
113
bcmainwindow.cpp
113
bcmainwindow.cpp
@@ -44,15 +44,59 @@ BCMainWindow::BCMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
initData();
|
||||
|
||||
|
||||
}
|
||||
|
||||
BCMainWindow::~BCMainWindow()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BCMainWindow::initData()
|
||||
{
|
||||
// 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 )
|
||||
{
|
||||
button->setDefaultAction( action);
|
||||
connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
|
||||
connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
|
||||
// new way
|
||||
connect( action, &QAction::triggered, this, [&]
|
||||
{
|
||||
onShowDevicePanel( deviceID );
|
||||
});
|
||||
};
|
||||
|
||||
// Wir wollen die Devices den Views zuordnen können
|
||||
_devicePanels[BCDevice::ID::Console] = _consolePanel;
|
||||
_devicePanels[BCDevice::ID::Battery] = _batteryPanel;
|
||||
_devicePanels[BCDevice::ID::Motor] = _motorPanel;
|
||||
|
||||
// Die actions an die Buttons binden
|
||||
_motorButton->setDefaultAction( _motorAction);
|
||||
_consoleButton->setDefaultAction( _consoleAction );
|
||||
_batteryButton->setDefaultAction( _batteryAction );
|
||||
_pimpButton->setDefaultAction( _pimpAction);
|
||||
configureAction(_motorButton, _motorAction, BCDevice::ID::Motor );
|
||||
configureAction(_consoleButton, _consoleAction, BCDevice::ID::Console );
|
||||
configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery );
|
||||
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp );
|
||||
|
||||
// die Daten des eBikes laden
|
||||
_dataManager.loadXmlBikeData();
|
||||
|
||||
// Die Daten und auch die Datenmodelle für die Views werden
|
||||
// vom DataManager verwaltet und an die Views weitergereicht.
|
||||
@@ -92,42 +136,49 @@ BCMainWindow::BCMainWindow(QWidget *parent)
|
||||
connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice );
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
BCMainWindow::~BCMainWindow()
|
||||
{
|
||||
|
||||
// wir wollen Bescheid wissen, wenn ein Device (entspricht einem Datenmodel)
|
||||
// fertig eingelesen wurde.
|
||||
connect( &_dataManager, &BCDataManager::valueListReady, this, &BCMainWindow::onValueListReady );
|
||||
// die Daten des eBikes laden
|
||||
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
||||
|
||||
}
|
||||
|
||||
void BCMainWindow::initData()
|
||||
{
|
||||
// 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 )
|
||||
|
||||
void BCMainWindow::onValueListReady( BCDevice::ID deviceID )
|
||||
{
|
||||
qDebug() << " --- onValueListReady!" << deviceID;
|
||||
if( _devicePanels.contains( deviceID ) )
|
||||
{
|
||||
auto model = _dataManager.getModel( deviceID );
|
||||
if( model)
|
||||
{
|
||||
QAbstractItemView* valueView = panel->getValueView();
|
||||
valueView->setModel( *model );
|
||||
//valueView->resizeColumnsToContents();
|
||||
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
_dataManager.loadXmlBikeData();
|
||||
|
||||
|
||||
const BCValueList& newValueList = _dataManager.getCurrentValueList();
|
||||
_devicePanels[deviceID]->setValueList( newValueList );
|
||||
}
|
||||
}
|
||||
|
||||
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
||||
{
|
||||
qDebug() << " --- onShowDevicePanel:" << deviceID;
|
||||
if( _devicePanels.contains( deviceID ) )
|
||||
{
|
||||
//const BCValueList& newValueList = _dataManager.getCurrentValueList();
|
||||
//_devicePanels[deviceID]->setValueList( newValueList );
|
||||
}
|
||||
}
|
||||
|
||||
void BCMainWindow::onActionButtonTriggered( bool checked)
|
||||
{
|
||||
qDebug() << " --- onActionButtonTriggered: " << checked;
|
||||
|
||||
}
|
||||
|
||||
void BCMainWindow::onActionButtonToggled( bool checked)
|
||||
{
|
||||
qDebug() << " --- onActionButtonToggled: " << checked;
|
||||
}
|
||||
|
||||
|
||||
void BCMainWindow::onConnectButtonToggled(bool checked )
|
||||
{
|
||||
//_dataManager.setDriverConnectionState( checked );
|
||||
|
||||
Reference in New Issue
Block a user