Sending BCValueList to ViewPanels.
This commit is contained in:
@@ -83,11 +83,6 @@ BCTransmitter* BCDataManager::getTransmitter()
|
|||||||
return &_transmitter;
|
return &_transmitter;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BCValueList& BCDataManager::getCurrentValueList()
|
|
||||||
{
|
|
||||||
return _currentValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BCDataManager::onCommandFinished(int id, bool success)
|
void BCDataManager::onCommandFinished(int id, bool success)
|
||||||
{
|
{
|
||||||
@@ -224,8 +219,8 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
|||||||
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1);
|
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1);
|
||||||
qDebug() << " XXX ---------------";
|
qDebug() << " XXX ---------------";
|
||||||
|
|
||||||
// Wertliste für neues Device leeren
|
// temporäre Wertliste für neues Device
|
||||||
_currentValues.clear();
|
BCValueList currentValues;
|
||||||
|
|
||||||
while( _xml.readNextStartElement() )
|
while( _xml.readNextStartElement() )
|
||||||
{
|
{
|
||||||
@@ -245,15 +240,15 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
|||||||
// nur gültige Werte sind vorhanden und können gespeichert werden
|
// nur gültige Werte sind vorhanden und können gespeichert werden
|
||||||
std::optional<BCDataValue> newValue = makeDataValue( deviceID, params );
|
std::optional<BCDataValue> newValue = makeDataValue( deviceID, params );
|
||||||
if(newValue)
|
if(newValue)
|
||||||
_currentValues.push_back( *newValue );
|
currentValues.push_back( *newValue );
|
||||||
}
|
}
|
||||||
// weiter zum nächsten Element
|
// weiter zum nächsten Element
|
||||||
_xml.skipCurrentElement();
|
_xml.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn dieses Device fertig geladen wurde, soll das MainWindow es abholen
|
// Wenn dieses Device fertig geladen wurde, soll das MainWindow es abholen
|
||||||
if( !_currentValues.isEmpty() )
|
if( !currentValues.isEmpty() )
|
||||||
emit valueListReady( deviceID );
|
emit valueListReady( deviceID, currentValues );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
|
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
|
||||||
BCTransmitter* getTransmitter();
|
BCTransmitter* getTransmitter();
|
||||||
const BCValueList& getCurrentValueList();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void valueListReady( BCDevice::ID deviceID );
|
void valueListReady( BCDevice::ID deviceID, BCValueList valueList );
|
||||||
|
|
||||||
// Internes Signal, um Daten an den Worker Thread zu senden
|
// Internes Signal, um Daten an den Worker Thread zu senden
|
||||||
void sendValueCommand( BC::OpID, const BCDataValue* cmd);
|
void sendValueCommand( BC::OpID, const BCDataValue* cmd);
|
||||||
@@ -95,7 +95,6 @@ protected:
|
|||||||
using BCValueTypeMap = QMap<QString,BCValueType*>;
|
using BCValueTypeMap = QMap<QString,BCValueType*>;
|
||||||
|
|
||||||
QXmlStreamReader _xml;
|
QXmlStreamReader _xml;
|
||||||
BCValueList _currentValues;
|
|
||||||
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
||||||
|
|
||||||
QThread _worker;
|
QThread _worker;
|
||||||
|
|||||||
@@ -100,12 +100,55 @@ public:
|
|||||||
//mutable std::optional<uint32_t> rawValue;
|
//mutable std::optional<uint32_t> rawValue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
// ?? ist das nötig?
|
||||||
Q_DECLARE_METATYPE(BCDataValue*)
|
Q_DECLARE_METATYPE(BCDataValue*)
|
||||||
|
|
||||||
|
|
||||||
using BCValueList = QList<BCDataValue>;
|
//using BCValueList = QList<BCDataValue>;
|
||||||
|
|
||||||
|
class BCValueList : public QList<BCDataValue>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
BCValueList()
|
||||||
|
{
|
||||||
|
qDebug() << "BC Construct: " << this;
|
||||||
|
}
|
||||||
|
|
||||||
|
BCValueList(const BCValueList& other)
|
||||||
|
: QList<BCDataValue>(other)
|
||||||
|
{
|
||||||
|
qDebug() << "BC: Copy from: " << &other << "to" << this;
|
||||||
|
}
|
||||||
|
|
||||||
|
BCValueList(BCValueList&& other) noexcept
|
||||||
|
: QList<BCDataValue>( other )
|
||||||
|
{
|
||||||
|
qDebug() << "Move from: " << &other << "to" << this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy Assignment Operator
|
||||||
|
BCValueList& operator=(const BCValueList& other)
|
||||||
|
{
|
||||||
|
QList<BCDataValue>::operator=( other );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move Assignment Operator
|
||||||
|
BCValueList& operator=(BCValueList&& other) noexcept
|
||||||
|
{
|
||||||
|
QList<BCDataValue>::operator=( other );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~BCValueList()
|
||||||
|
{
|
||||||
|
qDebug() << "Destruct: " << this;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
Q_DECLARE_METATYPE(BCValueList)
|
||||||
|
|
||||||
|
|
||||||
// abbreviations:
|
// abbreviations:
|
||||||
|
|||||||
@@ -35,9 +35,8 @@
|
|||||||
BCDevicePanel::BCDevicePanel(QWidget *parent)
|
BCDevicePanel::BCDevicePanel(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
_valueView->setModel( &_valueModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,18 +53,35 @@ QString BCDevicePanel::getHeaderText()
|
|||||||
|
|
||||||
QTableView* BCDevicePanel::getValueView()
|
QTableView* BCDevicePanel::getValueView()
|
||||||
{
|
{
|
||||||
|
//valueModel;
|
||||||
return _valueView;
|
return _valueView;
|
||||||
}
|
|
||||||
|
|
||||||
void BCDevicePanel::setValueList(const BCValueList& valueList)
|
// Die Daten und auch die Datenmodelle für die Views werden
|
||||||
|
// vom DataManager verwaltet und an die Views weitergereicht.
|
||||||
|
|
||||||
|
//auto model = _dataManager.getModel( BCDevice::ID::Console );
|
||||||
|
//_consolePanel->getValueView()->setModel( model.v );
|
||||||
|
|
||||||
|
/*
|
||||||
|
if( model)
|
||||||
{
|
{
|
||||||
|
_valueView->setModel( *model );
|
||||||
|
_valueView->resizeColumnsToContents();
|
||||||
|
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BCValueList& BCDevicePanel::exposeValueList()
|
||||||
const BCValueList& BCDevicePanel::getValueList()
|
|
||||||
{
|
{
|
||||||
|
return _myTmpList;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BCDevicePanel::onValueListReady( BCDevice::ID deviceID, BCValueList valueList )
|
||||||
|
{
|
||||||
|
qDebug() << " --- onValueListReady: " << getHeaderText() <<" : " << deviceID << ": " << valueList.size();
|
||||||
|
_valueModel.setValueList( valueList );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -48,15 +48,18 @@ public:
|
|||||||
void setHeaderText( const QString& headerText);
|
void setHeaderText( const QString& headerText);
|
||||||
QString getHeaderText();
|
QString getHeaderText();
|
||||||
|
|
||||||
void setValueList(const BCValueList& valueList);
|
BCValueList& exposeValueList();
|
||||||
const BCValueList& getValueList();
|
|
||||||
|
|
||||||
QTableView* getValueView();
|
QTableView* getValueView();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void onValueListReady( BCDevice::ID deviceID, BCValueList valueList );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
BCValueModel _valueModel;
|
BCValueModel _valueModel;
|
||||||
|
BCValueList _myTmpList;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@
|
|||||||
BCMainWindow::BCMainWindow(QWidget *parent)
|
BCMainWindow::BCMainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
|
// WICHTIG: Registriere sowohl das Struct als auch die LISTE des Structs
|
||||||
|
qRegisterMetaType<BCDataValue>("BCDataValue");
|
||||||
|
qRegisterMetaType<QList<BCDataValue>>("BCValueList");
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
initData();
|
initData();
|
||||||
|
|
||||||
@@ -79,17 +83,25 @@ void BCMainWindow::initData()
|
|||||||
// Action an den Button binden
|
// Action an den Button binden
|
||||||
button->setDefaultAction( action);
|
button->setDefaultAction( action);
|
||||||
// old school, not used
|
// old school, not used
|
||||||
connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
|
//connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
|
||||||
connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
|
//connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
|
||||||
|
|
||||||
// new way: die DeviceID muss aber explizit vom Lambda eingefanden werden.
|
// new way: die DeviceID muss aber explizit vom Lambda eingefanden werden.
|
||||||
connect( action, &QAction::triggered, this, [this,deviceID]()
|
connect( action, &QAction::triggered, this, [this,deviceID]()
|
||||||
{
|
{
|
||||||
onShowDevicePanel( deviceID );
|
onShowDevicePanel( deviceID );
|
||||||
});
|
});
|
||||||
// den Panels ihren title geben
|
|
||||||
if( _devicePanels.contains(deviceID) )
|
if( _devicePanels.contains(deviceID) )
|
||||||
{
|
{
|
||||||
_devicePanels[deviceID]->setHeaderText( panelTitle );
|
BCDevicePanel* currentPanel = _devicePanels[deviceID];
|
||||||
|
// den Panels ihren title geben
|
||||||
|
currentPanel->setHeaderText( panelTitle );
|
||||||
|
|
||||||
|
// Wenn ein Device (entspricht einem Datenmodel) fertig eingelesen wurde,
|
||||||
|
// wird es weitergereicht.
|
||||||
|
// Problem: alle Panels bekommen alle Datenmodelle angeboten.
|
||||||
|
connect( &_dataManager, &BCDataManager::valueListReady, currentPanel, &BCDevicePanel::onValueListReady );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,21 +119,8 @@ void BCMainWindow::initData()
|
|||||||
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp, "Pimp my Ride"_L1 );
|
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp, "Pimp my Ride"_L1 );
|
||||||
|
|
||||||
|
|
||||||
// Die Daten und auch die Datenmodelle für die Views werden
|
|
||||||
// vom DataManager verwaltet und an die Views weitergereicht.
|
|
||||||
|
|
||||||
//auto model = _dataManager.getModel( BCDevice::ID::Console );
|
|
||||||
//_consolePanel->getValueView()->setModel( model.v );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if( model)
|
|
||||||
{
|
|
||||||
_valueView->setModel( *model );
|
|
||||||
_valueView->resizeColumnsToContents();
|
|
||||||
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BCItemDelegate* _delegate = new BCItemDelegate( _valueView);
|
BCItemDelegate* _delegate = new BCItemDelegate( _valueView);
|
||||||
//_delegate = new AnimatedDelegate(_valueView );
|
//_delegate = new AnimatedDelegate(_valueView );
|
||||||
_valueView->setItemDelegate( _delegate );
|
_valueView->setItemDelegate( _delegate );
|
||||||
@@ -145,26 +144,28 @@ void BCMainWindow::initData()
|
|||||||
connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice );
|
connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// 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
|
// die Daten des eBikes laden
|
||||||
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void BCMainWindow::onValueListReady( BCDevice::ID deviceID )
|
void BCMainWindow::onValueListReady( BCDevice::ID deviceID )
|
||||||
{
|
{
|
||||||
qDebug() << " --- onValueListReady!" << deviceID;
|
qDebug() << " --- onValueListReady!" << deviceID;
|
||||||
if( _devicePanels.contains( deviceID ) )
|
if( _devicePanels.contains( deviceID ) )
|
||||||
{
|
{
|
||||||
const BCValueList& newValueList = _dataManager.getCurrentValueList();
|
BCDevicePanel& panel = *_devicePanels[deviceID];
|
||||||
_devicePanels[deviceID]->setValueList( newValueList );
|
BCValueList& victim = panel.exposeValueList();
|
||||||
|
BCValueList& newValueList = _dataManager.getCurrentValueList();
|
||||||
|
qDebug() << " --- Before: " << victim.size() << " orig:" << newValueList.size();
|
||||||
|
victim = std::exchange(newValueList, BCValueList());
|
||||||
|
//_devicePanels[deviceID]->setValueList( newValueList );
|
||||||
|
qDebug() << " ---After: " << victim.size() << " orig:" << newValueList.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void onValueListReady( BCDevice::ID deviceID );
|
//void onValueListReady( BCDevice::ID deviceID );
|
||||||
void onShowDevicePanel( BCDevice::ID deviceID );
|
void onShowDevicePanel( BCDevice::ID deviceID );
|
||||||
void onActionButtonTriggered( bool checked);
|
void onActionButtonTriggered( bool checked);
|
||||||
void onActionButtonToggled( bool checked);
|
void onActionButtonToggled( bool checked);
|
||||||
|
|||||||
@@ -21,25 +21,6 @@
|
|||||||
<string notr="true">background-color: grey;</string>
|
<string notr="true">background-color: grey;</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
|
||||||
<widget class="BCToolButton" name="_pimpButton">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>64</width>
|
|
||||||
<height>64</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>...</string>
|
|
||||||
</property>
|
|
||||||
<property name="iconSize">
|
|
||||||
<size>
|
|
||||||
<width>64</width>
|
|
||||||
<height>64</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="BCToolButton" name="_motorButton">
|
<widget class="BCToolButton" name="_motorButton">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
@@ -97,6 +78,25 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BCToolButton" name="_pimpButton">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>64</width>
|
||||||
|
<height>64</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>48</width>
|
||||||
|
<height>48</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@@ -149,6 +149,7 @@ int main(int argc, char *argv[])
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
//setApplicationStyleSheet( ":/bionxcontrol.qss"_L1 );
|
//setApplicationStyleSheet( ":/bionxcontrol.qss"_L1 );
|
||||||
|
|
||||||
|
|
||||||
mookoo myMookoo{"",1,1.0};
|
mookoo myMookoo{"",1,1.0};
|
||||||
mookoo myMooko2{"",1};
|
mookoo myMooko2{"",1};
|
||||||
mookoo2* myMooko3 = new mookoo2{{"superfitze",1},8};
|
mookoo2* myMooko3 = new mookoo2{{"superfitze",1},8};
|
||||||
|
|||||||
Reference in New Issue
Block a user