Skip to content
Permalink
Browse files
Rebase
  • Loading branch information
elpaso committed Jul 6, 2021
1 parent 1a94b07 commit 4201942bdde582d9ac836b28b80568d8ffcd9650
@@ -18,7 +18,7 @@ class QgsQueryResultModel : QAbstractTableModel
%Docstring(signature="appended")
The :py:class:`QgsQueryResultModel` class is a model for :py:class:`QgsAbstractDatabaseProviderConnection`.QueryResult

.. versionadded:: 3.18
.. versionadded:: 3.20
%End

%TypeHeaderCode
@@ -13,8 +13,8 @@

class QgsQueryResultWidget: QWidget
{
%Docstring
The :py:class:`QgsQueryResultWidget` class allow users to enter and run an SQL query on a
%Docstring(signature="appended")
The :py:class:`QgsQueryResultWidget` class allows users to enter and run an SQL query on a
DB connection (an instance of :py:class:`QgsAbstractDatabaseProviderConnection`).

Query results are displayed in a table view.
@@ -357,7 +357,7 @@ void QgsGeoPackageProviderConnection::setDefaultCapabilities()
Capability::DeleteSpatialIndex,
Capability::DeleteField,
Capability::AddField,
Capability::DropRasterTable
Capability::DropRasterTable,
Capability::SqlLayers
};
mGeometryColumnCapabilities =
@@ -74,7 +74,7 @@ class QgsQueryResultFetcher: public QObject
* \brief The QgsQueryResultModel class is a model for QgsAbstractDatabaseProviderConnection::QueryResult
*
* \ingroup core
* \since QGIS 3.18
* \since QGIS 3.20
*/
class CORE_EXPORT QgsQueryResultModel : public QAbstractTableModel
{
@@ -74,7 +74,7 @@ void QgsCodeEditorSQL::setFields( const QgsFields &fields )

QStringList fieldNames;

for ( const QgsField &field : qgis::as_const( fields ) )
for ( const QgsField &field : std::as_const( fields ) )
{
fieldNames.push_back( field.name() );
}
@@ -88,7 +88,7 @@ void QgsQueryResultWidget::executeQuery()
const auto sql = mSqlEditor->text( );

mWasCanceled = false;
mFeedback = qgis::make_unique<QgsFeedback>();
mFeedback = std::make_unique<QgsFeedback>();
mStopButton->setEnabled( true );
mStatusLabel->show();
mStatusLabel->setText( tr( "Running⋯" ) );
@@ -188,7 +188,7 @@ void QgsQueryResultWidget::startFetching()
else
{
QgsAbstractDatabaseProviderConnection::QueryResult result { mQueryResultWatcher.result() };
mModel = qgis::make_unique<QgsQueryResultModel>( result );
mModel = std::make_unique<QgsQueryResultModel>( result );
connect( mFeedback.get(), &QgsFeedback::canceled, mModel.get(), [ = ]
{
mModel->cancel();
@@ -343,14 +343,14 @@ void QgsConnectionsApiFetcher::fetchTokens()
schemas.push_back( QString() ); // Fake empty schema for DBs not supporting it
}

for ( const auto &schema : qgis::as_const( schemas ) )
for ( const auto &schema : std::as_const( schemas ) )
{
if ( mStopFetching ) { return; }
QStringList tableNames;
try
{
const auto tables = mConnection->tables( schema );
for ( const auto &table : qgis::as_const( tables ) )
for ( const auto &table : std::as_const( tables ) )
{
if ( mStopFetching ) { return; }
tableNames.push_back( table.tableName() );
@@ -363,15 +363,15 @@ void QgsConnectionsApiFetcher::fetchTokens()
}

// Get fields
for ( const auto &table : qgis::as_const( tableNames ) )
for ( const auto &table : std::as_const( tableNames ) )
{
if ( mStopFetching ) { return; }
QStringList fieldNames;
try
{
const auto fields( mConnection->fields( schema, table ) );
if ( mStopFetching ) { return; }
for ( const auto &field : qgis::as_const( fields ) )
for ( const auto &field : std::as_const( fields ) )
{
fieldNames.push_back( field.name() );
if ( mStopFetching ) { return; }
@@ -71,7 +71,7 @@ class GUI_EXPORT QgsConnectionsApiFetcher: public QObject
///@endcond private

/**
* \brief The QgsQueryResultWidget class allow users to enter and run an SQL query on a
* \brief The QgsQueryResultWidget class allows users to enter and run an SQL query on a
* DB connection (an instance of QgsAbstractDatabaseProviderConnection).
*
* Query results are displayed in a table view.
@@ -176,7 +176,7 @@ class GUI_EXPORT QgsQueryResultWidget: public QWidget, private Ui::QgsQueryResul
void updateSqlLayerColumns();

/**
* Cancel and wait for finish.
* Cancel and wait for finish
*/
void cancelRunningQuery();

@@ -248,8 +248,6 @@ ADD_PYTHON_TEST(PyQgsProviderSourceWidgetProviderRegistry test_qgssourcewidgetpr
ADD_PYTHON_TEST(PyQgsProviderSublayerDetails test_qgsprovidersublayerdetails.py)
ADD_PYTHON_TEST(PyQgsProviderSublayerModel test_qgsprovidersublayermodel.py)
ADD_PYTHON_TEST(TestQgsRandomMarkerSymbolLayer test_qgsrandommarkersymbollayer.py)
ADD_PYTHON_TEST(PyQgsQueryResultModel test_qgsqueryresultmodel.py)
ADD_PYTHON_TEST(PyQgsQueryResultWidget test_qgsqueryresultwidget.py)
ADD_PYTHON_TEST(PyQgsRange test_qgsrange.py)
ADD_PYTHON_TEST(PyQgsRangeSlider test_qgsrangeslider.py)
ADD_PYTHON_TEST(PyQgsRangeWidgets test_qgsrangewidgets.py)
@@ -380,8 +378,9 @@ endif()

if (ENABLE_PGTEST)
ADD_PYTHON_TEST(PyQgsImportIntoPostGIS test_processing_importintopostgis.py)
ADD_PYTHON_TEST(PyQgsQueryResultModel test_qgsqueryresultmodel.py)
ADD_PYTHON_TEST(PyQgsVectorFileWriterPostgres test_qgsvectorfilewriter_postgres.py)
ADD_PYTHON_TEST(PyQgsQueryResultModel test_qgsqueryresultmodel.py)
ADD_PYTHON_TEST(PyQgsQueryResultWidget test_qgsqueryresultwidget.py)
ADD_PYTHON_TEST(PyQgsVectorLayerUtilsPostgres test_qgsvectorlayerutils_postgres.py)
ADD_PYTHON_TEST(PyQgsPostgresProvider test_provider_postgres.py)
ADD_PYTHON_TEST(PyQgsPostgresRasterProvider test_provider_postgresraster.py)
@@ -407,7 +406,7 @@ if (ENABLE_PGTEST)
SET_TESTS_PROPERTIES(PyQgsServerWMSGetFeatureInfoPG PyQgsServerAccessControlWMSGetPrintPG PyQgsServerAccessControlWMSGetMapPG
PROPERTIES LABELS "POSTGRES")
endif()
SET_TESTS_PROPERTIES(PyQgsImportIntoPostGIS PyQgsQueryResultModel PyQgsVectorFileWriterPostgres PyQgsPostgresProvider
SET_TESTS_PROPERTIES(PyQgsImportIntoPostGIS PyQgsQueryResultWidget PyQgsQueryResultModel PyQgsVectorFileWriterPostgres PyQgsPostgresProvider
PyQgsVectorLayerUtilsPostgres PyQgsPostgresRasterProvider PyQgsPostgresDomain PyQgsPostgresTransaction
PyQgsRelationEditWidget PyQgsRelationPostgres PyQgsVectorLayerTools PyQgsProjectStoragePostgres
PyQgsAuthManagerPKIPostgresTest PyQgsAuthManagerPasswordPostgresTest PyQgsAuthManagerOgrPostgresTest
@@ -23,6 +23,7 @@
from qgis.testing import unittest, start_app
from qgis.PyQt.QtCore import QCoreApplication, QVariant, Qt, QTimer
from qgis.PyQt.QtWidgets import QListView, QDialog, QVBoxLayout, QLabel
from qgis.PyQt.QtTest import QAbstractItemModelTester


class TestPyQgsQgsQueryResultModel(unittest.TestCase):
@@ -72,6 +73,7 @@ def test_model(self):
conn = md.createConnection(self.uri, {})
res = conn.execSql('SELECT generate_series(1, 1000)')
model = QgsQueryResultModel(res)
tester = QAbstractItemModelTester(model, QAbstractItemModelTester.FailureReportingMode.Warning)
self.assertEqual(model.rowCount(model.index(-1, -1)), 0)

while model.rowCount(model.index(-1, -1)) < 1000:
@@ -102,6 +104,7 @@ def loop_exiter():
res = conn.execSql('SELECT * FROM qgis_test.random_big_data')

self.model = QgsQueryResultModel(res)
self.tester = QAbstractItemModelTester(model, QAbstractItemModelTester.FailureReportingMode.Warning)

self.running = True

@@ -131,6 +134,7 @@ def test_widget(self):
conn = md.createConnection(self.uri, {})
res = conn.execSql('SELECT * FROM qgis_test.random_big_data')
model = QgsQueryResultModel(res)
tester = QAbstractItemModelTester(model, QAbstractItemModelTester.FailureReportingMode.Warning)
v.setModel(model)

def _set_row_count(idx, first, last):
@@ -59,7 +59,7 @@ def _deleteBigData(cls):
md = QgsProviderRegistry.instance().providerMetadata('postgres')
conn = md.createConnection(cls.uri, {})
conn.dropVectorTable('qgis_test', 'random_big_data')
except:
except Exception:
pass

def test_widget(self):

0 comments on commit 4201942

Please sign in to comment.