diff --git a/.gitignore b/.gitignore index 1bb847c..7dc7dcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ BionxControl.pro.user build/ bcvalue.cpp.autosave -.qtcreator/BionxControl.pro.user \ No newline at end of file +.qtcreator/BionxControl.pro.user +.user \ No newline at end of file diff --git a/bcvaluedelegate.cpp b/bcvaluedelegate.cpp index b269385..4b53d78 100644 --- a/bcvaluedelegate.cpp +++ b/bcvaluedelegate.cpp @@ -6,6 +6,7 @@ #include "bcvaluedelegate.h" #include "bcvalue.h" +#include "qapplication.h" BCValueDelegate::BCValueDelegate(QObject *parent) @@ -117,3 +118,49 @@ void BCValueDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionVi { editor->setGeometry(option.rect); } + +QSize BCValueDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + return QStyledItemDelegate::sizeHint(option,index); + /* + QStyleOptionViewItem opt = option; + initStyleOption(&opt, index); + opt.text = formatDisplayString(index); + + QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); + return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), opt.widget); + */ +} + +QString BCValueDelegate::formatDisplayString(const QModelIndex &index) const +{ + if (!index.isValid()) + return QString(); + + QString displayStr; + + /* + QString label = index.data(BCValueListModel::LabelRole).toString(); + QVariant value = index.data(BCValueListModel::ValueRole); + QString unit = index.data(BCValueListModel::UnitRole).toString(); + + QString valueStr = value.toString(); + + // Formatierung für Zahlen + bool ok; + double numValue = value.toDouble(&ok); + if (ok) { + valueStr = QString::number(numValue, 'f', 2); + } + + // Zusammensetzen des Anzeige-Strings + QString displayStr = label; + if (!displayStr.isEmpty() && !valueStr.isEmpty()) + displayStr += ": "; + displayStr += valueStr; + if (!unit.isEmpty()) + displayStr += " " + unit; + */ + + return displayStr; +} diff --git a/bcvaluedelegate.h b/bcvaluedelegate.h index 19636aa..8077fa4 100644 --- a/bcvaluedelegate.h +++ b/bcvaluedelegate.h @@ -10,6 +10,7 @@ class BCValueDelegate : public QStyledItemDelegate Q_OBJECT public: + explicit BCValueDelegate(QObject *parent = nullptr); // WICHTIG: Zuständig für die normale Anzeige (ohne Editor) @@ -20,6 +21,11 @@ public: void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + + QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const override; + +private: + QString formatDisplayString(const QModelIndex &index) const; }; diff --git a/bcvaluemanager.cpp b/bcvaluemanager.cpp index 1770b0e..e6842a6 100644 --- a/bcvaluemanager.cpp +++ b/bcvaluemanager.cpp @@ -90,12 +90,12 @@ void BCValueManager::onToggleConnectionState( bool connect ) } - + qDebug() << " ---HAIL to the kings: " << hwVersion; } - - } + + std::optional BCValueManager::getModel(const QString& key ) { if( _valueModels.contains( key) )