This commit is contained in:
2025-12-23 20:47:03 +01:00
parent b219a71cba
commit 71cfb86e1f
10 changed files with 173 additions and 95 deletions

View File

@@ -41,7 +41,7 @@
#include <bcmainwindow.h>
#include <bcdataitem.h>
#include <bcvdatamanager.h>
#include <bcdatamanager.h>
#include <variant>
#include <string>
@@ -78,7 +78,7 @@ struct CpuLoad : public moo{ int percentage; };
struct Status : public moo{ std::string message; };
// Die Variant als universeller Datencontainer
using SensorReading = std::variant<Temperature, CpuLoad, Status>;
using SensorReadingPtr = std::variant<Temperature*, CpuLoad*, Status*>;
@@ -89,25 +89,28 @@ struct UIUpdateVisitor
QLabel* statusLabel;
// Überladene operator() für jeden Typ in der Variant
void operator()(const Temperature& t) const
double operator()(Temperature* t) const
{
tempLabel->setText(QString("Temp: %1°C").arg(t.celsius, 0, 'f', 1));
tempLabel->setStyleSheet(t.celsius > 40 ? "color: red;" : "color: black;");
//tempLabel->setText(QString("Temp: %1°C").arg(t.celsius, 0, 'f', 1));
//tempLabel->setStyleSheet(t.celsius > 40 ? "color: red;" : "color: black;");
return -1;
}
void operator()(const CpuLoad& c) const
double operator()(CpuLoad* c) const
{
cpuBar->setValue(c.percentage);
qDebug() << c.moo_str;
cpuBar->setValue(c->percentage);
qDebug() << c->moo_str;
return -42.0;
}
void operator()(const Status& s) const
double operator()(const Status* s) const
{
statusLabel->setText(QString::fromStdString(s.message));
//statusLabel->setText(QString::fromStdString(s.message));
return -1;
}
};
void onNewDataReceived(const SensorReading& data)
void onNewDataReceived(const SensorReadingPtr& data)
{
QLabel* labelTemp = nullptr;
QProgressBar* progressCpu = nullptr;
@@ -117,14 +120,39 @@ void onNewDataReceived(const SensorReading& data)
UIUpdateVisitor visitor { labelTemp, progressCpu, labelStatus };
// Die Magie: std::visit wählt zur Kompilierzeit die richtige Methode
std::visit(visitor, data);
double result = std::visit(visitor, data);
Q_UNUSED(result)
Temperature myTemp{};
SensorReadingPtr xxx{&myTemp};
double result2 = std::visit(visitor, SensorReadingPtr{&myTemp} );
}
// 2. Datei öffnen und lesen
struct mookoo
{
QString a="firz";
int b=2;
double c=1.0;
QString hidden{"Fatz!"};
};
struct mookoo2 : public mookoo
{
int another;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
setApplicationStyleSheet( ":/bionxcontrol.qss"_L1 );
mookoo myMookoo{"",1,1.0};
mookoo myMooko2{"",1};
mookoo2 myMooko3{{"superfitze",1},8};
qDebug() << " --- haha: " << myMooko3.a << ": " << myMooko3.hidden;
BCMainWindow w;
w.show();