Skip to content

Commit 85a7ba7

Browse files
authored
Merge pull request #5795 from elpaso/delegate-leaks
Fix Some Delegate leaks
2 parents 011e254 + efad2f6 commit 85a7ba7

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

src/app/nodetool/qgsnodeeditor.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ QgsNodeEditor::QgsNodeEditor(
297297

298298
mTableView->setSelectionMode( QTableWidget::ExtendedSelection );
299299
mTableView->setSelectionBehavior( QTableWidget::SelectRows );
300-
mTableView->setItemDelegateForColumn( 0, new CoordinateItemDelegate() );
301-
mTableView->setItemDelegateForColumn( 1, new CoordinateItemDelegate() );
302-
mTableView->setItemDelegateForColumn( 2, new CoordinateItemDelegate() );
303-
mTableView->setItemDelegateForColumn( 3, new CoordinateItemDelegate() );
304-
mTableView->setItemDelegateForColumn( 4, new CoordinateItemDelegate() );
300+
mTableView->setItemDelegateForColumn( 0, new CoordinateItemDelegate( this ) );
301+
mTableView->setItemDelegateForColumn( 1, new CoordinateItemDelegate( this ) );
302+
mTableView->setItemDelegateForColumn( 2, new CoordinateItemDelegate( this ) );
303+
mTableView->setItemDelegateForColumn( 3, new CoordinateItemDelegate( this ) );
304+
mTableView->setItemDelegateForColumn( 4, new CoordinateItemDelegate( this ) );
305305

306306
setWidget( mTableView );
307307

@@ -396,6 +396,12 @@ void QgsNodeEditor::keyPressEvent( QKeyEvent *e )
396396
// CoordinateItemDelegate
397397
//
398398

399+
CoordinateItemDelegate::CoordinateItemDelegate( QObject *parent )
400+
: QStyledItemDelegate( parent )
401+
{
402+
403+
}
404+
399405
QString CoordinateItemDelegate::displayText( const QVariant &value, const QLocale &locale ) const
400406
{
401407
return locale.toString( value.toDouble(), 'f', 4 );

src/app/nodetool/qgsnodeeditor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class CoordinateItemDelegate : public QStyledItemDelegate
107107
Q_OBJECT
108108

109109
public:
110+
111+
explicit CoordinateItemDelegate( QObject *parent = nullptr );
112+
110113
QString displayText( const QVariant &value, const QLocale &locale ) const override;
111114

112115
protected:

src/gui/qgsmetadatawidget.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
6363
constraintheaders << tr( "Type" ) << tr( "Constraint" );
6464
mConstraintsModel->setHorizontalHeaderLabels( constraintheaders );
6565
tabConstraints->setModel( mConstraintsModel );
66-
tabConstraints->setItemDelegate( new ConstraintItemDelegate() );
66+
tabConstraints->setItemDelegate( new ConstraintItemDelegate( this ) );
6767

6868
// Setup the link view
6969
mLinksModel = new QStandardItemModel( tabLinks );
@@ -72,7 +72,7 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
7272
headers << tr( "Name" ) << tr( "Type" ) << tr( "URL" ) << tr( "Description" ) << tr( "Format" ) << tr( "MIME" ) << tr( "Size" );
7373
mLinksModel->setHorizontalHeaderLabels( headers );
7474
tabLinks->setModel( mLinksModel );
75-
tabLinks->setItemDelegate( new LinkItemDelegate() );
75+
tabLinks->setItemDelegate( new LinkItemDelegate( this ) );
7676

7777
// History
7878
mHistoryModel = new QStringListModel( listHistory );
@@ -794,6 +794,12 @@ void QgsMetadataWidget::removeSelectedCategory() const
794794
}
795795
}
796796

797+
LinkItemDelegate::LinkItemDelegate( QObject *parent )
798+
: QStyledItemDelegate( parent )
799+
{
800+
801+
}
802+
797803
QWidget *LinkItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
798804
{
799805
if ( index.column() == 1 )
@@ -820,6 +826,12 @@ QWidget *LinkItemDelegate::createEditor( QWidget *parent, const QStyleOptionView
820826
return QStyledItemDelegate::createEditor( parent, option, index );
821827
}
822828

829+
ConstraintItemDelegate::ConstraintItemDelegate( QObject *parent )
830+
: QStyledItemDelegate( parent )
831+
{
832+
833+
}
834+
823835
QWidget *ConstraintItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
824836
{
825837
if ( index.column() == 0 )

src/gui/qgsmetadatawidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class LinkItemDelegate : public QStyledItemDelegate
140140

141141
public:
142142

143+
explicit LinkItemDelegate( QObject *parent = nullptr );
144+
143145
/**
144146
* Create a special editor with a QCombobox in the link view.
145147
*/
@@ -160,6 +162,8 @@ class ConstraintItemDelegate : public QStyledItemDelegate
160162

161163
public:
162164

165+
explicit ConstraintItemDelegate( QObject *parent = nullptr );
166+
163167
/**
164168
* Create a special editor with a QCombobox in the constraint view.
165169
*/

0 commit comments

Comments
 (0)