@@ -54,24 +54,23 @@ class QgsAttributeTableDock : public QDockWidget
5454
5555
5656QgsAttributeTableDialog::QgsAttributeTableDialog ( QgsVectorLayer *theLayer, QWidget *parent, Qt::WindowFlags flags )
57- : QDialog( parent, flags ), mDock( NULL )
57+ : QDialog( parent, flags ), mDock( 0 ), mLayer( theLayer ), mProgress( 0 ), mWorkaround( false )
5858{
59- mLayer = theLayer;
60-
6159 setupUi ( this );
6260
6361 setAttribute ( Qt::WA_DeleteOnClose );
6462
6563 QSettings settings;
6664 restoreGeometry ( settings.value ( " /Windows/BetterAttributeTable/geometry" ).toByteArray () );
6765
68- // extent has to be set before the model is created
69- QgsAttributeTableModel::setCurrentExtent ( QgisApp::instance ()->mapCanvas ()->extent () );
70- connect ( QgisApp::instance ()->mapCanvas (), SIGNAL ( extentsChanged () ), this , SLOT ( updateExtent () ) );
66+ mView ->setCanvasAndLayer ( QgisApp::instance ()->mapCanvas (), mLayer );
7167
72- mView ->setLayer ( mLayer );
7368 mFilterModel = ( QgsAttributeTableFilterModel * ) mView ->model ();
74- mModel = ( QgsAttributeTableModel * )(( QgsAttributeTableFilterModel * )mView ->model () )->sourceModel ();
69+ mModel = qobject_cast<QgsAttributeTableModel * >( dynamic_cast <QgsAttributeTableFilterModel *>( mView ->model () )->sourceModel () );
70+
71+ connect ( mModel , SIGNAL ( progress ( int , bool & ) ), this , SLOT ( progress ( int , bool & ) ) );
72+ mModel ->loadLayer ();
73+ delete mProgress ;
7574
7675 mQuery = query;
7776 mColumnBox = columnBox;
@@ -127,20 +126,21 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
127126 // info from layer to table
128127 connect ( mLayer , SIGNAL ( editingStarted () ), this , SLOT ( editingToggled () ) );
129128 connect ( mLayer , SIGNAL ( editingStopped () ), this , SLOT ( editingToggled () ) );
129+ connect ( mLayer , SIGNAL ( selectionChanged () ), this , SLOT ( updateSelectionFromLayer () ) );
130+ connect ( mLayer , SIGNAL ( layerDeleted () ), this , SLOT ( close () ) );
130131
131132 connect ( searchButton, SIGNAL ( clicked () ), this , SLOT ( search () ) );
132133 connect ( mAddFeature , SIGNAL ( clicked () ), this , SLOT ( addFeature () ) );
133134
134- connect ( mLayer , SIGNAL ( selectionChanged () ), this , SLOT ( updateSelectionFromLayer () ) );
135- connect ( mLayer , SIGNAL ( layerDeleted () ), this , SLOT ( close () ) );
136135 connect ( mView ->verticalHeader (), SIGNAL ( sectionClicked ( int ) ), this , SLOT ( updateRowSelection ( int ) ) );
137136 connect ( mView ->verticalHeader (), SIGNAL ( sectionPressed ( int ) ), this , SLOT ( updateRowPressed ( int ) ) );
137+
138138 connect ( mModel , SIGNAL ( modelChanged () ), this , SLOT ( updateSelection () ) );
139139
140140 connect ( mView , SIGNAL ( willShowContextMenu ( QMenu*, QModelIndex ) ), this , SLOT ( viewWillShowContextMenu ( QMenu*, QModelIndex ) ) );
141141
142142 mLastClickedHeaderIndex = 0 ;
143- mSelectionModel = new QItemSelectionModel ( mFilterModel );
143+ mSelectionModel = new QItemSelectionModel ( mFilterModel , this );
144144 updateSelectionFromLayer ();
145145
146146 // make sure to show all recs on first load
@@ -149,7 +149,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
149149
150150QgsAttributeTableDialog::~QgsAttributeTableDialog ()
151151{
152- delete mSelectionModel ;
153152}
154153
155154void QgsAttributeTableDialog::updateTitle ()
@@ -797,12 +796,6 @@ void QgsAttributeTableDialog::addFeature()
797796 }
798797}
799798
800- void QgsAttributeTableDialog::updateExtent ()
801- {
802- // let the model know about the new extent (we may be showing only features from current extent)
803- QgsAttributeTableModel::setCurrentExtent ( QgisApp::instance ()->mapCanvas ()->extent () );
804- }
805-
806799void QgsAttributeTableDialog::viewWillShowContextMenu ( QMenu* menu, QModelIndex atIndex )
807800{
808801 QModelIndex sourceIndex = mFilterModel ->mapToSource ( atIndex );
@@ -829,6 +822,38 @@ void QgsAttributeTableDialog::viewWillShowContextMenu( QMenu* menu, QModelIndex
829822 menu->addAction ( tr ( " Open form" ), a, SLOT ( featureForm () ) );
830823}
831824
825+ void QgsAttributeTableDialog::progress ( int i, bool &cancel )
826+ {
827+ if ( !mProgress )
828+ {
829+ mProgress = new QProgressDialog ( tr ( " Loading feature attributes..." ), tr ( " Abort" ), 0 , 0 , this );
830+ mProgress ->setWindowTitle ( tr ( " Attribute table" ) );
831+ mProgress ->setWindowModality ( Qt::WindowModal );
832+ mStarted .start ();
833+ }
834+
835+ mProgress ->setValue ( i );
836+
837+ if ( i > 0 && i % 1000 == 0 )
838+ {
839+ mProgress ->setLabelText ( tr ( " %1 features loaded." ).arg ( i ) );
840+ }
841+
842+ if ( !mProgress ->isVisible () && mStarted .elapsed () > mProgress ->minimumDuration ()*5 / 4 )
843+ {
844+ // for some reason this is sometimes necessary
845+ mProgress ->show ();
846+ mWorkaround = true ;
847+ }
848+
849+ if ( mWorkaround )
850+ {
851+ QCoreApplication::processEvents ();
852+ }
853+
854+ cancel = mProgress ->wasCanceled ();
855+ }
856+
832857void QgsAttributeTableAction::execute ()
833858{
834859 mModel ->executeAction ( mAction , mFieldIdx );
0 commit comments