Skip to content

Commit 86d08b6

Browse files
committedFeb 14, 2015
restore option to open the attribute table with only currently visible features
to improve performance (actually to make it usable with large tables again). When used as initial setting in options the open attribute table will have a fixed spatial filter to the canvas extent when it was opened. That extent is also highlighted to indicate the filter. fixes #10619
1 parent 553abbd commit 86d08b6

10 files changed

+53
-16
lines changed
 

‎src/app/qgsattributetabledialog.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "qgsexpressionselectiondialog.h"
4343
#include "qgsfeaturelistmodel.h"
4444
#include "qgsexpressionbuilderdialog.h"
45+
#include "qgsrubberband.h"
4546

4647
class QgsAttributeTableDock : public QDockWidget
4748
{
@@ -63,6 +64,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
6364
: QDialog( parent, flags )
6465
, mDock( 0 )
6566
, mLayer( theLayer )
67+
, mRubberBand( 0 )
6668
{
6769
setupUi( this );
6870

@@ -87,8 +89,21 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
8789
context.setDistanceArea( *myDa );
8890
context.setVectorLayerTools( QgisApp::instance()->vectorLayerTools() );
8991

92+
QgsFeatureRequest r;
93+
if ( settings.value( "/qgis/attributeTableBehaviour", QgsAttributeTableFilterModel::ShowAll ).toInt() == QgsAttributeTableFilterModel::ShowVisible )
94+
{
95+
QgsMapCanvas *mc = QgisApp::instance()->mapCanvas();
96+
QgsRectangle extent( mc->mapSettings().mapToLayerCoordinates( theLayer, mc->extent() ) );
97+
r.setFilterRect( extent );
98+
99+
QgsGeometry *g = QgsGeometry::fromRect( extent );
100+
mRubberBand = new QgsRubberBand( mc, true );
101+
mRubberBand->setToGeometry( g, theLayer );
102+
delete g;
103+
}
104+
90105
// Initialize dual view
91-
mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), QgsFeatureRequest(), context );
106+
mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), r, context );
92107

93108
// Initialize filter gui elements
94109
mFilterActionMapper = new QSignalMapper( this );
@@ -215,6 +230,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
215230
QgsAttributeTableDialog::~QgsAttributeTableDialog()
216231
{
217232
delete myDa;
233+
delete mRubberBand;
218234
}
219235

220236
void QgsAttributeTableDialog::updateTitle()
@@ -305,19 +321,17 @@ void QgsAttributeTableDialog::columnBoxInit()
305321
}
306322
}
307323

308-
309324
void QgsAttributeTableDialog::updateFieldFromExpression()
310325
{
311-
312326
bool filtered = mMainView->filterMode() != QgsAttributeTableFilterModel::ShowAll;
313327
QgsFeatureIds filteredIds = filtered ? mMainView->filteredFeatures() : QgsFeatureIds();
314-
this->runFieldCalculation( mLayer, mFieldCombo->currentText(), mUpdateExpressionText->currentField(), filteredIds );
328+
runFieldCalculation( mLayer, mFieldCombo->currentText(), mUpdateExpressionText->currentField(), filteredIds );
315329
}
316330

317331
void QgsAttributeTableDialog::updateFieldFromExpressionSelected()
318332
{
319333
QgsFeatureIds filteredIds = mLayer->selectedFeaturesIds();
320-
this->runFieldCalculation( mLayer, mFieldCombo->currentText(), mUpdateExpressionText->currentField(), filteredIds );
334+
runFieldCalculation( mLayer, mFieldCombo->currentText(), mUpdateExpressionText->currentField(), filteredIds );
321335
}
322336

323337
void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, QString fieldName, QString expression, QgsFeatureIds filteredIds )
@@ -336,7 +350,8 @@ void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, QStrin
336350
exp.setGeomCalculator( *myDa );
337351
bool useGeometry = exp.needsGeometry();
338352

339-
QgsFeatureRequest request;
353+
QgsFeatureRequest request( mMainView->masterModel()->request() );
354+
useGeometry |= request.filterType() == QgsFeatureRequest::FilterRect;
340355
request.setFlags( useGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry );
341356

342357
int rownum = 1;
@@ -736,7 +751,7 @@ void QgsAttributeTableDialog::setFilterExpression( QString filterString )
736751
QApplication::setOverrideCursor( Qt::WaitCursor );
737752

