Skip to content
Permalink
Browse files

Merge pull request #5779 from elpaso/bugfix-17003-16350-bookmarks

[bugfix] Bookmarks: fix a crash and show 6 digits
  • Loading branch information
elpaso committed Dec 1, 2017
2 parents 0e2207a + 6c897b6 commit b22825a41dfe81814148100ceea48e1e84f97f6e
Showing with 58 additions and 5 deletions.
  1. +25 −0 src/app/qgsbookmarks.cpp
  2. +22 −1 src/app/qgsbookmarks.h
  3. +11 −4 src/ui/qgsbookmarksbase.ui
@@ -30,9 +30,13 @@
#include <QSqlQuery>
#include <QSqlRecord>
#include <QModelIndex>
#include <QDoubleSpinBox>
#include <QAbstractTableModel>
#include <QToolButton>


const int QgsDoubleSpinBoxBookmarksDelegate::DECIMAL_PLACES = 6;

QgsBookmarks::QgsBookmarks( QWidget *parent )
: QgsDockWidget( parent )

@@ -105,6 +109,7 @@ QgsBookmarks::QgsBookmarks( QWidget *parent )
mProxyModel->setSourceModel( mModel );

lstBookmarks->setModel( mProxyModel );
lstBookmarks->setItemDelegate( new QgsDoubleSpinBoxBookmarksDelegate );

This comment has been minimized.

Copy link
@elpaso

elpaso Dec 2, 2017

Author Contributor

I'm afraid this leaks. @nyalldawson any suggestion how to manage this delegates? I took this code almost verbatim from the Qt official documentation and they do not delete the delegate.

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Dec 2, 2017

Contributor

Looking around we leak these a lot. Solutions are either to:

  1. parent the delegate to lstBookmarks or QgsBookmarks
  2. make the delegate a member of QgsBookmarks and manually delete it in the destructor

This comment has been minimized.

Copy link
@elpaso

elpaso Dec 4, 2017

Author Contributor

Fixed in e4dabe5


connect( mModel, &QgsMergedBookmarksTableModel::layoutChanged, mProxyModel, &QgsBookmarksProxyModel::_resetModel );

@@ -755,3 +760,23 @@ QVariant QgsBookmarksProxyModel::headerData( int section, Qt::Orientation orient
return sourceModel()->headerData( section, orientation, role );
}

QString QgsDoubleSpinBoxBookmarksDelegate::displayText( const QVariant &value, const QLocale &locale ) const
{
if ( value.userType() == QVariant::Double )
{
return locale.toString( value.toDouble(), 'f', QgsDoubleSpinBoxBookmarksDelegate::DECIMAL_PLACES );
}
else
{
return QStyledItemDelegate::displayText( value, locale );
}
}

QWidget *QgsDoubleSpinBoxBookmarksDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
QWidget *widget = QStyledItemDelegate::createEditor( parent, option, index );
QDoubleSpinBox *spinbox = qobject_cast<QDoubleSpinBox *>( widget );
if ( spinbox )
spinbox->setDecimals( QgsDoubleSpinBoxBookmarksDelegate::DECIMAL_PLACES );
return widget;
}
@@ -19,7 +19,7 @@

#include <QSqlTableModel>
#include <QSortFilterProxyModel>
#include <memory>
#include <QStyledItemDelegate>

#include "ui_qgsbookmarksbase.h"
#include "qgsdockwidget.h"
@@ -72,6 +72,27 @@ class QgsBookmarksProxyModel: public QSortFilterProxyModel
}
};


/**
* \brief QgsDoubleSpinBoxBookmarksDelegate class shows 6 digits when value is a double
*/
class QgsDoubleSpinBoxBookmarksDelegate : public QStyledItemDelegate
{
Q_OBJECT

public:

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

QWidget *createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const override;
private:

static const int DECIMAL_PLACES;

};

/*
* Model that merge the QGIS and project model
*/
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Spatial Bookmarks Panel</string>
<string>Sp&amp;atial Bookmarks Panel</string>
</property>
<widget class="QWidget" name="bookmarksDockContents">
<layout class="QGridLayout" name="gridLayout">
@@ -54,8 +54,14 @@
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="animated">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
</item>
@@ -103,8 +109,9 @@
<class>QgsDockWidget</class>
<extends>QDockWidget</extends>
<header>qgsdockwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
</customwidgets>
<resources>
<include location="../../images/images.qrc"/>
</resources>

0 comments on commit b22825a

Please sign in to comment.
You can’t perform that action at this time.