mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-26 15:54:15 +01:00
LP-286 make uavobject model data() method return the TreeItem when called with Qt::UserRole
also cleaned up data() method (use switch instead of if mumble jumble)
This commit is contained in:
parent
e550317fdf
commit
0f339dfef0
@ -363,50 +363,56 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
||||||
|
|
||||||
if (index.column() == TreeItem::DATA_COLUMN && role == Qt::EditRole) {
|
switch (role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
if (index.column() == TreeItem::DATA_COLUMN) {
|
||||||
|
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem *>(item);
|
||||||
|
if (fieldItem) {
|
||||||
|
int enumIndex = fieldItem->data(index.column()).toInt();
|
||||||
|
return fieldItem->enumOptions(enumIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
return item->data(index.column());
|
return item->data(index.column());
|
||||||
}
|
|
||||||
|
|
||||||
if (role == Qt::ToolTipRole) {
|
case Qt::EditRole:
|
||||||
|
if (index.column() == TreeItem::DATA_COLUMN) {
|
||||||
|
return item->data(index.column());
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
case Qt::ToolTipRole:
|
||||||
return item->description();
|
return item->description();
|
||||||
}
|
|
||||||
|
|
||||||
if (role == Qt::ForegroundRole) {
|
case Qt::ForegroundRole:
|
||||||
if (!dynamic_cast<TopTreeItem *>(item) && !item->isKnown()) {
|
if (!dynamic_cast<TopTreeItem *>(item) && !item->isKnown()) {
|
||||||
return QVariant(m_unknownObjectColor);
|
return m_unknownObjectColor;
|
||||||
}
|
}
|
||||||
}
|
return QVariant();
|
||||||
|
|
||||||
if (index.column() == 0 && role == Qt::BackgroundRole) {
|
case Qt::BackgroundRole:
|
||||||
if (!dynamic_cast<TopTreeItem *>(item) && item->highlighted()) {
|
if (index.column() == TreeItem::TITLE_COLUMN) {
|
||||||
return QVariant(m_recentlyUpdatedColor);
|
if (!dynamic_cast<TopTreeItem *>(item) && item->highlighted()) {
|
||||||
|
return m_recentlyUpdatedColor;
|
||||||
|
}
|
||||||
|
} else if (index.column() == TreeItem::DATA_COLUMN) {
|
||||||
|
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem *>(item);
|
||||||
|
if (fieldItem && fieldItem->highlighted()) {
|
||||||
|
return m_recentlyUpdatedColor;
|
||||||
|
}
|
||||||
|
if (fieldItem && fieldItem->changed()) {
|
||||||
|
return m_manuallyChangedColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return QVariant();
|
||||||
|
|
||||||
if (index.column() == TreeItem::DATA_COLUMN && role == Qt::BackgroundRole) {
|
case Qt::UserRole:
|
||||||
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem *>(item);
|
// UserRole gives access to TreeItem
|
||||||
if (fieldItem && fieldItem->highlighted()) {
|
// cast to void* is necessary
|
||||||
return QVariant(m_recentlyUpdatedColor);
|
return qVariantFromValue((void *)item);
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldItem && fieldItem->changed()) {
|
default:
|
||||||
return QVariant(m_manuallyChangedColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role != Qt::DisplayRole) {
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index.column() == TreeItem::DATA_COLUMN) {
|
|
||||||
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem *>(item);
|
|
||||||
if (fieldItem) {
|
|
||||||
int enumIndex = fieldItem->data(index.column()).toInt();
|
|
||||||
return fieldItem->enumOptions(enumIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return item->data(index.column());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
|
bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user