Closes #28
This commit is contained in:
1 parent
a0938cb29c
commit
3dd9230fca
21 files changed
+491
-450
No files matched your search
+41
-22
@@ -5,6 +5,23 @@
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace {
|
||||
QVariantList ToVariantList(const ValueDescriptions &values) {
|
||||
QVariantList descriptions;
|
||||
for (const ValueDescriptions::value_type &entry : values) {
|
||||
QVariantMap pair;
|
||||
if (const std::int64_t *number = std::get_if<std::int64_t>(&entry.first))
|
||||
pair.insert("value", QVariant::fromValue(static_cast<qlonglong>(*number)));
|
||||
else
|
||||
pair.insert("value", QVariant::fromValue(
|
||||
static_cast<qulonglong>(std::get<std::uint64_t>(entry.first))));
|
||||
pair.insert("description", QString::fromStdString(entry.second));
|
||||
descriptions.append(pair);
|
||||
}
|
||||
return descriptions;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DbcTreeModel::DbcTreeModel(QObject *parent) : QAbstractItemModel(parent) {}
|
||||
|
||||
void DbcTreeModel::SetTree(std::unique_ptr<TreeNode> root) {
|
||||
@@ -60,38 +77,40 @@ QVariant DbcTreeModel::data(const QModelIndex &item, int role) const {
|
||||
return {};
|
||||
const FrameInfo *frame = node->GetFrame();
|
||||
const SignalInfo *signal = node->GetSignal();
|
||||
const QString comment = QString::fromStdString(frame ? frame->comment : signal ? signal->comment
|
||||
: "");
|
||||
QString comment;
|
||||
if (frame != nullptr)
|
||||
comment = QString::fromStdString(frame->comment);
|
||||
else if (signal != nullptr)
|
||||
comment = QString::fromStdString(signal->comment);
|
||||
if (role == Qt::ToolTipRole || role == CommentRole)
|
||||
return comment;
|
||||
if (role == NodeTypeRole)
|
||||
return static_cast<int>(node->GetType());
|
||||
if (role == ValueDescriptionsRole && signal) {
|
||||
QVariantList descriptions;
|
||||
for (const auto &entry: signal->valueDescriptions) {
|
||||
QVariantMap pair;
|
||||
if (const auto *number = std::get_if<std::int64_t>(&entry.first))
|
||||
pair.insert("value", QVariant::fromValue(static_cast<qlonglong>(*number)));
|
||||
else
|
||||
pair.insert("value", QVariant::fromValue(static_cast<qulonglong>(std::get<std::uint64_t>(entry.first))));
|
||||
pair.insert("description", QString::fromStdString(entry.second));
|
||||
descriptions.append(pair);
|
||||
}
|
||||
return descriptions;
|
||||
return ToVariantList(signal->valueDescriptions);
|
||||
}
|
||||
if (frame) {
|
||||
if (role == CanIdRole) return frame->canId;
|
||||
if (role == PayloadLengthRole) return static_cast<int>(frame->dlc);
|
||||
if (role == ExtendedRole) return frame->isExtended;
|
||||
if (role == CanIdRole)
|
||||
return frame->canId;
|
||||
if (role == PayloadLengthRole)
|
||||
return static_cast<int>(frame->dlc);
|
||||
if (role == ExtendedRole)
|
||||
return frame->isExtended;
|
||||
}
|
||||
if (signal) {
|
||||
if (role == StartBitRole) return signal->startBit;
|
||||
if (role == BitLengthRole) return signal->length;
|
||||
if (role == LittleEndianRole) return signal->isLittleEndian;
|
||||
if (role == SignedRole) return signal->isSigned;
|
||||
if (role == UnitRole) return QString::fromStdString(signal->unit);
|
||||
if (role == StartBitRole)
|
||||
return signal->startBit;
|
||||
if (role == BitLengthRole)
|
||||
return signal->length;
|
||||
if (role == LittleEndianRole)
|
||||
return signal->isLittleEndian;
|
||||
if (role == SignedRole)
|
||||
return signal->isSigned;
|
||||
if (role == UnitRole)
|
||||
return QString::fromStdString(signal->unit);
|
||||
}
|
||||
if (role != Qt::DisplayRole) return {};
|
||||
if (role != Qt::DisplayRole)
|
||||
return {};
|
||||
switch (item.column()) {
|
||||
case Name:
|
||||
return QString::fromStdString(node->GetName());
|
||||
|
||||
Reference in new issue
Block a user