mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
enhanced performance of feature selection
git-svn-id: http://svn.osgeo.org/qgis/trunk@244 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
46f4945c00
commit
725b49eeb1
@ -40,6 +40,14 @@ void QgsAttributeTable::columnClicked(int col)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::waitCursor);
|
||||
sortColumn(col, true, true);
|
||||
//clear and rebuild rowIdMap. Overwrite sortColumn later and sort rowIdMap there
|
||||
rowIdMap.clear();
|
||||
int id;
|
||||
for(int i=0;i<numRows();i++)
|
||||
{
|
||||
id=text(i,0).toInt();
|
||||
rowIdMap.insert(id,i);
|
||||
}
|
||||
clearSelection(true);
|
||||
emit selectionRemoved();
|
||||
emit repaintRequested();
|
||||
@ -89,18 +97,24 @@ void QgsAttributeTable::handleChangedSelections()
|
||||
|
||||
}
|
||||
|
||||
void QgsAttributeTable::insertFeatureId(int id)
|
||||
{
|
||||
rowIdMap.insert(id,id+1);
|
||||
}
|
||||
|
||||
void QgsAttributeTable::selectRowWithId(int id)
|
||||
{
|
||||
//brute force approach, add a solution with a hash table or a search tree later (and rebuild this structure every time the table is sorted)
|
||||
for(int i=0;i<numRows();i++)
|
||||
/*for(int i=0;i<numRows();i++)
|
||||
{
|
||||
if(text(i,0).toInt()==id)
|
||||
{
|
||||
selectRow(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
QMap<int,int>::iterator it=rowIdMap.find(id);
|
||||
selectRow(it.data());
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define QGSATTRIBUTETABLE_H
|
||||
|
||||
#include <qtable.h>
|
||||
#include <qmap.h>
|
||||
|
||||
/**
|
||||
*@author Gary E.Sherman
|
||||
@ -33,6 +34,8 @@ class QgsAttributeTable:public QTable
|
||||
QgsAttributeTable(QWidget * parent = 0, const char *name = 0);
|
||||
~QgsAttributeTable();
|
||||
|
||||
/**Inserts the feature with the specified id into rowIdMap. This function has to be called (e.g. from QgsShapeFileLayer) when a row is inserted into the table*/
|
||||
void insertFeatureId(int id);
|
||||
/**Selects the row which belongs to the feature with the specified id*/
|
||||
void selectRowWithId(int id);
|
||||
|
||||
@ -43,6 +46,8 @@ class QgsAttributeTable:public QTable
|
||||
protected:
|
||||
/**Flag telling if the ctrl-button or the shift-button is pressed*/
|
||||
bool lockKeyPressed;
|
||||
/**Search tree to find a row corresponding to a feature id*/
|
||||
QMap<int,int> rowIdMap;
|
||||
void keyPressEvent(QKeyEvent* ev);
|
||||
void keyReleaseEvent(QKeyEvent* ev);
|
||||
signals:
|
||||
|
@ -410,6 +410,7 @@ void QgsShapeFileLayer::table()
|
||||
|
||||
//id-field
|
||||
tabledisplay->table()->setText(row,0,QString::number(fet->GetFID()));
|
||||
tabledisplay->table()->insertFeatureId(fet->GetFID());//insert the id into the search tree of qgsattributetable
|
||||
for (int i = 1; i < numFields+1; i++) {
|
||||
// get the field values
|
||||
QString val;
|
||||
|
Loading…
x
Reference in New Issue
Block a user