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

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 )
/**
* @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
*/
void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newVisisbleValue )
{
qDebug() << " Panel update: " << newValue;
const BCValueList& valueList = getValueList();
if( row > -1 && row < valueList.size() )
qDebug() << " Panel update: " << newVisisbleValue;
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;
}
if( valueChanged )
{
QModelIndex idx = index(row,1);
emit dataChanged(idx, idx, {Qt::DisplayRole});
const BCValue& value = _valueList[row];
QModelIndex idx = index(row,1);
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();
}
int BCValueModel::columnCount(const QModelIndex &parent) const
/**
* @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();
}
@@ -122,24 +164,7 @@ 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()];