358 changes: 339 additions & 19 deletions src/providers/spatialite/qgsspatialiteprovider.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
bool getQueryGeometryDetails();
bool getSridDetails();
bool getTableSummary();
#ifdef SPATIALITE_RECENT_VERSION
// only if libspatialite version is >= 4.0.0
bool checkLayerTypeAbstractInterface( gaiaVectorLayerPtr lyr );
bool getGeometryDetailsAbstractInterface( gaiaVectorLayerPtr lyr );
bool getTableSummaryAbstractInterface( gaiaVectorLayerPtr lyr );
void loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr );
void getViewSpatialIndexName();
#endif
bool prepareStatement( sqlite3_stmt *&stmt,
const QgsAttributeList &fetchAttributes,
bool fetchGeometry,
Expand Down
37 changes: 37 additions & 0 deletions src/providers/spatialite/qgsspatialitesourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget * parent, Qt::WFla
btnSave->hide();
btnLoad->hide();

mStatsButton = new QPushButton( tr( "&Update statistics" ) );
connect( mStatsButton, SIGNAL( clicked() ), this, SLOT( updateStatistics() ) );
mStatsButton->setEnabled( false );

mAddButton = new QPushButton( tr( "&Add" ) );
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addClicked() ) );
mAddButton->setEnabled( false );
Expand All @@ -69,6 +73,7 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget * parent, Qt::WFla
{
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
buttonBox->addButton( mStatsButton, QDialogButtonBox::ActionRole );
}

populateConnectionList();
Expand Down Expand Up @@ -132,6 +137,35 @@ void QgsSpatiaLiteSourceSelect::buildQuery()
setSql( mTablesTreeView->currentIndex() );
}

void QgsSpatiaLiteSourceSelect::updateStatistics()
{
QString subKey = cmbConnections->currentText();
int idx = subKey.indexOf( "@" );
if ( idx > 0 )
subKey.truncate( idx );

QString msg = tr( "Do you confirm updating the Internal Statistics for DB: %1 ?\n\n"
"This could take a long time (depending on the DB size),\n"
"but implies better performances in the afterwhile" ).arg( subKey );
QMessageBox::StandardButton result =
QMessageBox::information( this, tr( "Confirm Update Statistics" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
if ( result != QMessageBox::Ok )
return;

// trying to connect to SpatiaLite DB
QgsSpatiaLiteConnection conn( subKey );
if ( conn.updateStatistics() == true )
{
QMessageBox::information( this, tr( "Update Statistics" ),
tr( "Internal Statistics succesfully updated for: %1" ).arg( subKey ) );
}
else
{
QMessageBox::critical( this, tr( "Update Statistics" ),
tr( "Error while updating Internal Statistics for: %1" ).arg( subKey ) );
}
}

void QgsSpatiaLiteSourceSelect::on_cbxAllowGeometrylessTables_stateChanged( int )
{
on_btnConnect_clicked();
Expand Down Expand Up @@ -423,7 +457,10 @@ void QgsSpatiaLiteSourceSelect::on_btnConnect_clicked()
}

if ( cmbConnections->count() > 0 )
{
mAddButton->setEnabled( true );
mStatsButton->setEnabled( true );
}

mTablesTreeView->sortByColumn( 0, Qt::AscendingOrder );

Expand Down
2 changes: 2 additions & 0 deletions src/providers/spatialite/qgsspatialitesourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
void on_btnConnect_clicked();
void buildQuery();
void addClicked();
void updateStatistics();
//! Opens the create connection dialog to build a new connection
void on_btnNew_clicked();
//! Deletes the selected connection
Expand Down Expand Up @@ -128,6 +129,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
QString layerURI( const QModelIndex &index );
QPushButton *mBuildQueryButton;
QPushButton *mAddButton;
QPushButton *mStatsButton;
};

#endif // QGSSPATIALITESOURCESELECT_H