43 #include <QtCore/QTimer>
44 #include <QtCore/QSignalMapper>
45 #include <QtCore/QDebug>
48 #include <QApplication>
51 : QAbstractItemModel(parent)
53 , m_recentlyUpdatedColor(QColor(255, 230, 230))
54 , m_manuallyChangedColor(QColor(230, 230, 255))
55 , m_updatedOnlyColor(QColor(174, 207, 250, 255))
56 , m_isPresentOnHwColor(QApplication::palette().text().color())
57 , m_notPresentOnHwColor(QColor(174, 207, 250, 255))
58 , m_useScientificFloatNotation(useScientificNotation)
59 , m_hideNotPresent(false)
60 , m_highlightManager(NULL)
61 , isInitialized(false)
67 m_defaultValueFont = font;
68 font.setWeight(QFont::Bold);
69 m_nonDefaultValueFont = font;
74 delete m_highlightManager;
86 bool useScientificFloatNotation)
88 m_useScientificFloatNotation = useScientificFloatNotation;
97 &UAVObjectTreeModel::updateHighlight);
99 delete m_highlightManager;
101 beginRemoveRows(
index(m_rootItem), 0, count);
109 rootData << tr(
"Property") << tr(
"Value") << tr(
"Unit");
110 m_rootItem =
new TreeItem(rootData);
112 m_settingsTree =
new TopTreeItem(tr(
"Settings"), m_rootItem);
115 m_nonSettingsTree =
new TopTreeItem(tr(
"Data Objects"), m_rootItem);
120 &UAVObjectTreeModel::updateHighlight);
123 foreach (QVector<UAVDataObject *> list, objList) {
129 Qt::UniqueConnection);
131 Qt::UniqueConnection);
146 setupModelData(objManager, useScientificFloatNotation);
162 if (inst && inst->
object() == obj) {
163 printf(
"removing an instance\n");
165 beginRemoveRows(
index(inst->
parent()), itemIdx, itemIdx);
184 addInstance(obj, existing);
194 addInstance(obj, dataTreeItem);
206 addArrayField(field, meta);
208 addSingleField(0, field, meta);
225 QString name = tr(
"Instance") +
" " + QString::number(obj->
getInstID());
227 item->setHighlightManager(m_highlightManager);
240 addArrayField(field, item);
242 addSingleField(0, field, item);
248 this, &UAVObjectTreeModel::presentOnHardwareChangedCB, Qt::UniqueConnection);
257 addSingleField(
i, field, item);
278 data.append(options.indexOf(value.toString()));
289 data.append(field->
getValue(index));
294 data.append(field->
getValue(index));
308 if (!hasIndex(row, column, parent))
309 return QModelIndex();
313 if (!parent.isValid())
314 parentItem = m_rootItem;
316 parentItem =
static_cast<TreeItem *
>(parent.internalPointer());
320 return createIndex(row, column, childItem);
322 return QModelIndex();
327 if (item->
parent() ==
nullptr)
328 return QModelIndex();
333 QModelIndex childIndex =
index(
i, 0, root);
339 return QModelIndex();
344 if (!index.isValid())
345 return QModelIndex();
349 if (parentItem == m_rootItem)
350 return QModelIndex();
352 return createIndex(parentItem->
row(), 0, parentItem);
358 if (parent.column() > 0)
361 if (!parent.isValid())
362 parentItem = m_rootItem;
364 parentItem =
static_cast<TreeItem *
>(parent.internalPointer());
371 if (parent.isValid())
372 return static_cast<TreeItem *>(parent.internalPointer())->
columnCount();
381 metaIndexes.append(
index(metaItem));
385 metaIndexes.append(
index(metaItem));
394 dataIndexes.append(
index(dataItem));
398 dataIndexes.append(
index(dataItem));
405 if (!index.isValid())
410 return item->
data(index.column());
413 if (role == Qt::ToolTipRole) {
420 if (index.column() == 0 && role == Qt::BackgroundRole) {
421 if (!dynamic_cast<TopTreeItem *>(item) && item->
highlighted())
422 return QVariant(m_recentlyUpdatedColor);
423 if (!dynamic_cast<TopTreeItem *>(item) && item->
updatedOnly())
424 return QVariant(m_updatedOnlyColor);
427 if (role == Qt::TextColorRole) {
430 return QVariant(m_isPresentOnHwColor);
432 return QVariant(m_notPresentOnHwColor);
436 if (role == Qt::FontRole) {
438 return m_nonDefaultValueFont;
439 return m_defaultValueFont;
445 return QVariant(m_recentlyUpdatedColor);
447 if (fieldItem && fieldItem->
changed())
448 return QVariant(m_manuallyChangedColor);
451 return QVariant(m_updatedOnlyColor);
454 if (role != Qt::DisplayRole)
460 int enumIndex = fieldItem->
data(index.column()).toInt();
468 return item->
data(index.column());
475 item->
setData(value, index.column());
481 if (!index.isValid())
487 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
490 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
495 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
496 return m_rootItem->
data(section);
501 void UAVObjectTreeModel::highlightUpdatedObject(
UAVObject *obj)
506 if (!m_onlyHighlightChangedValues) {
510 if (!m_onlyHighlightChangedValues) {
511 QModelIndex itemIndex =
index(item);
512 Q_ASSERT(itemIndex != QModelIndex());
513 emit dataChanged(itemIndex, itemIndex);
521 Q_ASSERT(dataObject || metaObject);
523 return findDataObjectTreeItem(dataObject);
525 return findMetaObjectTreeItem(metaObject);
540 Q_ASSERT(dataObject);
547 void UAVObjectTreeModel::updateHighlight(
TreeItem *item)
549 if (item == m_rootItem) {
553 QModelIndex itemIndex =
index(item);
554 Q_ASSERT(itemIndex.isValid());
558 void UAVObjectTreeModel::presentOnHardwareChangedCB(
UAVDataObject *obj)
UAVObjectTreeModel(QObject *parent=nullptr, bool useScientificNotation=false)
MetaObjectTreeItem * findMetaObjectTreeItemByObjectId(quint32 objectId)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void updateHighlight(TreeItem *)
void insertChild(TreeItem *child)
int columnCount(const QModelIndex &parent=QModelIndex()) const
QList< MetaObjectTreeItem * > getMetaObjectItems()
UAVObject * getParentObject()
void instanceRemoved(UAVObject *obj)
Core plugin system that manages the plugins, their life cycle and their registered objects...
void newInstance(UAVObject *obj)
QVariant getValue(int index=0) const
void newObject(UAVObject *obj)
int getNumElements() const
QVariant data(const QModelIndex &index, int role) const
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
virtual bool isEditable()
QModelIndex parent(const QModelIndex &index) const
virtual void removeChild(TreeItem *child)
virtual void setObject(UAVObject *obj) override
int rowCount(const QModelIndex &parent=QModelIndex()) const
QList< QModelIndex > getMetaDataIndexes()
UAVMetaObject * getMetaObject()
QString getDescription() const
QStringList getOptions() const
QList< QModelIndex > getDataObjectIndexes()
QList< TreeItem * > treeChildren() const
void addObjectTreeItem(quint32 objectId, DataObjectTreeItem *oti)
void instanceRemove(UAVObject *)
virtual bool getIsPresentOnHardware() const
Qt::ItemFlags flags(const QModelIndex &index) const
virtual void setHighlightManager(HighLightManager *mgr)
QList< DataObjectTreeItem * > getDataObjectItems()
bool setData(const QModelIndex &index, const QVariant &value, int role)
QList< UAVObjectField * > getFields()
virtual void appendChild(TreeItem *child)
virtual void setData(QVariant value, int column=1)
QStringList getElementNames() const
TreeItem * getChild(int index)
QVariant data(int column=1) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
DataObjectTreeItem * findDataObjectTreeItemByObjectId(quint32 objectId)
void initializeModel(bool useScientificFloatNotation=true)
void setDescription(QString d)
void addMetaObjectTreeItem(quint32 objectId, MetaObjectTreeItem *oti)
void presentOnHardwareChanged()
QVector< QVector< UAVDataObject * > > getDataObjectsVector()
virtual bool isDefaultValue() const
QString enumOptions(int index)
FieldType getType() const
static const int dataColumn
void presentOnHardwareChanged(UAVDataObject *)
void newObject(UAVObject *obj)