Skip to content

Commit

Permalink
Merge pull request #5795 from elpaso/delegate-leaks
Browse files Browse the repository at this point in the history
Fix Some Delegate leaks
  • Loading branch information
elpaso committed Dec 5, 2017
2 parents 011e254 + efad2f6 commit 85a7ba7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/app/nodetool/qgsnodeeditor.cpp
Expand Up @@ -297,11 +297,11 @@ QgsNodeEditor::QgsNodeEditor(

mTableView->setSelectionMode( QTableWidget::ExtendedSelection );
mTableView->setSelectionBehavior( QTableWidget::SelectRows );
mTableView->setItemDelegateForColumn( 0, new CoordinateItemDelegate() );
mTableView->setItemDelegateForColumn( 1, new CoordinateItemDelegate() );
mTableView->setItemDelegateForColumn( 2, new CoordinateItemDelegate() );
mTableView->setItemDelegateForColumn( 3, new CoordinateItemDelegate() );
mTableView->setItemDelegateForColumn( 4, new CoordinateItemDelegate() );
mTableView->setItemDelegateForColumn( 0, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 1, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 2, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 3, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 4, new CoordinateItemDelegate( this ) );

setWidget( mTableView );

Expand Down Expand Up @@ -396,6 +396,12 @@ void QgsNodeEditor::keyPressEvent( QKeyEvent *e )
// CoordinateItemDelegate
//

CoordinateItemDelegate::CoordinateItemDelegate( QObject *parent )
: QStyledItemDelegate( parent )
{

}

QString CoordinateItemDelegate::displayText( const QVariant &value, const QLocale &locale ) const
{
return locale.toString( value.toDouble(), 'f', 4 );
Expand Down
3 changes: 3 additions & 0 deletions src/app/nodetool/qgsnodeeditor.h
Expand Up @@ -107,6 +107,9 @@ class CoordinateItemDelegate : public QStyledItemDelegate
Q_OBJECT

public:

explicit CoordinateItemDelegate( QObject *parent = nullptr );

QString displayText( const QVariant &value, const QLocale &locale ) const override;

protected:
Expand Down
16 changes: 14 additions & 2 deletions src/gui/qgsmetadatawidget.cpp
Expand Up @@ -63,7 +63,7 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
constraintheaders << tr( "Type" ) << tr( "Constraint" );
mConstraintsModel->setHorizontalHeaderLabels( constraintheaders );
tabConstraints->setModel( mConstraintsModel );
tabConstraints->setItemDelegate( new ConstraintItemDelegate() );
tabConstraints->setItemDelegate( new ConstraintItemDelegate( this ) );

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

// History
mHistoryModel = new QStringListModel( listHistory );
Expand Down Expand Up @@ -794,6 +794,12 @@ void QgsMetadataWidget::removeSelectedCategory() const
}
}

LinkItemDelegate::LinkItemDelegate( QObject *parent )
: QStyledItemDelegate( parent )
{

}

QWidget *LinkItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
if ( index.column() == 1 )
Expand All @@ -820,6 +826,12 @@ QWidget *LinkItemDelegate::createEditor( QWidget *parent, const QStyleOptionView
return QStyledItemDelegate::createEditor( parent, option, index );
}

ConstraintItemDelegate::ConstraintItemDelegate( QObject *parent )
: QStyledItemDelegate( parent )
{

}

QWidget *ConstraintItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
if ( index.column() == 0 )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmetadatawidget.h
Expand Up @@ -140,6 +140,8 @@ class LinkItemDelegate : public QStyledItemDelegate

public:

explicit LinkItemDelegate( QObject *parent = nullptr );

/**
* Create a special editor with a QCombobox in the link view.
*/
Expand All @@ -160,6 +162,8 @@ class ConstraintItemDelegate : public QStyledItemDelegate

public:

explicit ConstraintItemDelegate( QObject *parent = nullptr );

/**
* Create a special editor with a QCombobox in the constraint view.
*/
Expand Down

0 comments on commit 85a7ba7

Please sign in to comment.