Try BCValue as smartptr
This commit is contained in:
@@ -44,9 +44,6 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "bcanimateddelegate.h"
|
#include "bcanimateddelegate.h"
|
||||||
#include "bcvalue.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* view)
|
BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* view)
|
||||||
@@ -59,9 +56,9 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView*
|
|||||||
QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
||||||
{
|
{
|
||||||
// Wir prüfen, ob im Variant unser Struct steckt
|
// Wir prüfen, ob im Variant unser Struct steckt
|
||||||
if (dataValue.canConvert<const BCValue*>())
|
if (dataValue.canConvert<const BCValue&>())
|
||||||
{
|
{
|
||||||
const BCValue& bc = *dataValue.value<const BCValue*>();
|
const BCValue& bc = dataValue.value<const BCValue/>();
|
||||||
//qDebug() << " --- YES: " << bc.label;
|
//qDebug() << " --- YES: " << bc.label;
|
||||||
// Hier bauen wir den String zusammen, den man sieht,
|
// Hier bauen wir den String zusammen, den man sieht,
|
||||||
// wenn KEIN Editor offen ist.
|
// wenn KEIN Editor offen ist.
|
||||||
|
|||||||
@@ -35,10 +35,12 @@
|
|||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include <bcvalue.h>
|
||||||
|
|
||||||
class QPropertyAnimation;
|
class QPropertyAnimation;
|
||||||
class QVariantAnimation;
|
class QVariantAnimation;
|
||||||
class QTableView;
|
class QTableView;
|
||||||
class BCValueList;
|
|
||||||
|
|
||||||
class BCAnimatedDelegate : public QStyledItemDelegate
|
class BCAnimatedDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -250,13 +250,13 @@ void BCMainWindow::onSyncFromDevice()
|
|||||||
|
|
||||||
// alle einzeln? echt jetzt?
|
// alle einzeln? echt jetzt?
|
||||||
|
|
||||||
for( const BCValue& value : currentList )
|
for( const BCValuePtr &value : currentList )
|
||||||
{
|
{
|
||||||
qDebug() << " --- value: " << value.label;
|
qDebug() << " --- begin sync of value: " << value->label;
|
||||||
|
// wir setze
|
||||||
// statt '_transmitter.enqueueValueCommand( value )' entkoppeln
|
// statt '_transmitter.enqueueValueCommand( value )' entkoppeln
|
||||||
// wir das eleganter über emit requestValueUpdate()
|
// wir das eleganter über emit requestValueUpdate()
|
||||||
emit requestValueUpdate( BCValue::OpID::ReadValue, &value);
|
//emit requestValueUpdate( value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
|
|
||||||
// Internes Signal, um Daten an den Worker Thread zu senden
|
// Internes Signal, um Daten an den Worker Thread zu senden
|
||||||
void requestValueUpdate( BCValue::OpID, const BCValue* cmd);
|
void requestValueUpdate( const BCValue& value);
|
||||||
//void valuedTouched(const BCValue& cmd);
|
|
||||||
void valueTouched(int indexRow );
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,9 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BCTransmitter::enqueueValueOp(BCValue::OpID opID, const BCValue* value)
|
void BCTransmitter::enqueueValueOp( const BCValue& value)
|
||||||
{
|
{
|
||||||
|
// Hier sind wir noch in GUI Thread
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
_valueQueue.enqueue( value );
|
_valueQueue.enqueue( value );
|
||||||
|
|
||||||
@@ -81,13 +82,13 @@ void BCTransmitter::enqueueValueOp(BCValue::OpID opID, const BCValue* value)
|
|||||||
// damit enqueueValueOp sofort zurückkehrt (non-blocking für den Aufrufer).
|
// damit enqueueValueOp sofort zurückkehrt (non-blocking für den Aufrufer).
|
||||||
|
|
||||||
//QMetaObject::invokeMethod(this, "processValueOp", Qt::QueuedConnection);
|
//QMetaObject::invokeMethod(this, "processValueOp", Qt::QueuedConnection);
|
||||||
QMetaObject::invokeMethod(this, [this, opID]()
|
QMetaObject::invokeMethod(this, [this]()
|
||||||
{
|
{
|
||||||
processValueOp(opID);
|
processValueOp();
|
||||||
}, Qt::QueuedConnection );
|
}, Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCTransmitter::processValueOp( BCValue::OpID opID )
|
void BCTransmitter::processValueOp()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_isBusy)
|
if (_isBusy)
|
||||||
@@ -97,7 +98,7 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
const BCValue* currentValue{};
|
BCValue* currentValue{};
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
if (_valueQueue.isEmpty())
|
if (_valueQueue.isEmpty())
|
||||||
@@ -105,23 +106,25 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
|||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
break; // Schleife verlassen, warten auf neue Events
|
break; // Schleife verlassen, warten auf neue Events
|
||||||
}
|
}
|
||||||
currentValue =_valueQueue.dequeue();
|
//currentValue =_valueQueue.dequeue();
|
||||||
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
||||||
|
|
||||||
|
/*
|
||||||
// Abkürzung
|
// Abkürzung
|
||||||
const BCValue& val = *currentValue;
|
const BCValue& value = *currentValue;
|
||||||
// Value ist 'under construction'
|
// Value ist 'under construction'
|
||||||
//emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::Locked );
|
//emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::Locked );
|
||||||
|
|
||||||
if( opID == BCValue::OpID::ReadValue )
|
if( opID == BCValue::OpID::ReadValue )
|
||||||
{
|
{
|
||||||
QString result = currentValue->readRawValueX( *this );
|
QString result = currentValue->readRawValueX( *this );
|
||||||
emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::InSync, result );
|
emit valueUpdated( valuel.deviceID, value.indexRow, BCValue::State::InSync, result );
|
||||||
}
|
}
|
||||||
else if( opID == BCValue::OpID::WriteValue )
|
else if( opID == BCValue::OpID::WriteValue )
|
||||||
{
|
{
|
||||||
currentValue->writeRawValueX( *this );
|
currentValue->writeRawValueX( *this );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// __fix
|
// __fix
|
||||||
bc::processEventsFor(50);
|
bc::processEventsFor(50);
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void onToggleConnectionState( bool connect );
|
void onToggleConnectionState( bool connect );
|
||||||
void enqueueValueOp(BCValue::OpID opID, const BCValue* value );
|
void enqueueValueOp(const BCValue& value );
|
||||||
void processValueOp(BCValue::OpID opID);
|
void processValueOp();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
using BCDataQueue = QQueue<const BCValue*>;
|
using BCDataQueue = QQueue<BCValue>;
|
||||||
|
|
||||||
BCDataQueue _valueQueue;
|
BCDataQueue _valueQueue;
|
||||||
QMutex _mutex;
|
QMutex _mutex;
|
||||||
|
|||||||
30
bcvalue.h
30
bcvalue.h
@@ -78,20 +78,16 @@ class BCValue
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum class OpID : uint8_t
|
|
||||||
{
|
|
||||||
ReadValue,
|
|
||||||
WriteValue,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class State : uint8_t
|
enum class State : uint8_t
|
||||||
{
|
{
|
||||||
NoState = 0x0,
|
NoState = 0x00,
|
||||||
ReadOnly = 0x1,
|
ReadMe = 0x01,
|
||||||
Locked = 0x2,
|
WriteMe = 0x02,
|
||||||
Failed = 0x4,
|
ReadOnly = 0x04,
|
||||||
InSync = 0x8,
|
Locked = 0x08,
|
||||||
OK = 0x10
|
Failed = 0x10,
|
||||||
|
InSync = 0x20,
|
||||||
|
OK = 0x40
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(States, State )
|
Q_DECLARE_FLAGS(States, State )
|
||||||
|
|
||||||
@@ -109,13 +105,18 @@ public:
|
|||||||
mutable QString visibleValue;
|
mutable QString visibleValue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States)
|
||||||
Q_DECLARE_METATYPE(const BCValue*)
|
|
||||||
|
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(const BCValue&)
|
||||||
//Q_DECLARE_METATYPE(const BCValue&)
|
//Q_DECLARE_METATYPE(const BCValue&)
|
||||||
|
|
||||||
|
using BCValuePtr = std::shared_ptr<BCValue>;
|
||||||
//using BCValueList = QList<BCValue>;
|
//using BCValueList = QList<BCValue>;
|
||||||
|
using BCValueList = QList<BCValuePtr>;
|
||||||
|
|
||||||
|
/*
|
||||||
class BCValueList : public QList<BCValue>
|
class BCValueList : public QList<BCValue>
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -160,6 +161,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
Q_DECLARE_METATYPE(BCValueList)
|
Q_DECLARE_METATYPE(BCValueList)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,18 +45,6 @@ BCValueModel::BCValueModel(QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Einen Einzelwert hinzufügen
|
|
||||||
* @param val der neue Wert
|
|
||||||
*/
|
|
||||||
|
|
||||||
void BCValueModel::addValue(const BCValue& val)
|
|
||||||
{
|
|
||||||
int row = _valueList.size();
|
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
|
||||||
_valueList.append(val);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,12 +86,12 @@ void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString&
|
|||||||
qDebug() << " BCValueModel::onValueUpdated update: " << newVisisbleValue;
|
qDebug() << " BCValueModel::onValueUpdated update: " << newVisisbleValue;
|
||||||
if( row > -1 && row < _valueList.size() )
|
if( row > -1 && row < _valueList.size() )
|
||||||
{
|
{
|
||||||
const BCValue& value = _valueList[row];
|
BCValuePtr value = _valueList[row];
|
||||||
QModelIndex idx = index(row,1);
|
QModelIndex idx = index(row,1);
|
||||||
value.state = state;
|
value->state = state;
|
||||||
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue )
|
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value->visibleValue )
|
||||||
{
|
{
|
||||||
value.visibleValue = newVisisbleValue;
|
value->visibleValue = newVisisbleValue;
|
||||||
}
|
}
|
||||||
// wir schicken auf jeden fall einen update request
|
// wir schicken auf jeden fall einen update request
|
||||||
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
|
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
|
||||||
@@ -156,17 +144,17 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const
|
|||||||
if (wrongRole || !index.isValid() || row >= _valueList.size() )
|
if (wrongRole || !index.isValid() || row >= _valueList.size() )
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const BCValue& value = _valueList.at( row );
|
BCValuePtr value = _valueList.at( row );
|
||||||
|
|
||||||
if( col == 0 )
|
if( col == 0 )
|
||||||
return value.label;
|
return value->label;
|
||||||
|
|
||||||
if( col == 1)
|
if( col == 1)
|
||||||
{
|
{
|
||||||
if( role == Qt::DisplayRole )
|
if( role == Qt::DisplayRole )
|
||||||
return QString("%1 %2").arg( value.visibleValue, value.valueType->unitLabel);
|
return QString("%1 %2").arg( value->visibleValue, value->valueType->unitLabel);
|
||||||
|
|
||||||
return value.visibleValue;
|
return value->visibleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -208,13 +196,13 @@ bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int
|
|||||||
|
|
||||||
if (index.isValid() && role == Qt::EditRole)
|
if (index.isValid() && role == Qt::EditRole)
|
||||||
{
|
{
|
||||||
BCValue& item = _valueList[index.row()];
|
BCValuePtr item = _valueList[index.row()];
|
||||||
|
|
||||||
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
|
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
|
||||||
// Checken ob Int oder Double
|
// Checken ob Int oder Double
|
||||||
if (value.canConvert<double>())
|
if (value.canConvert<double>())
|
||||||
{
|
{
|
||||||
item.visibleValue = value.toString();
|
item->visibleValue = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
_valueList[index.row()] = item;
|
_valueList[index.row()] = item;
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public:
|
|||||||
|
|
||||||
explicit BCValueModel(QObject *parent = nullptr);
|
explicit BCValueModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
void addValue(const BCValue& val);
|
|
||||||
void takeValueList(BCValueList& valueList);
|
void takeValueList(BCValueList& valueList);
|
||||||
const BCValueList& getValueList() const;
|
const BCValueList& getValueList() const;
|
||||||
|
|
||||||
|
|||||||
@@ -176,11 +176,11 @@ void BCXmlLoader::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<BCValue> newValue = makeDataValue( deviceID, params );
|
std::optional<BCValuePtr> newValue = makeDataValue( deviceID, params );
|
||||||
if(newValue)
|
if(newValue)
|
||||||
{
|
{
|
||||||
// wir merken uns gleich den index in der Werteliste
|
// wir merken uns gleich den index in der Werteliste
|
||||||
(*newValue).indexRow = currentValues.size();
|
(*newValue)->indexRow = currentValues.size();
|
||||||
currentValues.push_back( *newValue );
|
currentValues.push_back( *newValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BCValue> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
|
std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -221,7 +221,7 @@ std::optional<BCValue> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::optional<BCValue> newValue;
|
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||||
@@ -233,7 +233,7 @@ std::optional<BCValue> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const
|
|||||||
auto valueType = BCValueType::fetchValueType(params.UnitType);
|
auto valueType = BCValueType::fetchValueType(params.UnitType);
|
||||||
if( valueType.has_value() )
|
if( valueType.has_value() )
|
||||||
{
|
{
|
||||||
newValue = BCValue( *valueType, deviceID, static_cast<BC::ID>(IDVal) );
|
BCValuePtr newValue = std::make_shared<BCValue>( *valueType, deviceID, static_cast<BC::ID>(IDVal) );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
setIfExists( params.Factor, newValue.factor );
|
setIfExists( params.Factor, newValue.factor );
|
||||||
@@ -242,10 +242,12 @@ std::optional<BCValue> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const
|
|||||||
*/
|
*/
|
||||||
newValue->label = params.Label;
|
newValue->label = params.Label;
|
||||||
qDebug() << " --- created: " << params.Label;
|
qDebug() << " --- created: " << params.Label;
|
||||||
|
|
||||||
|
return std::optional<BCValuePtr>( newValue );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newValue;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- NEU: Speichern mit QXmlStreamWriter ---
|
// --- NEU: Speichern mit QXmlStreamWriter ---
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ protected:
|
|||||||
|
|
||||||
void loadXmlBikeDeviceData( BCDevice::ID deviceID );
|
void loadXmlBikeDeviceData( BCDevice::ID deviceID );
|
||||||
|
|
||||||
std::optional<BCValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
|
std::optional<BCValuePtr> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
|
||||||
|
|
||||||
QXmlStreamReader _xml;
|
QXmlStreamReader _xml;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user