Skip to content

Commit

Permalink
replace raw Property pointer with QPointer
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschmeisser committed May 16, 2023
1 parent f923c15 commit 9b8e790
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/rviz/properties/property_tree_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define PROPERTY_MODEL_H

#include <QAbstractItemModel>
#include <QPointer>

namespace rviz
{
Expand Down Expand Up @@ -132,7 +133,7 @@ class PropertyTreeModel : public QAbstractItemModel
Property* getProp(const QModelIndex& index) const;

/** @brief Emit the propertyHiddenChanged() signal for the given Property. */
void emitPropertyHiddenChanged(const Property* property)
void emitPropertyHiddenChanged(const QPointer<Property> property)
{
Q_EMIT propertyHiddenChanged(property);
}
Expand All @@ -149,7 +150,7 @@ class PropertyTreeModel : public QAbstractItemModel

Q_SIGNALS:
/** @brief Emitted when a property within the model is hidden or shown. */
void propertyHiddenChanged(const Property* property);
void propertyHiddenChanged(const QPointer<Property> property);

/** @brief Emitted when a Property which should be saved changes. */
void configChanged();
Expand Down
13 changes: 7 additions & 6 deletions src/rviz/properties/property_tree_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QTimer>
#include <QHash>
#include <QSet>
#include <QPointer>

#include <rviz/properties/property.h>
#include <rviz/properties/property_tree_delegate.h>
Expand Down Expand Up @@ -95,8 +96,8 @@ void PropertyTreeWidget::setModel(PropertyTreeModel* model)
{
if (model_)
{
disconnect(model_, SIGNAL(propertyHiddenChanged(const Property*)), this,
SLOT(propertyHiddenChanged(const Property*)));
disconnect(model_, &PropertyTreeModel::propertyHiddenChanged, this,
&PropertyTreeWidget::propertyHiddenChanged);
disconnect(model_, SIGNAL(expand(const QModelIndex&)), this, SLOT(expand(const QModelIndex&)));
disconnect(model_, SIGNAL(collapse(const QModelIndex&)), this, SLOT(collapse(const QModelIndex&)));
}
Expand All @@ -108,8 +109,8 @@ void PropertyTreeWidget::setModel(PropertyTreeModel* model)
setSelectionModel(new PropertySelectionModel(model_));
m->deleteLater();

connect(model_, SIGNAL(propertyHiddenChanged(const Property*)), this,
SLOT(propertyHiddenChanged(const Property*)));
connect(model_, &PropertyTreeModel::propertyHiddenChanged, this,
&PropertyTreeWidget::propertyHiddenChanged, Qt::QueuedConnection);
connect(model_, SIGNAL(expand(const QModelIndex&)), this, SLOT(expand(const QModelIndex&)));
connect(model_, SIGNAL(collapse(const QModelIndex&)), this, SLOT(collapse(const QModelIndex&)));

Expand All @@ -118,9 +119,9 @@ void PropertyTreeWidget::setModel(PropertyTreeModel* model)
}
}

void PropertyTreeWidget::propertyHiddenChanged(const Property* property)
void PropertyTreeWidget::propertyHiddenChanged(const QPointer<Property> property)
{
if (model_)
if (property && model_)
{
setRowHidden(property->rowNumberInParent(), model_->parentIndex(property), property->getHidden());
}
Expand Down
2 changes: 1 addition & 1 deletion src/rviz/properties/property_tree_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class RVIZ_EXPORT PropertyTreeWidget : public QTreeView
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override;

protected Q_SLOTS:
virtual void propertyHiddenChanged(const Property* property);
virtual void propertyHiddenChanged(const QPointer<rviz::Property> property);

Q_SIGNALS:
void currentPropertyChanged(const Property* new_current_property);
Expand Down

0 comments on commit 9b8e790

Please sign in to comment.