diff --git a/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.cpp b/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.cpp index 6fddafa1d..d7b1031db 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.cpp +++ b/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.cpp @@ -30,53 +30,45 @@ #include "browseritemdelegate.h" #include "fieldtreeitem.h" -BrowserItemDelegate::BrowserItemDelegate(TreeSortFilterProxyModel *proxyModel, QObject *parent) : +BrowserItemDelegate::BrowserItemDelegate(QObject *parent) : QStyledItemDelegate(parent) -{ - this->proxyModel = proxyModel; -} +{} QWidget *BrowserItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & option, - const QModelIndex & proxyIndex) const + const QModelIndex & index) const { Q_UNUSED(option) - QModelIndex index = proxyModel->mapToSource(proxyIndex); - - FieldTreeItem *item = static_cast(index.internalPointer()); - QWidget *editor = item->createEditor(parent); + FieldTreeItem * item = static_cast(index.data(Qt::UserRole).value()); + QWidget *editor = item->createEditor(parent); Q_ASSERT(editor); return editor; } - void BrowserItemDelegate::setEditorData(QWidget *editor, - const QModelIndex & proxyIndex) const + const QModelIndex & index) const { - QModelIndex index = proxyModel->mapToSource(proxyIndex); - - FieldTreeItem *item = static_cast(index.internalPointer()); - QVariant value = proxyIndex.model()->data(proxyIndex, Qt::EditRole); + FieldTreeItem *item = static_cast(index.data(Qt::UserRole).value()); + QVariant value = index.model()->data(index, Qt::EditRole); item->setEditorValue(editor, value); } void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &proxyIndex) const + const QModelIndex &index) const { - QModelIndex index = proxyModel->mapToSource(proxyIndex); - - FieldTreeItem *item = static_cast(index.internalPointer()); + FieldTreeItem *item = static_cast(index.data(Qt::UserRole).value()); QVariant value = item->getEditorValue(editor); - bool ret = model->setData(proxyIndex, value, Qt::EditRole); + bool ret = model->setData(index, value, Qt::EditRole); Q_ASSERT(ret); } void BrowserItemDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex & /* index */) const + const QStyleOptionViewItem &option, const QModelIndex &index) const { + Q_UNUSED(index); editor->setGeometry(option.rect); } diff --git a/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.h b/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.h index 2605db7dc..b9d12af04 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.h +++ b/ground/gcs/src/plugins/uavobjectbrowser/browseritemdelegate.h @@ -31,12 +31,10 @@ #include -class TreeSortFilterProxyModel; - class BrowserItemDelegate : public QStyledItemDelegate { Q_OBJECT public: - explicit BrowserItemDelegate(TreeSortFilterProxyModel *proxyModel, QObject *parent = 0); + explicit BrowserItemDelegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -49,14 +47,6 @@ public: const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const; - - -signals: - -public slots: - -private: - TreeSortFilterProxyModel *proxyModel; }; #endif // BROWSERITEMDELEGATE_H diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index 59efba6e1..1e3628649 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -56,8 +56,7 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent m_browser->treeView->setModel(m_modelProxy); m_browser->treeView->setColumnWidth(0, 300); - BrowserItemDelegate *m_delegate = new BrowserItemDelegate(m_modelProxy); - m_browser->treeView->setItemDelegate(m_delegate); + m_browser->treeView->setItemDelegate(new BrowserItemDelegate()); m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers); m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems); m_mustacheTemplate = loadFileIntoString(QString(":/uavobjectbrowser/resources/uavodescription.mustache")); @@ -191,8 +190,8 @@ void UAVObjectBrowserWidget::requestUpdate() ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem() { - QModelIndex current = m_modelProxy->mapToSource(m_browser->treeView->currentIndex()); - TreeItem *item = static_cast(current.internalPointer()); + QModelIndex current = m_browser->treeView->currentIndex(); + TreeItem *item = static_cast(current.data(Qt::UserRole).value()); ObjectTreeItem *objItem = 0; while (item) { @@ -277,11 +276,9 @@ void UAVObjectBrowserWidget::currentChanged(const QModelIndex ¤t, const QM { Q_UNUSED(previous); - QModelIndex cindex = m_modelProxy->mapToSource(current); - - TreeItem *item = static_cast(cindex.internalPointer()); - bool enable = true; - if (cindex == QModelIndex()) { + TreeItem *item = static_cast(current.data(Qt::UserRole).value()); + bool enable = true; + if (!current.isValid()) { enable = false; } TopTreeItem *top = dynamic_cast(item);