Skip to content

Commit

Permalink
[bugfix] Bookmarks: fix a crash and show 6 digits
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elpaso committed Dec 1, 2017
1 parent 0e2207a commit 6c897b6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/app/qgsbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

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

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

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

Expand Down Expand Up @@ -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;
}
23 changes: 22 additions & 1 deletion src/app/qgsbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

#include "ui_qgsbookmarksbase.h"
#include "qgsdockwidget.h"
Expand Down Expand Up @@ -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
*/
Expand Down
15 changes: 11 additions & 4 deletions src/ui/qgsbookmarksbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 6c897b6

Please sign in to comment.