Skip to content

Commit

Permalink
add first/last buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed May 15, 2019
1 parent f680466 commit c0a0f7d
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 56 deletions.
2 changes: 2 additions & 0 deletions images/images.qrc
Expand Up @@ -751,6 +751,8 @@
<file>themes/default/mIconDataDefineColor.svg</file>
<file>themes/default/mIconDataDefineColorOn.svg</file>
<file>themes/default/mActionNewVirtualLayer.svg</file>
<file>themes/default/mActionDoubleArrowRight.svg</file>
<file>themes/default/mActionDoubleArrowLeft.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
81 changes: 81 additions & 0 deletions images/themes/default/mActionDoubleArrowLeft.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions images/themes/default/mActionDoubleArrowRight.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 18 additions & 2 deletions python/gui/auto_generated/attributetable/qgsfeaturelistview.sip.in
Expand Up @@ -172,20 +172,36 @@ Select all currently visible features
void repaintRequested( const QModelIndexList &indexes );
void repaintRequested();

void editFirstFeature();
%Docstring
editFirstFeature will try to edit the first feature of the list

.. versionadded:: 3.8
%End

void editNextFeature();
%Docstring
editNextFeature will try to edit next feature in form
editNextFeature will try to edit next feature of the list

.. versionadded:: 3.8
%End

void editPreviousFeature();
%Docstring
editPreviousFeature will try to edit previous feature in form
editPreviousFeature will try to edit previous feature of the list

.. versionadded:: 3.8
%End

void editLastFeature();
%Docstring
editLastFeature will try to edit the last feature of the list

.. versionadded:: 3.8
%End



};

/************************************************************************
Expand Down
6 changes: 6 additions & 0 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -64,6 +64,8 @@ QgsDualView::QgsDualView( QWidget *parent )

connect( mNextFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editNextFeature );
connect( mPreviousFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editPreviousFeature );
connect( mFirstFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editFirstFeature );
connect( mLastFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editLastFeature );

QButtonGroup *buttonGroup = new QButtonGroup( this );
buttonGroup->setExclusive( false );
Expand Down Expand Up @@ -423,10 +425,14 @@ void QgsDualView::updateEditSelectionProgress( int progress, int count )
mProgressCount->setText( QStringLiteral( "%1 / %2" ).arg( progress + 1 ).arg( count ) );
mPreviousFeatureButton->setEnabled( progress > 0 );
mNextFeatureButton->setEnabled( progress + 1 < count );
mFirstFeatureButton->setEnabled( progress > 0 );
mLastFeatureButton->setEnabled( progress + 1 < count );
}

void QgsDualView::panOrZoomToFeature( const QgsFeatureIds &featureset )
{
//QgsDebugMsg("hey");

QgsMapCanvas *canvas = mFilterModel->mapCanvas();
if ( canvas )
{
Expand Down
34 changes: 18 additions & 16 deletions src/gui/attributetable/qgsfeaturelistview.cpp
Expand Up @@ -264,19 +264,19 @@ void QgsFeatureListView::keyPressEvent( QKeyEvent *event )
switch ( event->key() )
{
case Qt::Key_Up:
editNextOrPreviousFeature( Previous );
editOtherFeature( Previous );
break;

case Qt::Key_Down:
editNextOrPreviousFeature( Next );
editOtherFeature( Next );
break;

default:
QListView::keyPressEvent( event );
}
}

void QgsFeatureListView::editNextOrPreviousFeature( QgsFeatureListView::NextOrPrevious nextOrPrevious )
void QgsFeatureListView::editOtherFeature( QgsFeatureListView::PositionInList positionInList )
{
int currentRow = 0;
if ( 0 != mCurrentEditSelectionModel->selectedIndexes().count() )
Expand All @@ -288,29 +288,31 @@ void QgsFeatureListView::editNextOrPreviousFeature( QgsFeatureListView::NextOrPr
QModelIndex newLocalIndex;
QModelIndex newIndex;

switch ( nextOrPrevious )
switch ( positionInList )
{
case First:
newLocalIndex = mModel->index( 0, 0 );
break;

case Previous:
newLocalIndex = mModel->index( currentRow - 1, 0 );
newIndex = mModel->mapToMaster( newLocalIndex );
if ( newIndex.isValid() )
{
setEditSelection( newIndex, QItemSelectionModel::ClearAndSelect );
scrollTo( newLocalIndex );
}
break;

case Next:
newLocalIndex = mModel->index( currentRow + 1, 0 );
newIndex = mModel->mapToMaster( newLocalIndex );
if ( newIndex.isValid() )
{
setEditSelection( newIndex, QItemSelectionModel::ClearAndSelect );
scrollTo( newLocalIndex );
}
break;

case Last:
newLocalIndex = mModel->index( mModel->rowCount() - 1, 0 );
break;
}

newIndex = mModel->mapToMaster( newLocalIndex );
if ( newIndex.isValid() )
{
setEditSelection( newIndex, QItemSelectionModel::ClearAndSelect );
scrollTo( newLocalIndex );
}
}

void QgsFeatureListView::contextMenuEvent( QContextMenuEvent *event )
Expand Down
30 changes: 23 additions & 7 deletions src/gui/attributetable/qgsfeaturelistview.h
Expand Up @@ -186,16 +186,30 @@ class GUI_EXPORT QgsFeatureListView : public QListView
void repaintRequested();

/**
* editNextFeature will try to edit next feature in form
* editFirstFeature will try to edit the first feature of the list
* \since QGIS 3.8
*/
void editNextFeature() {editNextOrPreviousFeature( Next );}
void editFirstFeature() {editOtherFeature( First );}

/**
* editPreviousFeature will try to edit previous feature in form
* editNextFeature will try to edit next feature of the list
* \since QGIS 3.8
*/
void editPreviousFeature() {editNextOrPreviousFeature( Previous );}
void editNextFeature() {editOtherFeature( Next );}

/**
* editPreviousFeature will try to edit previous feature of the list
* \since QGIS 3.8
*/
void editPreviousFeature() {editOtherFeature( Previous );}

/**
* editLastFeature will try to edit the last feature of the list
* \since QGIS 3.8
*/
void editLastFeature() {editOtherFeature( Last );}



private slots:
void editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected );
Expand All @@ -211,13 +225,15 @@ class GUI_EXPORT QgsFeatureListView : public QListView
private:
void selectRow( const QModelIndex &index, bool anchor );

enum NextOrPrevious
enum PositionInList
{
First,
Next,
Previous
Previous,
Last
};

void editNextOrPreviousFeature( NextOrPrevious nextOrPrevious );
void editOtherFeature( PositionInList positionInList );


QgsFeatureListModel *mModel = nullptr;
Expand Down

0 comments on commit c0a0f7d

Please sign in to comment.