Cosmetics and some commenting.

This commit is contained in:
2025-12-29 13:05:35 +01:00
parent 1a450e30ff
commit 527f66759f
9 changed files with 171 additions and 133 deletions

4
bc.h
View File

@@ -802,6 +802,10 @@ namespace BCTags
inline constexpr auto Min = "Min"_L1;
inline constexpr auto Max = "Max"_L1;
inline constexpr auto Factor = "Factor"_L1;
inline constexpr auto ValueTag = "Wert"_L1;
inline constexpr auto LabelTag = "Bezeichnung"_L1;
}
#endif // BC_H

View File

@@ -74,13 +74,13 @@ void BCCanDriver::onStartDriver()
if( _driverState == DriverState::NotPresent)
_driverState = loadDriver();
emit stateChanged( (int) _driverState );
emit stateChanged( _driverState );
// DLL geladen, Verbindungsversuch
_driverState = initDriver();
// Wir haben was erreicht
emit stateChanged( (int) _driverState );
emit stateChanged( _driverState );
}
catch( std::exception& except )
{

View File

@@ -114,10 +114,11 @@ public:
signals:
// __fix wird das gebraucht?
void errorOccured( const QString& errMsg );
void statusHint( const QString& msg ) const;
void stateChanged( int state );
void stateChanged( DriverState state );
public slots:

View File

@@ -169,8 +169,13 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
// nur gültige Werte sind vorhanden und können gespeichert werden
std::optional<BCValue> newValue = makeDataValue( deviceID, params );
if(newValue)
{
// wir merken uns gleich den index in der Werteliste
(*newValue).indexRow = currentValues.size();
currentValues.push_back( *newValue );
}
}
// weiter zum nächsten Element
_xml.skipCurrentElement();
}

View File

@@ -33,7 +33,7 @@
#ifndef BCDATAMANAGER_H
#define BCDATAMANAGER_H
#include <QMap>
#include <QHash>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QMetaEnum>
@@ -79,7 +79,7 @@ protected:
std::optional<BCValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
using BCValueTypeMap = QMap<QString,BCValueType*>;
using BCValueTypeMap = QHash<QString,BCValueType*>;
QXmlStreamReader _xml;
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};

View File

@@ -78,7 +78,7 @@ protected:
// Wir brauchen eine Verbindung zwischen den Views
// und dem Device, das sie darstellen.
using BCDevicePanels = QMap<BCDevice::ID, BCDevicePanel*>;
using BCDevicePanels = QHash<BCDevice::ID, BCDevicePanel*>;
BCDevicePanels _devicePanels;
BCDevicePanel* _currentPanel{};

View File

@@ -32,6 +32,10 @@
#include <bcvaluemodel.h>
/**
* @brief Konstruktor, ohne Besonderheiten
* @param parent Das Elternobject
*/
BCValueModel::BCValueModel(QObject *parent)
: QAbstractTableModel(parent)
@@ -40,6 +44,11 @@ BCValueModel::BCValueModel(QObject *parent)
}
/**
* @brief Einen Einzelwert hinzufügen
* @param val der neue Wert
*/
void BCValueModel::addValue(const BCValue& val)
{
int row = _valueList.size();
@@ -49,12 +58,22 @@ void BCValueModel::addValue(const BCValue& val)
}
/**
* @brief Gibt die interne Werteliste als const ref zurück
* @return Die WerteListe
*/
const BCValueList& BCValueModel::getValueList() const
{
return _valueList;
}
/**
* @brief Nimmt eine Werteliste in Besitz.
* @param newValueList Die Wertelist. Nach dem Aufruf leer.
*/
void BCValueModel::takeValueList(BCValueList& newValueList)
{
beginResetModel();
@@ -63,34 +82,40 @@ void BCValueModel::takeValueList(BCValueList& newValueList)
endResetModel();
}
void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newValue )
{
qDebug() << " Panel update: " << newValue;
const BCValueList& valueList = getValueList();
if( row > -1 && row < valueList.size() )
{
bool valueChanged = false;
const BCValue& value = valueList[row];
if( value.state != state )
{
valueChanged = true;
value.state = state;
}
if( !newValue.isEmpty() && newValue != value.visibleValue )
{
valueChanged = true;
value.visibleValue = newValue;
}
/**
* @brief SLOT, der aufgerufen wird, wenn sich ein Wert und/oder der Zustand eines Wertes geändert hat.
* Emitted 'dataChanged' um die zuständige View upzudaten.
*
* @param row Der Index des geänderten Wertes in der Liste
* @param state Der neue state des Wertes
* @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall
*/
if( valueChanged )
void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newVisisbleValue )
{
qDebug() << " Panel update: " << newVisisbleValue;
if( row > -1 && row < _valueList.size() )
{
const BCValue& value = _valueList[row];
QModelIndex idx = index(row,1);
emit dataChanged(idx, idx, {Qt::DisplayRole});
}
value.state = state;
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue )
{
value.visibleValue = newVisisbleValue;
}
// wir schicken auf jeden fall einen update request
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
}
}
/**
* @brief Gibt die Zeilenanzahl zurück
* @param parent Der Elternindex
* @return die Zeilenanzahl
*/
int BCValueModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
@@ -98,12 +123,29 @@ int BCValueModel::rowCount(const QModelIndex& parent) const
return _valueList.size();
}
/**
* @brief Gibt die Spaltenanzahl zurück
* @param parent Der Elternindex
* @return die Spaltenanzahl
*/
int BCValueModel::columnCount(const QModelIndex& parent) const
{
if (parent.isValid()) return 0;
if (parent.isValid())
return 0;
return 2;
}
/**
* @brief Gibt die Header-Einträge zurück
* @param section
* @param orientation
* @param role
* @return
*/
QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
@@ -112,9 +154,9 @@ QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int
switch (section)
{
case 0:
return QString("Bezeichnung");
return BCTags::LabelTag;
case 1:
return QString("Wert");
return BCTags::ValueTag;
default:
return QVariant();
}
@@ -123,23 +165,6 @@ QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int
QVariant BCValueModel::data(const QModelIndex& index, int role) const
{
/*
if (!index.isValid() || index.row() >= static_cast<int>(m_items.size()))
return QVariant();
const auto& item = m_items.at(index.row());
if (role == Qt::DisplayRole) {
switch (index.column()) {
case 0: return item.id;
case 1: return item.name;
case 2: {
// Hier nutzen wir QLocale für das Komma!
return QLocale(QLocale::German).toString(item.value, 'f', 2);
}
}
}
// Bonus: Rechtsbündig für Zahlen
if (role == Qt::TextAlignmentRole && (index.column() == 0 || index.column() == 2)) {
return Qt::AlignRight | Qt::AlignVCenter;
@@ -152,8 +177,8 @@ if (!index.isValid() || index.row() >= static_cast<int>(m_items.size()))
if (!index.isValid() || row >= _valueList.size())
return QVariant();
BCValue& entry = const_cast<BCValue&>(_valueList.at( row ));
entry.indexRow = row;
const BCValue& entry = _valueList.at( row );
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
@@ -178,6 +203,9 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
// __fix!
if (index.isValid() && role == Qt::EditRole)
{
BCValue& item = _valueList[index.row()];

View File

@@ -70,7 +70,7 @@ public:
public slots:
void onValueUpdated( int index, BC::State state, const QString& newValue="" );
void onValueUpdated(int index, BC::State state, const QString& newVisisbleValue="" );
protected: