Skip to content

Commit

Permalink
fix #4822
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 16, 2012
1 parent 5afa34c commit 3ba2fe9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
QSettings settings;
restoreGeometry( settings.value( "/Windows/BetterAttributeTable/geometry" ).toByteArray() );

connect( mView, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
connect( mView, SIGNAL( finished() ), this, SLOT( finished() ) );
mView->setCanvasAndLayer( QgisApp::instance()->mapCanvas(), mLayer );

mFilterModel = ( QgsAttributeTableFilterModel * ) mView->model();
mModel = qobject_cast<QgsAttributeTableModel * >( dynamic_cast<QgsAttributeTableFilterModel *>( mView->model() )->sourceModel() );

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

mQuery = query;
mColumnBox = columnBox;
columnBoxInit();
Expand Down Expand Up @@ -834,7 +832,7 @@ void QgsAttributeTableDialog::progress( int i, bool &cancel )

mProgress->setValue( i );

if ( i > 0 && i % 1000 == 0 )
if ( i > 0 && i % 5000 == 0 )
{
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );
}
Expand Down
8 changes: 7 additions & 1 deletion src/gui/attributetable/qgsattributetablememorymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ void QgsAttributeTableMemoryModel::loadLayer()
mIdRowMap.insert( f.id(), n );
mRowIdMap.insert( n, f.id() );
mFeatureMap.insert( f.id(), f );
n++;

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

emit finished();

mFieldCount = mAttributes.size();
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/attributetable/qgsattributetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
* @parem inOperation guard insertion with beginInsertRows() / endInsertRows()
*/
virtual void featureAdded( QgsFeatureId fid, bool inOperation = true );

/**
* Launched when layer has been deleted
*/
Expand Down
16 changes: 13 additions & 3 deletions src/gui/attributetable/qgsattributetableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,24 @@ void QgsAttributeTableView::setCanvasAndLayer( QgsMapCanvas *canvas, QgsVectorLa
mModel = new QgsAttributeTableMemoryModel( canvas, layer );
}

mFilterModel = new QgsAttributeTableFilterModel( layer );
mFilterModel->setSourceModel( mModel );
setModel( mFilterModel );
connect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );

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 );
}

QgsAttributeTableView::~QgsAttributeTableView()
{
delete mModel;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/attributetable/qgsattributetableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView

void contextMenuEvent( QContextMenuEvent* );

public slots:
void setFilterModel();

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

void finished();
void progress( int i, bool &cancel );

private:
QgsMapCanvas *mCanvas;
QgsAttributeTableModel* mModel;
Expand Down

0 comments on commit 3ba2fe9

Please sign in to comment.