Skip to content
Permalink
Browse files

add browsing buttons

  • Loading branch information
3nids committed Apr 30, 2020
1 parent 4c2e552 commit 3fd45ecaff234290d0030b2299c8fab9de8b597c
@@ -10,6 +10,7 @@




class QgsFeaturePickerWidget : QWidget
{
%Docstring
@@ -111,6 +112,17 @@ Returns the feature request fetch limit
Defines the feature request fetch limit
%End

bool showBrowserButtons() const;
%Docstring
Returns if the browsing buttons are shown
%End

void setShowBrowserButtons( bool showBrowserButtons );
%Docstring
Defines if the browsing buttons are shown
%End


QModelIndex currentModelIndex() const;
%Docstring
The index of the currently selected item.
@@ -164,6 +176,11 @@ Emitted when the fetching of the geometry changes
void fetchLimitChanged();
%Docstring
Emitted when the fetching limit for the feature request changes
%End

void showBrowserButtonsChanged();
%Docstring
Emitted when showing the browser buttons changes
%End

};
@@ -27,15 +27,16 @@ QgsExpressionPreviewWidget::QgsExpressionPreviewWidget( QWidget *parent )
{
setupUi( this );
mPreviewLabel->clear();
mFeaturePickerWidget->setShowBrowserButtons( true );

connect( mFeatureChooserWidget, &QgsFeaturePickerWidget::featureChanged, this, &QgsExpressionPreviewWidget::setCurrentFeature );
connect( mFeaturePickerWidget, &QgsFeaturePickerWidget::featureChanged, this, &QgsExpressionPreviewWidget::setCurrentFeature );
connect( mPreviewLabel, &QLabel::linkActivated, this, &QgsExpressionPreviewWidget::linkActivated );
}

void QgsExpressionPreviewWidget::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
mFeatureChooserWidget->setLayer( layer );
mFeaturePickerWidget->setLayer( layer );
}

void QgsExpressionPreviewWidget::setExpressionText( const QString &expression )
@@ -14,6 +14,7 @@
***************************************************************************/

#include <QHBoxLayout>
#include <QToolButton>
#include <QKeyEvent>

#include "qgsfeaturepickerwidget.h"
@@ -29,6 +30,19 @@ QgsFeaturePickerWidget::QgsFeaturePickerWidget( QWidget *parent )
mComboBox = new QComboBox( this );
mComboBox->setEditable( true );
layout->addWidget( mComboBox );

mPreviousButton = new QToolButton( this );
mPreviousButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowLeft.svg" ) ) );
mPreviousButton->setEnabled( false );
mPreviousButton->setVisible( mShowBrowserButtons );
layout->addWidget( mPreviousButton );

mNextButton = new QToolButton( this );
mNextButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowRight.svg" ) ) );
mNextButton->setEnabled( false );
mNextButton->setVisible( mShowBrowserButtons );
layout->addWidget( mNextButton );

setLayout( layout );

mCompleter->setCaseSensitivity( Qt::CaseInsensitive );
@@ -54,6 +68,9 @@ QgsFeaturePickerWidget::QgsFeaturePickerWidget( QWidget *parent )

connect( mComboBox, static_cast<void( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFeaturePickerWidget::onCurrentIndexChanged );

connect( mPreviousButton, &QToolButton::clicked, this, [ = ]() {browseFeatures( -1 );} );
connect( mNextButton, &QToolButton::clicked, this, [ = ]() {browseFeatures( 1 );} );

mLineEdit = new QgsFilterLineEdit( nullptr, QgsApplication::nullRepresentation() );
mLineEdit->setSelectOnFocus( true );
mLineEdit->setShowClearButton( allowNull() );
@@ -64,7 +81,6 @@ QgsFeaturePickerWidget::QgsFeaturePickerWidget( QWidget *parent )

connect( mLineEdit, &QgsFilterLineEdit::textEdited, this, &QgsFeaturePickerWidget::onCurrentTextChanged );

setToolTip( tr( "Just start typing what you are looking for." ) );
}

