Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5779 from elpaso/bugfix-17003-16350-bookmarks
[bugfix] Bookmarks: fix a crash and show 6 digits
- Loading branch information
Showing
3 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nyalldawson
Collaborator
|
||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.