From 029e9d2909d6fc7dc6d59a3991d19bfa8608ef81 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Wed, 24 Dec 2025 15:43:50 +0100 Subject: [PATCH] Redesign UI, part I --- bcdatamanager.cpp | 10 +- bcdatamodel.cpp | 33 ++++- bcmainwindow.cpp | 6 + bcmainwindow.ui | 210 ++++++++++++----------------- bcmainwindow.ui.autosave | 230 -------------------------------- doc/material_dummy/main.cpp | 2 + doc/material_dummy/mainwindow.h | 1 - 7 files changed, 134 insertions(+), 358 deletions(-) delete mode 100644 bcmainwindow.ui.autosave diff --git a/bcdatamanager.cpp b/bcdatamanager.cpp index e4763a7..11e5f57 100644 --- a/bcdatamanager.cpp +++ b/bcdatamanager.cpp @@ -282,6 +282,9 @@ std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, static BCValueTypeMap s_bcDataTypes { + { "Byte", new BCValueTypeWord( "", 1.5625F) }, + { "Word", new BCValueTypeWord( "", 1.5625F) }, + { "Float", new BCValueTypeWord( "", 1.5625F) }, { "Percent",new BCValueTypeWord( "%", 1.5625 ) }, { "KWh", new BCValueTypeWord( "kwh", 1.5625 ) }, @@ -323,8 +326,10 @@ std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, std::optional newValue; std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); + qDebug() << " --- should create: " << params.Label << ": " << params.UnitType; if( IDVal.has_value() ) { + if( s_bcDataTypes.contains( params.UnitType ) ) { @@ -338,10 +343,9 @@ std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, */ newValue->label = params.Label; newValue->defaultValue = params.Default; - /* - //qDebug() << " --- created: " << params.Label; - */ + qDebug() << " --- created: " << params.Label; + } } diff --git a/bcdatamodel.cpp b/bcdatamodel.cpp index 36596ab..518605e 100644 --- a/bcdatamodel.cpp +++ b/bcdatamodel.cpp @@ -90,7 +90,33 @@ QVariant BCDataModel::headerData(int section, Qt::Orientation orientation, int r QVariant BCDataModel::data(const QModelIndex& index, int role) const { + /* + +if (!index.isValid() || index.row() >= static_cast(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; + } + + return QVariant(); + */ int row = index.row(); + int col = index.column(); if (!index.isValid() || row >= _valueList.size()) return QVariant(); @@ -98,7 +124,12 @@ QVariant BCDataModel::data(const QModelIndex& index, int role) const entry.rowInModel = row; if (role == Qt::DisplayRole || role == Qt::EditRole) - return entry.visibleValue; + { + if( col == 0 ) + return entry.label; + else if( col == 1 ) + return entry.visibleValue; + } return QVariant(); } diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index 1c66b0f..0907ffc 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -43,7 +43,12 @@ BCMainWindow::BCMainWindow(QWidget *parent) _valueManager.loadXmlBikeData(); auto model = _valueManager.getModel( BCDevice::ID::Console ); if( model) + { _valueView->setModel( *model ); + _valueView->resizeColumnsToContents(); + //_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + } + BCItemDelegate* _delegate = new BCItemDelegate( _valueView); //_delegate = new AnimatedDelegate(_valueView ); @@ -66,6 +71,7 @@ BCMainWindow::BCMainWindow(QWidget *parent) connect( _connectButton, &QPushButton::clicked, transmitter, &BCTransmitter::onToggleConnectionState ); connect( _syncButton, &QPushButton::clicked, &_valueManager, &BCDataManager::onSyncFromDevice ); + } BCMainWindow::~BCMainWindow() diff --git a/bcmainwindow.ui b/bcmainwindow.ui index 4c86684..8e0694a 100644 --- a/bcmainwindow.ui +++ b/bcmainwindow.ui @@ -14,139 +14,103 @@ BCMainWindow - + - - - Qt::Orientation::Horizontal - - - - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised - - - - - 30 - 50 - 171 - 51 - - - - Sync - - - - - - 20 - 140 - 171 - 51 - - - - Connect - - - true - - - - - - 70 - 240 - 71 - 71 - - - - ... - - + + + + - 64 - 64 + 200 + 0 - + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + 30 + 50 + 171 + 51 + + + + Sync + + + + + + 10 + 180 + 171 + 51 + + + + Connect + + + true + + + + + + 70 + 240 + 71 + 71 + + + + ... + + + + 64 + 64 + + + + true + + + + + + + + QFrame::Shape::NoFrame + + + QFrame::Shadow::Plain + + + false + + + false + + + Qt::PenStyle::NoPen + + true - + - - - - 50 - 320 - 22 - 22 - - - - ... - - - - - - QFrame::Shape::NoFrame - - - QFrame::Shadow::Plain - - - false - - - + + - - - - 0 - 0 - - - - - 200 - 0 - - - - toolBar - - - false - - - - 64 - 64 - - - - true - - - LeftToolBarArea - - - false - - - - - - diff --git a/bcmainwindow.ui.autosave b/bcmainwindow.ui.autosave deleted file mode 100644 index fbfa924..0000000 --- a/bcmainwindow.ui.autosave +++ /dev/null @@ -1,230 +0,0 @@ - - - BCMainWindow - - - - 0 - 0 - 800 - 600 - - - - BCMainWindow - - - - - - - Qt::Orientation::Horizontal - - - - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised - - - - - 30 - 50 - 171 - 51 - - - - Sync - - - - - - 10 - 180 - 171 - 51 - - - - Connect - - - true - - - - - - 70 - 240 - 71 - 71 - - - - ... - - - - 64 - 64 - - - - true - - - - - - 50 - 320 - 22 - 22 - - - - ... - - - - - - QFrame::Shape::NoFrame - - - QFrame::Shadow::Plain - - - false - - - - - - - - - - - 0 - 0 - - - - - 200 - 0 - - - - toolBar - - - false - - - - 64 - 64 - - - - true - - - LeftToolBarArea - - - false - - - - - - - - - - :restart.png:restart.png - - - pimp - - - Pimp my Ride - - - - - - :bionx_motor.png:bionx_motor.png - - - motor - - - Show motor settings - - - - - - :bionx_akku.png:bionx_akku.png - - - battery - - - Show battery settings - - - - - - :bionx_console.png:bionx_console.png - - - console - - - Show console settings - - - - - - :exit.png:exit.png - - - Exit - - - Exit - - - - - - :/connected.png:/connected.png - - - connect - - - connect to bike - - - QAction::MenuRole::TextHeuristicRole - - - - - - - - diff --git a/doc/material_dummy/main.cpp b/doc/material_dummy/main.cpp index 03ba1d3..c4e5ba8 100644 --- a/doc/material_dummy/main.cpp +++ b/doc/material_dummy/main.cpp @@ -13,6 +13,8 @@ #include #include "mainwindow.h" +#include "sliderdelegate.h" + // Fluent Design Demo Widget class FluentWidgetDemo : public QWidget { diff --git a/doc/material_dummy/mainwindow.h b/doc/material_dummy/mainwindow.h index 06d61b4..806d852 100644 --- a/doc/material_dummy/mainwindow.h +++ b/doc/material_dummy/mainwindow.h @@ -26,7 +26,6 @@ #include #include -#include "sliderdelegate.h" class TableViewDemo : public QWidget {