QgsVectorLayer *QgsFeaturePickerWidget::layer() const
@@ -126,8 +142,13 @@ void QgsFeaturePickerWidget::onCurrentIndexChanged( int i )
{
if ( !mHasStoredEditState )
mIsCurrentlyEdited = false;

mPreviousButton->setEnabled( i > 0 );
mNextButton->setEnabled( i < mComboBox->model()->rowCount() - 1 );

if ( i < 0 )
return;

QModelIndex modelIndex = mModel->index( i, 0, QModelIndex() );
mModel->setFeature( mModel->data( modelIndex, QgsFeaturePickerModel::FeatureIdRole ).value<QgsFeatureId>() );
mLineEdit->setText( mModel->data( modelIndex, QgsFeaturePickerModel::ValueRole ).toString() );
@@ -187,6 +208,12 @@ void QgsFeaturePickerWidget::onDataChanged( const QModelIndex &topLeft, const QM
}
}

void QgsFeaturePickerWidget::browseFeatures( int direction )
{
int newIndex = std::min( std::max( 0, mComboBox->currentIndex() + direction ), mComboBox->model()->rowCount() - 1 );
mComboBox->setCurrentIndex( newIndex );
}

QModelIndex QgsFeaturePickerWidget::currentModelIndex() const
{
return mModel->index( mModel->extraIdentifierValueIndex(), 0, QModelIndex() );
@@ -264,3 +291,19 @@ void QgsFeaturePickerWidget::setFetchLimit( int fetchLimit )
{
mModel->setFetchLimit( fetchLimit );
}

bool QgsFeaturePickerWidget::showBrowserButtons() const
{
return mShowBrowserButtons;
}

void QgsFeaturePickerWidget::setShowBrowserButtons( bool showBrowserButtons )
{
if ( showBrowserButtons == mShowBrowserButtons )
return;

mShowBrowserButtons = showBrowserButtons;
mPreviousButton->setVisible( mShowBrowserButtons );
mNextButton->setVisible( mShowBrowserButtons );
emit showBrowserButtonsChanged();
}
@@ -24,6 +24,8 @@
#include "qgsfeaturerequest.h"
#include "qgis_gui.h"

class QToolButton;

class QgsVectorLayer;
class QgsFeaturePickerModel;
class QgsAnimatedIcon;
@@ -49,6 +51,7 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
Q_PROPERTY( bool showBrowserButtons READ showBrowserButtons WRITE setShowBrowserButtons NOTIFY showBrowserButtonsChanged )

public:

@@ -137,6 +140,17 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
*/
void setFetchLimit( int fetchLimit );

/**
* Returns if the browsing buttons are shown
*/
bool showBrowserButtons() const;

/**
* Defines if the browsing buttons are shown
*/
void setShowBrowserButtons( bool showBrowserButtons );


/**
* The index of the currently selected item.
*/
@@ -188,6 +202,9 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
*/
void fetchLimitChanged();

//! Emitted when showing the browser buttons changes
void showBrowserButtonsChanged();

private slots:
void onCurrentTextChanged( const QString &text );
void onFilterUpdateCompleted();
@@ -198,6 +215,7 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
void storeLineEditState();
void restoreLineEditState();
void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
void browseFeatures( int direction );

private:
struct LineEditState
@@ -212,13 +230,16 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
};

QComboBox *mComboBox;
QToolButton *mPreviousButton;
QToolButton *mNextButton;
QgsFeaturePickerModel *mModel = nullptr;
QCompleter *mCompleter = nullptr;
QgsFilterLineEdit *mLineEdit;
bool mPopupRequested = false;
bool mIsCurrentlyEdited = false;
bool mHasStoredEditState = false;
LineEditState mLineEditState;
bool mShowBrowserButtons = false;

friend class TestQgsFeaturePickerWidget;
};
@@ -68,7 +68,7 @@
</widget>
</item>
<item>
<widget class="QgsFeaturePickerWidget" name="mFeatureChooserWidget"/>
<widget class="QgsFeaturePickerWidget" name="mFeaturePickerWidget"/>
</item>
</layout>
</item>

0 comments on commit 3fd45ec

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