738753
filterExpression.setGeomCalculator( myDa );
739-
QgsFeatureRequest request;
754+
QgsFeatureRequest request( mMainView->masterModel()->request() );
740755
request.setSubsetOfAttributes( filterExpression.referencedColumns(), mLayer->pendingFields() );
741756
if ( !fetchGeom )
742757
{

‎src/app/qgsattributetabledialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class QSignalMapper;
4040

4141
class QgsAttributeTableModel;
4242
class QgsAttributeTableFilterModel;
43+
class QgsRubberBand;
4344

4445
class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttributeTableDialog
4546
{
@@ -201,6 +202,8 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
201202

202203
QgsVectorLayer* mLayer;
203204
QgsFieldModel* mFieldModel;
205+
206+
QgsRubberBand *mRubberBand;
204207
};
205208

206209
#endif

‎src/app/qgsidentifyresultsdialog.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,6 @@ void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
14901490
if ( !featItem )
14911491
return;
14921492

1493-
14941493
if ( mHighlights.contains( featItem ) )
14951494
return;
14961495

‎src/core/qgsvectorlayercache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void QgsVectorLayerCache::setFullCache( bool fullCache )
8585
// Initialize the cache...
8686
QgsFeatureIterator it( new QgsCachedFeatureWriterIterator( this, QgsFeatureRequest()
8787
.setSubsetOfAttributes( mCachedAttributes )
88-
.setFlags( !mCacheGeometry ? QgsFeatureRequest::NoGeometry : QgsFeatureRequest::Flags( 0 ) ) ) );
88+
.setFlags( mCacheGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) ) );
8989

9090
int i = 0;
9191

‎src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,16 @@ void QgsAttributeTableFilterModel::generateListOfVisibleFeatures()
265265

266266
renderer->startRender( renderContext, layer()->pendingFields() );
267267

268-
QgsFeatureIterator features = masterModel()->layerCache()->getFeatures( QgsFeatureRequest().setFilterRect( rect ) );
268+
QgsFeatureRequest r( masterModel()->request() );
269+
if ( r.filterType() == QgsFeatureRequest::FilterRect )
270+
{
271+
r.setFilterRect( r.filterRect().intersect( &rect ) );
272+
}
273+
else
274+
{
275+
r.setFilterRect( rect );
276+
}
277+
QgsFeatureIterator features = masterModel()->layerCache()->getFeatures( r );
269278

270279
QgsFeature f;
271280

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ void QgsAttributeTableModel::prefetchColumnData( int column )
620620
QStringList fldNames;
621621
fldNames << fields[ fieldId ].name();
622622

623-
QgsFeatureIterator it = mLayerCache->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( fldNames, fields ) );
623+
QgsFeatureRequest r( mFeatureRequest );
624+
QgsFeatureIterator it = mLayerCache->getFeatures( r.setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( fldNames, fields ) );
624625

625626
QgsFeature f;
626627
while ( it.nextFeature( f ) )
@@ -638,3 +639,8 @@ void QgsAttributeTableModel::setRequest( const QgsFeatureRequest& request )
638639
if ( layer() && !layer()->hasGeometryType() )
639640
mFeatureRequest.setFlags( mFeatureRequest.flags() | QgsFeatureRequest::NoGeometry );
640641
}
642+
643+
const QgsFeatureRequest &QgsAttributeTableModel::request() const
644+
{
645+
return mFeatureRequest;
646+
}

‎src/gui/attributetable/qgsattributetablemodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
203203
*/
204204
void setRequest( const QgsFeatureRequest& request );
205205

206+
/**
207+
* Get the the feature request
208+
*/
209+
const QgsFeatureRequest &request() const;
210+
206211
/**
207212
* Sets the context in which this table is shown.
208213
* Will be forwarded to any editor widget created when editing data on this model.

‎src/gui/attributetable/qgsdualview.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
6666

6767
connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
6868

69-
initLayerCache( layer );
69+
initLayerCache( layer, request.filterType() == QgsFeatureRequest::FilterRect );
7070
initModels( mapCanvas, request );
7171

7272
mTableView->setModel( mFilterModel );
@@ -205,13 +205,13 @@ void QgsDualView::setSelectedOnTop( bool selectedOnTop )
205205
mFilterModel->setSelectedOnTop( selectedOnTop );
206206
}
207207

208-
void QgsDualView::initLayerCache( QgsVectorLayer* layer )
208+
void QgsDualView::initLayerCache( QgsVectorLayer* layer, bool cacheGeometry )
209209
{
210210
// Initialize the cache
211211
QSettings settings;
212212
int cacheSize = settings.value( "/qgis/attributeTableRowCache", "10000" ).toInt();
213213
mLayerCache = new QgsVectorLayerCache( layer, cacheSize, this );
214-
mLayerCache->setCacheGeometry( false );
214+
mLayerCache->setCacheGeometry( cacheGeometry );
215215
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayerCache->layer()->dataProvider()->capabilities() ) )
216216
{
217217
connect( mLayerCache, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );

‎src/gui/attributetable/qgsdualview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
215215
virtual void finished();
216216

217217
private:
218-
void initLayerCache( QgsVectorLayer *layer );
218+
void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
219219
void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );
220220

221221
QgsAttributeEditorContext mEditorContext;

‎src/gui/qgshighlight.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
/*!
5252
\class QgsHighlight
5353
\brief The QgsHighlight class provides a transparent overlay widget
54-
for highlightng features on the map.
54+
for highlighting features on the map.
5555
*/
5656
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsMapLayer *layer )
5757
: QgsMapCanvasItem( mapCanvas )

0 commit comments

Comments
 (0)
Please sign in to comment.