Skip to content

Commit 6c897b6

Browse files
committedDec 1, 2017
[bugfix] Bookmarks: fix a crash and show 6 digits
Fixes #17003 Spatial bookmarks keyboard navigation: right-arrow causes a row to appear below the current one and looks like a tree expansion (actually crashes master) Fixes #16350 Spatial Bookmark Panel: precision gets trimmed
1 parent 0e2207a commit 6c897b6

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed
 

‎src/app/qgsbookmarks.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
#include <QSqlQuery>
3131
#include <QSqlRecord>
3232
#include <QModelIndex>
33+
#include <QDoubleSpinBox>
3334
#include <QAbstractTableModel>
3435
#include <QToolButton>
3536

37+
38+
const int QgsDoubleSpinBoxBookmarksDelegate::DECIMAL_PLACES = 6;
39+
3640
QgsBookmarks::QgsBookmarks( QWidget *parent )
3741
: QgsDockWidget( parent )
3842

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

107111
lstBookmarks->setModel( mProxyModel );
112+
lstBookmarks->setItemDelegate( new QgsDoubleSpinBoxBookmarksDelegate );
108113

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

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

763+
QString QgsDoubleSpinBoxBookmarksDelegate::displayText( const QVariant &value, const QLocale &locale ) const
764+
{
765+
if ( value.userType() == QVariant::Double )
766+
{
767+
return locale.toString( value.toDouble(), 'f', QgsDoubleSpinBoxBookmarksDelegate::DECIMAL_PLACES );
768+
}
769+
else
770+
{
771+
return QStyledItemDelegate::displayText( value, locale );
772+
}
773+
}
774+
775+
QWidget *QgsDoubleSpinBoxBookmarksDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
776+
{
777+
QWidget *widget = QStyledItemDelegate::createEditor( parent, option, index );
778+
QDoubleSpinBox *spinbox = qobject_cast<QDoubleSpinBox *>( widget );
779+
if ( spinbox )
780+
spinbox->setDecimals( QgsDoubleSpinBoxBookmarksDelegate::DECIMAL_PLACES );
781+
return widget;
782+
}

‎src/app/qgsbookmarks.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <QSqlTableModel>
2121
#include <QSortFilterProxyModel>
22-
#include <memory>
22+
#include <QStyledItemDelegate>
2323

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

75+
76+
/**
77+
* \brief QgsDoubleSpinBoxBookmarksDelegate class shows 6 digits when value is a double
78+
*/
79+
class QgsDoubleSpinBoxBookmarksDelegate : public QStyledItemDelegate
80+
{
81+
Q_OBJECT
82+
83+
public:
84+
85+
QString displayText( const QVariant &value, const QLocale &locale ) const override;
86+
87+
QWidget *createEditor( QWidget *parent,
88+
const QStyleOptionViewItem &option,
89+
const QModelIndex &index ) const override;
90+
private:
91+
92+
static const int DECIMAL_PLACES;
93+
94+
};
95+
7596
/*
7697
* Model that merge the QGIS and project model
7798
*/

‎src/ui/qgsbookmarksbase.ui

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
14-
<string>Spatial Bookmarks Panel</string>
14+
<string>Sp&amp;atial Bookmarks Panel</string>
1515
</property>
1616
<widget class="QWidget" name="bookmarksDockContents">
1717
<layout class="QGridLayout" name="gridLayout">
@@ -54,8 +54,14 @@
5454
<property name="rootIsDecorated">
5555
<bool>false</bool>
5656
</property>
57-
<property name="sortingEnabled">
58-
<bool>true</bool>
57+
<property name="itemsExpandable">
58+
<bool>false</bool>
59+
</property>
60+
<property name="animated">
61+
<bool>false</bool>
62+
</property>
63+
<property name="expandsOnDoubleClick">
64+
<bool>false</bool>
5965
</property>
6066
</widget>
6167
</item>
@@ -103,8 +109,9 @@
103109
<class>QgsDockWidget</class>
104110
<extends>QDockWidget</extends>
105111
<header>qgsdockwidget.h</header>
112+
<container>1</container>
106113
</customwidget>
107-
</customwidgets>
114+
</customwidgets>
108115
<resources>
109116
<include location="../../images/images.qrc"/>
110117
</resources>

0 commit comments

Comments
 (0)
Please sign in to comment.