5 #include <QRandomGenerator>
25 return mDataEntries.size();
38 case 1:
return entry.
key;
40 case 3:
return style.valueString;
44 return style.valueColor;
89 const char* horizontalHeader[] = {
"Category",
"Key",
"Type",
"Value"};
91 return QString(horizontalHeader[section]);
106 return mDataEntries.at(row);
112 mDataEntries.clear();
113 mEntryToRowStyle.
clear();
114 for(
const auto& [
key,
value] : dataMap)
122 mDataEntries.append(e);
125 qSort(mDataEntries.begin(), mDataEntries.end(),
129 if(a.category == b.category)
131 return (a.key < b.key);
135 if(a.category ==
"generic")
137 else if(b.category ==
"generic")
140 return (a.category < b.category);
146 for(
const DataEntry& entry : mDataEntries)
148 mEntryToRowStyle[
QPair(entry.category, entry.key)] = getRowStyleByEntry(entry, rowIdx);
152 Q_EMIT layoutChanged();
155 DataTableModel::RowStyle DataTableModel::getRowStyleByEntry(
const DataEntry& entry,
int rowIdx)
const
158 style.keyFont =
QFont();
160 style.valueToolTip =
QString();
161 style.valueColor =
QColor();
164 if(entry.dataType ==
"string")
166 style.valueString =
QString(
"\"%1\"").
arg(entry.value);
167 style.valueColor = PythonQssAdapter::instance()->doubleQuotedStringColor();
169 else if(entry.dataType ==
"bit_value" || entry.dataType ==
"bit_vector")
171 style.valueString =
QString(
"0x%1").
arg(entry.value);
172 style.valueColor = PythonQssAdapter::instance()->numberColor();
174 else if(entry.dataType ==
"integer")
176 style.valueString = entry.value;
177 style.valueColor = PythonQssAdapter::instance()->numberColor();
181 style.valueString = entry.value;
189 style.keyToolTip = entry.category +
" ";
190 style.valueToolTip = entry.dataType +
" ";
195 style.keyToolTip = entry.category +
QChar(0x00A0);
196 style.valueToolTip = entry.dataType +
QChar(0x00A0);
DataTableModel(QObject *parent=nullptr)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
DataEntry getEntryAtRow(int row) const
QVariant data(const QModelIndex &index, int role) const override
void updateData(const std::map< std::tuple< std::string, std::string >, std::tuple< std::string, std::string >> &dc)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QObject * parent() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
QString key
The data's category.
QString dataType
The data's key.