Skip to content

Commit

Permalink
attribute table: show progress only every 5s
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 17, 2012
1 parent 2e7867a commit 0c9e60f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
8 changes: 2 additions & 6 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -831,13 +831,9 @@ void QgsAttributeTableDialog::progress( int i, bool &cancel )
}

mProgress->setValue( i );
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );

if ( i > 0 && i % 5000 == 0 )
{
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );
}

if ( !mProgress->isVisible() && mStarted.elapsed() > mProgress->minimumDuration()*5 / 4 )
if ( !mProgress->isVisible() && mStarted.elapsed() > mProgress->minimumDuration()* 5 / 4 )
{
// for some reason this is sometimes necessary
mProgress->show();
Expand Down
24 changes: 17 additions & 7 deletions src/gui/attributetable/qgsattributetablememorymodel.cpp 100644 → 100755
Expand Up @@ -54,22 +54,32 @@ void QgsAttributeTableMemoryModel::loadLayer()
else
mFeatureMap.reserve( mLayer->selectedFeatureCount() );

int n = 0;
int i = 0;

QTime t;
t.start();

QgsFeature f;
while ( mLayer->nextFeature( f ) )
{
if ( behaviour == 1 && !mLayer->selectedFeaturesIds().contains( f.id() ) )
continue;

mIdRowMap.insert( f.id(), n );
mRowIdMap.insert( n, f.id() );
mIdRowMap.insert( f.id(), i );
mRowIdMap.insert( i, f.id() );
mFeatureMap.insert( f.id(), f );

bool cancel = false;
emit progress( n++, cancel );
if ( cancel )
break;
i++;

if ( t.elapsed() > 5000 )
{
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;

t.restart();
}
}

emit finished();
Expand Down
31 changes: 23 additions & 8 deletions src/gui/attributetable/qgsattributetablemodel.cpp 100644 → 100755
Expand Up @@ -247,17 +247,27 @@ void QgsAttributeTableModel::loadLayer()
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();
int i = 0;

QTime t;
t.start();

if ( behaviour == 1 )
{
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() - 1 );
foreach( QgsFeatureId fid, mLayer->selectedFeaturesIds() )
{
featureAdded( fid, false );

bool cancel = false;
emit progress( i++, cancel );
if ( cancel )
break;
i++;

if ( t.elapsed() > 5000 )
{
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;

t.restart();
}
}
emit finished();
endInsertRows();
Expand All @@ -278,10 +288,15 @@ void QgsAttributeTableModel::loadLayer()
{
featureAdded( f.id() );

bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;
if ( t.elapsed() > 5000 )
{
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;

t.restart();
}
}
emit finished();
}
Expand Down
14 changes: 4 additions & 10 deletions src/gui/attributetable/qgsattributetableview.cpp 100644 → 100755
Expand Up @@ -74,22 +74,16 @@ void QgsAttributeTableView::setCanvasAndLayer( QgsMapCanvas *canvas, QgsVectorLa
mModel = new QgsAttributeTableMemoryModel( canvas, layer );
}

connect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );

connect( mModel, SIGNAL( progress(int, bool&) ), this, SIGNAL( progress(int, bool&) ) );
connect( mModel, SIGNAL( progress( int, bool& ) ), this, SIGNAL( progress( int, bool& ) ) );
connect( mModel, SIGNAL( finished() ), this, SIGNAL( finished() ) );
mModel->loadLayer();

delete oldModel;
delete filterModel;
}

void QgsAttributeTableView::setFilterModel()
{
disconnect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );
mFilterModel = new QgsAttributeTableFilterModel( mModel->layer() );
mFilterModel->setSourceModel( mModel );
setModel( mFilterModel );

delete oldModel;
delete filterModel;
}

QgsAttributeTableView::~QgsAttributeTableView()
Expand Down
3 changes: 0 additions & 3 deletions src/gui/attributetable/qgsattributetableview.h
Expand Up @@ -50,9 +50,6 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView

void contextMenuEvent( QContextMenuEvent* );

public slots:
void setFilterModel();

signals:
void willShowContextMenu( QMenu* menu, QModelIndex atIndex );

Expand Down

0 comments on commit 0c9e60f

Please sign in to comment.